import{J as v,j as l}from"./vendor-mui-core-DnR6WYuU.js";import{m as B,r}from"./vendor-react-CTtPmzVP.js";import{C as W,D as L}from"./vendor-utils-BqKQizRf.js";import{V as O,aJ as A}from"./vendor-ux-KtPBvlG0.js";import{h as d,b as T,t as _}from"./vendor-hooks-DpqqC65c.js";import{A as $,S as F}from"./add-component-core-L7bwC_64.js";import{y as K,an as J}from"./index-DGg3AL9l.js";import"./lottie-web-4koyQiv_.js";import"./item-D8-oGTEp.js";import"./index-DBs9Ljax.js";import"./delete-confirm-BT4RGlre.js";import"./click-to-copy-03_3P1nz.js";import"./confirm-Dul9DyCY.js";import"./session-Bavobyzn.js";import"./get-safe-url-CqIO9371.js";import"./did-address-DpdRECuJ.js";import"./wait-connect-BwtwczC4.js";import"./vendor-arcblock-DRfhQ9Yl.js";import"./launch-result-message-MNpx7ysR.js";import"./page-header-CHAwrgX-.js";import"./engine-BaNtB6sW.js";import"./config-space-DnDf6PO2.js";import"./spaces-DKfk45f5.js";import"./api-2a4FTO9k.js";import"./required-BQln5OcV.js";import"./index-CueIV4dA.js";import"./Google-CQ1n6aSx.js";import"./cloneDeep-DqDclz1x.js";import"./create-passport-svg-Cs4mVLsE.js";import"./form-wrapper-PT5ZzMQy.js";import"./logo-uploader-CPZeytzo.js";import"./collapse-B7gUzFaX.js";import"./index-B0Q9wWG1.js";import"./config-B8HbrPnF.js";import"./isURL-HdHdFI5D.js";import"./section-jXB9AxBb.js";import"./form-text-input-CsXLsIFW.js";import"./edit.svg-RRSklUg-.js";import"./index-_tncRnTu.js";import"./useLocalStorage-8LihN_xG.js";import"./index-CiQKtWIW.js";import"./util-CqIowTns.js";import"./use-mobile-BINJTzMb.js";import"./content-layout-DmSBGGVm.js";import"./connect-to-DNZM_E4B.js";import"./index-Bh8glecC.js";import"./index-DRYJ0xIl.js";import"./index-BojVbZw0.js";import"./index-CeGNmiXz.js";import"./search-4YYphs0l.js";function $t(){const{t:u}=O(),{blocklet:h}=K(),{componentDid:s}=B(),w=v(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")||"",C=e.searchParams.get("showFromUrl")!=="false",R=e.searchParams.get("showResourcesSwitch")!=="false",y=e.searchParams.get("enableRunBackground")!=="false",S=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),[b,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=W(o,"/api/store.json"),{data:M}=await L.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=J();return a&&t.connect(),()=>{a&&t.isConnected()&&t.disconnect()}},[a]),d(()=>{window.parent.postMessage({event:"resourceDialog.loaded",componentDid:s},"*")});const c=T(t=>{t.data?.event==="resourceDialog.select"&&t.data?.componentDid===s&&(D(t.data.data),j(t.data.storeUrl))});d(()=>{window.addEventListener("message",c)}),_(()=>{window.removeEventListener("message",c)});const p=({inDialog:t=!0}={})=>l.jsx($,{stores:b,selectedMeta:P,storeUrl:U,resourceType:n,resourceDid:m,mode:"embed",inDialog:t,storageKey:F(`${n}+${m}`),showResourcesSwitch:R,showFromUrl:C,enableRunBackground:y,showCategory:S});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"&&k()},showCloseButton:!0,disableEscapeKeyDown:!0,open:!0,children:p()}):p({inDialog:!1})}export{$t as default};
