const c=document.getElementById("sidebar"),m=document.getElementById("overlay"),i=document.getElementById("dropdownMenu"),s=document.getElementById("userDropdownBtn"),p=768,g={dashboard:"Dashboard",pendaftaran:"Administrator","pendaftaran-tambah":"Users",customer:"List Customer","customer-detail":"Detail Customer",report:"Laporan",management:"Management"},w={pendaftaran:"pendaftaran-sub",user:"user-sub",aplikasi:"app-sub",laporan:"lap-sub"};function d(){return window.innerWidth<=p}window.toggleSub=function(e,t){const n=document.getElementById(e);if(!n)return;const a=n.classList.contains("open");document.querySelectorAll(".nav-sub").forEach(o=>o.classList.remove("open")),document.querySelectorAll(".nav-item[data-group]").forEach(o=>o.classList.remove("open")),a||(n.classList.add("open"),t.classList.add("open"))};window.openSidebar=function(){c.classList.add("open"),m.classList.add("visible"),document.body.style.overflow="hidden"};window.closeSidebar=function(){c.classList.remove("open"),m.classList.remove("visible"),document.body.style.overflow=""};function b(){d()?c.classList.contains("open")?window.closeSidebar():window.openSidebar():document.body.classList.toggle("sidebar-collapsed")}window.logout=function(){document.getElementById("logout-form").submit()};window.changePassword=function(){window.location.href="/password/change"};s&&s.addEventListener("click",function(e){e.stopPropagation(),i.classList.toggle("show"),s.classList.toggle("active")});document.addEventListener("click",function(){i&&i.classList.remove("show"),s&&s.classList.remove("active")});function v(){const e=window.location.pathname.split("/").filter(Boolean),t=e[0];if(t==="user-management"){if(e[1]==="administrator")return"pendaftaran";if(e[1]==="user")return"pendaftaran-tambah"}return t==="customer"?"customer":t==="report"?"report":t==="management"?"management":t||"dashboard"}function h(){const e=v();document.querySelectorAll(".nav-item, .nav-sub-item").forEach(o=>o.classList.remove("active")),document.querySelectorAll(".nav-sub, .nav-item[data-group]").forEach(o=>o.classList.remove("open"));let t=document.querySelector(`[data-page="${e}"]`);if(t||document.querySelectorAll("a[href]").forEach(r=>{r.href===window.location.href&&(t=r)}),t){t.classList.add("active");const o=t.closest(".nav-sub");if(o){o.classList.add("open");for(const[r,f]of Object.entries(w))if(f===o.id){const l=document.querySelector(`.nav-item[data-group="${r}"]`);l&&l.classList.add("open")}}}const n=g[e]||"Sumans",a=document.getElementById("topbar-title");a&&(a.textContent=n)}const u=document.querySelector(".topbar-menu");u&&u.addEventListener("click",b);document.querySelectorAll(".nav-item[data-page], .nav-sub-item[data-page]").forEach(e=>{e.addEventListener("click",()=>{d()&&window.closeSidebar()})});window.addEventListener("resize",()=>{d()||window.closeSidebar()});document.addEventListener("DOMContentLoaded",()=>{h();const e=window.flashMessages;console.log(e),e?.success&&Toast.show(e.success,"success"),e?.error&&Toast.show(e.error,"error"),e?.errors&&e?.errors.length>0&&e?.errors.forEach(t=>{Toast.show(t,"error")})});
