
/* Smart UI v9.3.56 (2021-05-12) 
Copyright (c) 2011-2021 jQWidgets. 
License: https://htmlelements.com/license/ */ //

Smart.Utilities.Assign("Router",class{constructor(e,t="/"){const n=this,i=document.createElement("a");if(e instanceof HTMLElement)n.view=e;else if("string"==typeof e){if(!(e=document.getElementById(e)))throw new Error("smartRouter: Provided view does not exist in the DOM.");n.view=e}"/"!==t.charAt(t.length-1)&&(t+="/"),n.base=t,i.href=t,n._resolvedBase=i.pathname,n.cache=!1,n.routes=[],n._visited={},n._titleElement=document.querySelector("title"),n._addWindowEventListeners()}setRoutes(e){const t=[];for(let n=0;n<e.length;n++){const i=e[n];i.path&&i.template&&t.push(i)}this.routes=t}route(e,t,n=!0){const i=this,o=i.routes.find((t=>t.path===e));if(!o)return;const s=o.template,l=document.createElement("div");if(-1!==s.indexOf("/")||-1!==s.indexOf("."))new Smart.Ajax({url:s,type:"GET",dataType:"text/html"},(function(e,t){t>=200&&t<=299&&(l.innerHTML=e,i._templateLoadComplete(o,l))}));else{const e=document.getElementById(s);if(!s)return;const t=document.importNode(e.content,!0);l.appendChild(t),i._templateLoadComplete(o,l)}t&&(window.history.pushState({},"",i.base+e.slice(1)),t.preventDefault()),n&&window.history.replaceState({},"",i.base+e.slice(1))}_templateLoadComplete(e,t){const n=this,i=document.createElement("div"),o=e.styleUrls,s=e.style,l=e.scriptUrls,a=e.script,r=[];let d=!1,c=0;function p(){t.style.opacity=1,t.style.visibility="visible",n._visited[e.path]=!0,n.templateApplied&&"function"==typeof n.templateApplied&&n.templateApplied(e)}if(e.title&&n._titleElement&&(n._titleElement.innerHTML=e.title),(!n.cache||!n._visited[e.path])&&l&&Array.isArray(l)&&l.length>0&&(d=!0,c+=l.length,function e(t){const n=document.createElement("script"),o=l[t];"string"==typeof o?(n.src=o,n.type="module"):"object"==typeof o&&o.src&&(n.src=o.src,n.type=o.type||"module"),n.onload=function(){-1===r.indexOf(n)&&(r.push(n),c===r.length?p():t<l.length-1&&e(t+1))},i.appendChild(n)}(0)),a&&"string"==typeof a){const e=document.createElement("script");e.type="text/javascript",e.innerHTML=a,i.appendChild(e),d=!0}if(o&&Array.isArray(o)&&o.length>0){d=!0;for(let e=0;e<=o.length-1;e++){const t=document.createElement("link");c++,t.rel="stylesheet",t.type="text/css",t.href=o[e],t.onload=function(){-1===r.indexOf(t)&&(r.push(t),c===r.length&&p())},i.appendChild(t)}}if(s&&"string"==typeof s){const e=document.createElement("style");e.innerHTML=s,i.appendChild(e),d=!0}function h(e){e&&(this.ontransitionend=null),n.view.innerHTML="",t.classList.add("view-content"),t.style.opacity=0,t.style.visibility="hidden",t.style.transition="opacity 0.3s ease-out, visibility 0.3s ease-out",d?(n.view.appendChild(i),n.view.appendChild(t),0===c&&p()):(n.view.appendChild(t),p())}const u=n.view.querySelector(".view-content");u?(u.ontransitionend=h,u.style.opacity=0,u.style.visibility="hidden"):h()}_addWindowEventListeners(){const e=this;e._actualClickHandler=e._clickHandler.bind(this),e._actualPopstateHandler=e._popstateHandler.bind(this),document.body.addEventListener("click",e._actualClickHandler),window.addEventListener("popstate",e._actualPopstateHandler)}_clickHandler(e){const t=e.target.closest("a");if(!t)return;const n=this,i=t.pathname;t.origin===window.location.origin&&(i!==window.location.pathname||""===t.hash&&"#"!==t.href.charAt(t.href.length-1))&&0===i.indexOf(n._resolvedBase)&&n.route(n._resolvePath(i),e,!1)}_resolvePath(e){return-1!==(e=e.split("/"))[e.length-1].indexOf(".")&&(e.pop(),e.push("")),e="/"+(e=e.join("/")).replace(this._resolvedBase,"")}_popstateHandler(e){null!==e.state&&this._routeToCurrentLocation(!1)}_routeToCurrentLocation(e){this.route(this._resolvePath(window.location.pathname),void 0,e)}_removeWindowEventListeners(){document.body.removeEventListener("click",this._actualClickHandler),window.removeEventListener("popstate",this._actualPopstateHandler)}}),Smart.Router=Smart.Utilities.Router;