import{r as b,g as $e,a as qe}from"./vendor-react-CTtPmzVP.js";import{g as Ue,q as V}from"./vendor-hooks-BZ19vVZ7.js";import{j as e,ak as t,at as $,b6 as Y,a6 as E,aZ as He,am as G,br as Ge,U as Ye,T as B,a3 as Ke,W as S,z as O,M as J,I as _,dZ as ge,bi as ye,A as Ze,x as Ve,cs as Je,ct as ee,ca as Qe,F as Xe,bZ as es,s as ss}from"./vendor-mui-core-DnR6WYuU.js";import{V as A,aU as W,b3 as ts,aZ as ae,bb as se,Q as D,J as L,aY as re,bz as je,D as be,b4 as as,bi as rs}from"./vendor-ux-DMZIE6wA.js";import{Z as P,C as os,Q as ve,c as M,G as X,Y as ns,q as is,J as ls,e as Z,ck as cs}from"./index-DwyzCfdd.js";import{W as oe}from"./did-address-uvYuZ4wv.js";import{b as N}from"./team-BWkxYdcc.js";import{r as ne,a as ie,b as le,c as Se,d as Q,e as ds,u as ps,f as us}from"./passport-item-QbgyHapR.js";import{p as Ce}from"./util-C9cWBCZz.js";import{u as ms}from"./use-mobile-BINJTzMb.js";import{v as H}from"./index-D29her4n.js";import{w as q,P as fs}from"./permission-C0bmOzVj.js";import{C as xs}from"./Google-DA3WTnLE.js";import{c as hs}from"./create-passport-svg-DGPNsGUE.js";import{A as gs}from"./vendor-arcblock-DkdOhPyM.js";import{G as K,az as ys}from"./vendor-utils-D5UG1a5Y.js";import{e as Te}from"./edit.svg-RRSklUg-.js";import{H as ce,b as js}from"./index-Bf3Peb0q.js";import{C as we}from"./confirm-Bpit6U3-.js";import{L as Ie}from"./list-header-Cl3jykCe.js";import{f as te}from"./index-DBs9Ljax.js";import{u as bs}from"./useSetState-L-f8mSga.js";import"./lottie-web-4koyQiv_.js";import"./session-Des-0R_y.js";import"./isURL-ZFgr0DWl.js";import"./use-app-logo-BAGvxEU-.js";import"./ua-parser-DP5omx3I.js";import"./base32-B-7CnEFd.js";import"./cloneDeep-B_fYlLpl.js";import"./lock.svg-BgybwZNe.js";const me="info";function De({createPassportSvg:c,passport:s,onCancel:p,onSwitchPassport:u=()=>{}}){const{t:f}=A(),i=Ue({tab:me}),d={info:{label:f("common.basicInfo"),value:me,component:()=>e.jsx(Pe,{passport:s,createPassportSvg:c})},logs:{label:f("common.logs"),value:"logs",component:()=>e.jsx(Ae,{passport:s})},related:{label:f("team.passport.related"),value:"related",component:()=>e.jsx(ze,{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(vs,{children:[e.jsx(t,{className:"tabs",children:e.jsx(ts,{tabs:l,current:i.tab,onChange:n,scrollButtons:"auto"})}),e.jsx(t,{className:"body",children:e.jsx(r.component,{})})]})})}De.propTypes={createPassportSvg:S.func.isRequired,passport:S.object.isRequired,onCancel:S.func.isRequired,onSwitchPassport:S.func};const vs=$(t)`
  margin-top: -16px;

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

  .body {
    margin-top: 24px;
  }
`;function Pe({createPassportSvg:c,passport:s}){const{t:p,locale:u}=A(),{teamDid:f}=N(),{inService:i}=P(),d=ms(),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(Ye,{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(se,{value:s.issuanceDate,type:"all",locale:u}):"-"},{label:p("team.member.lastLogin"),content:s.lastLoginAt?e.jsx(se,{value:s.lastLoginAt,type:"all",locale:u}):"-"},{label:p("common.expires"),content:s.expirationDate?e.jsx(se,{value:s.expirationDate,type:"all",locale:u}):"-"}]},{title:p("blocklet.overview.source"),items:[{label:p("blocklet.overview.source"),content:Q(s.source)}]}];return e.jsxs(Ss,{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?Ce(s.user?.avatar,f,i):"",revoked:s.revoked,extra:s?.expirationDate?{key:"Exp",value:ve(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))})]})}Pe.propTypes={passport:S.object.isRequired,createPassportSvg:S.func.isRequired};const Ss=$(Y)`
  .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;
    }
  }
`,ke=10,Re=1;function Ae({passport:c}){const{api:s}=P(),{teamDid:p}=N(),{t:u,locale:f}=A(),[i,d]=b.useState({pageSize:ke,page:Re}),{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===M.PASSPORT_LOG_ACTION.APPROVE||x.action===M.PASSPORT_LOG_ACTION.REVOKE?x?.metadata?.operator?.fullName?`${u("common.operator")}: ${x?.metadata?.operator?.fullName}`:null:x.action===M.PASSPORT_LOG_ACTION.ISSUE&&x.metadata?.action===M.PASSPORT_ISSUE_ACTION.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(G,{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:ds(o.operatorUa)}),o.operatorUa&&e.jsx(G,{title:o.operatorUa,children:e.jsx(Ge,{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}))},w={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(Y,{direction:"row",spacing:1,sx:{position:"relative",pb:2},children:e.jsx(E,{})})}):e.jsx(t,{children:e.jsx(ae,{className:"logs-table",verticalKeyWidth:100,locale:f,data:n,columns:m,options:w,loading:r,onChange:g})})}Ae.propTypes={passport:S.object.isRequired};function ze({passport:c,onSwitchPassport:s}){const{api:p}=P(),{teamDid:u}=N(),{t:f,locale:i}=A(),[d,l]=b.useState({pageSize:ke,page:Re}),{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=>Se(a,i)}},{label:f("blocklet.overview.source"),name:"source",options:{customBodyRender:Q}}],[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}))},w=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(w.current?.contains(v.target)){const j=h[o];s(j)}}};return n?e.jsx(t,{sx:{py:2},children:e.jsx(Y,{direction:"row",spacing:1,sx:{position:"relative",pb:2},children:e.jsx(E,{})})}):e.jsxs(Y,{spacing:1,children:[e.jsx(He,{severity:"warning",children:f("team.passport.relatedDescription")}),e.jsx(t,{ref:w,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})})]})}ze.propTypes={passport:S.object.isRequired,onSwitchPassport:S.func.isRequired};function de({onCancel:c,onSuccess:s}){const{api:p}=P(),{blocklet:u}=ns(),{t:f}=A(),[i,d]=b.useState(!1),l=(u.environments.find(g=>g.key==="BLOCKLET_PASSPORT_COLOR")||{}).value||"auto",r=l==="auto"?gs(u.appDid):l,[n,h]=b.useState(r),m=async()=>{const g=[{key:ls.BLOCKLET_CONFIGURABLE_KEY.BLOCKLET_PASSPORT_COLOR,value:n}];try{d(!0),await p.configBlocklet({input:{did:u.meta.did,configs:g}}),s()}catch(w){D.error(w.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(E,{size:16}),f("common.save")]})]}),children:e.jsxs(t,{className:"dialog-content",sx:{display:"flex",justifyContent:"center",alignItems:"center"},children:[e.jsx(xs,{disableAlpha:!0,color:n,onChange:g=>h(g.hex)}),e.jsx("div",{style:{width:220,marginLeft:24},dangerouslySetInnerHTML:{__html:hs({scope:"passport",role:"owner",title:"Owner",issuer:is.getDisplayName(u),issuerDid:u.appDid,ownerName:"Your Name",ownerDid:u.appDid,preferredColor:n})}})]})})}const Cs=q(de,"mutate_team"),Ts=q(de,"",X);function ws(c){const{inService:s}=P();return s?e.jsx(Ts,{...c}):e.jsx(Cs,{...c})}de.propTypes={onCancel:S.func.isRequired,onSuccess:S.func.isRequired};var Le=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"})})};Le.defaultProps={width:"65",height:"16",fill:"none",xmlns:"http://www.w3.org/2000/svg"};const Is=(c,s)=>c?!s.some(p=>!p.from.passport||!p.to.role):!1;function Ne({onCancel:c,onSuccess:s,data:p={},trustedPassports:u=[]}){const{api:f}=P(),{roles:i,teamDid:d}=N(),{t:l}=A(),[r,n]=b.useState(!1),[h,m]=b.useState(p.issuerDid||""),[g,w]=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(T=>({...T,to:{...T.to,ttl:T.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 Z(800),n(!1),D.success(l("common.saveSuccess")),s()}catch(T){n(!1),D.error(te(T))}};return e.jsx(W,{title:l("team.passport.trustedIssuers"),open:!0,showCloseButton:!1,PaperProps:{style:{minHeight:"80vh"}},fullWidth:!0,prepend:e.jsx(_,{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:!Is(h,x)||!g||r,variant:"contained",autoFocus:!0,"data-cy":"save-mapping",children:[r&&e.jsx(E,{size:16}),l("common.save")]})]}),children:e.jsx(Ds,{children:e.jsxs("div",{className:"dialog-content",children:[e.jsx(O,{fullWidth:!0,"data-cy":"input-issuer-did",placeholder:l("team.passport.issuerDid"),value:h,onChange:j=>{m(j.target.value)}}),e.jsx(O,{style:{marginTop:16},fullWidth:!0,"data-cy":"input-issuer-remark",placeholder:l("common.remark"),value:g,onChange:j=>{w(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:M.ROLES.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(O,{fullWidth:!0,size:"small","data-cy":`input-${C}-from`,placeholder:"Issuer’s Passport Name/ID *",value:j.from.passport,onChange:T=>{const{value:k}=T.target;a(z=>{const U=[...z];return U[C].from.passport=k,U})},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(Le,{})}),e.jsx(t,{sx:{flexGrow:1,flexBasis:1},children:e.jsx(O,{fullWidth:!0,size:"small",select:!0,value:j.to.role,onChange:T=>{a(k=>{const z=[...k];return z[C].to.role=T.target.value,z})},variant:"outlined",children:i.filter(T=>T.name!=="owner").map(T=>e.jsx(J,{value:T.name,"data-cy":`passport-mapping-select-option-${T.name}`,children:e.jsx("span",{children:T.title||T.name})},T.name))})})]}),e.jsx(t,{sx:{flexShrink:0},children:e.jsx(_,{onClick:()=>{a(T=>{const k=[...T];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")})})]})]})})})}Ne.propTypes={onCancel:S.func.isRequired,onSuccess:S.func.isRequired,trustedPassports:S.array,data:S.object};const Ds=$.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}=N(),{t:i}=A(),[d,l]=b.useState(null),[r,n]=b.useState(!1),[h,m]=b.useState(!1),[g,w]=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 Z(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(As,{children:e.jsxs("div",{className:"dialog-content",children:[e.jsx("div",{className:"dialog-h1",children:i("team.passport.trustedPassportIssuers")}),e.jsx(Ie,{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:w,searchClose:()=>w(""),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:be.toAddress(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(_,{onClick:()=>m({mode:"update",data:K(o)}),"data-cy":"edit-mapping-rule",size:"large",children:e.jsx(Te,{})}),e.jsx(_,{"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(Ne,{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 Ps=q(pe,"mutate_team"),ks=q(pe,"",X);function Rs(c){const{inService:s}=P();return s?e.jsx(ks,{...c}):e.jsx(Ps,{...c})}const As=$.div`
  .list {
    .MuiIconButton-root {
      svg {
        fill: #bfbfbf;
      }
    }
  }
