import{c as $,j as i,r as u,p as T,dg as H,cu as M,q as v,o as s,bz as E,B as y,dh as q,V as w,d as A,b6 as D,di as U,cE as F,k as j,x as O,dj as W,W as B,dk as V,dl as k,dm as I,dn as Y,b8 as J,i as K,C as X,a3 as G}from"./index-DR3HTfO6.js";import{p as Q}from"./index-6zqs-c3t.js";import{N as Z}from"./index-aa4ujRU0.js";import{b as ee}from"./sdk-ByxTU3LQ.js";import{w as ie}from"./wrap-locale-C0doVwDy.js";const se=$(i.jsx("path",{d:"M19 3H4.99c-1.11 0-1.98.89-1.98 2L3 19c0 1.1.88 2 1.99 2H19c1.1 0 2-.9 2-2V5c0-1.11-.9-2-2-2m0 12h-4c0 1.66-1.35 3-3 3s-3-1.34-3-3H4.99V5H19z"}));function P({invitation:e,createPassportSvg:n,passportColor:l="auto"}){const[p,r]=u.useState(!1),{t:c}=u.useContext(T),t=u.useMemo(()=>(e.role.title||e.role.name).toUpperCase(),[e.role.title,e.role.name]),d=u.useMemo(()=>n({title:t,issuer:e.info.name,issuerDid:e.info.appDid,ownerName:"Your Name",ownerDid:e.info.appDid,preferredColor:e.info.passportColor||l,extra:e.passportExpireTime?{key:"Exp",value:H(e.passportExpireTime).format("YYYY-MM-DD HH:mm:ss")}:void 0}),[e,t]),m=u.useCallback(()=>{r(!0)},[]),o=u.useCallback(()=>{r(!1)},[]);return i.jsxs(i.Fragment,{children:[i.jsx(te,{children:i.jsxs("div",{className:"invite-passport__card",onClick:m,children:[!!e.display&&i.jsx(Z,{data:e.display,style:{width:"100%",height:"100%"}}),!e.display&&i.jsx("div",{className:"invite-passport__cover",dangerouslySetInnerHTML:{__html:d}})]})}),i.jsx(M,{open:p,title:c("invite.viewPermission"),PaperProps:{style:{minHeight:"auto",paddingBottom:"20px"}},onClose:o,children:e.role.permissions&&e.role.permissions.length>0?i.jsx("ul",{style:{listStyle:"circle",padding:"0 20px"},children:e.role.permissions.map(x=>i.jsx("li",{style:{listStyle:"circle"},children:x.description},x.name))}):i.jsxs("div",{style:{color:"#999",textAlign:"center"},children:[i.jsx(se,{style:{width:"30px",height:"30px"}}),i.jsx("div",{children:c("invite.emptyPermission")})]})})]})}P.propTypes={invitation:s.object.isRequired,createPassportSvg:s.func.isRequired,passportColor:s.string};const te=v.div`
  display: flex;
  max-width: 350px;
  margin: 30px auto;
  .invite-passport__card {
    margin: 0 auto;
    width: 228px;
    height: 258px;
    flex-shrink: 0;
    .invite-passport__cover {
      cursor: pointer;
      width: 100%;
      height: 100%;
    }
  }
  .invite-passport__content {
    flex: 1;
    display: flex;
    flex-direction: column;
  }
  .invite-passport__title {
    font-weight: 700;
    font-size: 16px;
  }
  .invite-passport__description {
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    height: 3em;
    color: #999;
    font-size: 14px;
  }
  .invite-passport__view-permission {
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    line-height: 18px;
    color: ${({theme:e})=>e.palette.primary.main};
  }
`;function b({children:e=null,...n}){return i.jsxs(E,{color:"did",variant:"contained",...n,children:[i.jsx(y,{sx:{fontWeight:400},children:e||"Continue With"}),i.jsx(q,{style:{width:"auto",height:"1.2em",margin:"0 4px 0 8px"}})]})}b.propTypes={children:s.any};function C({invitation:e,onLogin:n=()=>{},onReceive:l=null,inService:p=!1,action:r="invite",orgId:c=""}){const{t,locale:d}=w(),{connectApi:m}=A(),{getPassportId:o}=F();let x;typeof window<"u"&&(x=window?.blocklet?.componentId);const a=D({loading:!1,extraParams:{baseUrl:window.location.origin,componentId:x,sourceAppPid:e?.sourceAppPid||null}});U(async()=>{const f=o();if(f&&(a.extraParams.passportId=f),r==="invite"?(a.extraParams.inviteId=e.inviteId,a.extraParams.orgId=c):r==="issue-passport"&&(a.extraParams.inviteId=e.inviteId,a.extraParams.id=e.inviteId),p&&e?.receiver?.did){a.loading=!0;try{const g=await ee.user.getUserPublicInfo({did:e.receiver.did});g?.sourceAppPid&&(a.extraParams.sourceAppPid=g.sourceAppPid)}finally{a.loading=!1}}});const h=j(()=>{m.close()}),_=j((...f)=>{m.close(),n(...f)}),L=j(()=>{if(typeof l=="function"){l();return}const f=e?.receiver?.did||!1,g=f?t("receive.dialog.scanWithDid",{did:e?.receiver?.did}):t("receive.dialog.scan");p?m.open({action:r,className:"connect",forceConnected:f,autoConnect:!1,disableSwitchApp:!0,locale:d,extraParams:{provider:"wallet",...a.extraParams},baseUrl:window.location.origin,prefix:O(window.location.origin,B,W),messages:{title:t("receive.dialog.title"),scan:g,confirm:t("receive.dialog.confirm"),success:t("receive.dialog.success")},onSuccess:_,onClose:h,passkeyBehavior:c?"only-existing":"both"},{locale:d}):m.open({action:r,className:"connect",forceConnected:f,autoConnect:!1,disableSwitchApp:!0,locale:d,extraParams:a.extraParams,messages:{title:t("receive.dialog.title"),scan:g,confirm:t("receive.dialog.confirm"),success:t("receive.dialog.success")},onSuccess:_,onClose:h,passkeyBehavior:c?"only-existing":"both"},{locale:d})});return i.jsxs(re,{children:[i.jsx(b,{loading:a.loading,size:"large",variant:"contained",className:"invite-receive__button","data-cy":"invite-receive-passport",color:"primary",onClick:L,children:t("invite.receive")}),i.jsxs("div",{className:"invite-receive__until",children:[t("invite.validUntil"),V(e.expireDate,d)]})]})}C.propTypes={invitation:s.object.isRequired,onLogin:s.func,onReceive:s.func,inService:s.bool,action:s.oneOf(["invite","issue-passport"]),orgId:s.string};const re=v.div`
  text-align: center;
  .invite-receive__logo-wrapper {
    display: inline-flex;
    align-items: center;
    color: #9397a1;
    font-size: 14px;
  }
  .invite-receive__logo {
    height: 16px;
    margin-left: 8px;
  }
  .invite-receive__button {
    width: 100%;
    margin: 16px 0;
    white-space: nowrap;
  }
  .invite-receive__until {
    text-align: center;
    font-size: 14px;
  }
  .invite-receive__description {
    color: #999;
    text-align: left;
    list-style: decimal;
    padding: 0;
    padding-left: 1.2em;
    margin: 40px 0;
  }
  .invite-receive__description-item {
    list-style: decimal;
  }
  .invite-receive__link {
    color: ${({theme:e})=>e.palette.primary.main};
  }
`;function N({onLogin:e=()=>{}}){const{t:n}=w();return i.jsx(ne,{children:i.jsx(b,{size:"large",variant:"contained",className:"invite-receive__button","data-cy":"invite-receive-passport",color:"primary",onClick:()=>e(),children:n("common.connect")})})}N.propTypes={onLogin:s.func};const ne=v.div`
  text-align: center;
  .invite-receive__logo-wrapper {
    display: inline-flex;
    align-items: center;
    color: #9397a1;
    font-size: 14px;
  }
  .invite-receive__logo {
    height: 16px;
    margin-left: 8px;
  }
  .invite-receive__button {
    width: 100%;
    margin: 16px 0;
    white-space: nowrap;
  }
  .invite-receive__until {
    text-align: center;
    font-size: 14px;
  }
  .invite-receive__description {
    color: #999;
    text-align: left;
    list-style: decimal;
    padding: 0;
    padding-left: 1.2em;
    margin: 40px 0;
  }
  .invite-receive__description-item {
    list-style: decimal;
  }
  .invite-receive__link {
    color: ${({theme:e})=>e.palette.primary.main};
  }
`;function R({invitation:e}){const{t:n}=w(),l=u.useMemo(()=>(e.role.title||e.role.name).toUpperCase(),[e.role.title,e.role.name]),p=u.useMemo(()=>n("invite.message",{name:"{{name}}",role:l,dapp:"{{dapp}}"}),[n,l]),r=k(e.info.chainHost,e.inviter.did,"account"),c=I(p,{name(){return r?i.jsx("a",{target:"_blank",href:r,className:"invite-user__link",rel:"noreferrer",children:e.inviter.fullName},"name"):e.inviter.fullName},dapp(){return i.jsx("a",{target:"_blank",href:e.info.url,className:"invite-user__link",rel:"noreferrer",children:e.info.name},"dapp")}});return i.jsxs(oe,{children:[i.jsx(Y,{did:e.inviter.did,src:encodeURI(e.inviter.avatar),size:80,shape:"circle",variant:"circle"}),i.jsx("div",{className:"invite-user__message",children:c})]})}R.propTypes={invitation:s.object.isRequired};const oe=v.div`
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  .invite-user__name {
    font-weight: 700;
    font-size: 16px;
    margin: 8px 0 2px 0;
  }
  .invite-user__address {
    font-size: 12px;
  }
  .invite-user__message {
    margin-top: 20px;
    font-weight: 700;
    /* width: 90%; */
    text-align: center;
    font-size: 18px;
  }
  .invite-user__link {
    color: ${({theme:e})=>e.palette.primary.main};
  }
`;function S({invitation:e,type:n="inviter"}){const{t:l}=w(),p=u.useMemo(()=>l("invite.success",{dapp:"{{dapp}}"}),[l]),r=k(e.info.chainHost,e.inviter.did,"account"),c=n==="receiver"?e.receiver:e.inviter,t=I(p,{name(){return r?i.jsx("a",{target:"_blank",href:r,className:"invite-user__link",rel:"noreferrer",children:c.fullName},"name"):c.fullName},dapp(){return i.jsx("a",{target:"_blank",href:e.info.url,className:"invite-user__link",rel:"noreferrer",children:e.info.name},"dapp")}});return i.jsxs(ae,{children:[i.jsx(y,{sx:{pt:1,color:"success.main"},children:i.jsx(J,{style:{fontSize:80}})}),i.jsx("div",{className:"invite-user__message",children:t})]})}S.propTypes={invitation:s.object.isRequired,type:s.oneOf(["inviter","receiver"])};const ae=v.div`
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  .invite-user__name {
    font-weight: 700;
    font-size: 16px;
    margin: 8px 0 2px 0;
  }
  .invite-user__address {
    font-size: 12px;
  }
  .invite-user__message {
    margin-top: 20px;
    font-weight: 700;
    /* width: 90%; */
    text-align: center;
    font-size: 18px;
  }
  .invite-user__link {
    color: ${({theme:e})=>e.palette.primary.main};
  }
`;function z({getDataFn:e,passportColor:n="auto",createPassportSvg:l,onLoginSuccess:p=()=>{},checkFn:r,onReceive:c=null,inService:t=!1,action:d="invite",status:m=""}){const o=K(e),x=u.useMemo(()=>o?.data?.orgId||"",[o?.data?.orgId]);if(o?.loading)return i.jsx(X,{});if(o?.error)return i.jsx(Q,{status:"404",title:o?.error?.response?.data,description:""});const a=m==="success"||o?.data?.status==="success",h=a?S:R,_=a?N:C;return i.jsx(ce,{className:"page-invite__wrapper",children:o?.data?i.jsxs(y,{className:"page-invite__card",children:[i.jsx(h,{invitation:o.data}),i.jsx(P,{invitation:o.data,action:d,createPassportSvg:l,passportColor:n}),i.jsx(_,{invitation:o.data,action:d,onLogin:p,checkFn:r,onReceive:c,inService:t,orgId:x})]}):null})}z.propTypes={getDataFn:s.func.isRequired,checkFn:s.func.isRequired,createPassportSvg:s.func.isRequired,onLoginSuccess:s.func,onReceive:s.func,passportColor:s.string,inService:s.bool,action:s.oneOf(["invite","issue-passpor"]),status:s.oneOf(["success",""])};const ce=G(y)`
  max-width: 460px;
  max-height: 650px;
  min-height: 450px;
  width: 90%;
  height: 80%;
  display: flex;
  flex-direction: column;
  margin: auto;
  box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.05);
  .page-invite__card {
    background-color: ${({theme:e})=>e.palette.background.paper};
    border-radius: 12px;
    flex: 1;
    padding: 20px 30px;
  }
  .page-invite__app {
    margin-top: 20px;
  }
`,xe=ie(z);export{xe as I};
