import{am as u,an as l,x as s,ao as f,ap as i,aq as m}from"./index-DR3HTfO6.js";import{a as o}from"./api-D3nN3geQ.js";function P(t){const e=t.replace(/\/api\/space\/.+/,""),a=t.replace(/\/$/,"").split("/"),r=a.at(-4),n=a.at(-2);return s(e,"space",r,"apps",n,`explorer?key=/apps/${n}/.did-objects/${n}/`)}function U(t){const e=t.replace(/\/api\/space\/.+/,""),r=t.replace(/\/$/,"").split("/").at(-4);return s(e,"space",r)}function h(t){return t.replace(/\/$/,"").split("/").at(-4)}async function C(t){try{if(!i(t))return!1;const{headers:e}=await o.head(t,{timeout:5e3});return e["x-listable"]==="true"&&e["x-readable"]==="true"&&e["x-writeable"]==="true"}catch(e){return console.error(e),!1}}function L(t){return t?.find(e=>e.key===u.BLOCKLET_CONFIGURABLE_KEY.BLOCKLET_APP_BACKUP_ENDPOINT)?.value||""}function y(t){return t?.replace(/\/api\/space\/.+/,"")}function E(t){const e=new URL(t);return s(e.origin,e.pathname)}async function _(t){try{if(!i(t))return!1;const e=E(t),a=s(e,"space/api/did/one-click-authorization/token"),{status:r,data:n}=await o.get(a,{timeout:5e3});return r===200&&m(n)}catch(e){return console.error(e),!1}}async function w(t,{timeout:e}={timeout:3e3}){try{if(!i(t))return"";const{headers:a}=await o.head(t,{timeout:e}),r=a["x-space-name"];return r?decodeURIComponent(r):""}catch(a){return console.error(a),""}}const A=t=>t?.configs?.find(e=>e.key===u.BLOCKLET_CONFIGURABLE_KEY.BLOCKLET_APP_SPACE_ENDPOINT)?.value||null;async function x(t){const e={};return e.did=h(t),e.name=await w(t),e.url=y(t),e.endpoint=t,e}async function k(t,e={timeout:3e4,withSearchParams:!0}){if(!l(t))throw new Error(`url(${t}) must be a string`);const a=t.startsWith("http")?t:`https://${t}`,r=new URL(a),{data:n}=await o.get(s(r.origin,"/__blocklet__.js?type=json"),{timeout:e.timeout}),c=n.componentMountPoints.findLast(d=>d.did==="z8iZnaYxnkMD5AKRjTKiCb8pQr1ut8UantAcf")?.mountPoint;if(!c)throw new Error(`MountPoint(${c}) not found`);const p=s(r.origin,c);return e.withSearchParams&&r.searchParams.get("spaceDid")?f(p,{spaceDid:r.searchParams.get("spaceDid")}):p}export{k as a,w as b,h as c,U as d,P as e,A as f,L as g,C as h,_ as i,x as j};
