import{J as v,j as l}from"./vendor-mui-core-CnXrAOs3.js";import{j as B,r}from"./vendor-react-Dvs43sk9.js";import{C as W,D as L}from"./vendor-utils-cJEl_UEd.js";import{V as O,b as A}from"./vendor-ux-5OlTXZBe.js";import{h as d,b as T,m as _}from"./vendor-hooks-CjESGRlR.js";import{A as $,S as F}from"./add-component-core-CZQBpP2b.js";import{l as K,I as z}from"./index-Cq3xfsOS.js";import"./lottie-web-4koyQiv_.js";import"./item-D48n_jCS.js";import"./index-DBs9Ljax.js";import"./delete-confirm-DwFvaC6s.js";import"./click-to-copy-CzGMi2Jw.js";import"./confirm-D_oS4C5N.js";import"./session-BYq9-2GE.js";import"./get-safe-url-mKD2PdwN.js";import"./did-address-C5FXzeAS.js";import"./wait-connect-BA-9v9IK.js";import"./vendor-arcblock-CqplRmyi.js";import"./launch-result-message-DWeUg9rM.js";import"./page-header-DCvzRay5.js";import"./engine-DXhw4g-J.js";import"./config-space-DVbXpK0p.js";import"./spaces-Bhd_JZon.js";import"./api-Btn0Tp3W.js";import"./required-BGaDOGrj.js";import"./index-phW48DJg.js";import"./Google-BT1deiYa.js";import"./cloneDeep-C6qewg0C.js";import"./create-passport-svg-B2TKOs7K.js";import"./form-wrapper-C8oo_Fdy.js";import"./logo-uploader-D9dqlBcG.js";import"./collapse-BMy0GGFk.js";import"./index-De-Vgsb6.js";import"./config-Bg2nv4Ct.js";import"./isURL-DmCvTfVx.js";import"./section-C75bzkkL.js";import"./form-text-input-B2T0zM2q.js";import"./edit.svg-DycWG9v3.js";import"./index-BPy8_fa2.js";import"./useLocalStorage-CvPFnddH.js";import"./index-DTj7lG0j.js";import"./util-B1w9UqzK.js";import"./use-mobile-maRlSUwU.js";import"./content-layout-oyz1EqNZ.js";import"./connect-to-CK_BBgim.js";import"./index-S8uuD-j6.js";import"./index-DRYJ0xIl.js";import"./index-BojVbZw0.js";import"./index-CsRxFZuh.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",b=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),[y,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=z();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:y,selectedMeta:P,storeUrl:U,resourceType:n,resourceDid:m,mode:"embed",inDialog:t,storageKey:F(`${n}+${m}`),showResourcesSwitch:R,showFromUrl:C,enableRunBackground:b,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};
