import{J as v,j as l}from"./vendor-mui-core-B5XNUjey.js";import{j as B,r}from"./vendor-react-CUXIiAnY.js";import{C as W,D as L}from"./vendor-utils-CFxoplqC.js";import{V as O,b as A}from"./vendor-ux-BX9dSNUy.js";import{h as d,b as T,m as _}from"./vendor-hooks-U4TTuKG0.js";import{A as $,S as F}from"./add-component-core-CFL73x1V.js";import{l as K,I as z}from"./index-Dijoh4El.js";import"./lottie-web-4koyQiv_.js";import"./item-Bpf_gGYt.js";import"./index-DBs9Ljax.js";import"./delete-confirm-DSQSBte5.js";import"./click-to-copy-DXHOGoUP.js";import"./confirm-BIsS5xyi.js";import"./session-DUT2afHJ.js";import"./get-safe-url-pZvXlaJu.js";import"./did-address-Qmm0nyiR.js";import"./wait-connect-CCXiMHZY.js";import"./vendor-arcblock-D4Rvz_D3.js";import"./launch-result-message-BTBdTioQ.js";import"./page-header-Cgwo2np-.js";import"./engine-Cx3nUUOw.js";import"./config-space-3dNLmLWy.js";import"./spaces-DM95DgFM.js";import"./api-Cjc501Es.js";import"./required-B0Gua-D1.js";import"./index-RxqUBm3A.js";import"./Google-qCiUM9VP.js";import"./cloneDeep-DjDct56M.js";import"./create-passport-svg-BwqsyTOz.js";import"./form-wrapper-dz0PgYyA.js";import"./logo-uploader-CMuaTg_2.js";import"./collapse-DRXViE1U.js";import"./index-Dnont80V.js";import"./config-CwbUhIlW.js";import"./isURL-wZZwzwyC.js";import"./section-BkMzBpvM.js";import"./form-text-input-CbjI2VZQ.js";import"./edit.svg-Dz9cVo7r.js";import"./index-BsA1v5Kx.js";import"./useLocalStorage-oIIa9C3F.js";import"./index-BjLM8Gon.js";import"./util-BxX0TJKJ.js";import"./use-mobile-Vtj5nBdp.js";import"./content-layout-B5NObRcH.js";import"./connect-to-D3C0j8V8.js";import"./index-DHn4LCaq.js";import"./index-DRYJ0xIl.js";import"./index-BojVbZw0.js";import"./index-C0q1NhNR.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};
