import{jsxs as e,jsx as r,Fragment as t}from"react/jsx-runtime";import{useState as o,useEffect as i,useRef as a}from"react";import{isMobile as n,isIOS as s}from"react-device-detect";import{styled as l}from"styled-components";import{L as c}from"./useActiveWallet-BEfvREjE.mjs";import{O as d}from"./OpenLink-DZHy38vr.mjs";import{Q as m}from"./QrCode-CvO4k-hN.mjs";import{Check as p,Copy as u}from"lucide-react";import{S as h}from"./ModalHeader-DffkxvO4.mjs";import{L as v}from"./LabelXs-oqZNqbm_.mjs";import{u as f,r as g}from"./context-BKnOUECq.mjs";import{a as y,j as b}from"./errors-Dd6zfYtp.mjs";import{u as w}from"./internal-context-dfitw7Ot.mjs";import{u as x}from"./modal-context-DBwfUxD-.mjs";import{u as j}from"./privy-context-Bi6vqCPc.mjs";import{s as k}from"./shouldProceedtoEmbeddedWalletCreationFlow-SyjOJUom.mjs";import{S as C}from"./ScreenLayout-Caq5mGD8.mjs";import{F as S}from"./farcaster-DPlSjvF5.mjs";import"viem/utils";import"./wallet-connect-58EobR5U.mjs";import"./getPublicClient-D4yNgeGy.mjs";import"viem";import"viem/chains";import"@privy-io/js-sdk-core";import"eventemitter3";import"./events-context-BJ75xIIf.mjs";import"./index-BtwxknTg.mjs";import"zustand";import"./get-entropy-details-for-user-BIWg0YxF.mjs";import"./user-D5cqJNp9.mjs";import"qrcode";import"@heroicons/react/24/outline/ArrowLeftIcon";import"@heroicons/react/24/outline/ArrowRightIcon";import"@heroicons/react/24/outline/QuestionMarkCircleIcon";import"@heroicons/react/24/outline/XMarkIcon";import"tinycolor2";import"ofetch";import"@privy-io/are-addresses-equal";import"./index-C5jxD-zy.mjs";import"./toViemAccount-4iGGrW4w.mjs";import"jose";import"@coinbase/wallet-sdk";import"@walletconnect/ethereum-provider";import"./pkce-BinverJO.mjs";import"./paths-BH8W4zMc.mjs";import"./PrivyPluginContext-DA-yS5vO.mjs";import"js-cookie";import"@privy-io/ethereum";import"viem/accounts";import"mipd";import"@scure/base";import"./usePrivy-BhL-ltvm.mjs";import"./use-unlink-wallet-oAguM2-k.mjs";import"@privy-io/popup";import"@headlessui/react";import"@privy-io/urls";import"./getEmbeddedConnectedWallet-Ba6LFHzY.mjs";import"./frame-DtizlaLu.mjs";import"@privy-io/routes";import"./use-deposit-address-BwThybOQ.mjs";import"x402/client";import"@privy-io/api-base";import"./use-sign-with-user-signer-CQI6hUH7.mjs";import"./Screen-D8KNyGVj.mjs";import"./index-Dq_xe9dz.mjs";let E=l.div`
  width: 100%;
`,T=l.div`
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem;
  height: 56px;
  background: ${e=>e.$disabled?"var(--privy-color-background-2)":"var(--privy-color-background)"};
  border: 1px solid var(--privy-color-foreground-4);
  border-radius: var(--privy-border-radius-md);

  &:hover {
    border-color: ${e=>e.$disabled?"var(--privy-color-foreground-4)":"var(--privy-color-foreground-3)"};
  }
`,A=l.div`
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
`,L=l.span`
  display: block;
  font-size: 16px;
  line-height: 24px;
  color: ${e=>e.$disabled?"var(--privy-color-foreground-2)":"var(--privy-color-foreground)"};
  overflow: hidden;
  text-overflow: ellipsis;
  /* Use single-line truncation without nowrap to respect container width */
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  word-break: break-all;

  @media (min-width: 441px) {
    font-size: 14px;
    line-height: 20px;
  }
`,F=l(L)`
  color: var(--privy-color-foreground-3);
  font-style: italic;
`,O=l(v)`
  margin-bottom: 0.5rem;
`,_=l(h)`
  && {
    gap: 0.375rem;
    font-size: 14px;
    flex-shrink: 0;
  }
`;const I=({value:a,title:n,placeholder:s,className:l,showCopyButton:c=!0,truncate:d,maxLength:m=40,disabled:h=!1})=>{let[v,f]=o(!1),g=d&&a?((e,r,t)=>{if((e=e.startsWith("https://")?e.slice(8):e).length<=t)return e;if("middle"===r){let r=Math.ceil(t/2)-2,o=Math.floor(t/2)-1;return`${e.slice(0,r)}...${e.slice(-o)}`}return`${e.slice(0,t-3)}...`})(a,d,m):a;return i((()=>{if(v){let e=setTimeout((()=>f(!1)),3e3);return()=>clearTimeout(e)}}),[v]),/*#__PURE__*/e(E,{className:l,children:[n&&/*#__PURE__*/r(O,{children:n}),/*#__PURE__*/e(T,{$disabled:h,children:[/*#__PURE__*/r(A,{children:a?/*#__PURE__*/r(L,{$disabled:h,title:a,children:g}):/*#__PURE__*/r(F,{$disabled:h,children:s||"No value"})}),c&&a&&/*#__PURE__*/r(_,{onClick:function(e){e.stopPropagation(),navigator.clipboard.writeText(a).then((()=>f(!0))).catch(console.error)},size:"sm",children:/*#__PURE__*/e(t,v?{children:["Copied",/*#__PURE__*/r(p,{size:14})]}:{children:["Copy",/*#__PURE__*/r(u,{size:14})]})})]})]})},R=({connectUri:t,loading:o,success:i,errorMessage:a,onBack:l,onClose:p,onOpenFarcaster:u})=>/*#__PURE__*/r(C,n||o?s?{title:a?a.message:"Sign in with Farcaster",subtitle:a?a.detail:"To sign in with Farcaster, please open the Farcaster app.",icon:S,iconVariant:"loading",iconLoadingStatus:{success:i,fail:!!a},primaryCta:t&&u?{label:"Open Farcaster app",onClick:u}:void 0,onBack:l,onClose:p,watermark:!0}:{title:a?a.message:"Signing in with Farcaster",subtitle:a?a.detail:"This should only take a moment",icon:S,iconVariant:"loading",iconLoadingStatus:{success:i,fail:!!a},onBack:l,onClose:p,watermark:!0,children:t&&n&&/*#__PURE__*/r(U,{children:/*#__PURE__*/r(d,{text:"Take me to Farcaster",url:t,color:"#8a63d2"})})}:{title:"Sign in with Farcaster",subtitle:"Scan with your phone's camera to continue.",onBack:l,onClose:p,watermark:!0,children:/*#__PURE__*/e(M,{children:[/*#__PURE__*/r($,{children:t?/*#__PURE__*/r(m,{url:t,size:275,squareLogoElement:S}):/*#__PURE__*/r(z,{children:/*#__PURE__*/r(c,{})})}),/*#__PURE__*/e(W,{children:[/*#__PURE__*/r(D,{children:"Or copy this link and paste it into a phone browser to open the Farcaster app."}),t&&/*#__PURE__*/r(I,{value:t,truncate:"end",maxLength:30,showCopyButton:!0,disabled:!0})]})]})}),N={component:()=>{let{authenticated:e,logout:t,ready:n,user:s}=j(),{lastScreen:l,navigate:c,navigateBack:d,setModalData:m}=x(),p=f(),{getAuthFlow:u,loginWithFarcaster:h,closePrivyModal:v,createAnalyticsEvent:C}=w(),[S,E]=o(void 0),[T,A]=o(!1),[L,F]=o(!1),O=a([]),_=u(),I=_?.meta.connectUri;return i((()=>{let e=Date.now(),r=setInterval((async()=>{let t=await _.pollForReady.execute(),o=Date.now()-e;if(t){clearInterval(r),A(!0);try{await h(),F(!0)}catch(e){let r={retryable:!1,message:"Authentication failed"};if(e?.privyErrorCode===y.ALLOWLIST_REJECTED)return void c("AllowlistRejectionScreen");if(e?.privyErrorCode===y.USER_LIMIT_REACHED)return console.error(new b(e).toString()),void c("UserLimitReachedScreen");if(e?.privyErrorCode===y.USER_DOES_NOT_EXIST)return void c("AccountNotFoundScreen");if(e?.privyErrorCode===y.LINKED_TO_ANOTHER_USER)r.detail=e.message??"This account has already been linked to another user.";else{if(e?.privyErrorCode===y.ACCOUNT_TRANSFER_REQUIRED&&e.data?.data?.nonce)return m({accountTransfer:{nonce:e.data?.data?.nonce,account:e.data?.data?.subject,displayName:e.data?.data?.account?.displayName,linkMethod:"farcaster",embeddedWalletAddress:e.data?.data?.otherUser?.embeddedWalletAddress,farcasterEmbeddedAddress:e.data?.data?.otherUser?.farcasterEmbeddedAddress}}),void c("LinkConflictScreen");e?.privyErrorCode===y.INVALID_CREDENTIALS?(r.retryable=!0,r.detail="Something went wrong. Try again."):e?.privyErrorCode===y.TOO_MANY_REQUESTS&&(r.detail="Too many requests. Please wait before trying again.")}E(r)}}else o>12e4&&(clearInterval(r),E({retryable:!0,message:"Authentication failed",detail:"The request timed out. Try again."}))}),2e3);return()=>{clearInterval(r),O.current.forEach((e=>clearTimeout(e)))}}),[]),i((()=>{if(n&&e&&L&&s){if(p?.legal.requireUsersAcceptTerms&&!s.hasAcceptedTerms){let e=setTimeout((()=>{c("AffirmativeConsentScreen")}),g);return()=>clearTimeout(e)}L&&(k(s,p.embeddedWallets)?O.current.push(setTimeout((()=>{m({createWallet:{onSuccess:()=>{},onFailure:e=>{console.error(e),C({eventName:"embedded_wallet_creation_failure_logout",payload:{error:e,screen:"FarcasterConnectStatusScreen"}}),t()},callAuthOnSuccessOnClose:!0}}),c("EmbeddedWalletOnAccountCreateScreen")}),g)):O.current.push(setTimeout((()=>v({shouldCallAuthOnSuccess:!0,isSuccess:!0})),g)))}}),[L,n,e,s]),/*#__PURE__*/r(R,{connectUri:I,loading:T,success:L,errorMessage:S,onBack:l?d:void 0,onClose:v,onOpenFarcaster:()=>{I&&(window.location.href=I)}})}};let U=l.div`
  margin-top: 24px;
`,M=l.div`
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
`,$=l.div`
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 275px;
`,W=l.div`
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
`,D=l.div`
  font-size: 0.875rem;
  text-align: center;
  color: var(--privy-color-foreground-2);
`,z=l.div`
  position: relative;
  width: 82px;
  height: 82px;
`;export{N as FarcasterConnectStatusScreen,R as FarcasterConnectStatusView,N as default};
//# sourceMappingURL=FarcasterConnectStatusScreen-FVkT-G3_.mjs.map
