!function(e,t){"use strict";var r=e.EasyChatAdminShell,n=e.EasyChatDom,a={},o={},i=0;function c(t){try{var r=new URL(String(t||""),e.location.href);return r.origin!==e.location.origin?"":(r.hash="",r.href)}catch(e){return""}}function l(e){var t=r.routeFromUrl(e);return r.isShellRoute(t)?t:""}function s(){Object.keys(a).sort(function(e,t){return a[t].createdAt-a[e].createdAt}).slice(5).forEach(function(e){delete a[e]})}function u(e){var t=c(e),r=a[t];return r?r.expiresAt<Date.now()?(delete a[t],null):r:null}function f(e,t){e&&e.setAttribute("data-easychat-prefetch-state",t||"")}function h(e){var t=e&&e.target;if(t&&1===t.nodeType&&"function"==typeof t.closest)return t.closest("[data-easychat-shell-route]");for(var r=e&&"function"==typeof e.composedPath?e.composedPath():[],n=0;n<r.length;n+=1){var a=r[n];if(a&&1===a.nodeType&&"function"==typeof a.matches&&a.matches("[data-easychat-shell-route]"))return a;if(a&&1===a.nodeType&&"function"==typeof a.closest){var o=a.closest("[data-easychat-shell-route]");if(o)return o}}return null}function d(r,i,h){h=h||{};var d=l(r=c(r));if(!r||!d||!h.allowCurrent&&c(e.location.href)===r)return Promise.resolve(null);if(u(r))return f(i,"ready"),Promise.resolve(a[r]);if(o[r])return f(i,"warming"),o[r].promise;var y="AbortController"in e?new AbortController:null;f(i,"warming");var p=function(t){if("function"==typeof e.EasyChatRouteUrl)return e.EasyChatRouteUrl(t);var r=String(t||""),n="index.php?route=",a=String(e.EasyChatRouteBase||"");return a&&0===r.indexOf(n)?a+r.substring(16):r}(r);return o[r]={controller:y,promise:fetch(p,{method:"GET",credentials:"same-origin",signal:y?y.signal:void 0,headers:{Accept:"text/html","X-EasyChat-Shell":"1","X-EasyChat-Prefetch":"1"}}).then(function(e){if(!e.ok)throw new Error("prefetch_http_"+e.status);return e.text()}).then(function(e){if(-1===e.indexOf('id="easychat-main-shell"')&&-1===e.indexOf("id='easychat-main-shell'"))throw new Error("prefetch_missing_shell");return a[r]={url:r,route:d,html:e,createdAt:Date.now(),expiresAt:Date.now()+45e3},s(),f(i,"ready"),n.trigger(t.body,"easychat:admin-prefetch-ready",{route:d,url:r}),a[r]}).catch(function(e){return e&&"AbortError"===e.name||f(i,"miss"),null}).finally(function(){delete o[r]})},o[r].promise}function y(e){return d(e&&e.href,e)}function p(t){t&&"1"!==t.getAttribute("data-easychat-prefetch-disabled")&&(e.clearTimeout(t.easychatPrefetchTimer),t.easychatPrefetchTimer=e.setTimeout(function(){y(t)},90))}function m(t){var n=t&&t.state?t.state:null;if(n&&!0===n.easychatShell){var o=c(e.location.href);if(o&&l(o)){var s=++i,f=u(o);f?h(f):(r.setBusy(!0),d(o,null,{allowCurrent:!0}).then(h))}}function h(t){s===i&&c(e.location.href)===o?t?(delete a[o],r.applyPrefetchedShell(o,t.html,{push:!1})||e.location.reload()):e.location.reload():r.setBusy(!1)}}function v(){t.addEventListener("pointerenter",function(e){var t=h(e);t&&p(t)},!0),t.addEventListener("focusin",function(e){var t=h(e);t&&p(t)}),t.addEventListener("pointerleave",function(t){var r=h(t);r&&function(t){if(t){e.clearTimeout(t.easychatPrefetchTimer);var r=c(t.href),n=o[r];n&&n.controller&&(n.controller.abort(),delete o[r]),u(r)||f(t,"")}}(r)},!0),t.addEventListener("click",function(o){var i=h(o);i&&function(o,i){var l=c(o&&o.href),s=u(l);!!s&&(delete a[l],i.preventDefault(),"function"==typeof i.stopImmediatePropagation&&i.stopImmediatePropagation(),r.applyPrefetchedShell(l,s.html,{push:!0})?(f(o,"used"),n.trigger(t.body,"easychat:admin-prefetch-used",{route:s.route,url:l})):(delete a[l],e.location.assign(l)))}(i,o)},!0),e.addEventListener("popstate",m)}r&&n&&!e.EasyChatAdminInstantConfigured&&(e.EasyChatAdminInstantConfigured=!0,n.ready(function(){v()}),e.EasyChatAdminInstant={prefetch:y,cached:u,routes:r.routes.slice()})}(window,document);