import{aF as L,j as i,r as u,p as T,bg as H,$ as M,s as v,o as s,v as D,K as y,cZ as E,V as w,n as A,aP as q,c_ as U,cD as F,aT as j,y as O,c$ as V,aH as W,d0 as Y,d1 as k,d2 as I,at as B,b8 as K,cw as J,C as X,b9 as Z}from"./index-CCv_8omK.js";import{p as G}from"./index-yORTeDE5.js";import{N as Q}from"./index-g_RqxcM4.js";import{b as ee}from"./sdk-BJ8ul4G_.js";import{w as ie}from"./wrap-locale-B1uKF2jP.js";const se=L(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:c="auto"}){const[p,r]=u.useState(!1),{t:l}=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||c,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(Q,{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:l("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:l("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(D,{color:"did",variant:"contained",...n,children:[i.jsx(y,{sx:{fontWeight:400},children:e||"Continue With"}),i.jsx(E,{style:{width:"auto",height:"1.2em",margin:"0 4px 0 8px"}})]})}b.propTypes={children:s.any};function C({invitation:e,onLogin:n=()=>{},onReceive:c=null,inService:p=!1,action:r="invite",orgId:l=""}){const{t,locale:d}=w(),{connectApi:m}=A(),{getPassportId:o}=F();let x;typeof window<"u"&&(x=window?.blocklet?.componentId);const a=q({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=l):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)}),$=j(()=>{if(typeof c=="function"){c();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,W.WELLKNOWN_SERVICE_PATH_PREFIX,V),messages:{title:t("receive.dialog.title"),scan:g,confirm:t("receive.dialog.confirm"),success:t("receive.dialog.success")},onSuccess:_,onClose:h,passkeyBehavior:"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:"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:$,children:t("invite.receive")}),i.jsxs("div",{className:"invite-receive__until",children:[t("invite.validUntil"),Y(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(),c=u.useMemo(()=>(e.role.title||e.role.name).toUpperCase(),[e.role.title,e.role.name]),p=u.useMemo(()=>n("invite.message",{name:"{{name}}",role:c,dapp:"{{dapp}}"}),[n,c]),r=k(e.info.chainHost,e.inviter.did,"account"),l=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(B,{did:e.inviter.did,src:encodeURI(e.inviter.avatar),size:80,shape:"circle",variant:"circle"}),i.jsx("div",{className:"invite-user__message",children:l})]})}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:c}=w(),p=u.useMemo(()=>c("invite.success",{dapp:"{{dapp}}"}),[c]),r=k(e.info.chainHost,e.inviter.did,"account"),l=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:l.fullName},"name"):l.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(K,{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:c,onLoginSuccess:p=()=>{},checkFn:r,onReceive:l=null,inService:t=!1,action:d="invite",status:m=""}){const o=J(e),x=u.useMemo(()=>o?.data?.orgId||"",[o?.data?.orgId]);if(o?.loading)return i.jsx(X,{});if(o?.error)return i.jsx(G,{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:c,passportColor:n}),i.jsx(_,{invitation:o.data,action:d,onLogin:p,checkFn:r,onReceive:l,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=Z(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};
