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-CxWN1dT3.js";import{V as O,aK as A}from"./vendor-ux-DTEmWsko.js";import{h as d,b as K,t as T}from"./vendor-hooks-qxhUUbW5.js";import{A as _,S as $}from"./add-component-core-DB6FFHib.js";import{y as F,ao as z}from"./index-BZxsCCR_.js";import"./lottie-web-4koyQiv_.js";import"./item-Sc9nk8VE.js";import"./index-DBs9Ljax.js";import"./delete-confirm-CRZxojEX.js";import"./click-to-copy-Y_g1bzK1.js";import"./confirm-CkoSEAQA.js";import"./session-DwQKgNVz.js";import"./get-safe-url-D4mirsKD.js";import"./did-address-CQO2MAbB.js";import"./wait-connect-CBmpE7OF.js";import"./vendor-arcblock-CIBaEWEy.js";import"./launch-result-message-MNpx7ysR.js";import"./page-header-CHAwrgX-.js";import"./engine-D3NlocNz.js";import"./config-space-LrsWMRQl.js";import"./spaces-DBCz6tUn.js";import"./api-FQQlzPOP.js";import"./required-BQln5OcV.js";import"./index-D5sBpp1t.js";import"./Google-DPANLEPw.js";import"./cloneDeep-C2rlAYcK.js";import"./create-passport-svg-DXpLsb6S.js";import"./form-wrapper-PT5ZzMQy.js";import"./logo-uploader-BksS6OGe.js";import"./collapse-B7gUzFaX.js";import"./index-B0Q9wWG1.js";import"./config-ZxMxtwH7.js";import"./isURL-4Bkt0jKV.js";import"./section-jXB9AxBb.js";import"./form-text-input-DlypNadC.js";import"./edit.svg-RRSklUg-.js";import"./index-_tncRnTu.js";import"./useLocalStorage-DzhcQ3lj.js";import"./index-icvBZv9S.js";import"./util-BYnhSg2W.js";import"./use-mobile-BINJTzMb.js";import"./content-layout-DmSBGGVm.js";import"./connect-to-Bimfzs2e.js";import"./index-CnCY99ka.js";import"./index-DRYJ0xIl.js";import"./index-BojVbZw0.js";import"./index-BqdvWprH.js";import"./search-4YYphs0l.js";function _t(){const{t:u}=O(),{blocklet:h}=F(),{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=z();return a&&t.connect(),()=>{a&&t.isConnected()&&t.disconnect()}},[a]),d(()=>{window.parent.postMessage({event:"resourceDialog.loaded",componentDid:s},"*")});const c=K(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:$(`${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};
