document.addEventListener('DOMContentLoaded',function(){let currentScriptId=null;let router;function loadScript(url,callback){const script=document.createElement('script');script.src=url;script.onload=callback;script.defer=!0;document.head.appendChild(script)} function executeScript(src,name){const scriptPath=`/ctrl/pagesjs${src}`;const newScriptId=`script-${name}`;if(currentScriptId){const oldScript=document.getElementById(currentScriptId);if(oldScript){oldScript.parentNode.removeChild(oldScript)}} const script=document.createElement('script');script.src=scriptPath;script.id=newScriptId;document.head.appendChild(script);currentScriptId=newScriptId} function initializeDynamicContent(){} document.body.addEventListener('click',function(event){let target=event.target.closest('a');if(!target)return;const href=target.getAttribute('href');if(href.startsWith('#')){return} if(href.startsWith('http')){return} event.preventDefault();if(href&&href!=='#'){router.navigate(href)}});loadScript('/node_modules/navigo/lib/navigo.js',function(){const path=`/core/Json/Routes.json?t=${new Date().getTime()}`;fetch(path).then(response=>response.json()).then(data=>{router=new Navigo('/');data.routes.forEach(route=>{router.on(route.path,function(){const pagePath=`/ctrl/pages${route.path}`;fetch(pagePath).then(response=>response.ok?response.text():Promise.reject('Página não encontrada')).then(html=>{const appElement=document.getElementById('app');appElement.innerHTML=html;executeScript(route.path,route.controller);initializeDynamicContent()}).catch(error=>{console.error('Erro ao carregar a página:',error);router.navigate('/404')})})});router.notFound(function(){fetch('/templates/error/404.php').then(response=>response.text()).then(html=>{const appElement=document.getElementById('app');appElement.innerHTML=html;executeScript('/404',404);initializeDynamicContent()}).catch(error=>console.error('Erro ao carregar a página 404:',error))});router.resolve()}).catch(error=>console.error('Erro ao carregar as rotas:',error))})});const mob={get:function(url,successCallback,errorCallback){var xhr=new XMLHttpRequest();xhr.open('GET',url,!0);xhr.onload=function(){if(xhr.status>=200&&xhr.status<300){successCallback(xhr.responseText)}else{errorCallback(xhr.statusText)}};xhr.onerror=function(){errorCallback("Erro de rede")};xhr.send()},post:function(url,formData,successCallback,errorCallback,progressCallback){var xhr=new XMLHttpRequest();xhr.open('POST',url,!0);xhr.upload.onprogress=function(event){if(event.lengthComputable){var percentComplete=(event.loaded/event.total)*100;if(progressCallback){progressCallback(percentComplete)}}};xhr.onload=function(){if(xhr.status>=200&&xhr.status<300){successCallback(xhr.responseText)}else{errorCallback(xhr.statusText)}};xhr.onerror=function(){errorCallback("Erro de rede")};xhr.send(formData)},put:function(url,data,successCallback,errorCallback){var xhr=new XMLHttpRequest();xhr.open('PUT',url,!0);xhr.onload=function(){if(xhr.status>=200&&xhr.status<300){successCallback(xhr.responseText)}else{errorCallback(xhr.statusText)}};xhr.onerror=function(){errorCallback("Erro de rede")};var formData=new FormData();for(var key in data){formData.append(key,data[key])} xhr.send(formData)}}