import{r as b,g as _e,a as $e}from"./vendor-react-DX7tU9aY.js";import{i as qe,r as V}from"./vendor-hooks-Ca2cSNuD.js";import{j as e,al as t,aT as _,b3 as G,a7 as F,b4 as Ue,an as H,bd as He,V as Ge,T as B,a4 as Ke,X as S,A as M,M as Z,I as O,e0 as ge,cu as ye,C as Ye,y as Ve,cq as Ze,cr as J,c3 as Xe,F as Qe,bN as Je,s as es}from"./vendor-mui-core-CDEc-eG6.js";import{aa as A,b1 as W,br as ss,b3 as ae,bA as ee,a3 as D,bk as L,b2 as re,ce as je,W as ts,bp as as,bS as rs}from"./vendor-ux-PO0jFgJf.js";import{X as P,A as os,M as be,cQ as se,cR as ns,E as Q,V as is,n as ls,F as cs,at as ds,e as Y,cE as ps,cF as us,cG as ms,cN as fs}from"./index-CgSpL7jz.js";import{W as oe}from"./did-address-BNKX5oDP.js";import{b as z}from"./team-Bso_Sjaa.js";import{r as ne,a as ie,b as le,c as ve,d as X,e as xs,u as hs,f as gs}from"./passport-item-CeYGFFGn.js";import{p as Se}from"./util-CIgNPQhV.js";import{u as ys}from"./use-mobile-CnCzXOEv.js";import{O as U}from"./index-BY7bAdcP.js";import{w as $,P as js}from"./permission-C2bdzuoM.js";import{C as bs}from"./Google-BpkBLSiL.js";import{c as vs}from"./create-passport-svg-DNOT-xbE.js";import{A as Ss}from"./vendor-arcblock-BVQTtbN-.js";import{A as K,aD as Cs}from"./vendor-utils-_C9URqjS.js";import{e as Ce}from"./edit.svg-BGhTyO6h.js";import{h as ce,b as ws}from"./index-BaK_cJO7.js";import{C as we}from"./confirm-DhDNorbd.js";import{L as Te}from"./list-header-BKicL0iB.js";import{f as te}from"./index-DBs9Ljax.js";import{u as Ts}from"./useSetState-CUbypYGT.js";import"./session-BEf_KK-i.js";import"./purify.es-HRjpPm7y.js";import"./wallet-hidden-topbar-CZaZNW94.js";import"./theme-mode-toggle-WRMGhjzA.js";import"./use-mobile-DKWj9MJD.js";import"./index-BLYrVxV3.js";import"./isURL-CpQHQuaa.js";import"./isIP-BBY240SU.js";import"./use-blocklet-logo-nVOJALp0.js";import"./use-app-logo-DcBQK--f.js";import"./ua-parser-D6QF1h5N.js";import"./base32-Cx5Qjcq5.js";import"./cloneDeep-D_udiNLL.js";import"./lock.svg-BOhdQlHW.js";const me="info";function Ie({createPassportSvg:c,passport:s,onCancel:p,onSwitchPassport:u=()=>{}}){const{t:f}=A(),i=qe({tab:me}),d={info:{label:f("common.basicInfo"),value:me,component:()=>e.jsx(De,{passport:s,createPassportSvg:c})},logs:{label:f("common.logs"),value:"logs",component:()=>e.jsx(Re,{passport:s})},related:{label:f("team.passport.related"),value:"related",component:()=>e.jsx(Ae,{passport:s,onSwitchPassport:u})}},l=Object.values(d).map(({label:h,value:m})=>({label:h,value:m})).filter(h=>h.value==="related"?s.parentDid:!0),r=d[i.tab]||d.info,n=h=>{i.tab=h};return e.jsx(W,{title:f("common.passport"),onClose:p,open:!0,PaperProps:{style:{maxWidth:800,minHeight:"80vh"}},fullWidth:!0,children:e.jsxs(Is,{children:[e.jsx(t,{className:"tabs",children:e.jsx(ss,{tabs:l,current:i.tab,onChange:n,scrollButtons:"auto"})}),e.jsx(t,{className:"body",children:e.jsx(r.component,{})})]})})}Ie.propTypes={createPassportSvg:S.func.isRequired,passport:S.object.isRequired,onCancel:S.func.isRequired,onSwitchPassport:S.func};const Is=_(t)`
  margin-top: -16px;

  .tabs {
    margin-left: 0;
    margin-right: 0;
  }

  .body {
    margin-top: 24px;
  }
`;function De({createPassportSvg:c,passport:s}){const{t:p,locale:u}=A(),{teamDid:f}=z(),{inService:i}=P(),d=ys(),l=[{items:[{label:p("common.role"),content:ne(s.title)},{label:p("common.did"),content:e.jsx(oe,{did:s.id})},{label:p("team.passport.status"),content:le(s.status)},{label:p("common.type"),content:e.jsx(t,{sx:{display:"flex",gap:1,flexWrap:"wrap"},children:(s.type||[]).map(n=>e.jsx(Ge,{label:n,variant:"outlined",size:"small",sx:{borderRadius:1}},n))})}]}],r=[{title:p("team.passport.owner"),items:[{label:p("team.passport.owner"),content:e.jsx(t,{children:ie(s.user,i)})}]},{title:p("common.timeInfo"),items:[{label:p("team.passport.issuanceTime"),content:s.issuanceDate?e.jsx(ee,{value:s.issuanceDate,type:"all",locale:u}):"-"},{label:p("team.member.lastLogin"),content:s.lastLoginAt?e.jsx(ee,{value:s.lastLoginAt,type:"all",locale:u}):"-"},{label:p("common.expires"),content:s.expirationDate?e.jsx(ee,{value:s.expirationDate,type:"all",locale:u}):"-"}]},{title:p("blocklet.overview.source"),items:[{label:p("blocklet.overview.source"),content:X(s.source)}]}];return e.jsxs(Ds,{gap:3,children:[e.jsxs(t,{sx:{display:"flex",flexDirection:d?"column":"row",alignItems:d?"flex-start":"center",justifyContent:d?"center":"flex-start",width:"100%",overflow:"hidden",gap:d?2:4},children:[e.jsx(t,{sx:{display:"flex",width:"180px"},className:"passport-image",dangerouslySetInnerHTML:{__html:c({scope:s.scope,role:s.role,title:s.scope==="kyc"?s.name:s.title,issuer:s.issuer&&s.issuer.name,issuerDid:s.issuer&&s.issuer.id,ownerName:s.user?.fullName,ownerDid:s.user?.did,ownerAvatarUrl:s.user?.avatar?Se(s.user?.avatar,f,i):"",revoked:s.revoked,extra:s?.expirationDate?{key:"Exp",value:be(s.expirationDate).format("YYYY-MM-DD HH:mm:ss")}:null})}}),e.jsx(t,{className:"info-area",children:l.map(n=>e.jsxs(t,{children:[n.title&&e.jsx(B,{variant:"h6",sx:{mb:2},children:n.title}),e.jsx(t,{className:"info-grid",sx:{gap:"12px !important"},children:n.items.map(h=>e.jsxs(t,{className:"info-item",children:[e.jsx(t,{className:"info-label",sx:{maxWidth:40},children:e.jsx(B,{variant:"subtitle2",color:"textSecondary",children:h.label})}),e.jsx(t,{sx:{display:"flex",flexWrap:"wrap",gap:.5,minWidth:0},children:h.content})]},h.label))})]},n.title))})]}),e.jsx(Ke,{}),e.jsx(t,{className:"info-area",children:r.map(n=>e.jsxs(t,{children:[e.jsx(B,{variant:"h5",sx:{mb:1.5},children:n.title}),e.jsx(t,{className:"info-grid",children:n.items.map(h=>e.jsxs(t,{className:"info-item",children:[e.jsx(t,{className:"info-label",children:e.jsx(B,{variant:"subtitle2",color:"textSecondary",children:h.label})}),e.jsx(t,{sx:{minWidth:500},children:h.content})]},h.label))})]},n.title))})]})}De.propTypes={passport:S.object.isRequired,createPassportSvg:S.func.isRequired};const Ds=_(G)`
  .info-card {
    margin-bottom: 24px;
    overflow: hidden;
  }

  .card-content {
    display: flex;
    gap: 32px;
    padding: 24px;
  }

  .passport-image {
    flex-shrink: 0;
    transition: transform 0.2s ease-in-out;
    cursor: pointer;

    &:hover {
      transform: scale(1.05);
    }
  }

  .info-area {
    flex: 1;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow: auto;
  }

  .info-header {
    padding-bottom: 16px;
    border-bottom: 1px solid;
    border-color: ${({theme:c})=>c.palette.divider};
  }

  .info-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .info-item {
    display: flex;
    gap: 8px;
  }

  .info-label {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100px;
  }

  .logs-card {
    .card-header {
      display: flex;
      align-items: center;
      gap: 8px;
      padding: 16px 24px;
      border-bottom: 1px solid;
      border-color: ${({theme:c})=>c.palette.divider};
    }

    .MuiTimeline-root {
      padding: 24px;
    }

    .MuiTimelineContent-root {
      padding: 0px 16px;
    }

    .MuiTimelineDot-root {
      margin: 0;
    }
  }
`,Pe=10,ke=1;function Re({passport:c}){const{api:s}=P(),{teamDid:p}=z(),{t:u,locale:f}=A(),[i,d]=b.useState({pageSize:Pe,page:ke}),{data:l,loading:r}=V(async()=>{const x={teamDid:p,query:{passportId:c.id},paging:{page:i.page,pageSize:i.pageSize}},a=await s.getPassportLogs({input:x});return{logs:a.passportLogs||[],total:a.paging.total}},{refreshDeps:[i.page,i.pageSize],onError:x=>D.error(x.message)}),n=b.useMemo(()=>l?.logs||[],[l?.logs]),h=x=>x.action===se.APPROVE||x.action===se.REVOKE?x?.metadata?.operator?.fullName?`${u("common.operator")}: ${x?.metadata?.operator?.fullName}`:null:x.action===se.ISSUE&&x.metadata?.action===ns.ISSUE_ON_INVITE?x?.metadata?.inviter?.fullName?`${u("common.inviter")}: ${x?.metadata?.inviter?.fullName}`:null:`passportId: ${x.passportId}`,m=b.useMemo(()=>[{label:u("common.action"),name:"action",options:{customBodyRender:(x,{rowIndex:a})=>{const o=n[a];return e.jsx(H,{title:h(o),children:`${x} ${o.metadata?.action?`(${o.metadata.action})`:""}`})}}},{label:"IP",name:"operatorIp",options:{customBodyRender:x=>e.jsx(t,{sx:{display:"flex",alignItems:"center",gap:1},children:e.jsx("span",{children:x||"-"})})}},{label:"UA",width:250,name:"operatorUa",options:{customBodyRender:(x,{rowIndex:a})=>{const o=n[a];return e.jsxs(t,{sx:{display:"flex",alignItems:"center",gap:1},children:[o.operatorUa&&e.jsx(t,{children:xs(o.operatorUa)}),o.operatorUa&&e.jsx(H,{title:o.operatorUa,children:e.jsx(He,{fontSize:"small",color:"action",sx:{fontSize:16,cursor:"pointer"}})})]})}}},{label:u("common.createdAt"),name:"createdAt",options:{customBodyRender:x=>os(x,f)}}],[u,f,n]),g=({page:x,rowsPerPage:a})=>{i.pageSize!==a?d(o=>({...o,pageSize:a,page:1})):i.page!==x+1&&d(o=>({...o,page:x+1}))},T={sort:!1,download:!1,filter:!1,print:!1,viewColumns:!1,search:!1,page:i.page-1,rowsPerPage:i.pageSize,count:l?.total||0};return r?e.jsx(t,{sx:{py:2},children:e.jsx(G,{direction:"row",spacing:1,sx:{position:"relative",pb:2},children:e.jsx(F,{})})}):e.jsx(t,{children:e.jsx(ae,{className:"logs-table",verticalKeyWidth:100,locale:f,data:n,columns:m,options:T,loading:r,onChange:g})})}Re.propTypes={passport:S.object.isRequired};function Ae({passport:c,onSwitchPassport:s}){const{api:p}=P(),{teamDid:u}=z(),{t:f,locale:i}=A(),[d,l]=b.useState({pageSize:Pe,page:ke}),{data:r,loading:n}=V(async()=>{const a={teamDid:u,passportId:c.parentDid,paging:{page:d.page,pageSize:d.pageSize}},o=await p.getRelatedPassports({input:a});return{passports:o.passports||[],total:o.paging.total}},{refreshDeps:[d.page,d.pageSize],onError:a=>D.error(a.message)}),h=b.useMemo(()=>r?.passports||[],[r?.passports]),m=b.useMemo(()=>[{label:f("team.passport.role"),name:"role",options:{customBodyRender:ne}},{label:f("team.passport.owner"),name:"user",options:{customBodyRender:ie}},{label:f("team.passport.status"),name:"status",options:{customBodyRender:le}},{label:f("team.member.lastLogin"),name:"lastLoginAt",options:{customBodyRender:a=>ve(a,i)}},{label:f("blocklet.overview.source"),name:"source",options:{customBodyRender:X}}],[f,i]),g=({page:a,rowsPerPage:o})=>{d.pageSize!==o?l(v=>({...v,pageSize:o,page:1})):d.page!==a+1&&l(v=>({...v,page:a+1}))},T=b.useRef(null),x={sort:!1,download:!1,filter:!1,print:!1,viewColumns:!1,search:!1,page:d.page-1,rowsPerPage:d.pageSize,count:r?.total||0,onRowClick(a,{dataIndex:o},v){if(T.current?.contains(v.target)){const j=h[o];s(j)}}};return n?e.jsx(t,{sx:{py:2},children:e.jsx(G,{direction:"row",spacing:1,sx:{position:"relative",pb:2},children:e.jsx(F,{})})}):e.jsxs(G,{spacing:1,children:[e.jsx(Ue,{severity:"warning",children:f("team.passport.relatedDescription")}),e.jsx(t,{ref:T,sx:{".MuiTableRow-root":{cursor:"pointer"}},children:e.jsx(ae,{className:"related-table",verticalKeyWidth:100,locale:i,data:h.filter(a=>a.id!==c.id),columns:m,options:x,loading:n,onChange:g})})]})}Ae.propTypes={passport:S.object.isRequired,onSwitchPassport:S.func.isRequired};function de({onCancel:c,onSuccess:s}){const{api:p}=P(),{blocklet:u}=is(),{t:f}=A(),[i,d]=b.useState(!1),l=(u.environments.find(g=>g.key==="BLOCKLET_PASSPORT_COLOR")||{}).value||"auto",r=l==="auto"?Ss(u.appDid):l,[n,h]=b.useState(r),m=async()=>{const g=[{key:cs.BLOCKLET_CONFIGURABLE_KEY.BLOCKLET_PASSPORT_COLOR,value:n}];try{d(!0),await p.configBlocklet({input:{did:u.meta.did,configs:g}}),s()}catch(T){D.error(T.message)}finally{d(!1)}};return e.jsx(W,{title:f("team.passport.color"),onClose:c,open:!0,fullWidth:!0,actions:e.jsxs(e.Fragment,{children:[e.jsx(L,{onClick:c,color:"inherit",children:f("common.cancel")}),e.jsxs(L,{onClick:m,color:"primary",disabled:i,variant:"contained",autoFocus:!0,"data-cy":"color-btn-confirm",children:[i&&e.jsx(F,{size:16}),f("common.save")]})]}),children:e.jsxs(t,{className:"dialog-content",sx:{display:"flex",justifyContent:"center",alignItems:"center"},children:[e.jsx(bs,{disableAlpha:!0,color:n,onChange:g=>h(g.hex)}),e.jsx("div",{style:{width:220,marginLeft:24},dangerouslySetInnerHTML:{__html:vs({scope:"passport",role:"owner",title:"Owner",issuer:ls.getDisplayName(u),issuerDid:u.appDid,ownerName:"Your Name",ownerDid:u.appDid,preferredColor:n})}})]})})}const Ps=$(de,"mutate_team"),ks=$(de,"",Q);function Rs(c){const{inService:s}=P();return s?e.jsx(ks,{...c}):e.jsx(Ps,{...c})}de.propTypes={onCancel:S.func.isRequired,onSuccess:S.func.isRequired};var Ne=function(s){return e.jsx("svg",{...s,children:e.jsx("path",{d:"M64.707 8.707a1 1 0 0 0 0-1.414L58.343.929a1 1 0 1 0-1.414 1.414L62.586 8l-5.657 5.657a1 1 0 0 0 1.414 1.414l6.364-6.364ZM0 9h64V7H0v2Z",fill:"#666"})})};Ne.defaultProps={width:"65",height:"16",fill:"none",xmlns:"http://www.w3.org/2000/svg"};const As=(c,s)=>c?!s.some(p=>!p.from.passport||!p.to.role):!1;function Le({onCancel:c,onSuccess:s,data:p={},trustedPassports:u=[]}){const{api:f}=P(),{roles:i,teamDid:d}=z(),{t:l}=A(),[r,n]=b.useState(!1),[h,m]=b.useState(p.issuerDid||""),[g,T]=b.useState(p.remark||""),[x,a]=b.useState(K(p.mappings)||[]),o=u.findIndex(j=>j.issuerDid===p.issuerDid),v=async()=>{if(r)return;const j={issuerDid:h,remark:g,mappings:x.map(w=>({...w,to:{...w.to,ttl:w.to.ttl||0}}))},C=[...u];o===-1?C.unshift(j):C[o]=j;try{n(!0),await f.configTrustedPassports({input:{teamDid:d,trustedPassports:C}}),await Y(800),n(!1),D.success(l("common.saveSuccess")),s()}catch(w){n(!1),D.error(te(w))}};return e.jsx(W,{title:l("team.passport.trustedIssuers"),open:!0,showCloseButton:!1,PaperProps:{style:{minHeight:"80vh"}},fullWidth:!0,prepend:e.jsx(O,{onClick:c,"data-cy":"trusted-issuer-close",size:"large",children:e.jsx(ge,{})}),actions:e.jsxs(e.Fragment,{children:[e.jsx(L,{onClick:c,color:"inherit",children:l("common.cancel")}),e.jsxs(L,{onClick:()=>v(),color:"primary",disabled:!As(h,x)||!g||r,variant:"contained",autoFocus:!0,"data-cy":"save-mapping",children:[r&&e.jsx(F,{size:16}),l("common.save")]})]}),children:e.jsx(Ns,{children:e.jsxs("div",{className:"dialog-content",children:[e.jsx(M,{fullWidth:!0,"data-cy":"input-issuer-did",placeholder:l("team.passport.issuerDid"),value:h,onChange:j=>{m(j.target.value)}}),e.jsx(M,{style:{marginTop:16},fullWidth:!0,"data-cy":"input-issuer-remark",placeholder:l("common.remark"),value:g,onChange:j=>{T(j.target.value)}}),e.jsxs(t,{sx:{mt:"30px",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e.jsx(t,{className:"dialog-h1",children:l("team.passport.mappingRule")}),e.jsx(t,{children:e.jsx(L,{variant:"outlined",color:"primary","data-cy":"add-mapping",onClick:()=>{a(j=>{const C=[...j];return C.unshift({from:{passport:""},to:{role:ds.GUEST}}),C})},children:l("team.add")})})]}),e.jsxs(t,{className:"list",sx:{mt:-.5},children:[x.map((j,C)=>e.jsxs(t,{className:"mapping-item",sx:{display:"flex",alignItems:"center",justifyContent:"space-between",my:1},children:[e.jsxs(t,{sx:{display:"flex",alignItems:"center",flexGrow:1},children:[e.jsx(t,{sx:{flexGrow:1,flexBasis:1},children:e.jsx(M,{fullWidth:!0,size:"small","data-cy":`input-${C}-from`,placeholder:"Issuer’s Passport Name/ID *",value:j.from.passport,onChange:w=>{const{value:k}=w.target;a(N=>{const q=[...N];return q[C].from.passport=k,q})},sx:{"& .MuiInputBase-input::placeholder":{fontSize:14},"& .Mui-focused .MuiOutlinedInput-notchedOutline":{borderColor:"primary.main"}}})}),e.jsx(t,{sx:{flexShrink:0,mx:1,width:65,height:16},children:e.jsx(Ne,{})}),e.jsx(t,{sx:{flexGrow:1,flexBasis:1},children:e.jsx(M,{fullWidth:!0,size:"small",select:!0,value:j.to.role,onChange:w=>{a(k=>{const N=[...k];return N[C].to.role=w.target.value,N})},variant:"outlined",children:i.filter(w=>w.name!=="owner").map(w=>e.jsx(Z,{value:w.name,"data-cy":`passport-mapping-select-option-${w.name}`,children:e.jsx("span",{children:w.title||w.name})},w.name))})})]}),e.jsx(t,{sx:{flexShrink:0},children:e.jsx(O,{onClick:()=>{a(w=>{const k=[...w];return k.splice(C,1),k})},size:"large",children:e.jsx(ce,{})})})]},`mapping-${C}`)),!x.length&&e.jsx(t,{sx:{my:2,color:"text.secondary",fontSize:"16px"},children:e.jsx(re,{children:l("common.empty")})})]})]})})})}Le.propTypes={onCancel:S.func.isRequired,onSuccess:S.func.isRequired,trustedPassports:S.array,data:S.object};const Ns=_.div`
  .dialog-h1 {
    font-size: 18px;
  }

  .list {
    .MuiIconButton-root {
      svg {
        fill: #bfbfbf;
      }
    }
  }
`;function pe({onCancel:c,hasPermission:s=!1}){const{api:p}=P(),{teamDid:u,trustedPassports:f}=z(),{t:i}=A(),[d,l]=b.useState(null),[r,n]=b.useState(!1),[h,m]=b.useState(!1),[g,T]=b.useState(""),x=async o=>{if(r)return;const v=f.findIndex(C=>C.issuerDid===o);v===-1&&D.error("Cannot find passports");const j=[...f];j.splice(v,1);try{n(!0),await p.configTrustedPassports({input:{teamDid:u,trustedPassports:j}}),await Y(800),n(!1),D.success(i("common.saveSuccess")),l(!1)}catch(C){n(!1),D.error(C.message)}},a=f.filter(o=>!g||o.issuerDid.toLowerCase().includes(g.toLowerCase()));return e.jsxs(W,{title:i("team.passport.trustedIssuers"),open:!0,onClose:c,fullWidth:!0,PaperProps:{style:{minHeight:"80vh"}},children:[e.jsx(Es,{children:e.jsxs("div",{className:"dialog-content",children:[e.jsx("div",{className:"dialog-h1",children:i("team.passport.trustedPassportIssuers")}),e.jsx(Te,{sx:{mt:3},actions:e.jsxs(e.Fragment,{children:[e.jsx(je,{options:{searchPlaceholder:i("team.passport.searchIssuerDid"),searchDebounceTime:600},search:g,searchText:g,searchTextUpdate:T,searchClose:()=>T(""),onSearchOpen:()=>{}}),s&&e.jsxs(L,{variant:"contained",color:"primary","data-cy":"add-trusted-issuer",onClick:()=>m({mode:"add"}),children:[e.jsx(ye,{style:{fontSize:16,marginRight:4}}),i("team.add")]})]})}),e.jsxs("div",{className:"list",children:[a.map(o=>e.jsxs(t,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mt:"20px"},children:[e.jsxs(t,{sx:{flexShrink:0},children:[e.jsx(oe,{copyable:!1,size:16,did:ts(o.issuerDid),showDidLogo:!1}),!!o.remark&&e.jsx(t,{sx:{fontSize:12,maxWidth:"300px"},children:o.remark})]}),e.jsx(t,{sx:{color:"gray",ml:"28px",flexGrow:1},children:o.mappings&&o.mappings.length?`${o.mappings.length} ${i("team.passport.mappingRule")}`:i("team.passport.defaultRule")}),e.jsxs(t,{sx:{flexShrink:0,display:"flex",alignItems:"center"},children:[e.jsx(O,{onClick:()=>m({mode:"update",data:K(o)}),"data-cy":"edit-mapping-rule",size:"large",children:e.jsx(Ce,{})}),e.jsx(O,{"data-cy":"delete-mapping-rule",onClick:()=>l({title:i("common.delete"),description:i("common.delConfirmDescription",{data:o.issuerDid}),confirm:i("common.delConfirm"),cancel:i("common.cancel"),onConfirm:()=>x(o.issuerDid),onCancel:()=>{n(!1),l(null)}}),size:"large",children:e.jsx(ce,{})})]})]},o.issuerDid)),!f.length&&e.jsx(re,{children:i("common.empty")})]})]})}),h&&e.jsx(Le,{mode:h.mode,data:h.data,trustedPassports:K(f),onCancel:()=>m(null),onSuccess:()=>{m(null)}}),d&&e.jsx(we,{title:d.title,description:d.description,confirm:d.confirm,cancel:d.cancel,params:d.params,onConfirm:d.onConfirm,onCancel:d.onCancel})]})}pe.propTypes={onCancel:S.func.isRequired,hasPermission:S.bool};const Ls=$(pe,"mutate_team"),zs=$(pe,"",Q);function Fs(c){const{inService:s}=P();return s?e.jsx(zs,{...c}):e.jsx(Ls,{...c})}const Es=_.div`
  .list {
    .MuiIconButton-root {
      svg {
        fill: #bfbfbf;
      }
    }
  }
`;var Bs=Cs();const fe=_e(Bs);function ze({onCancel:c,onSuccess:s,data:p={},trustedFactories:u=[]}){const{api:f}=P(),{roles:i,teamDid:d}=z(),{t:l}=A(),[r,n]=Ts({loading:!1,fetching:!1,fetched:[],errored:[],factoryAddress:p.factoryAddress||"",remark:p.remark||"",role:p.passport?.role||"member",ttlPolicy:p.passport?.ttlPolicy||"never",ttl:fe(+p.passport?.ttl||365*24*60*60*1e3),error:""}),h=u.findIndex(a=>a.factoryAddress===p.factoryAddress),m=async()=>{if(r.loading)return;const{factoryAddress:a,remark:o,role:v,ttlPolicy:j,ttl:C}=r,w={factoryAddress:a,remark:o,passport:{role:v,ttlPolicy:j,ttl:j==="never"?0:fe(C)}},k=[...u];h===-1?k.unshift(w):k[h]=w;try{n({loading:!0}),await f.configTrustedFactories({input:{teamDid:d,trustedFactories:k}}),await Y(800),D.success(l("common.saveSuccess")),s()}catch(N){console.error(N),D.error(te(N))}finally{n({loading:!1})}};b.useEffect(()=>{const a=r.fetched.find(v=>v.address===r.factoryAddress),o=r.errored.find(v=>v.address===r.factoryAddress);ps(r.factoryAddress)&&!r.fetching&&!a&&!o&&(n({fetching:!0}),us(ms).getFactoryState({address:r.factoryAddress}).then(j=>{j.state?n({fetching:!1,fetched:[...r.fetched.filter(C=>C.address!==r.factoryAddress),j.state],remark:j.state.name}):n({fetching:!1,errored:[...r.errored.filter(C=>C.address!==r.factoryAddress),{address:r.factoryAddress}],error:l("team.passport.factory404",r)})}).catch(j=>{console.error(j),n({fetching:!1,error:te(j)})}))},[r.factoryAddress,r.fetching]);let g=r.error;const T=r.factoryAddress?r.errored.find(a=>a.address===r.factoryAddress):null;!g&&T&&(g=l("team.passport.factory404",r));const x=r.factoryAddress?r.fetched.find(a=>a.address===r.factoryAddress):null;return!g&&x&&(g=x.description),g||(g=l("team.passport.factoryAddressTip")),e.jsx(W,{title:l("team.passport.trustedFactories"),open:!0,showCloseButton:!1,PaperProps:{style:{minHeight:"80vh"}},fullWidth:!0,prepend:e.jsx(O,{onClick:c,"data-cy":"close-trusted-factory",size:"large",children:e.jsx(ge,{})}),actions:e.jsxs(e.Fragment,{children:[e.jsx(L,{onClick:c,color:"inherit",children:l("common.cancel")}),e.jsxs(L,{onClick:()=>m(),color:"primary",disabled:!r.factoryAddress||!r.remark||!r.role||r.loading||r.error||T,variant:"contained",autoFocus:!0,"data-cy":"save-trusted-factory",children:[r.loading&&e.jsx(F,{size:16}),l("common.save")]})]}),children:e.jsx(Ms,{children:e.jsxs("div",{className:"dialog-content",children:[e.jsx(M,{fullWidth:!0,error:!!r.error||!!T,"data-cy":"input-factory-address",label:l("team.passport.factoryAddress"),helperText:g,value:r.factoryAddress,onChange:a=>{n({factoryAddress:a.target.value,error:""})},slotProps:{input:{endAdornment:r.fetching?e.jsx(Ye,{position:"end",children:e.jsx(F,{size:16})}):null}}}),e.jsx(M,{style:{marginTop:32},fullWidth:!0,"data-cy":"input-factory-remark",label:l("common.remark"),value:r.remark,onChange:a=>{n({remark:a.target.value})}}),e.jsx(M,{style:{marginTop:32},fullWidth:!0,"data-cy":"input-passport-role",label:l("team.passport.role"),select:!0,value:r.role,onChange:a=>{n({role:a.target.value})},variant:"outlined",children:i.filter(a=>a.name!=="owner").map(a=>e.jsx(Z,{value:a.name,"data-cy":`passport-role-select-option-${a.name}`,children:e.jsx("span",{children:a.title||a.name})},a.name))}),e.jsxs("div",{style:{marginTop:32},children:[e.jsx(Ve,{children:l("team.passport.ttl")}),e.jsxs(Ze,{color:"primary",size:"small",value:r.ttlPolicy,exclusive:!0,style:{marginTop:16},onChange:(a,o)=>n({ttlPolicy:o}),"data-cy":"input-passport-ttl-since","aria-label":"Expire Policy",children:[e.jsx(J,{value:"never","data-cy":"input-passport-ttl-never",children:e.jsx(H,{title:l("team.passport.ttlNeverTip"),children:e.jsx(B,{children:l("team.passport.ttlNever")})})}),e.jsx(J,{value:"mint","data-cy":"input-passport-ttl-mint",children:e.jsx(H,{title:l("team.passport.ttlMintTip"),children:e.jsx(B,{children:l("team.passport.ttlMint")})})}),e.jsx(J,{value:"exchange","data-cy":"input-passport-ttl-exchange",children:e.jsx(H,{title:l("team.passport.ttlExchangeTip"),children:e.jsx(B,{children:l("team.passport.ttlExchange")})})})]}),r.ttlPolicy!=="never"&&e.jsxs(e.Fragment,{children:[e.jsx(Xe,{fullWidth:!0,type:"text",style:{marginTop:16},"data-cy":"input-passport-ttl",value:r.ttl,onChange:a=>{n({ttl:a.target.value})}}),e.jsx(Qe,{children:l("team.passport.ttlTip")})]})]})]})})})}ze.propTypes={onCancel:S.func.isRequired,onSuccess:S.func.isRequired,trustedFactories:S.array,data:S.object};const Ms=_.div`
  .dialog-h1 {
    font-size: 18px;
  }

  .list {
    .MuiIconButton-root {
      svg {
        fill: #bfbfbf;
      }
    }
  }
`;function ue({onCancel:c,hasPermission:s=!1}){const{api:p}=P(),{teamDid:u,trustedFactories:f}=z(),{t:i}=A(),[d,l]=b.useState(null),[r,n]=b.useState(!1),[h,m]=b.useState(null),[g,T]=b.useState(""),x=async o=>{if(!r)try{n(!0),await p.configTrustedFactories({input:{teamDid:u,trustedFactories:f.filter(v=>v.factoryAddress!==o)}}),await Y(800),n(!1),D.success(i("common.saveSuccess")),l(null)}catch(v){n(!1),D.error(v.message)}},a=f.filter(o=>!g||o.factoryAddress.toLowerCase().includes(g.toLowerCase()));return e.jsxs(W,{title:i("team.passport.trustedFactories"),open:!0,onClose:c,fullWidth:!0,PaperProps:{style:{minHeight:"80vh"}},children:[e.jsx($s,{children:e.jsxs("div",{className:"dialog-content",children:[e.jsx("div",{className:"dialog-h1",children:i("team.passport.trustedFactoriesTip")}),e.jsx(Te,{sx:{mt:3},actions:e.jsxs(e.Fragment,{children:[e.jsx(je,{options:{searchPlaceholder:i("team.passport.searchFactoryAddress"),searchDebounceTime:600},search:g,searchText:g,searchTextUpdate:T,searchClose:()=>T(""),onSearchOpen:()=>{}}),s&&e.jsxs(L,{variant:"contained",color:"primary",size:"small","data-cy":"add-trusted-factory",onClick:()=>m({mode:"add"}),children:[e.jsx(ye,{style:{fontSize:16,marginRight:4}}),i("team.add")]})]})}),e.jsxs("div",{className:"list",children:[a.map(o=>e.jsxs(t,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mt:"20px"},children:[e.jsxs(t,{sx:{flexGrow:1},children:[e.jsx(oe,{copyable:!1,did:o.factoryAddress,size:16,showDidLogo:!1}),!!o.remark&&e.jsx(t,{sx:{fontSize:12,maxWidth:"300px"},children:o.remark})]}),e.jsx(t,{sx:{color:"gray",mr:"24px"},children:e.jsx(as,{type:"success",children:o.passport.role})}),e.jsxs(t,{sx:{flexShrink:0,display:"flex",alignItems:"center"},children:[e.jsx(O,{onClick:()=>m({mode:"update",data:K(o)}),"data-cy":"edit-trusted-factory",size:"large",children:e.jsx(Ce,{})}),e.jsx(O,{"data-cy":"delete-trusted-factory",onClick:()=>l({title:i("common.delete"),description:i("common.delConfirmDescription",{data:o.factoryAddress}),confirm:i("common.delConfirm"),cancel:i("common.cancel"),onConfirm:()=>x(o.factoryAddress),onCancel:()=>{n(!1),l(null)}}),size:"large",children:e.jsx(ce,{})})]})]},o.factoryAddress)),!f.length&&e.jsx(re,{children:i("common.empty")})]})]})}),h&&e.jsx(ze,{data:h.data,trustedFactories:K(f),onCancel:()=>m(null),onSuccess:()=>{m(null)}}),d&&e.jsx(we,{title:d.title,description:d.description,confirm:d.confirm,cancel:d.cancel,params:d.params,onConfirm:d.onConfirm,onCancel:d.onCancel})]})}ue.propTypes={onCancel:S.func.isRequired,hasPermission:S.bool};const Os=$(ue,"mutate_team"),Ws=$(ue,"",Q);function _s(c){const{inService:s}=P();return s?e.jsx(Ws,{...c}):e.jsx(Os,{...c})}const $s=_.div`
  .list {
    .MuiIconButton-root {
      svg {
        fill: #bfbfbf;
      }
    }
  }
`;function Fe({createPassportSvg:c}){const{t:s}=A(),{api:p,inService:u}=P(),{teamDid:f,refresh:i,enablePassportIssuance:d,isNodeTeam:l}=z(),[r,n]=b.useState(!1),[h,m]=b.useState(!1),[g,T]=b.useState(!1),[x,a]=b.useState(!1),[o,v]=b.useState(!1),j=async C=>{if(C.stopPropagation(),!x){a(!0);try{await p.configPassportIssuance({input:{teamDid:f,enable:!d}}),i(),await Y(800),D.success(s("common.configSuccess"))}catch(w){D.error(w.message)}finally{a(!1)}}};return e.jsxs(t,{sx:{display:"flex",alignItems:"center",gap:1,ml:1},children:[e.jsx(js,{permission:u?"":"mutate_team",role:u?Q:[],children:e.jsx(U,{variant:"outlined",menuButtonProps:{"data-cy":"trusted-issuers-more"},menu:e.jsxs(e.Fragment,{children:[e.jsx(U.Item,{onClick:()=>m(!0),"data-cy":"config-trusted-issuers",children:e.jsxs(t,{children:[s("team.passport.trustedPassportIssuers"),e.jsx(t,{sx:{fontSize:12,color:"#888"},children:s("team.passport.trustedPassportIssuersTip")})]})}),e.jsx(U.Item,{onClick:()=>T(!0),"data-cy":"config-show-trusted-factories",children:e.jsxs(t,{children:[s("team.passport.configFactories"),e.jsx(t,{sx:{fontSize:12,color:"#888"},children:s("team.passport.configFactoriesTip")})]})}),e.jsx(U.Item,{"data-cy":"config-show-issue-passport",onClick:j,children:e.jsxs(t,{sx:{display:"flex",alignItems:"center"},children:[x&&e.jsx(F,{size:16,style:{marginRight:8}}),e.jsxs(t,{children:[s(d?"team.passport.disableIssuance":"team.passport.enableIssuance"),e.jsx(t,{sx:{fontSize:12,color:"#888"},children:s(d?"team.passport.disableIssuanceTip":"team.passport.enableIssuanceTip")})]})]})}),!l&&e.jsx(U.Item,{onClick:()=>n(!0),"data-cy":"config-passport-color",children:e.jsxs(t,{children:[s("team.passport.configColor"),e.jsx(t,{sx:{fontSize:12,color:"#888"},children:s("team.passport.configColorTip")})]})})]}),children:()=>e.jsx(L,{variant:"outlined",onClick:()=>{v(!0)},children:s("team.passport.view")})})}),h&&e.jsx(Fs,{onCancel:()=>m(!1)}),g&&e.jsx(_s,{onCancel:()=>T(!1)}),r&&e.jsx(Rs,{onCancel:()=>n(!1),onSuccess:()=>n(!1)}),o&&e.jsx(W,{open:!0,maxWidth:"lg",onClose:()=>v(!1),onBackdropClick:()=>v(!1),onEscapeKeyDown:()=>v(!1),title:s("team.passport.view"),children:e.jsx(ws,{createPassportSvg:c,onCancel:()=>v(!1)})})]})}Fe.propTypes={createPassportSvg:S.func.isRequired};const xe="$all",he="",Ee=$e.memo(({createPassportSvg:c,passport:s,teamDid:p,inService:u})=>e.jsx(t,{sx:{display:"flex"},dangerouslySetInnerHTML:{__html:c({scope:s.scope,role:s.role,title:s.scope==="kyc"?s.name:s.title,issuer:s.issuer&&s.issuer.name,issuerDid:s.issuer&&s.issuer.id,ownerName:s.user?.fullName,ownerDid:s.user?.did,ownerAvatarUrl:s.user?.avatar?Se(s.user?.avatar,p,u):"",revoked:s.revoked,width:"36px",extra:s?.expirationDate?{key:"Exp",value:be(s.expirationDate).format("YYYY-MM-DD HH:mm:ss")}:null})}}));Ee.propTypes={passport:S.object.isRequired,createPassportSvg:S.func.isRequired,teamDid:S.string.isRequired,inService:S.bool.isRequired};function qs({createPassportSvg:c}){const{api:s}=P(),{teamDid:p}=z(),{t:u,locale:f}=A(),{SYSTEM_ROLES:i}=hs(),{inService:d}=P(),[l,r]=b.useState(!1),n=`passports-${p}`,h=rs(n),[m,g]=b.useState({role:xe,status:he,searchText:h.searchText||"",pageSize:h.rowsPerPage||10,page:h.page?h.page+1:1}),{data:T,loading:x}=V(async()=>(await s.getPassportRoleCounts({input:{teamDid:p}})).counts||[],{refreshDeps:[p]}),{data:a,loading:o}=V(async()=>{const y={};m.role!==xe&&(y.role=m.role),m.status&&(y.status=m.status);const I=await s.getPassportsByRole({input:{teamDid:p,query:y,paging:{page:m.page,pageSize:m.pageSize}}});return{passports:I.passports||[],total:I.paging.total}},{refreshDeps:[m.role,m.status,m.page,m.pageSize],onError:y=>D.error(y.message)}),v=y=>T?.find(R=>R.key===y)?.value||0,j=b.useMemo(()=>Object.keys(i).map(y=>({name:y,title:i[y],num:v(y)})),[T,v]),C=b.useMemo(()=>[{label:u("team.passport.role"),name:"role",options:{customBodyRender:(y,{rowIndex:I})=>{const R=a?.passports[I];return e.jsxs(t,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(Ee,{createPassportSvg:c,passport:R,teamDid:p}),e.jsx(t,{children:ne(R.title)})]})}}},{label:u("team.passport.owner"),name:"user",options:{customBodyRender:y=>ie(y,d)}},{label:u("team.passport.status"),name:"status",options:{customBodyRender:le}},{label:u("team.member.lastLogin"),name:"lastLoginAt",options:{customBodyRender:y=>ve(y,f)}},{label:u("common.address"),name:"id",options:{customBodyRender:gs}},{label:u("blocklet.overview.source"),name:"source",options:{customBodyRender:(y,{rowIndex:I})=>{const R=a?.passports[I];return R.parentDid?X("recover"):X(R.source)}}}],[u,f,a?.passports,p,c,d]),w=y=>{g(I=>({...I,role:y,page:1}))},k=({page:y,rowsPerPage:I,searchText:R})=>{m.pageSize!==I?g(E=>({...E,searchText:"",pageSize:I,page:1})):m.page!==y+1?g(E=>({...E,searchText:"",page:y+1})):m.searchText!==R&&g(E=>({...E,searchText:R,page:1}))},N=b.useRef(null),q=a?.passports||[],Be=m.searchText?q.filter(y=>y.id.includes(m.searchText)||(y?.user?.fullName||"").includes(m.searchText)):q,Me={sort:!1,download:!1,filter:!1,print:!1,viewColumns:!1,onRowClick(y,{dataIndex:I},R){if(N.current?.contains(R.target)){const E=a?.passports[I];r(E)}},page:m.page-1,rowsPerPage:m.pageSize,count:a?.total||0,searchDebounceTime:600},Oe=y=>{g(I=>({...I,status:y.target.value,page:1}))},We=e.jsxs(t,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsxs(t,{sx:{fontSize:16,fontWeight:400},children:[u("team.passport.status"),":"]}),e.jsxs(Je,{size:"small",value:m.status,onChange:Oe,displayEmpty:!0,sx:{minWidth:120,height:36,".MuiSelect-select":{py:.5,px:1.5}},children:[e.jsx(Z,{value:he,children:u("common.all")}),Object.values(fs).map(y=>e.jsx(Z,{value:y,sx:{py:1},children:u(`team.passport.statusMap.${y}`)},y))]})]});return x?e.jsx(t,{sx:{py:2},children:e.jsx(G,{direction:"row",spacing:1,sx:{justifyContent:"center",alignItems:"center",position:"relative",pb:2},children:e.jsx(F,{})})}):e.jsxs(Us,{children:[e.jsxs(t,{className:"main",sx:{display:"flex",mt:0,gap:3},children:[e.jsx(t,{className:"left",children:e.jsx(t,{className:"tabs",children:j.map(y=>e.jsxs(t,{className:`tab ${m.role===y.name?"active":""}`,onClick:()=>w(y.name),children:[e.jsx("span",{className:"text",children:y.title}),e.jsx(t,{sx:{color:"text.secondary"},children:y.num})]},y.name))})}),e.jsx(t,{ref:N,className:"right",children:e.jsx(ae,{className:"main-table",verticalKeyWidth:100,locale:f,durable:n,durableKeys:["page","rowsPerPage"],data:Be,columns:C,options:Me,loading:o,onChange:k,customButtons:[e.jsx(Fe,{createPassportSvg:c})],title:We})})]}),l&&e.jsx(Ie,{createPassportSvg:c,onCancel:()=>r(null),passport:l,onSwitchPassport:r})]})}qs.propTypes={createPassportSvg:S.func.isRequired};const Us=es(t)`
  .main {
    .left {
      width: 256px;
      flex-shrink: 0;

      .tabs {
        padding-top: 16px;
        .tab {
          display: flex;
          justify-content: space-between;
          align-items: center;
          padding: 8px 16px;
          transition: background 0.4s;

          width: 256px;
          height: 36px;
          border-radius: 8px;

          cursor: pointer;
          user-select: none;

          &:nth-child(n + 2) {
            margin-top: 24px;
          }

          &.active {
            background-color: ${({theme:c})=>c.palette.grey[100]};
          }

          &:hover {
            background-color: ${({theme:c})=>c.palette.grey[100]};
          }

          .text {
            font-weight: 400;
            font-size: 16px;
            line-height: 19px;
            color: ${({theme:c})=>c.palette.text.primary};
          }

          .badge {
            display: flex;
            flex-shrink: 0;
            justify-content: center;
            align-items: center;
            width: 20px;
            height: 20px;
            border-radius: 100%;
            color: #fff;
            background: #666666;
            font-size: 10px;
            font-weight: 400;
            &.is-rect {
              width: auto;
              border-radius: 8px;
              padding: 0 4px;
            }
          }
        }
      }
      @media (max-width: ${c=>c.theme.breakpoints.values.md}px) {
        display: none;
      }
    }
    .right {
      flex: 1;
      overflow: auto;
    }
  }
`;export{qs as default};
