import{G as C,j as t,al as I,ai as E,d$ as N,R as v,a7 as P,X as $}from"./vendor-mui-core-CDEc-eG6.js";import{v as y}from"./index-BEbBg3NW.js";import{n as h,aC as S,y as T,a as U}from"./vendor-utils-_C9URqjS.js";import{bo as q,V as M,X as O,W as z}from"./index-CgSpL7jz.js";import{r as W}from"./base32-Cx5Qjcq5.js";import{r as b}from"./vendor-react-DX7tU9aY.js";import{bj as X,bq as k,b1 as G}from"./vendor-ux-PO0jFgJf.js";import{i as V,b as n,a as H}from"./vendor-hooks-Ca2cSNuD.js";var D,R;function J(){if(R)return D;R=1;const{DEFAULT_IP_DOMAIN_SUFFIX:m,SLOT_FOR_IP_DNS_SITE:r,DEFAULT_DID_DOMAIN:c}=q(),{encode:l}=W();return D={getIpDnsDomainForBlocklet:d=>`${l(d.meta.did)}-${r}.${m}`,getDidDomainForBlocklet:({did:d,didDomain:u=c})=>`${l(d)}.${u}`},D}var K=J();function Q({ref:m=null}){const{t:r}=b.useContext(X),{blocklet:c}=M(),{api:l}=O(),e=V({loadingReject:!1,loadingApprove:!1,mode:"view",show:!1,data:{},callback:h}),d=C()?.transitions?.duration?.leavingScreen||300,u=n(()=>{e.mode="view",e.data={},e.callback=h}),i=n(()=>{e.show=!1,setTimeout(()=>{u()},d)}),F=n(o=>{e.mode="view",e.show=!0,e.data=o}),j=n((o,s=h)=>{e.mode="approve",e.show=!0,e.data=o,e.callback=s});b.useImperativeHandle(m,()=>({open:F,close:i,approve:j}),[F,i,j]);const B=H(()=>{if(!e.show)return[];e.data.migratedFrom=[e.data.appId,e.data.appPid];const o=["appName","appLogo","appId","appPid","migratedFrom","appDescription","appUrl","version","appliedAt","status","serverId","serverVersion"];return e.data.isMaster!==!1&&S(o,"appliedAt","status"),o.map(s=>{const _=r(`federated.info.${s}`);let a=e.data[s];if(s==="appName"&&e.data.isMaster&&(a=t.jsxs(I,{sx:{display:"flex",alignItems:"center",gap:.5},children:[t.jsx(E,{component:N}),a]})),["appId","appPid","serverId"].includes(s)&&(a=t.jsx(k,{children:a})),["appUrl"].includes(s)&&(a=t.jsx(I,{component:"a",href:a,target:"_blank",children:a})),["appLogo"].includes(s)){const g=T(`https://${K.getDidDomainForBlocklet({did:e.data.appPid})}`,z,"/blocklet/logo");try{const p=new URL(g);p.searchParams.set("imageFilter","resize"),p.searchParams.set("w","80"),p.searchParams.set("h","80"),a=t.jsx("img",{src:p.href,width:"60",height:"60",alt:e.data.appName})}catch{a=t.jsx("img",{src:g,width:"60",height:"60",alt:e.data.appName})}}return s==="status"&&(a=a&&r(`federated.status.${a}`)),s==="migratedFrom"&&(a=(e.data.migratedFrom||[]).filter(f=>![e.data.appId,e.data.appPid].includes(f)).map(f=>t.jsx(k,{children:f}))),U(a)&&(a="-"),{name:_,value:a}})},[e.data]),x=e.mode==="approve",w=n(async()=>{try{e.loadingReject=!0,await l.auditFederatedLogin({input:{memberPid:e.data.appPid,did:c.appPid,status:"rejected"}}),i(),e?.callback(!1)}finally{e.loadingReject=!1}}),L=n(async()=>{try{e.loadingApprove=!0,await l.auditFederatedLogin({input:{memberPid:e.data.appPid,did:c.appPid,status:"approved"}}),i(),e?.callback(!0)}finally{e.loadingApprove=!1}});return t.jsx(G,{open:e.show,title:r(x?"federated.approveToJoinLogin":"federated.siteDetail"),onClose:i,actions:x?t.jsxs(t.Fragment,{children:[t.jsxs(v,{color:"error",variant:"contained",onClick:w,disabled:e.loadingReject,children:[e.loadingReject?t.jsx(P,{size:16,color:"grey"}):null,r("common.reject")]}),t.jsxs(v,{variant:"contained",onClick:L,disabled:e.loadingApprove,children:[e.loadingApprove?t.jsx(P,{size:16,color:"grey"}):null,r("common.approve")]})]}):t.jsx(v,{variant:"outlined",onClick:i,children:r("common.close")}),children:B.map(o=>t.jsx(y,{style:{alignItems:"flex-start"},valueComponent:"div",nameWidth:180,name:o.name,children:o.value},o.name))})}Q.propTypes={ref:$.any};export{Q as F};
