$(function() {
    'use strict';
    
    // Potpuno preuzimanje kontrole nad klikovima na menu
    $('.nav-sidebar .has-treeview > .nav-link').off('click').on('click', function(e) {
        e.preventDefault();
        e.stopPropagation();
        
        var $parentLi = $(this).parent('li');
        var $childUl = $(this).next('.nav-treeview');
        
        console.log('Menu clicked, is open:', $parentLi.hasClass('menu-open'));
        
        if ($parentLi.hasClass('menu-open')) {
            $parentLi.removeClass('menu-open');
            $childUl.slideUp(300);
        } else {
            $parentLi.addClass('menu-open');
            $childUl.slideDown(300);
        }
    });
    
    // Inicijalno postavi stanje menija
    $('.nav-sidebar .has-treeview').each(function() {
        var $li = $(this);
        var $childUl = $li.find('> .nav-treeview');
        
        if ($li.hasClass('menu-open')) {
            $childUl.show();
        } else {
            $childUl.hide();
        }
    });
    
    // Deaktiviraj AdminLTE sidebar controller
    if ($.fn.Treeview !== undefined) {
        $('[data-widget="treeview"]').Treeview('destroy');
    }
});