import{r as f}from"./svn-lib-models-CnHFhceI.js";const m={};function y(r){const e=document.querySelector(`script[src="${r}"]`),n=e==null?void 0:e.getAttribute("data-status");return{node:e,status:n}}function E(r,e){const[n,l]=f.useState(()=>!r||e!=null&&e.shouldPreventLoad?"idle":typeof document>"u"?"loading":m[r]??"loading");return f.useEffect(()=>{if(!r||e!=null&&e.shouldPreventLoad)return;const a=m[r];if(a==="ready"||a==="error"){l(a);return}const v=y(r);let t=v.node;if(t)l(v.status??a??"loading");else{t=document.createElement("script"),t.src=r,t.async=!0,t.setAttribute("data-status","loading"),e!=null&&e.type&&(t.type=e.type),document.body.appendChild(t);const u=c=>{const s=c.type==="load"?"ready":"error";t==null||t.setAttribute("data-status",s)};t.addEventListener("load",u),t.addEventListener("error",u)}const d=u=>{const c=u.type==="load"?"ready":"error";l(c),m[r]=c};return t.addEventListener("load",d),t.addEventListener("error",d),()=>{t&&(t.removeEventListener("load",d),t.removeEventListener("error",d)),t&&(e!=null&&e.removeOnUnmount)&&t.remove()}},[r,e==null?void 0:e.shouldPreventLoad,e==null?void 0:e.removeOnUnmount,e==null?void 0:e.type]),n}export{E as u};
