"use strict";
const AdminFunctions = (() => {
    function toggleMenuVisibility(hideLargeMenu) {
        const contentContainer = $('#js-admin-content-container');
        const largeMenu = $('#js-menu-big');
        const smallMenu = $('#js-menu-small');
        const searchForm = $('#js-form-search');
        contentContainer.toggleClass('show-large-menu', !hideLargeMenu);
        largeMenu.toggleClass('hidden', hideLargeMenu);
        smallMenu.toggleClass('hidden', !hideLargeMenu);
        searchForm.toggleClass('menu-hide', hideLargeMenu);
        localStorage.setItem(hideLargeMenu ? 'menu_big' : 'menu_small', 'hidden');
        localStorage.removeItem(hideLargeMenu ? 'menu_small' : 'menu_big');
    }
    function debounce(func, wait, immediate) {
        let timeout = null;
        return function (...args) {
            const context = this;
            const later = function () {
                timeout = null;
                if (!immediate)
                    func.apply(context, args);
            };
            const callNow = immediate && !timeout;
            if (timeout !== null) {
                clearTimeout(timeout);
            }
            timeout = setTimeout(later, wait);
            if (callNow)
                func.apply(context, args);
        };
    }
    function addProductToCategory(productId) {
        const statusElement = $('#status_' + productId);
        statusElement.html('<span class="loading loading-bars loading-sm"></span><span class="ml-[3px]">Processing...</span>');
        setTimeout(() => {
            statusElement.html('');
        }, 1000);
    }
    function searchSuggestions(inputSelector) {
        $(inputSelector).keyup(debounce(function () {
            $('#js-show-search').show();
        }, 300, false));
        $('body').click(function () {
            $('#js-show-search').hide();
        });
    }
    function markProductAsHot(productId) {
        const statusElement = $('#js-status-hottype-' + productId);
        statusElement.html('<span class="loading loading-bars loading-sm"></span><span class="ml-[3px]">Processing...</span>');
        setTimeout(() => {
            statusElement.html('');
        }, 1000);
    }
    function initializeSearchDropdown(selector) {
        $(selector).select2();
    }
    return {
        toggleMenuVisibility,
        addProductToCategory,
        searchSuggestions,
        initializeSearchDropdown,
        markProductAsHot
    };
})();
