let layoutTicketNotification = document.getElementById('layout-ticket-notification');

if (document.getElementById('btn-logout')!=null){

    /*const notificationSimpleBar = new SimpleBar(layoutTicketNotification);

    let layoutCommentNotification = document.getElementById('layout-comment-notification');
    const commentSimpleBar = new SimpleBar(layoutCommentNotification);

    let layoutNotificationCount = document.getElementById('layout-notification-count');
    let txtNotificationCount = document.getElementById('txt-notification-count');
    let layoutNoDisplayComment = document.getElementById('layout-no-display-comment');
    let layoutNoDisplayTicket = document.getElementById('layout-no-display-ticket');
    let txtNotificationCounter = document.getElementById('txt-notification-counter');

    const dbRefNotificationTicket = firebase.database().ref('/business/' + getCookie('fbs') + '/notifications/tickets');
    dbRefNotificationTicket.on("child_added", function (snapshot) {

        if (snapshot.val().user_id === getCookies('userId')) {

            if (snapshot.val().read != null) {

                let readStatusJson = JSON.parse(JSON.stringify(snapshot.val().read));
                if (readStatusJson[getCookies('userId')] == null) {

                    onTicketChange(snapshot);

                }

            }
            else {

                onTicketChange(snapshot);

            }

        }

    });

    const dbRefNotificationComment = firebase.database().ref('/business/' + getCookie('fbs') + '/notifications/comments');
    dbRefNotificationComment.on("child_added", function (snapshot) {

        if (snapshot.val().user_id !== getCookies('userId')) {

            if (snapshot.val().read != null) {

                let readStatusJson = JSON.parse(JSON.stringify(snapshot.val().read));
                if (readStatusJson[getCookies('userId')] == null) {

                    onCommentChange(snapshot);

                }

            } else {

                onCommentChange(snapshot);

            }

        }


    });

    function getNotificationItemLayoutTemp(type, notificationObject) {
        return `<div class="text-reset notification-item d-block dropdown-item position-relative active mb-2" id="layout-not-item-` + notificationObject.val().id + `">
                <div class="d-flex">
                    
                    <!--<img src="assets/images/users/avatar-2.jpg" class="me-3 rounded-circle avatar-xs" alt="user-pic">-->
                    
                    <div class="flex-1">
                        <a href="#!" class="stretched-link">
                            <h6 class="mt-0 mb-1 fs-13 fw-semibold">` + notificationObject.val().name + `</h6>
                        </a>
                        <div class="fs-13 text-muted">
                            <p class="mb-1">` + notificationObject.val().message + " " + notificationObject.val().title + `</p>
                        </div>
                        <p class="mb-0 fs-11 fw-medium text-uppercase text-muted">
                            <span><i class="mdi mdi-clock-outline me-2"></i>` + notificationObject.val().dateTime + `</span>
                        </p>
                    </div>
                    
                    <div class="px-2 fs-15">
                        <div class="form-check notification-check">
                            <input class="form-check-input" type="checkbox" value="" onchange="readNotification(` + notificationObject.val().id + `, ` + notificationObject.val().ticket_id + ` ,'` + type + `')" id="messages-notification-check02">
                            <label class="form-check-label" for="messages-notification-check02"></label>
                        </div>
                    </div>
                    
                </div>
            </div>`;
    }

    function readNotification(id, ticketId, type) {

        ///console.log("Data = " + id);
        document.getElementById('layout-not-item-' + id).classList.toggle("position-relative");
        document.getElementById('layout-not-item-' + id).classList.toggle("active");

        if (type === "comment") {

            let userId = getCookies('userId');
            firebase.database().ref('/business/' + getCookie('fbs') + '/notifications/comments/' + id + '/read/' + userId).set({
                status: true
            });

        } else if (type === "ticket") {

            let userId = getCookies('userId');
            firebase.database().ref('/business/' + getCookie('fbs') + '/notifications/tickets/' + id + '/read/' + userId).set({
                status: true
            });

        }

        ////window.location.assign("ticket-detail.php?id=" + ticketId);


    }

    function getCookies(cname) {
        let name = cname + "=";
        let decodedCookie = decodeURIComponent(document.cookie);
        let ca = decodedCookie.split(';');
        for (let i = 0; i < ca.length; i++) {
            let c = ca[i];
            while (c.charAt(0) == ' ') {
                c = c.substring(1);
            }
            if (c.indexOf(name) == 0) {
                return c.substring(name.length, c.length);
            }
        }
        return "";
    }

    function onCommentChange(snapshot) {

        let counter = parseInt(txtNotificationCount.innerText);
        txtNotificationCounter.style.setProperty('display', 'block');
        layoutNotificationCount.style.setProperty('display', 'block');
        layoutNoDisplayComment.style.setProperty("display", "none");
        commentSimpleBar.getContentElement().innerHTML += getNotificationItemLayoutTemp("comment", snapshot);
        commentSimpleBar.recalculate();

        counter++;
        txtNotificationCount.innerText = counter;
        txtNotificationCounter.innerText = counter;

    }

    function onTicketChange(snapshot) {

        let counter = parseInt(txtNotificationCount.innerText);
        txtNotificationCounter.style.setProperty('display', 'block');
        layoutNotificationCount.style.setProperty('display', 'block');
        layoutNoDisplayTicket.style.setProperty("display", "none");
        notificationSimpleBar.getContentElement().innerHTML += getNotificationItemLayoutTemp("ticket", snapshot);
        notificationSimpleBar.recalculate();

        counter++;
        txtNotificationCount.innerText = counter;
        txtNotificationCounter.innerText = counter;

    }*/

}
