import{L as W,j as l}from"./vendor-mui-core-D7t4vMS5.js";import{m as v,r}from"./vendor-react-DX7tU9aY.js";import{z as B,D as L}from"./vendor-utils-BzQg432x.js";import{W as O,aO as A}from"./vendor-ux-Dl3wVbv_.js";import{A as T,S as _}from"./add-component-core-DOIm-W83.js";import{j as d,b as $,x as F}from"./vendor-hooks-DAZ1H6Va.js";import{x as K,a8 as z}from"./index-Ca33rdd_.js";import"./item-DoUn7xhc.js";import"./index-DBs9Ljax.js";import"./delete-confirm-CpaOkuin.js";import"./click-to-copy-RBTqACSW.js";import"./confirm-DQYDHHdS.js";import"./session-lE2gmzzF.js";import"./get-safe-url-D4zRnTpF.js";import"./did-address-DRYM96gB.js";import"./wait-connect-DOIonmAv.js";import"./vendor-arcblock-ivFYo5vP.js";import"./launch-result-message-B2nhmkKt.js";import"./page-header-B0HpJClf.js";import"./engine-L1SEogaX.js";import"./config-space-HmsYCb6s.js";import"./spaces-Ckljlc4d.js";import"./api-B8JXuhVp.js";import"./required-11pmtzQr.js";import"./index-BuucS_rQ.js";import"./Google-BMSeyXdi.js";import"./cloneDeep-YxES7wNt.js";import"./create-passport-svg-De1vqcmo.js";import"./form-wrapper-EixE0Jkw.js";import"./logo-uploader-DjKJkvts.js";import"./collapse-DWmyzfnW.js";import"./index-DvQIPWQ6.js";import"./config-fYkZxdEr.js";import"./isURL-CpQHQuaa.js";import"./isIP-BBY240SU.js";import"./section-ewv0pNWr.js";import"./form-text-input-Cs-LuCu0.js";import"./edit.svg-BGhTyO6h.js";import"./index-jIvFgWDS.js";import"./joi-browser.min-CUdv8seQ.js";import"./index-sb6EjUcD.js";import"./useLocalStorage-D6axLnAi.js";import"./index-CxOxF1pg.js";import"./login-method-item-KhJ672kA.js";import"./passkey-rounded-_WDHIZVd.js";import"./util-ad0rjUA1.js";import"./use-mobile-BSL5RsRd.js";import"./content-layout-CanSZTqf.js";import"./connect-to-C3ac4B-g.js";import"./index-Cw8Yly1u.js";import"./index-D29L5UKE.js";import"./index-BojVbZw0.js";import"./index-_bvucGkF.js";import"./fallback-CZRO9TTQ.js";import"./search-4YYphs0l.js";function Ht(){const{t:u}=O(),{blocklet:h}=K(),{componentDid:s}=v(),w=W(t=>t.breakpoints.down("md")),e=new URL(window.location.href),f=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",C=e.searchParams.get("showResourcesSwitch")!=="false",S=e.searchParams.get("enableRunBackground")!=="false",b=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),[y,E]=r.useState(i.map(t=>({url:t,name:t.replace("https://","")}))),[P,D]=r.useState(null),[x,U]=r.useState("");r.useEffect(()=>{(async()=>{try{const t=await Promise.all(i.map(async o=>{const k=B(o,"/api/store.json"),{data:M}=await L.get(k);return{url:o,name:M.name}}));E(t||[])}catch(t){console.error(t)}})()},[i.join(",")]);const j=()=>{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 p=$(t=>{t.data?.event==="resourceDialog.select"&&t.data?.componentDid===s&&(D(t.data.data),U(t.data.storeUrl))});d(()=>{window.addEventListener("message",p)}),F(()=>{window.removeEventListener("message",p)});const c=({inDialog:t=!0}={})=>l.jsx(T,{stores:y,selectedMeta:P,storeUrl:x,resourceType:n,resourceDid:m,mode:"embed",inDialog:t,storageKey:_(`${n}+${m}`),showResourcesSwitch:C,showFromUrl:R,enableRunBackground:S,showCategory:b});return f?l.jsx(A,{className:"resource-dialog",title:u("blocklet.publish.addResource"),maxWidth:!1,fullWidth:!1,PaperProps:{style:w?{width:"100%",height:window.innerHeight}:{maxWidth:1350,minWidth:930,width:"80%"}},onClose:(t,o)=>{o!=="backdropClick"&&j()},showCloseButton:!0,disableEscapeKeyDown:!0,open:!0,children:c()}):c({inDialog:!1})}export{Ht as default};
