"use strict";var e=require("react/jsx-runtime"),r=require("lucide-react"),i=require("react"),t=require("styled-components"),n=require("./useActiveWallet-dTc6deka.js"),o=require("./TodoList-Cii_KrAk.js"),s=require("./errors-CBapWvRs.js"),a=require("./internal-context-CdsQ3LEl.js"),c=require("./modal-context-BgeioxwT.js"),l=require("./privy-context-UTJouJ1x.js"),d=require("./usePrivy-Dt4_yE6Q.js"),u=require("./ScreenLayout-DaFW0I3a.js");require("viem/utils"),require("./wallet-connect-BuohfvHK.js"),require("./getPublicClient-CFd_sHBk.js"),require("viem"),require("viem/chains"),require("@privy-io/js-sdk-core"),require("eventemitter3"),require("./context-rs-ygOK2.js"),require("tinycolor2"),require("./events-context-Di6--rDg.js"),require("./index-Ub4KpwSY.js"),require("zustand"),require("react-device-detect"),require("./get-entropy-details-for-user-D63rM5_a.js"),require("./user-D2oPA-vS.js"),require("ofetch"),require("@privy-io/are-addresses-equal"),require("./use-unlink-wallet-DAxmY7kq.js"),require("@privy-io/popup"),require("./paths-DizMb-lU.js"),require("./pkce-CmuJlEgn.js"),require("jose"),require("./ModalHeader-Cpls13mi.js"),require("@heroicons/react/24/outline/ArrowLeftIcon"),require("@heroicons/react/24/outline/ArrowRightIcon"),require("@heroicons/react/24/outline/QuestionMarkCircleIcon"),require("@heroicons/react/24/outline/XMarkIcon"),require("./Screen-8NusMFtu.js"),require("./index-ByFhjjzH.js");const p=({passkeys:i,name:t,isLoading:n,errorReason:o,success:s,expanded:a,onLinkPasskey:c,onUnlinkPasskey:l,onExpand:d,onBack:p,onClose:g})=>s?/*#__PURE__*/e.jsx(u.ScreenLayout,{title:"Passkeys updated",icon:r.CheckCircle,iconVariant:"success",primaryCta:{label:"Done",onClick:g},onClose:g,watermark:!0}):a?/*#__PURE__*/e.jsx(u.ScreenLayout,{icon:r.FingerprintIcon,title:"Your passkeys",onBack:p,onClose:g,watermark:!0,children:/*#__PURE__*/e.jsx(v,{passkeys:i,expanded:a,onUnlink:l,onExpand:d})}):/*#__PURE__*/e.jsxs(u.ScreenLayout,{icon:r.FingerprintIcon,title:"Set up passkey verification",subtitle:"Verify with passkey",primaryCta:{label:"Add new passkey",onClick:c,loading:n},onClose:g,watermark:!0,helpText:o||void 0,children:[0===i.length?/*#__PURE__*/e.jsx(k,{}):/*#__PURE__*/e.jsx(y,{children:/*#__PURE__*/e.jsx(v,{passkeys:i,expanded:a,onUnlink:l,onExpand:d})}),t?/*#__PURE__*/e.jsxs(h,{children:[/*#__PURE__*/e.jsx(x,{children:"New Passkey Name"}),/*#__PURE__*/e.jsx(m,{children:t})]}):null]});let y=t.styled.div`
  margin-bottom: 0.75rem;
`,h=t.styled.div`
  margin-top: 0.25rem;
`,x=t.styled.div`
  color: var(--privy-color-foreground-2);
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1rem;
  margin-bottom: 0.25rem;
`,m=t.styled.div`
  color: var(--privy-color-foreground);
  font-size: 0.875rem;
  line-height: 1.25rem;
`,v=({passkeys:t,expanded:o,onUnlink:s,onExpand:a})=>{let[c,l]=i.useState([]),d=o?t.length:2;/*#__PURE__*/return e.jsxs("div",{children:[/*#__PURE__*/e.jsx(C,{children:"Your passkeys"}),/*#__PURE__*/e.jsxs(w,{children:[t.slice(0,d).map((i=>{/*#__PURE__*/return e.jsxs(I,{children:[/*#__PURE__*/e.jsxs("div",{children:[/*#__PURE__*/e.jsx(P,{children:(t=i,t.authenticatorName?t.createdWithBrowser?`${t.authenticatorName} on ${t.createdWithBrowser}`:t.authenticatorName:t.createdWithBrowser?t.createdWithOs?`${t.createdWithBrowser} on ${t.createdWithOs}`:`${t.createdWithBrowser}`:"Unknown device")}),/*#__PURE__*/e.jsxs(b,{children:["Last used:"," ",(i.latestVerifiedAt??i.firstVerifiedAt)?.toLocaleString()??"N/A"]})]}),/*#__PURE__*/e.jsx(E,{disabled:c.includes(i.credentialId),onClick:()=>(async e=>{l((r=>r.concat([e]))),await s(e),l((r=>r.filter((r=>r!==e))))})(i.credentialId),children:c.includes(i.credentialId)?/*#__PURE__*/e.jsx(n.ButtonLoader,{}):/*#__PURE__*/e.jsx(r.Trash2,{size:16})})]},i.credentialId);var t})),t.length>2&&!o&&/*#__PURE__*/e.jsx(q,{onClick:a,children:"View all"})]})]})},k=()=>/*#__PURE__*/e.jsxs(o.TodoList,{style:{color:"var(--privy-color-foreground)"},children:[/*#__PURE__*/e.jsx(o.TodoItem,{children:"Verify with Touch ID, Face ID, PIN, or hardware key"}),/*#__PURE__*/e.jsx(o.TodoItem,{children:"Takes seconds to set up and use"}),/*#__PURE__*/e.jsx(o.TodoItem,{children:"Use your passkey to verify transactions and login to your account"})]});const g={component:()=>{let{user:r}=l.usePrivyContext(),{unlink:t}=d.useUnlinkPasskey(),{linkWithPasskey:n,closePrivyModal:o}=a.usePrivyInternal(),{data:u}=c.usePrivyModal(),y=r?.linkedAccounts.filter((e=>"passkey"===e.type)),[h,x]=i.useState(!1),[m,v]=i.useState(""),[k,g]=i.useState(!1),[f,j]=i.useState(!1);i.useEffect((()=>{0===y.length&&j(!1)}),[y.length]);/*#__PURE__*/return e.jsx(p,{passkeys:y,name:u?.passkeyAuthModalData?.name,isLoading:h,errorReason:m,success:k,expanded:f,onLinkPasskey:()=>{x(!0),n({name:u?.passkeyAuthModalData?.name}).then((()=>g(!0))).catch((e=>{if(e instanceof s.PrivyError){if(e.privyErrorCode===s.PrivyErrorCode.CANNOT_LINK_MORE_OF_TYPE)return void v("Cannot link more passkeys to account.");if(e.privyErrorCode===s.PrivyErrorCode.PASSKEY_NOT_ALLOWED)return void v("Passkey request timed out or rejected by user.")}v("Unknown error occurred.")})).finally((()=>{x(!1)}))},onUnlinkPasskey:async e=>(x(!0),await t({credentialId:e}).then((()=>g(!0))).catch((e=>{e instanceof s.PrivyError&&e.privyErrorCode===s.PrivyErrorCode.MISSING_MFA_CREDENTIALS?v("Cannot unlink a passkey enrolled in MFA"):v("Unknown error occurred.")})).finally((()=>{x(!1)}))),onExpand:()=>j(!0),onBack:()=>j(!1),onClose:()=>o()})}},f=t.styled.div`
  display: flex;
  align-items: center;
  justify-content: center;
  width: 180px;
  height: 90px;
  border-radius: 50%;
  svg + svg {
    margin-left: 12px;
  }
  > svg {
    z-index: 2;
    color: var(--privy-color-accent) !important;
    stroke: var(--privy-color-accent) !important;
    fill: var(--privy-color-accent) !important;
  }
`;let j=t.css`
  && {
    width: 100%;
    font-size: 0.875rem;
    line-height: 1rem;

    /* Tablet and Up */
    @media (min-width: 440px) {
      font-size: 14px;
    }

    display: flex;
    gap: 12px;
    justify-content: center;

    padding: 6px 8px;
    background-color: var(--privy-color-background);
    transition: background-color 200ms ease;
    color: var(--privy-color-accent) !important;

    :focus {
      outline: none;
      box-shadow: none;
    }
  }
`;const q=t.styled.button`
  ${j}
`;let w=t.styled.div`
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.8rem;
  padding: 0.5rem 0rem 0rem;
  flex-grow: 1;
  width: 100%;
`,C=t.styled.div`
  line-height: 20px;
  height: 20px;
  font-size: 1em;
  font-weight: 450;
  display: flex;
  justify-content: flex-beginning;
  width: 100%;
`,P=t.styled.div`
  font-size: 1em;
  line-height: 1.3em;
  font-weight: 500;
  color: var(--privy-color-foreground-2);
  padding: 0.2em 0;
`,b=t.styled.div`
  font-size: 0.875rem;
  line-height: 1rem;
  color: #64668b;
  padding: 0.2em 0;
`,I=t.styled.div`
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1em;
  gap: 10px;
  font-size: 0.875rem;
  line-height: 1rem;
  text-align: left;
  border-radius: 8px;
  border: 1px solid #e2e3f0 !important;
  width: 100%;
  height: 5em;
`,L=t.css`
  :focus,
  :hover,
  :active {
    outline: none;
  }
  display: flex;
  width: 2em;
  height: 2em;
  justify-content: center;
  align-items: center;
  svg {
    color: var(--privy-color-error);
  }
  svg:hover {
    color: var(--privy-color-foreground-3);
  }
`,E=t.styled.button`
  ${L}
`;exports.DoubleIconWrapper=f,exports.LinkButton=q,exports.LinkPasskeyScreen=g,exports.LinkPasskeyView=p,exports.default=g;
//# sourceMappingURL=LinkPasskeyScreen-C2FrXW9H.js.map
