"use strict";var e=require("react/jsx-runtime"),r=require("react"),t=require("react-device-detect"),i=require("styled-components"),o=require("./useActiveWallet-dTc6deka.js"),a=require("./OpenLink-L5LZ-pEm.js"),s=require("./QrCode-ErbyIBDF.js"),n=require("lucide-react"),l=require("./ModalHeader-Cpls13mi.js"),c=require("./LabelXs-C8rLnCfU.js"),d=require("./context-rs-ygOK2.js"),u=require("./errors-CBapWvRs.js"),p=require("./internal-context-CdsQ3LEl.js"),h=require("./modal-context-BgeioxwT.js"),y=require("./privy-context-UTJouJ1x.js"),v=require("./shouldProceedtoEmbeddedWalletCreationFlow-DTSTIV1u.js"),m=require("./ScreenLayout-DaFW0I3a.js"),g=require("./farcaster-CWHXGAib.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("./events-context-Di6--rDg.js"),require("./index-Ub4KpwSY.js"),require("zustand"),require("./get-entropy-details-for-user-D63rM5_a.js"),require("./user-D2oPA-vS.js"),require("qrcode"),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("tinycolor2"),require("ofetch"),require("@privy-io/are-addresses-equal"),require("./index-BoiKFBqR.js"),require("./toViemAccount-CopJpCYv.js"),require("jose"),require("@coinbase/wallet-sdk"),require("@walletconnect/ethereum-provider"),require("./pkce-CmuJlEgn.js"),require("./paths-DizMb-lU.js"),require("./PrivyPluginContext-DsLtVhZA.js"),require("js-cookie"),require("@privy-io/ethereum"),require("viem/accounts"),require("mipd"),require("@scure/base"),require("./usePrivy-Dt4_yE6Q.js"),require("./use-unlink-wallet-DAxmY7kq.js"),require("@privy-io/popup"),require("@headlessui/react"),require("@privy-io/urls"),require("./getEmbeddedConnectedWallet-D6YL2FS9.js"),require("./frame-BHa-PKpX.js"),require("@privy-io/routes"),require("./use-deposit-address-CVyd0fqP.js"),require("x402/client"),require("@privy-io/api-base"),require("./use-sign-with-user-signer-BhoaqeNG.js"),require("./Screen-8NusMFtu.js"),require("./index-ByFhjjzH.js");let q=i.styled.div`
  width: 100%;
`,x=i.styled.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)"};
  }
`,f=i.styled.div`
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
`,j=i.styled.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;
  }
`,S=i.styled(j)`
  color: var(--privy-color-foreground-3);
  font-style: italic;
`,C=i.styled(c.LabelXs)`
  margin-bottom: 0.5rem;
`,E=i.styled(l.SecondaryButton)`
  && {
    gap: 0.375rem;
    font-size: 14px;
    flex-shrink: 0;
  }
