import{L as v,j as l}from"./vendor-mui-core-CDEc-eG6.js";import{m as B,r}from"./vendor-react-DX7tU9aY.js";import{y as L,D as W}from"./vendor-utils-_C9URqjS.js";import{aa as O,b1 as A}from"./vendor-ux-PO0jFgJf.js";import{A as T,S as _}from"./add-component-core-B8HzULLJ.js";import{j as d,b as $,z as F}from"./vendor-hooks-Ca2cSNuD.js";import{v as K,af as z}from"./index-CgSpL7jz.js";import"./item-Cno3GsuG.js";import"./index-DBs9Ljax.js";import"./delete-confirm-C0N4quT9.js";import"./click-to-copy-BmatCVrP.js";import"./confirm-DhDNorbd.js";import"./session-BEf_KK-i.js";import"./get-safe-url-uxJSMQTF.js";import"./did-address-BNKX5oDP.js";import"./wait-connect-2CirehkG.js";import"./vendor-arcblock-BVQTtbN-.js";import"./launch-result-message-Br6OdJMs.js";import"./page-header-CEL5h6do.js";import"./engine-BmJsBu5Z.js";import"./config-space-CjtdFXkd.js";import"./spaces-DiyZ082O.js";import"./api-Bo6lutcq.js";import"./required-BO8emcue.js";import"./index-CZWagtq4.js";import"./Google-BpkBLSiL.js";import"./cloneDeep-D_udiNLL.js";import"./create-passport-svg-DNOT-xbE.js";import"./form-wrapper-BqPFgoVY.js";import"./logo-uploader-CEZXDf8O.js";import"./collapse-DRkXbQaT.js";import"./index-B0cxyMBd.js";import"./config-rELfdDu6.js";import"./isURL-CpQHQuaa.js";import"./isIP-BBY240SU.js";import"./section-CC2BHD5s.js";import"./form-text-input-XsQkiayU.js";import"./edit.svg-BGhTyO6h.js";import"./index-jIvFgWDS.js";import"./index-BLYrVxV3.js";import"./useLocalStorage-CSvyQkk-.js";import"./index-BEbBg3NW.js";import"./login-method-item-CmdeSlz8.js";import"./passkey-rounded-_WDHIZVd.js";import"./util-Cz5-V-1E.js";import"./use-mobile-CnCzXOEv.js";import"./content-layout-D49-hpq6.js";import"./connect-to-BRIhV6_s.js";import"./index-CeSwZI3Q.js";import"./index-D29L5UKE.js";import"./index-BojVbZw0.js";import"./index-BY7bAdcP.js";import"./fallback-DAsXuNMP.js";import"./search-4YYphs0l.js";function Gt(){const{t:u}=O(),{blocklet:h}=K(),{componentDid:s}=B(),f=v(t=>t.breakpoints.down("md")),e=new URL(window.location.href),w=e.searchParams.get("mode")==="dialog",n=e.searchParams.get("resourceType")||"",m=e.searchParams.get("resourceDid")||s,g=e.searchParams.get("store")||"",R=e.searchParams.get("showFromUrl")!=="false",b=e.searchParams.get("showResourcesSwitch")!=="false",y=e.searchParams.get("enableRunBackground")!=="false",C=e.searchParams.get("showCategory")!=="false",a=h?.meta?.did,i=g.split(",").filter(Boolean).map(t=>{try{return new URL(t.startsWith("http")?t:`https://${t}`).origin}catch(o){return console.error(o),null}}).filter(Boolean),[S,E]=r.useState(i.map(t=>({url:t,name:t.replace("https://","")}))),[P,D]=r.useState(null),[U,j]=r.useState("");r.useEffect(()=>{(async()=>{try{const t=await Promise.all(i.map(async o=>{const x=L(o,"/api/store.json"),{data:M}=await W.get(x);return{url:o,name:M.name}}));E(t||[])}catch(t){console.error(t)}})()},[i.join(",")]);const k=()=>{window.parent.postMessage({event:"resourceDialog.close",componentDid:s},"*")};r.useEffect(()=>{const t=z();return a&&t.connect(),()=>{a&&t.isConnected()&&t.disconnect()}},[a]),d(()=>{window.parent.postMessage({event:"resourceDialog.loaded",componentDid:s},"*")});const c=$(t=>{t.data?.event==="resourceDialog.select"&&t.data?.componentDid===s&&(D(t.data.data),j(t.data.storeUrl))});d(()=>{window.addEventListener("message",c)}),F(()=>{window.removeEventListener("message",c)});const p=({inDialog:t=!0}={})=>l.jsx(T,{stores:S,selectedMeta:P,storeUrl:U,resourceType:n,resourceDid:m,mode:"embed",inDialog:t,storageKey:_(`${n}+${m}`),showResourcesSwitch:b,showFromUrl:R,enableRunBackground:y,showCategory:C});return w?l.jsx(A,{className:"resource-dialog",title:u("blocklet.publish.addResource"),maxWidth:!1,fullWidth:!1,PaperProps:{style:f?{width:"100%",height:window.innerHeight}:{maxWidth:1350,minWidth:930,width:"80%"}},onClose:(t,o)=>{o!=="backdropClick"&&k()},showCloseButton:!0,disableEscapeKeyDown:!0,open:!0,children:p()}):p({inDialog:!1})}export{Gt as default};
