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-D5UG1a5Y.js";import{V as O,aU as A}from"./vendor-ux-DMZIE6wA.js";import{h as d,b as T,t as _}from"./vendor-hooks-BZ19vVZ7.js";import{A as $,S as F}from"./add-component-core-CNH5E2RR.js";import{y as K,an as z}from"./index-DwyzCfdd.js";import"./lottie-web-4koyQiv_.js";import"./item-DfQKizv4.js";import"./index-DBs9Ljax.js";import"./delete-confirm-L0HXJtqt.js";import"./click-to-copy-CwdgHxjB.js";import"./confirm-Bpit6U3-.js";import"./session-Des-0R_y.js";import"./get-safe-url-gaxZoVzJ.js";import"./did-address-uvYuZ4wv.js";import"./wait-connect-D2wPrbE3.js";import"./vendor-arcblock-DkdOhPyM.js";import"./launch-result-message-MNpx7ysR.js";import"./page-header-CHAwrgX-.js";import"./engine-DWk3y4cO.js";import"./config-space-Dw6ITGIj.js";import"./spaces-2YPkTkBR.js";import"./api-C75sLx9p.js";import"./required-BQln5OcV.js";import"./index-lK6Pf_qM.js";import"./Google-DA3WTnLE.js";import"./cloneDeep-B_fYlLpl.js";import"./create-passport-svg-DGPNsGUE.js";import"./form-wrapper-PT5ZzMQy.js";import"./logo-uploader-TLOlwvRt.js";import"./collapse-B7gUzFaX.js";import"./index-B0Q9wWG1.js";import"./config-BkqISfFO.js";import"./isURL-ZFgr0DWl.js";import"./section-jXB9AxBb.js";import"./form-text-input-B_h8beXh.js";import"./edit.svg-RRSklUg-.js";import"./index-_tncRnTu.js";import"./useLocalStorage-Bj52e1ZW.js";import"./index-CaTDaKrX.js";import"./util-DXf_zMuU.js";import"./use-mobile-BINJTzMb.js";import"./content-layout-DmSBGGVm.js";import"./connect-to-BsxW3JJi.js";import"./index-OMkyTUNX.js";import"./index-DRYJ0xIl.js";import"./index-BojVbZw0.js";import"./index-D29her4n.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=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: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};
