// Bottom Navigation Panel Toggles
$(document).ready(function () {
    console.log('Bottom nav script loaded');

    const cartPanel = document.getElementById('cartPanel');
    const accountPanel = document.getElementById('accountPanel');
    const searchPanel = document.getElementById('searchPanel');
    const toggleSearch = document.getElementById('toggleSearchPanel');
    const toggleCart = document.getElementById('toggleCartPanel');
    const toggleAccount = document.getElementById('toggleAccountPanel');

    console.log('Elements found:', {
        cartPanel: !!cartPanel,
        accountPanel: !!accountPanel,
        searchPanel: !!searchPanel,
        toggleSearch: !!toggleSearch,
        toggleCart: !!toggleCart,
        toggleAccount: !!toggleAccount
    });

    if (toggleSearch) {
        toggleSearch.addEventListener('click', function (e) {
            console.log('Search button clicked');
            e.stopPropagation();
            if (cartPanel) cartPanel.classList.remove('show');
            if (accountPanel) accountPanel.classList.remove('show');
            if (searchPanel) {
                searchPanel.classList.toggle('show');
                console.log('Search panel show class:', searchPanel.classList.contains('show'));
            }
        });
    }

    if (toggleCart) {
        toggleCart.addEventListener('click', function (e) {
            console.log('Cart button clicked');
            e.stopPropagation();
            if (searchPanel) searchPanel.classList.remove('show');
            if (accountPanel) accountPanel.classList.remove('show');
            if (cartPanel) {
                cartPanel.classList.toggle('show');
                console.log('Cart panel show class:', cartPanel.classList.contains('show'));
            }
        });
    }

    if (toggleAccount) {
        toggleAccount.addEventListener('click', function (e) {
            console.log('Account button clicked');
            e.stopPropagation();
            if (searchPanel) searchPanel.classList.remove('show');
            if (cartPanel) cartPanel.classList.remove('show');
            if (accountPanel) {
                accountPanel.classList.toggle('show');
                console.log('Account panel show class:', accountPanel.classList.contains('show'));
            }
        });
    }

    $(document).on('click', function (e) {
        if (searchPanel && !$(e.target).closest('#searchPanel').length && !$(e.target).closest('#toggleSearchPanel').length) {
            searchPanel.classList.remove('show');
        }
        if (cartPanel && !$(e.target).closest('#cartPanel').length && !$(e.target).closest('#toggleCartPanel').length) {
            cartPanel.classList.remove('show');
        }
        if (accountPanel && !$(e.target).closest('#accountPanel').length && !$(e.target).closest('#toggleAccountPanel').length) {
            accountPanel.classList.remove('show');
        }
    });
});