`;const b=({value:t,title:i,placeholder:o,className:a,showCopyButton:s=!0,truncate:l,maxLength:c=40,disabled:d=!1})=>{let[u,p]=r.useState(!1),h=l&&t?((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,i=Math.floor(t/2)-1;return`${e.slice(0,r)}...${e.slice(-i)}`}return`${e.slice(0,t-3)}...`})(t,l,c):t;return r.useEffect((()=>{if(u){let e=setTimeout((()=>p(!1)),3e3);return()=>clearTimeout(e)}}),[u]),/*#__PURE__*/e.jsxs(q,{className:a,children:[i&&/*#__PURE__*/e.jsx(C,{children:i}),/*#__PURE__*/e.jsxs(x,{$disabled:d,children:[/*#__PURE__*/e.jsx(f,{children:t?/*#__PURE__*/e.jsx(j,{$disabled:d,title:t,children:h}):/*#__PURE__*/e.jsx(S,{$disabled:d,children:o||"No value"})}),s&&t&&/*#__PURE__*/e.jsx(E,{onClick:function(e){e.stopPropagation(),navigator.clipboard.writeText(t).then((()=>p(!0))).catch(console.error)},size:"sm",children:u?/*#__PURE__*/e.jsxs(e.Fragment,{children:["Copied",/*#__PURE__*/e.jsx(n.Check,{size:14})]}):/*#__PURE__*/e.jsxs(e.Fragment,{children:["Copy",/*#__PURE__*/e.jsx(n.Copy,{size:14})]})})]})]})},w=({connectUri:r,loading:i,success:n,errorMessage:l,onBack:c,onClose:d,onOpenFarcaster:u})=>t.isMobile||i?t.isIOS?/*#__PURE__*/e.jsx(m.ScreenLayout,{title:l?l.message:"Sign in with Farcaster",subtitle:l?l.detail:"To sign in with Farcaster, please open the Farcaster app.",icon:g.Farcaster,iconVariant:"loading",iconLoadingStatus:{success:n,fail:!!l},primaryCta:r&&u?{label:"Open Farcaster app",onClick:u}:void 0,onBack:c,onClose:d,watermark:!0}):/*#__PURE__*/e.jsx(m.ScreenLayout,{title:l?l.message:"Signing in with Farcaster",subtitle:l?l.detail:"This should only take a moment",icon:g.Farcaster,iconVariant:"loading",iconLoadingStatus:{success:n,fail:!!l},onBack:c,onClose:d,watermark:!0,children:r&&t.isMobile&&/*#__PURE__*/e.jsx(T,{children:/*#__PURE__*/e.jsx(a.OpenLinkButton,{text:"Take me to Farcaster",url:r,color:"#8a63d2"})})}):
/*#__PURE__*/e.jsx(m.ScreenLayout,{title:"Sign in with Farcaster",subtitle:"Scan with your phone's camera to continue.",onBack:c,onClose:d,watermark:!0,children:/*#__PURE__*/e.jsxs(A,{children:[/*#__PURE__*/e.jsx(_,{children:r?/*#__PURE__*/e.jsx(s.QrCode,{url:r,size:275,squareLogoElement:g.Farcaster}):/*#__PURE__*/e.jsx(R,{children:/*#__PURE__*/e.jsx(o.Loader,{})})}),/*#__PURE__*/e.jsxs(F,{children:[/*#__PURE__*/e.jsx(L,{children:"Or copy this link and paste it into a phone browser to open the Farcaster app."}),r&&/*#__PURE__*/e.jsx(b,{value:r,truncate:"end",maxLength:30,showCopyButton:!0,disabled:!0})]})]})}),k={component:()=>{let{authenticated:t,logout:i,ready:o,user:a}=y.usePrivyContext(),{lastScreen:s,navigate:n,navigateBack:l,setModalData:c}=h.usePrivyModal(),m=d.useAppConfig(),{getAuthFlow:g,loginWithFarcaster:q,closePrivyModal:x,createAnalyticsEvent:f}=p.usePrivyInternal(),[j,S]=r.useState(void 0),[C,E]=r.useState(!1),[b,k]=r.useState(!1),T=r.useRef([]),A=g(),_=A?.meta.connectUri;return r.useEffect((()=>{let e=Date.now(),r=setInterval((async()=>{let t=await A.pollForReady.execute(),i=Date.now()-e;if(t){clearInterval(r),E(!0);try{await q(),k(!0)}catch(e){let r={retryable:!1,message:"Authentication failed"};if(e?.privyErrorCode===u.PrivyErrorCode.ALLOWLIST_REJECTED)return void n("AllowlistRejectionScreen");if(e?.privyErrorCode===u.PrivyErrorCode.USER_LIMIT_REACHED)return console.error(new u.PrivyUserLimitReachedError(e).toString()),void n("UserLimitReachedScreen");if(e?.privyErrorCode===u.PrivyErrorCode.USER_DOES_NOT_EXIST)return void n("AccountNotFoundScreen");if(e?.privyErrorCode===u.PrivyErrorCode.LINKED_TO_ANOTHER_USER)r.detail=e.message??"This account has already been linked to another user.";else{if(e?.privyErrorCode===u.PrivyErrorCode.ACCOUNT_TRANSFER_REQUIRED&&e.data?.data?.nonce)return c({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 n("LinkConflictScreen");e?.privyErrorCode===u.PrivyErrorCode.INVALID_CREDENTIALS?(r.retryable=!0,r.detail="Something went wrong. Try again."):e?.privyErrorCode===u.PrivyErrorCode.TOO_MANY_REQUESTS&&(r.detail="Too many requests. Please wait before trying again.")}S(r)}}else i>12e4&&(clearInterval(r),S({retryable:!0,message:"Authentication failed",detail:"The request timed out. Try again."}))}),2e3);return()=>{clearInterval(r),T.current.forEach((e=>clearTimeout(e)))}}),[]),r.useEffect((()=>{if(o&&t&&b&&a){if(m?.legal.requireUsersAcceptTerms&&!a.hasAcceptedTerms){let e=setTimeout((()=>{n("AffirmativeConsentScreen")}),d.DEFAULT_SUCCESS_SCREEN_DURATION_MS);return()=>clearTimeout(e)}b&&(v.shouldProceedtoEmbeddedWalletCreationFlow(a,m.embeddedWallets)?T.current.push(setTimeout((()=>{c({createWallet:{onSuccess:()=>{},onFailure:e=>{console.error(e),f({eventName:"embedded_wallet_creation_failure_logout",payload:{error:e,screen:"FarcasterConnectStatusScreen"}}),i()},callAuthOnSuccessOnClose:!0}}),n("EmbeddedWalletOnAccountCreateScreen")}),d.DEFAULT_SUCCESS_SCREEN_DURATION_MS)):T.current.push(setTimeout((()=>x({shouldCallAuthOnSuccess:!0,isSuccess:!0})),d.DEFAULT_SUCCESS_SCREEN_DURATION_MS)))}}),[b,o,t,a]),/*#__PURE__*/e.jsx(w,{connectUri:_,loading:C,success:b,errorMessage:j,onBack:s?l:void 0,onClose:x,onOpenFarcaster:()=>{_&&(window.location.href=_)}})}};let T=i.styled.div`
  margin-top: 24px;
`,A=i.styled.div`
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
`,_=i.styled.div`
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 275px;
`,F=i.styled.div`
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
`,L=i.styled.div`
  font-size: 0.875rem;
  text-align: center;
  color: var(--privy-color-foreground-2);
`,R=i.styled.div`
  position: relative;
  width: 82px;
  height: 82px;
`;exports.FarcasterConnectStatusScreen=k,exports.FarcasterConnectStatusView=w,exports.default=k;
//# sourceMappingURL=FarcasterConnectStatusScreen-77NBZ9hx.js.map
