import{r as h}from"./vendor-react-CTtPmzVP.js";import{V as x,R as C,W as f}from"./vendor-ux-DjXlxcvL.js";import{c as w,b,a as R}from"./index-CNGNZ6kv.js";import{q as y,J as I,Y as E,Z as T,bF as P,bV as U}from"./index-BEfIUbZC.js";import{j as t,ak as m,T as g,I as q,bO as B,W as r,cq as F}from"./vendor-mui-core-CKKG_1TN.js";import"./index-BB8sYq-N.js";import"./index-BojVbZw0.js";import{u as O}from"./config-space-BZQrckxG.js";import{f as D}from"./index-DBs9Ljax.js";import{a as W,A,z as N}from"./vendor-utils-CUs2ebe7.js";import"./api-B24x7kOD.js";function M(){const{t:e}=x();return t.jsx(m,{children:t.jsxs(m,{sx:{display:"flex",flexDirection:"column",justifyContent:"center",alignItems:"center",alignContent:"center"},children:[t.jsx(w,{style:{width:250,height:250}}),t.jsx(g,{sx:{marginTop:"24px"},children:e("storage.spaces.connect.providerForStorage")})]})})}function j({spaceGateway:e,onDeleteSpace:c=()=>{}}){const{t:n}=x(),[a,l]=h.useState(!1),[o,d]=h.useState(!1),u=(s,p)=>{s?.stopPropagation(),l(p)},i=async s=>{try{s?.stopPropagation(),d(!0),await c(e),l(!1)}catch(p){console.error(p),f.error(`${n("storage.spaces.gateway.delete.failed")}: ${D(p)}`)}finally{d(!1)}};return t.jsxs(t.Fragment,{children:[t.jsx(q,{size:"small",onClick:s=>u(s,!0),children:t.jsx(B,{})}),t.jsx(C,{title:n("storage.spaces.gateway.delete.title"),open:a,confirmButton:{text:n("common.confirm"),props:{size:"small",variant:"contained",color:"error",loading:o}},cancelButton:{text:n("common.cancel"),props:{size:"small",variant:"outlined"}},onConfirm:i,onCancel:s=>u(s,!1),children:t.jsx(g,{sx:{wordWrap:"break-word"},children:n("storage.spaces.gateway.delete.descForStorage",{name:`${e?.name}`})})})]})}j.propTypes={onDeleteSpace:r.func,spaceGateway:r.shape({name:r.string.isRequired,url:r.string.isRequired,protected:r.bool}).isRequired};function S({spaceGateway:e,onDisconnect:c=()=>{}}){const{t:n}=x(),a=async()=>{try{await c(),f.success(n("storage.spaces.gateway.delete.succeeded",{name:e.name?`(${e.name})`:""}))}catch(l){console.error(l),f.error(D(l))}};return t.jsx(j,{spaceGateway:e,onDeleteSpace:a})}S.propTypes={spaceGateway:r.shape({did:r.string.isRequired,name:r.string.isRequired,url:r.string.isRequired,endpoint:r.string.isRequired}).isRequired,onDisconnect:r.func};function Q(){const{t:e}=x(),{spaceGateway:c,settingStorageEndpoint:n}=O();return t.jsxs(m,{sx:{display:"flex",flexDirection:"column"},children:[t.jsx(m,{sx:{display:"flex",flexDirection:"row",alignItems:"center",justifyContent:"space-between"},children:t.jsx(g,{sx:{fontSize:"1rem",fontWeight:"bold"},children:e("storage.spaces.connected.title")})}),t.jsx(m,{children:t.jsx(b,{sx:{marginTop:2},endpoint:c.endpoint,selected:!0,action:a=>t.jsx(S,{...a,onDisconnect:()=>n(null)})})})]})}function $({blocklet:e}){if(W(e))return{};const{appDid:c}=e,n=y.getAppName(e),a=y.getAppDescription(e),o=e?.site?.domainAliases?.sort((i,s)=>i.accessibility.accessible&&s.accessibility.accessible?+i.isProtected-+s.isProtected:+s.accessibility.accessible-+i.accessibility.accessible)?.map(i=>{const s=i?.domainStatus?.isHttps?"https://":"http://",p=i?.value;return`${s}${p}`}).filter(Boolean)?.[0],d=I.DID_SPACES.AUTHORIZE.DEFAULT_SCOPE,u=window.location.href;return{appDid:c,appName:n,appDescription:a,appUrl:o,scopes:d,referrer:u,isReady:!!o}}function v({onConnect:e=()=>{},...c}){const{blocklet:n}=E(),{info:a}=T(),{t:l}=x(),o=$({blocklet:n}),d=P(a),u={checkFn:A.create({baseURL:N(window.location.origin,U())}).get,webWalletUrl:d,extraParams:{appPid:n.appPid,appDid:o.appDid,appName:o.appName,appDescription:o.appDescription,appUrl:o.appUrl,referrer:o.referrer,scopes:o.scopes,nodeDid:a.did}},i=async({spaceGateway:s})=>{try{await e(s),f.success(l("storage.spaces.connectedWithName",{name:s.name}))}catch(p){console.error(p),f.error(D(p))}};return t.jsx(R,{...c,options:u,onSuccess:i})}v.propTypes={onConnect:F.func};export{Q as C,M as D,v as a,$ as u};
