const LAZY_LOAD_TIMEOUT=5e3,DEFAULT_TIME_BASED_DELAY=5e3,moduleRegistry={usermanager:{path:"./user-manager.min.js?hash=00479d58",loadStrategy:"timeBased",delay:1e3,userRole:"user"},imagePage:{path:"./image-page.min.js?hash=b1ede1f6",loadStrategy:"domContentLoaded"},forumPost:{path:"./topicposts.min.js?hash=863c9882",loadStrategy:"domContentLoaded"},forumIndex:{path:"./forum-index.min.js?hash=6ed902b8",loadStrategy:"domContentLoaded"},forummember:{path:"./forummember.min.js?hash=5cd58b7f",loadStrategy:"timeBased",delay:1e3,userRole:"user"},forummoderator:{path:"./forummoderator2.min.js?hash=93d1d69f",loadStrategy:"timeBased",delay:1e3,userRole:"user"},comment:{path:"./comments.min.js?hash=451d3cd7",loadStrategy:"domContentLoaded"},homepage:{path:"./homepage.min.js?hash=332434d6",loadStrategy:"domContentLoaded"},floating:{path:"./floating.min.js?hash=1859f678",loadStrategy:"domContentLoaded"},utils:{path:"./utils.min.js?hash=a48608c6",loadStrategy:"domContentLoaded"},reactions:{path:"./reactions.min.js?hash=accf0bfc",loadStrategy:"domContentLoaded"},entity:{path:"./entity.min.js?hash=175061b6",loadStrategy:"domContentLoaded"},xScroll:{path:"./x-scroll.min.js?hash=2471b19e",loadStrategy:"domContentLoaded"},copyContent:{path:"./copycontent.min.js?hash=5b7ab7ed",loadStrategy:"domContentLoaded"},oembed:{path:"./oembed.min.js?hash=638d0974",loadStrategy:"domContentLoaded"},formatdates:{path:"./formatdates.min.js?hash=0705780c",loadStrategy:"domContentLoaded"},antiforgery:{path:"./antiforgerytoken.min.js?hash=5d71bf75",loadStrategy:"domContentLoaded"}},conditionHandlers={deviceType:e=>{const t=/Mobi|Android/i.test(navigator.userAgent);return"mobile"===e?t:"desktop"===e&&!t},custom:e=>{try{return e()}catch(e){return console.error("Custom condition error:",e),!1}}};class ModuleLoader{constructor({registry:e,handlers:t,lazyTimeout:o,timeDelay:a}){this.registry=e,this.handlers=t,this.lazyTimeout=o,this.timeDelay=a,this.pending=[],this.cache=new Map,this.dataModules=this.getDataModules(),this.init()}getDataModules(){return document.querySelector("script[data-modules]")?.getAttribute("data-modules")?.split(",")||[]}async evaluateModule(e){if(e.userRole){const t=window.userInfo||{isLoggedIn:!1,isAdmin:!1,isModerator:!1};if("admin"===e.userRole&&!t.isAdmin)return!1;if("moderator"===e.userRole&&!t.isModerator)return!1;if("user"===e.userRole&&!t.isLoggedIn)return!1}if(e.conditionType){const t=this.handlers[e.conditionType];return t?await t(e.conditionParam):(console.warn("No handler for",e.conditionType),!1)}return!0}async loadModule(e){try{const t=await import(e.path);t.init?.()}catch(t){throw console.error("Load error",e.path,t),t}}async processModules(e){const t=e.map((async e=>{if(e.userRole&&!window.userInfo)return void(this.pending.includes(e)||this.pending.push(e));return await this.evaluateModule(e)?this.loadModule(e):void 0}));(await Promise.allSettled(t)).forEach(((t,o)=>"rejected"===t.status&&console.error("Module failed",e[o].path,t.reason)))}handleImmediate(e){return this.processModules(e)}handleDomContentLoaded(e){const t=()=>this.processModules(e);"loading"===document.readyState?document.addEventListener("DOMContentLoaded",t,{once:!0}):t()}handleTimeBased(e){e.forEach((e=>setTimeout((()=>this.processModules([e])),e.delay||this.timeDelay)))}handleViewport(e){e.forEach((e=>{const t=document.querySelector(e.targetSelector);if(t){const o=new IntersectionObserver((t=>t.forEach((async t=>{t.isIntersecting&&(await this.processModules([e]),o.unobserve(t.target))}))));o.observe(t)}}))}handleLazyLoad(e){const t=()=>this.processModules(e),o=setTimeout((()=>t()),this.lazyTimeout);"complete"===document.readyState?(clearTimeout(o),t()):window.addEventListener("load",(()=>(clearTimeout(o),t())),{once:!0})}async handleUserInfoReady(e){window.userInfo=e.detail,this.cache.clear(),this.pending.length&&(await this.processModules(this.pending),this.pending=[])}init(){const e={immediate:[],domContentLoaded:[],timeBased:[],viewport:[],lazyLoad:[]};Object.entries(this.registry).forEach((([t,o])=>this.dataModules.includes(t)&&e[o.loadStrategy]?.push(o))),e.immediate.length&&this.handleImmediate(e.immediate),e.domContentLoaded.length&&this.handleDomContentLoaded(e.domContentLoaded),e.timeBased.length&&this.handleTimeBased(e.timeBased),e.viewport.length&&this.handleViewport(e.viewport),e.lazyLoad.length&&this.handleLazyLoad(e.lazyLoad)}}new ModuleLoader({registry:moduleRegistry,handlers:conditionHandlers,lazyTimeout:5e3,timeDelay:5e3});
