


function Logout()
{
    var data = new FormData();
    data.append("request", "logout");
    $.ajax
    ({
        type: "POST",
        enctype: 'multipart/form-data',
        url: base_url + "controllers/logout.php",
        data: data,
        processData: false,
        contentType: false, 
        cache: false,
        timeout: 600000,
        async: false,
        success: function (response) 
        {
            response    =   JSON.parse(response);
            if((response["R_URL"]))
            {
                window.location.href    =   response["R_URL"];
            }
        },
        error: function (e) 
        {
            console.log("ERROR : ", e);
        }
    });
}


function getHeader()
{
    var data = new FormData();
    data.append("request", "get_header");
    $.ajax
    ({
        type: "POST",
        enctype: 'multipart/form-data',
        url: base_url + "controllers/header.php",
        data: data,
        processData: false,
        contentType: false,
        cache: false,
        timeout: 600000,
        async: false,
        success: function (response) 
        {
            response    =   JSON.parse(response);
            if((response["html"]))
            {
                $("#header").html('');
                $("#header").html(response["html"]);
                const mobileNavToggleBtn = document.querySelector('.mobile-nav-toggle');
                function mobileNavToogle() 
                {
                    document.querySelector('body').classList.toggle('mobile-nav-active');
                    mobileNavToggleBtn.classList.toggle('bi-list');
                    mobileNavToggleBtn.classList.toggle('bi-x');
                }
                mobileNavToggleBtn.addEventListener('click', mobileNavToogle);
                document.querySelectorAll('.navmenu .toggle-dropdown').forEach(navmenu => 
                {
                    navmenu.addEventListener('click', function(e) 
                    {
                        e.preventDefault();
                        this.parentNode.classList.toggle('active');
                        this.parentNode.nextElementSibling.classList.toggle('dropdown-active');
                        e.stopImmediatePropagation();
                    });
                });

                $(".logout").on("click", function(e)
                {
                    e.preventDefault();
                    Logout();
                });
            }
        },
        error: function (e) 
        {
            console.log("ERROR : ", e);
        }
    });
}


$(document).ready(function()
{
    getHeader();

});