import{J as v,j as l}from"./vendor-mui-core-BPQ6AEW_.js";import{j as B,r}from"./vendor-react-CUXIiAnY.js";import{C as W,D as L}from"./vendor-utils-BgSaqjGx.js";import{V as O,b as A}from"./vendor-ux-r9bApERu.js";import{h as d,b as T,m as _}from"./vendor-hooks-PN9SWiQm.js";import{A as $,S as F}from"./add-component-core-CbHQ3LY3.js";import{l as K,I as z}from"./index-DY2wgD65.js";import"./lottie-web-4koyQiv_.js";import"./item-CkQtfUug.js";import"./index-DBs9Ljax.js";import"./delete-confirm-CP7dMVbK.js";import"./click-to-copy-BuSTGPjJ.js";import"./confirm-B8poMcDB.js";import"./session-f4MooMkP.js";import"./get-safe-url-DqysS0i0.js";import"./did-address-j4poFq12.js";import"./wait-connect-DEq0_d-q.js";import"./vendor-arcblock-D8WYBDYe.js";import"./launch-result-message-CO-R7GIB.js";import"./page-header-BkgoSN-0.js";import"./engine-B4EBuR9s.js";import"./config-space-D3N5gAYj.js";import"./spaces-Cgv_XshJ.js";import"./api-uGeIZn4a.js";import"./required-Btg6mEmX.js";import"./index-ROfvHq3O.js";import"./Google-FE-PKKgg.js";import"./cloneDeep-DHlHhGOY.js";import"./create-passport-svg-CIUyZVGt.js";import"./form-wrapper-CU8kJXy5.js";import"./logo-uploader-DY97Qerr.js";import"./collapse-CzqKk-Uw.js";import"./index-Dx6HKVtJ.js";import"./config-NQEwUL-b.js";import"./isURL-C1rexYxN.js";import"./section-Cyr0YvGa.js";import"./form-text-input-Sp9mVO8Z.js";import"./edit.svg-Dz9cVo7r.js";import"./index-BsA1v5Kx.js";import"./useLocalStorage-6wbaKET6.js";import"./index-ySP_m_Ux.js";import"./util-lUirhe3W.js";import"./use-mobile-ajdJIsoX.js";import"./content-layout-B-2tfq3i.js";import"./connect-to-loiyl2FX.js";import"./index-CTf9yUdG.js";import"./index-DRYJ0xIl.js";import"./index-BojVbZw0.js";import"./index-CJ1z6qNA.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};
