import{r as h}from"./vendor-react-DX7tU9aY.js";import{W as x,R as C,Q as f}from"./vendor-ux-Dl3wVbv_.js";import{c as w,b,a as R}from"./index-Cw8Yly1u.js";import{o as y,G as I,V as E,W as T,b7 as P,bm as U}from"./index-Ca33rdd_.js";import{j as t,al as m,T as g,I as B,bB as q,X as r,cp as W}from"./vendor-mui-core-D7t4vMS5.js";import"./index-BojVbZw0.js";import{u as F}from"./config-space-HmsYCb6s.js";import{f as D}from"./index-DBs9Ljax.js";import{a as N,D as O,z as A}from"./vendor-utils-BzQg432x.js";import"./api-B8JXuhVp.js";function J(){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:i=()=>{}}){const{t:n}=x(),[a,l]=h.useState(!1),[o,d]=h.useState(!1),u=(s,p)=>{s?.stopPropagation(),l(p)},c=async s=>{try{s?.stopPropagation(),d(!0),await i(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(B,{size:"small",onClick:s=>u(s,!0),children:t.jsx(q,{})}),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:c,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:i=()=>{}}){const{t:n}=x(),a=async()=>{try{await i(),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 K(){const{t:e}=x(),{spaceGateway:i,settingStorageEndpoint:n}=F();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:i.endpoint,selected:!0,action:a=>t.jsx(S,{...a,onDisconnect:()=>n(null)})})})]})}function $({blocklet:e}){if(N(e))return{};const{appDid:i}=e,n=y.getAppName(e),a=y.getAppDescription(e),o=e?.site?.domainAliases?.sort((c,s)=>c.accessibility.accessible&&s.accessibility.accessible?+c.isProtected-+s.isProtected:+s.accessibility.accessible-+c.accessibility.accessible)?.map(c=>{const s=c?.domainStatus?.isHttps?"https://":"http://",p=c?.value;return`${s}${p}`}).filter(Boolean)?.[0],d=I.DID_SPACES.AUTHORIZE.DEFAULT_SCOPE,u=window.location.href;return{appDid:i,appName:n,appDescription:a,appUrl:o,scopes:d,referrer:u,isReady:!!o}}function v({onConnect:e=()=>{},...i}){const{blocklet:n}=E(),{info:a}=T(),{t:l}=x(),o=$({blocklet:n}),d=P(a),u={checkFn:O.create({baseURL:A(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}},c=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,{...i,options:u,onSuccess:c})}v.propTypes={onConnect:W.func};export{K as C,J as D,v as a,$ as u};
