document.addEventListener("DOMContentLoaded", function() {

      const fullName = localStorage.getItem('full_name');

 if (!fullName) {
        window.location.href = "lm-login.html";
        return;
    }



    // Fetch the content of sidebarview.html
            fetch('partails_admin/sidebar.html',{cache:'no-store'})
        .then(response => {
            if (!response.ok) {
                throw new Error('Network response was not ok ' + response.statusText);
            }
            return response.text();
        })
        .then(html => {
            
            document.getElementById('sidebarPanel').innerHTML = html;
            // Retrieve data from localStorage
            const fullName = localStorage.getItem('full_name');
            const image = localStorage.getItem('image');
            const location =localStorage.getItem('usertype'); // You can replace this with another stored value if available
        
            // Bind data to HTML elements
            document.getElementById('profile-name').textContent = fullName || "Username";  // Fallback to default if not set
            document.getElementById('profile-image').src = image || "admin";  // Fallback to default image if not set
            document.getElementById('profile-location').textContent = location; 
            
            
            
        })
        .catch(error => {
            console.error('Error fetching sidebar.html:', error);
        });

        fetch('partails_admin/bottom_menu.html',{cache:'no-store'})
        .then(response => {
            if (!response.ok) {
                throw new Error('Network response was not ok ' + response.statusText);
            }
            return response.text();
        })
        .then(html => {
            document.getElementById('appBottomMenu').innerHTML = html;
            // Retrieve data from localStorage
            const fullName = localStorage.getItem('full_name');
            const image = localStorage.getItem('image');
            const location =localStorage.getItem('usertype'); // You can replace this with another stored value if available
        
            // Bind data to HTML elements
            document.getElementById('profile-name').textContent = fullName || "Username";  // Fallback to default if not set
            document.getElementById('profile-image').src = image || "admin";  // Fallback to default image if not set
            document.getElementById('profile-location').textContent = location; 
        })
        .catch(error => {
            console.error('Error fetching sidebar.html:', error);
        });
});



document.addEventListener("DOMContentLoaded", function() {
    // Fetch the content of sidebarview.html
            fetch('partails_admin/sales_sidebar.html',{cache:'no-store'})
        .then(response => {
            if (!response.ok) {
                throw new Error('Network response was not ok ' + response.statusText);
            }
            return response.text();
        })
        .then(html => {
            
            document.getElementById('sidebarPanelsale').innerHTML = html;
            // Retrieve data from localStorage
            const fullName = localStorage.getItem('full_name');
            const image = localStorage.getItem('image');
            const location =localStorage.getItem('usertype'); // You can replace this with another stored value if available
        
            // Bind data to HTML elements
            document.getElementById('profile-name').textContent = fullName || "Username";  // Fallback to default if not set
            document.getElementById('profile-image').src = image || "admin";  // Fallback to default image if not set
            document.getElementById('profile-location').textContent = location; 
            
            
            
        })
        .catch(error => {
            console.error('Error fetching sidebar.html:', error);
        });

        fetch('partails_admin/bottom_menusales.html',{cache:'no-store'})
        .then(response => {
            if (!response.ok) {
                throw new Error('Network response was not ok ' + response.statusText);
            }
            return response.text();
        })
        .then(html => {
            document.getElementById('appBottomMenusales').innerHTML = html;
            // Retrieve data from localStorage
            const fullName = localStorage.getItem('full_name');
            const image = localStorage.getItem('image');
            const location =localStorage.getItem('usertype'); // You can replace this with another stored value if available
        
            // Bind data to HTML elements
            document.getElementById('profile-name').textContent = fullName || "Username";  // Fallback to default if not set
            document.getElementById('profile-image').src = image || "admin";  // Fallback to default image if not set
            document.getElementById('profile-location').textContent = location; 
        })
        .catch(error => {
            console.error('Error fetching bottom_menusales.html:', error);
        });
});


function logout() {
    // Remove user_id from both storages
    localStorage.removeItem('user_id');
    sessionStorage.removeItem('user_id');

    // Optionally clear everything
    localStorage.clear();
    sessionStorage.clear();

    // Redirect to login page
    window.location.href = 'lm-login.html'; // Change to your actual login URL
  }



