(()=>{(function(l,s){"use strict";let a=l.FOSSBilling||{},c=[],f=new WeakMap,u=new Map,g=new Map;function h(t){try{t(a)}catch(e){console.error("FOSSBilling ready callback failed:",e)}}a.ready=function(t){if(typeof t=="function"){if(s.readyState==="loading"){c.push(t);return}h(t)}},s.addEventListener("DOMContentLoaded",function(){for(;c.length>0;)h(c.shift())}),a.ui=Object.assign({notify(t,e="info"){if(typeof a.message=="function"){a.message(t,e);return}if(e==="error"){console.error(t);return}console.info(t)}},a.ui||{}),a.cookieCreate=a.cookieCreate||function(t,e,r){let n="";if(r){let o=new Date;o.setTime(o.getTime()+r*24*60*60*1e3),n=`; expires=${o.toUTCString()}`}s.cookie=`${t}=${e}${n}; path=/`},a.cookieRead=a.cookieRead||function(t){let e=`${t}=`,r=s.cookie.split(";");for(let n=0;n<r.length;n++){let o=r[n];for(;o.charAt(0)===" ";)o=o.substring(1);if(o.indexOf(e)===0)return o.substring(e.length)}return null};function y(t){return t.getAttribute("name")||t.id||null}function d(t,e){let r=e.getData();"value"in t?t.value=r:t.textContent=r}function w(t,e){if(!e||typeof e.getData!="function"||typeof e.setData!="function")throw new Error("Editor adapters must return getData() and setData() methods.");return{raw:e.raw||e,getData:()=>e.getData(),setData:r=>e.setData(r),focus:()=>{var r,n;if(typeof e.focus=="function"){e.focus();return}(n=(r=e.editing)==null?void 0:r.view)!=null&&n.focus&&e.editing.view.focus()},destroy:()=>typeof e.destroy=="function"?e.destroy():Promise.resolve(),onChange:r=>{var n,o;if(typeof e.onChange=="function")return e.onChange(r);(o=(n=e.model)==null?void 0:n.document)!=null&&o.on&&e.model.document.on("change:data",r)},element:t,name:y(t),required:t.dataset.editorRequired==="true"}}a.editor=Object.assign({registerAdapter(t,e){if(!t||!e||typeof e.create!="function")throw new Error("Editor adapter registration requires a name and create() method.");g.set(t,e)},async create(t,e={}){if(!t)throw new Error("Cannot initialize an editor without an element.");let r=e.adapter||"ckeditor",n=g.get(r);if(!n)throw new Error(`Editor adapter "${r}" is not registered.`);t.hasAttribute("required")&&(t.dataset.editorRequired="true",t.removeAttribute("required"));let o=await n.create(t,e),i=w(t,o);return d(t,i),i.onChange(()=>d(t,i)),f.set(t,i),i.name&&u.set(i.name,i),t.editor=i,t.setAttribute("data-editor","true"),i},init(t,e={}){s.querySelectorAll(t).forEach(r=>{f.has(r)||a.editor.create(r,e).catch(n=>{console.error("Editor initialization error:",n)})})},get(t){return u.get(t)||null},getForElement(t){return f.get(t)||null},all(){return Array.from(u.values())},syncForm(t,e){let r=new Set(Array.from(t.elements||[]));u.forEach((n,o)=>{r.has(n.element)&&(d(n.element,n),e.set(o,n.getData()))})},validateForm(t){let e=new Set(Array.from(t.elements||[]));for(let r of u.values())if(e.has(r.element)&&r.required&&r.getData().trim()==="")return!1;return!0}},a.editor||{}),l.FOSSBilling=a})(window,document);})();
