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-drLlzTVq.js";import{V as O,aJ as A}from"./vendor-ux-DfSgTRg5.js";import{h as d,b as T,t as _}from"./vendor-hooks-cYMUGE4V.js";import{A as $,S as F}from"./add-component-core-BITgGwN0.js";import{y as K,an as J}from"./index-BHa1_Bjz.js";import"./lottie-web-4koyQiv_.js";import"./item-B3LlwO_A.js";import"./index-DBs9Ljax.js";import"./delete-confirm-HiRqbh9-.js";import"./click-to-copy-B2HIKJMV.js";import"./confirm-DTx9f3Ke.js";import"./session-Cm8j8XeZ.js";import"./get-safe-url-CqAaHb9L.js";import"./did-address-DqhneWXa.js";import"./wait-connect-Be1Dmt0P.js";import"./vendor-arcblock-CPCSE54a.js";import"./launch-result-message-MNpx7ysR.js";import"./page-header-CHAwrgX-.js";import"./engine-BzngvK61.js";import"./config-space-zEV0JkDF.js";import"./spaces-BuZf3GoQ.js";import"./api-C_w0YD2j.js";import"./required-BQln5OcV.js";import"./index-seQ_ufVM.js";import"./Google-Cwpw9PRe.js";import"./cloneDeep-BbaR0xRl.js";import"./create-passport-svg-BQhmIwWD.js";import"./form-wrapper-PT5ZzMQy.js";import"./logo-uploader-BmnoHisE.js";import"./collapse-B7gUzFaX.js";import"./index-B0Q9wWG1.js";import"./config-DuS3gx_m.js";import"./isURL-CASPeQFe.js";import"./section-jXB9AxBb.js";import"./form-text-input-BjQKx89L.js";import"./edit.svg-RRSklUg-.js";import"./index-_tncRnTu.js";import"./useLocalStorage-BV1BIwfo.js";import"./index-BP_Fl0Mu.js";import"./util-DIVJQVg1.js";import"./use-mobile-BINJTzMb.js";import"./content-layout-DmSBGGVm.js";import"./connect-to-eBtGI4_9.js";import"./index-BzU09Azd.js";import"./index-DRYJ0xIl.js";import"./index-BojVbZw0.js";import"./index-CHuKoofS.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};
