import{L as v,j as l}from"./vendor-mui-core-CDEc-eG6.js";import{m as W,r}from"./vendor-react-DX7tU9aY.js";import{y as B,D as L}from"./vendor-utils-_C9URqjS.js";import{W as O,aF as A}from"./vendor-ux-bFYdDLNG.js";import{A as F,S as T}from"./add-component-core-BWViGY-l.js";import{j as d,b as _,y as $}from"./vendor-hooks-BrgYeCrj.js";import{v as K,af as z}from"./index-DGZk149v.js";import"./item-C3aaDA7o.js";import"./index-DBs9Ljax.js";import"./delete-confirm-DS9-TjyF.js";import"./click-to-copy-CH2KjgKM.js";import"./confirm-o5NpDvNJ.js";import"./session-Dxo7LCKC.js";import"./get-safe-url-B1bR9jl-.js";import"./did-address-B_YXB1wQ.js";import"./wait-connect-D16c5vpx.js";import"./vendor-arcblock-DY2miJjh.js";import"./launch-result-message-Br6OdJMs.js";import"./page-header-CEL5h6do.js";import"./engine-B4Mxizj3.js";import"./config-space-B2Ba5sf-.js";import"./spaces-Cf-lxsd-.js";import"./api-Bo6lutcq.js";import"./required-BO8emcue.js";import"./index-C8L5ij1L.js";import"./Google-Cy5TxUZp.js";import"./cloneDeep-D_udiNLL.js";import"./create-passport-svg-BYi3UIaq.js";import"./form-wrapper-BqPFgoVY.js";import"./logo-uploader-d8M822Ti.js";import"./collapse-DRkXbQaT.js";import"./index-B0cxyMBd.js";import"./config-CinJV-4R.js";import"./isURL-CpQHQuaa.js";import"./isIP-BBY240SU.js";import"./section-CC2BHD5s.js";import"./form-text-input-C3xqzm2t.js";import"./edit.svg-BGhTyO6h.js";import"./index-jIvFgWDS.js";import"./index-lPcZKxFP.js";import"./isEqual-BQciOGCh.js";import"./useLocalStorage-b86DqcoU.js";import"./index-DqSGl7ap.js";import"./login-method-item-Bt2OfhXG.js";import"./passkey-rounded-_WDHIZVd.js";import"./util-BVpHGu1Y.js";import"./use-mobile-CnCzXOEv.js";import"./content-layout-D49-hpq6.js";import"./connect-to-BqtlydjT.js";import"./index-cDcYHAdY.js";import"./index-D29L5UKE.js";import"./index-BojVbZw0.js";import"./index-C0DMF4Dq.js";import"./fallback-DtbVvsNl.js";import"./search-4YYphs0l.js";function Ht(){const{t:u}=O(),{blocklet:h}=K(),{componentDid:s}=W(),f=v(t=>t.breakpoints.down("md")),e=new URL(window.location.href),w=e.searchParams.get("mode")==="dialog",n=e.searchParams.get("resourceType")||"",m=e.searchParams.get("resourceDid")||s,g=e.searchParams.get("store")||"",y=e.searchParams.get("showFromUrl")!=="false",R=e.searchParams.get("showResourcesSwitch")!=="false",C=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=B(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 p=_(t=>{t.data?.event==="resourceDialog.select"&&t.data?.componentDid===s&&(D(t.data.data),j(t.data.storeUrl))});d(()=>{window.addEventListener("message",p)}),$(()=>{window.removeEventListener("message",p)});const c=({inDialog:t=!0}={})=>l.jsx(F,{stores:b,selectedMeta:P,storeUrl:U,resourceType:n,resourceDid:m,mode:"embed",inDialog:t,storageKey:T(`${n}+${m}`),showResourcesSwitch:R,showFromUrl:y,enableRunBackground:C,showCategory:S});return w?l.jsx(A,{className:"resource-dialog",title:u("blocklet.publish.addResource"),maxWidth:!1,fullWidth:!1,PaperProps:{style:f?{width:"100%",height:window.innerHeight}:{maxWidth:1350,minWidth:930,width:"80%"}},onClose:(t,o)=>{o!=="backdropClick"&&k()},showCloseButton:!0,disableEscapeKeyDown:!0,open:!0,children:c()}):c({inDialog:!1})}export{Ht as default};