`;var zs=ys();const fe=$e(zs);function Ee({onCancel:c,onSuccess:s,data:p={},trustedFactories:u=[]}){const{api:f}=P(),{roles:i,teamDid:d}=N(),{t:l}=A(),[r,n]=bs({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,T={factoryAddress:a,remark:o,passport:{role:v,ttlPolicy:j,ttl:j==="never"?0:fe(C)}},k=[...u];h===-1?k.unshift(T):k[h]=T;try{n({loading:!0}),await f.configTrustedFactories({input:{teamDid:d,trustedFactories:k}}),await Z(800),D.success(l("common.saveSuccess")),s()}catch(z){console.error(z),D.error(te(z))}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);be.isValid(r.factoryAddress)&&!r.fetching&&!a&&!o&&(n({fetching:!0}),cs(M.MAIN_CHAIN_ENDPOINT).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 w=r.factoryAddress?r.errored.find(a=>a.address===r.factoryAddress):null;!g&&w&&(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(_,{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||w,variant:"contained",autoFocus:!0,"data-cy":"save-trusted-factory",children:[r.loading&&e.jsx(E,{size:16}),l("common.save")]})]}),children:e.jsx(Ls,{children:e.jsxs("div",{className:"dialog-content",children:[e.jsx(O,{fullWidth:!0,error:!!r.error||!!w,"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(Ze,{position:"end",children:e.jsx(E,{size:16})}):null}}}),e.jsx(O,{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(O,{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(J,{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(Je,{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(ee,{value:"never","data-cy":"input-passport-ttl-never",children:e.jsx(G,{title:l("team.passport.ttlNeverTip"),children:e.jsx(B,{children:l("team.passport.ttlNever")})})}),e.jsx(ee,{value:"mint","data-cy":"input-passport-ttl-mint",children:e.jsx(G,{title:l("team.passport.ttlMintTip"),children:e.jsx(B,{children:l("team.passport.ttlMint")})})}),e.jsx(ee,{value:"exchange","data-cy":"input-passport-ttl-exchange",children:e.jsx(G,{title:l("team.passport.ttlExchangeTip"),children:e.jsx(B,{children:l("team.passport.ttlExchange")})})})]}),r.ttlPolicy!=="never"&&e.jsxs(e.Fragment,{children:[e.jsx(Qe,{fullWidth:!0,type:"text",style:{marginTop:16},"data-cy":"input-passport-ttl",value:r.ttl,onChange:a=>{n({ttl:a.target.value})}}),e.jsx(Xe,{children:l("team.passport.ttlTip")})]})]})]})})})}Ee.propTypes={onCancel:S.func.isRequired,onSuccess:S.func.isRequired,trustedFactories:S.array,data:S.object};const Ls=$.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}=N(),{t:i}=A(),[d,l]=b.useState(null),[r,n]=b.useState(!1),[h,m]=b.useState(null),[g,w]=b.useState(""),x=async o=>{if(!r)try{n(!0),await p.configTrustedFactories({input:{teamDid:u,trustedFactories:f.filter(v=>v.factoryAddress!==o)}}),await Z(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(Bs,{children:e.jsxs("div",{className:"dialog-content",children:[e.jsx("div",{className:"dialog-h1",children:i("team.passport.trustedFactoriesTip")}),e.jsx(Ie,{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:w,searchClose:()=>w(""),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(_,{onClick:()=>m({mode:"update",data:K(o)}),"data-cy":"edit-trusted-factory",size:"large",children:e.jsx(Te,{})}),e.jsx(_,{"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(Ee,{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 Ns=q(ue,"mutate_team"),Es=q(ue,"",X);function Fs(c){const{inService:s}=P();return s?e.jsx(Es,{...c}):e.jsx(Ns,{...c})}const Bs=$.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}=N(),[r,n]=b.useState(!1),[h,m]=b.useState(!1),[g,w]=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 Z(800),D.success(s("common.configSuccess"))}catch(T){D.error(T.message)}finally{a(!1)}}};return e.jsxs(t,{sx:{display:"flex",alignItems:"center",gap:1,ml:1},children:[e.jsx(fs,{permission:u?"":"mutate_team",role:u?X:[],children:e.jsx(H,{variant:"outlined",menuButtonProps:{"data-cy":"trusted-issuers-more"},menu:e.jsxs(e.Fragment,{children:[e.jsx(H.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(H.Item,{onClick:()=>w(!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(H.Item,{"data-cy":"config-show-issue-passport",onClick:j,children:e.jsxs(t,{sx:{display:"flex",alignItems:"center"},children:[x&&e.jsx(E,{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(H.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(Rs,{onCancel:()=>m(!1)}),g&&e.jsx(Fs,{onCancel:()=>w(!1)}),r&&e.jsx(ws,{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(js,{createPassportSvg:c,onCancel:()=>v(!1)})})]})}Fe.propTypes={createPassportSvg:S.func.isRequired};const xe="$all",he="",Be=qe.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?Ce(s.user?.avatar,p,u):"",revoked:s.revoked,width:"36px",extra:s?.expirationDate?{key:"Exp",value:ve(s.expirationDate).format("YYYY-MM-DD HH:mm:ss")}:null})}}));Be.propTypes={passport:S.object.isRequired,createPassportSvg:S.func.isRequired,teamDid:S.string.isRequired,inService:S.bool.isRequired};function Os({createPassportSvg:c}){const{api:s}=P(),{teamDid:p}=N(),{t:u,locale:f}=A(),{SYSTEM_ROLES:i}=ps(),{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:w,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=>w?.find(R=>R.key===y)?.value||0,j=b.useMemo(()=>Object.keys(i).map(y=>({name:y,title:i[y],num:v(y)})),[w,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(Be,{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=>Se(y,f)}},{label:u("common.address"),name:"id",options:{customBodyRender:us}},{label:u("blocklet.overview.source"),name:"source",options:{customBodyRender:(y,{rowIndex:I})=>{const R=a?.passports[I];return R.parentDid?Q("recover"):Q(R.source)}}}],[u,f,a?.passports,p,c,d]),T=y=>{g(I=>({...I,role:y,page:1}))},k=({page:y,rowsPerPage:I,searchText:R})=>{m.pageSize!==I?g(F=>({...F,searchText:"",pageSize:I,page:1})):m.page!==y+1?g(F=>({...F,searchText:"",page:y+1})):m.searchText!==R&&g(F=>({...F,searchText:R,page:1}))},z=b.useRef(null),U=a?.passports||[],Oe=m.searchText?U.filter(y=>y.id.includes(m.searchText)||(y?.user?.fullName||"").includes(m.searchText)):U,Me={sort:!1,download:!1,filter:!1,print:!1,viewColumns:!1,onRowClick(y,{dataIndex:I},R){if(z.current?.contains(R.target)){const F=a?.passports[I];r(F)}},page:m.page-1,rowsPerPage:m.pageSize,count:a?.total||0,searchDebounceTime:600},_e=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(es,{size:"small",value:m.status,onChange:_e,displayEmpty:!0,sx:{minWidth:120,height:36,".MuiSelect-select":{py:.5,px:1.5}},children:[e.jsx(J,{value:he,children:u("common.all")}),Object.values(M.PASSPORT_STATUS).map(y=>e.jsx(J,{value:y,sx:{py:1},children:u(`team.passport.statusMap.${y}`)},y))]})]});return x?e.jsx(t,{sx:{py:2},children:e.jsx(Y,{direction:"row",spacing:1,sx:{justifyContent:"center",alignItems:"center",position:"relative",pb:2},children:e.jsx(E,{})})}):e.jsxs(Ms,{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:()=>T(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:z,className:"right",children:e.jsx(ae,{className:"main-table",verticalKeyWidth:100,locale:f,durable:n,durableKeys:["page","rowsPerPage"],data:Oe,columns:C,options:Me,loading:o,onChange:k,customButtons:[e.jsx(Fe,{createPassportSvg:c})],title:We})})]}),l&&e.jsx(De,{createPassportSvg:c,onCancel:()=>r(null),passport:l,onSwitchPassport:r})]})}Os.propTypes={createPassportSvg:S.func.isRequired};const Ms=ss(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{Os as default};
