import{J as v,j as l}from"./vendor-mui-core-CKKG_1TN.js";import{m as B,r}from"./vendor-react-CTtPmzVP.js";import{z as W,A}from"./vendor-utils-CUs2ebe7.js";import{V as L,a_ as O}from"./vendor-ux-DjXlxcvL.js";import{h as d,b as _,r as T}from"./vendor-hooks-DQAdyHrE.js";import{A as $,S as F}from"./add-component-core-DXBsHpN1.js";import{y as K,an as z}from"./index-BEfIUbZC.js";import"./lottie-web-4koyQiv_.js";import"./item-BabsiwzU.js";import"./index-DBs9Ljax.js";import"./delete-confirm-BLy-Oo1o.js";import"./click-to-copy-Dk6ZAJOw.js";import"./confirm-D6AvlbAp.js";import"./session-Cin9Rizr.js";import"./get-safe-url-DxqVk96E.js";import"./did-address-Cq16cwTy.js";import"./wait-connect-TKbZWSFd.js";import"./vendor-arcblock-BCP2x3BR.js";import"./launch-result-message-C04PaKk0.js";import"./page-header-BZv-tfgN.js";import"./engine-DOYgeVKF.js";import"./config-space-BZQrckxG.js";import"./spaces-DghHe7uP.js";import"./api-B24x7kOD.js";import"./required-DHjZE3-Y.js";import"./index-BrDWLIA2.js";import"./Google-JbLVL0lz.js";import"./cloneDeep-rgNCMFod.js";import"./create-passport-svg-DeDfPZeD.js";import"./form-wrapper-pwkkz4we.js";import"./logo-uploader-DEFzQY0j.js";import"./collapse-D72lnPa9.js";import"./index-oucqu2vy.js";import"./config-CoSaZVwp.js";import"./isURL-vNa-ZfGd.js";import"./section-CenHBXqj.js";import"./form-text-input-BsCymY_c.js";import"./edit.svg-CTE5eATX.js";import"./index-_tncRnTu.js";import"./useLocalStorage-Brr2PSz9.js";import"./index-BSZ3mQac.js";import"./util-CMCJQTXJ.js";import"./use-mobile-_vjPRYx2.js";import"./content-layout-Dtfb5X6M.js";import"./connect-to-CVH3cw77.js";import"./index-CNGNZ6kv.js";import"./index-DRYJ0xIl.js";import"./index-BojVbZw0.js";import"./index-BB8sYq-N.js";import"./search-4YYphs0l.js";function $t(){const{t:u}=L(),{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")||"",R=e.searchParams.get("showFromUrl")!=="false",y=e.searchParams.get("showResourcesSwitch")!=="false",C=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 A.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)}),T(()=>{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:y,showFromUrl:R,enableRunBackground:C,showCategory:S});return f?l.jsx(O,{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};
