import{a as e}from"../../shared/js/rolldown-runtime.WmLfqUcM.js";import{d as t}from"./vendor-query.DdXA9l73.js";import"./shared.6NMKG8zy.js";var n=e(t(),1),r=(e,t,n)=>{let r=document.createElement(`link`);r.dataset.handle=t,r.rel=`stylesheet`,r.href=n,e.appendChild(r)},i=(e,t,n)=>new Promise((r,i)=>{let a=document.createElement(`script`);a.dataset.handle=t,a.src=n,a.async=!1,a.onload=()=>r(),a.onerror=()=>i(Error(`Failed to load script: ${n}`)),e.appendChild(a)}),a=(e,t,n)=>{let r=document.getElementById(t.root);r||(r=document.createElement(`div`),r.id=t.root,n(e,r));let i=r.querySelector(`#${t.assets}`),a=r.querySelector(`#${t.markup}`);return i||(i=document.createElement(`div`),i.id=t.assets,r.appendChild(i)),a||(a=document.createElement(`div`),a.id=t.markup,r.appendChild(a)),i.innerHTML=``,a.innerHTML=``,{root:r,assetContainer:i,markupContainer:a}},o=({fragment:e,enabled:t=!0,ids:o,resolveHost:s,placeRoot:c=(e,t)=>e.insertAdjacentElement(`afterend`,t),applyData:l,onMount:u,onCleanup:d,onError:f})=>{let p=(0,n.useRef)(s),m=(0,n.useRef)(c),h=(0,n.useRef)(l),g=(0,n.useRef)(u),_=(0,n.useRef)(d),v=(0,n.useRef)(f);(0,n.useEffect)(()=>{p.current=s,m.current=c,h.current=l,g.current=u,_.current=d,v.current=f},[s,c,l,u,d,f]),(0,n.useEffect)(()=>{if(!t||!e)return;let n=p.current();if(!n)return;let s=a(n,o,m.current),c=!0,l={...s,fragment:e,applyData:()=>{h.current?.(e.data)},mountMarkup:()=>{s.markupContainer.innerHTML=e.html},mountAssets:async(t={})=>{let n=t.cssEntries??Object.entries(e.css_url??{}),a=t.jsEntries??Object.entries(e.js_url??{});n.forEach(([e,t])=>r(s.assetContainer,e,t));for(let[e,t]of a)await i(s.assetContainer,e,t)}};return Promise.resolve(g.current(l)).catch(e=>{c&&v.current?.(e)}),()=>{c=!1,_.current?.(l),s.root.remove()}},[t,e,o.assets,o.markup,o.root])},s=`wpcfto_metaboxes.js`,c=e=>{if(!e)return;let t=window;Object.entries(e).forEach(([e,n])=>{t[e]=n})},l=()=>{let e=window;e.Vue&&(e.WPCFTO_EventBus=new e.Vue)},u=e=>{(e?.querySelector(`[data-vue]`))?.__vue__?.$destroy?.()},d=async e=>{let t=Object.entries(e.fragment.js_url??{}),n=t.find(([e])=>e===s),r=t.filter(([e])=>e!==s);await e.mountAssets({cssEntries:Object.entries(e.fragment.css_url??{}),jsEntries:r}),l(),n&&await e.mountAssets({jsEntries:[n]})},f=({fragment:e,enabled:t=!0,hasInitialRoot:r=!1,ids:i,resolveHost:a,placeRoot:s,onError:l})=>{(0,n.useEffect)(()=>{if(!t||!r)return;let e=document.getElementById(i.root);if(e)return()=>{u(e),e.remove()}},[t,r,i.root]);let f=(0,n.useCallback)(async e=>{e.applyData(),e.mountMarkup(),await d(e)},[]),p=(0,n.useCallback)(e=>{u(e.markupContainer)},[]);o({fragment:e,enabled:t&&!r,ids:i,resolveHost:a,placeRoot:s,applyData:c,onMount:f,onCleanup:p,onError:l})};export{o as n,f as t};