import{c as w,j as t,dp as _,bk as N,dq as T,dr as U,ds as $,r as P,p as O,aS as z,b6 as M,af as F,ab as y,k as p,bF as q,x as W,W as H,dt as b,bt as V,B as A,du as G,cu as X,aB as j,C as L,o as J}from"./index-DR3HTfO6.js";import{v as K}from"./index-BM-Ox268.js";import{u as Q}from"./blocklet-DX83Lnjp.js";const de=w(t.jsx("path",{d:"m14.06 9.02.92.92L5.92 19H5v-.92zM17.66 3c-.25 0-.51.1-.7.29l-1.83 1.83 3.75 3.75 1.83-1.83c.39-.39.39-1.02 0-1.41l-2.34-2.34c-.2-.2-.45-.29-.71-.29m-3.6 3.19L3 17.25V21h3.75L17.81 9.94z"})),Y=w(t.jsx("path",{d:"M11.99 2C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2m4.24 16L12 15.45 7.77 18l1.12-4.81-3.73-3.23 4.92-.42L12 5l1.92 4.53 4.92.42-3.73 3.23z"}));var Z=Array.prototype,k=Z.splice;function ee(s,a,m,c){var e=N,g=-1,l=a.length,d=s;for(s===a&&(a=_(a));++g<l;)for(var i=0,f=a[g],h=f;(i=e(d,h,i))>-1;)d!==s&&k.call(d,i,1),k.call(s,i,1);return s}function ae(s,a){return s&&s.length&&a&&a.length?ee(s,a):s}var te=T(ae),D,B;function oe(){if(B)return D;B=1;const{DEFAULT_IP_DOMAIN_SUFFIX:s,SLOT_FOR_IP_DNS_SITE:a,DEFAULT_DID_DOMAIN:m}=U(),{encode:c}=$();return D={getIpDnsDomainForBlocklet:l=>`${c(l.meta.did)}-${a}.${s}`,getDidDomainForBlocklet:({did:l,didDomain:d=m})=>`${c(l)}.${d}`},D}var se=oe();function ie({ref:s=null}){const{t:a}=P.useContext(O),{blocklet:m}=Q(),{api:c}=z(),e=M({loadingReject:!1,loadingApprove:!1,mode:"view",show:!1,data:{},callback:F}),l=y()?.transitions?.duration?.leavingScreen||300,d=p(()=>{e.mode="view",e.data={},e.callback=F}),i=p(()=>{e.show=!1,setTimeout(()=>{d()},l)}),f=p(n=>{e.mode="view",e.show=!0,e.data=n}),h=p((n,r=F)=>{e.mode="approve",e.show=!0,e.data=n,e.callback=r});P.useImperativeHandle(s,()=>({open:f,close:i,approve:h}),[f,i,h]);const R=q(()=>{if(!e.show)return[];e.data.migratedFrom=[e.data.appId,e.data.appPid];const n=["appName","appLogo","appId","appPid","migratedFrom","appDescription","appUrl","version","appliedAt","status","serverId","serverVersion"];return e.data.isMaster!==!1&&te(n,"appliedAt","status"),n.map(r=>{const S=a(`federated.info.${r}`);let o=e.data[r];if(r==="appName"&&e.data.isMaster&&(o=t.jsxs(A,{sx:{display:"flex",alignItems:"center",gap:.5},children:[t.jsx(G,{component:Y}),o]})),["appId","appPid","serverId"].includes(r)&&(o=t.jsx(b,{children:o})),["appUrl"].includes(r)&&(o=t.jsx(A,{component:"a",href:o,target:"_blank",children:o})),["appLogo"].includes(r)){const v=W(`https://${se.getDidDomainForBlocklet({did:e.data.appPid})}`,H,"/blocklet/logo");try{const u=new URL(v);u.searchParams.set("imageFilter","resize"),u.searchParams.set("w","80"),u.searchParams.set("h","80"),o=t.jsx("img",{src:u.href,width:"60",height:"60",alt:e.data.appName})}catch{o=t.jsx("img",{src:v,width:"60",height:"60",alt:e.data.appName})}}return r==="status"&&(o=o&&a(`federated.status.${o}`)),r==="migratedFrom"&&(o=(e.data.migratedFrom||[]).filter(x=>![e.data.appId,e.data.appPid].includes(x)).map(x=>t.jsx(b,{children:x}))),V(o)&&(o="-"),{name:S,value:o}})},[e.data]),I=e.mode==="approve",C=p(async()=>{try{e.loadingReject=!0,await c.auditFederatedLogin({input:{memberPid:e.data.appPid,did:m.appPid,status:"rejected"}}),i(),e?.callback(!1)}finally{e.loadingReject=!1}}),E=p(async()=>{try{e.loadingApprove=!0,await c.auditFederatedLogin({input:{memberPid:e.data.appPid,did:m.appPid,status:"approved"}}),i(),e?.callback(!0)}finally{e.loadingApprove=!1}});return t.jsx(X,{open:e.show,title:a(I?"federated.approveToJoinLogin":"federated.siteDetail"),onClose:i,actions:I?t.jsxs(t.Fragment,{children:[t.jsxs(j,{color:"error",variant:"contained",onClick:C,disabled:e.loadingReject,children:[e.loadingReject?t.jsx(L,{size:16,color:"grey"}):null,a("common.reject")]}),t.jsxs(j,{variant:"contained",onClick:E,disabled:e.loadingApprove,children:[e.loadingApprove?t.jsx(L,{size:16,color:"grey"}):null,a("common.approve")]})]}):t.jsx(j,{variant:"outlined",onClick:i,children:a("common.close")}),children:R.map(n=>t.jsx(K,{style:{alignItems:"flex-start"},valueComponent:"div",nameWidth:180,name:n.name,children:n.value},n.name))})}ie.propTypes={ref:J.any};export{de as E,ie as F,Y as S};
