(()=>{"use strict";class t{constructor(t,e){this.ajaxUrl=t,this.nonce=e}async post(t,e={}){const s=new FormData;s.append("action",t),s.append("nonce",this.nonce),Object.entries(e).forEach(([t,e])=>{s.append(t,e)});const n=await fetch(this.ajaxUrl,{method:"POST",credentials:"same-origin",body:s}),r=await n.text();let i=r;try{i=r?JSON.parse(r):null}catch(t){i={_parseError:!0,raw:r,error:t?.message}}if(!n.ok){const t=i?.data?.error||i?.data?.message||i?.message||i?.raw||r||`HTTP Error ${n.status}`,e=new Error(String(t));throw e.status=n.status,e.body=i,e}if(i?._parseError){const t=String(i.raw||"").slice(0,300),e=new Error(`Invalid JSON response from server (status ${n.status}). Preview: ${t}`);throw e.status=n.status,e.body=i,e}if(!1===i?.success){const t=new Error(String(i?.data?.error||i?.data?.message||i?.message||"Request failed"));throw t.status=n.status,t.body=i,t}return i}}function e(t,e={},s=[]){const n=document.createElement(t);return Object.entries(e??{}).forEach(([t,e])=>{null!=e&&("className"===t?n.className=e:"dataset"===t?Object.entries(e).forEach(([t,e])=>n.dataset[t]=String(e)):t.startsWith("on")&&"function"==typeof e?n.addEventListener(t.substring(2).toLowerCase(),e):t in n?n[t]=e:n.setAttribute(t,String(e)))}),(Array.isArray(s)?s:[s]).flat(1/0).forEach(t=>{null!=t&&!1!==t&&("string"!=typeof t&&"number"!=typeof t?n.appendChild(t):n.appendChild(document.createTextNode(String(t))))}),n}class s{constructor(t="",e=null){this.containerSelector=t,this.apiService=e}renderNotice(t={}){return this.createNotice(this.containerSelector,t)}createNotice(t,s={}){const{type:n="info",message:r="",title:i="",dismissible:a=!0,timeoutMs:o=0}=s,c="string"==typeof t?document.querySelector(t):t;if(!c)return{destroy:()=>{},el:null};const d=[];if(i){const t=document.createTextNode(r),s=e("strong",{},[String(i)]),n=e("br",{},[]),a=e("p",{},[s,n,t]);d.push(a)}let l=null;a&&(l=e("button",{type:"button",className:"notice-dismiss",ariaLabel:"Dismiss"},[]),d.push(l));const u=e("div",{className:`notice notice-${n} ${a?"is-dismissible":""} tbk-admin-notice`,role:"alert"},d);c.prepend(u);let m=null;return o&&Number(o)>0&&(m=setTimeout(()=>this.destroy(m,u),Number(o))),a&&l&&l.addEventListener("click",()=>this.destroy(m,u)),{destroy:()=>this.destroy(m,u),el:u}}destroy(t,e){t&&clearTimeout(t),e&&"1"!==e?.dataset?.removing&&(e.dataset.removing="1",e.addEventListener("transitionend",this.handleTransitionEnd),e.classList.add("tbk-admin-notice--fade-out"),setTimeout(()=>{e.isConnected&&(e.removeEventListener("transitionend",this.handleTransitionEnd),e.remove())},350))}handleTransitionEnd(t){if(t.propertyName&&"opacity"!==t.propertyName)return;const e=t.currentTarget;e.removeEventListener("transitionend",this.handleTransitionEnd),e.remove()}async dismiss(t){try{await(this.apiService?.post?.("dismiss_notice",{notice_id:t}))}catch{}}initDismissListeners(t,e){const s=document.querySelector(this.containerSelector);s&&s.addEventListener("click",s=>{const n=s.target.closest(`.${t}`);if(!n)return;const r=n.closest(e);r?.id&&this.dismiss(r.id)})}}(class{static ready(t){"function"==typeof t&&("loading"!==document.readyState?Promise.resolve().then(t):document.addEventListener("DOMContentLoaded",t,{once:!0}))}}).ready(()=>{const e=(()=>{const t=globalThis.ajax_object;return t?.ajax_url&&t?.nonce?t:null})();if(!e)return;const n=new t(e.ajax_url,e.nonce);new s("#mainform",n).initDismissListeners("notice-dismiss",".notice")})})();