import{createPublicClient as e,http as r}from"viem";import{UsdcAddressMap as a,formatWalletAddress as o}from"@privy-io/js-sdk-core";import{a as i}from"./getPublicClient-D4yNgeGy.mjs";import{g as n}from"./getErc20Balance-Bkuf9-pm.mjs";import{jsx as t,jsxs as s,Fragment as c}from"react/jsx-runtime";import{useRef as l}from"react";import{c as m,B as d}from"./ModalHeader-DffkxvO4.mjs";import{b as h,R as p}from"./Layouts-BlFm53ED.mjs";import{t as u}from"./FundWalletMethodHeader-A50eT5P4.mjs";import{R as g}from"./Row-C9vrS4Zi.mjs";import{E as f}from"./ErrorMessage-D8VaAP5m.mjs";import{V as b,L as y}from"./Value-tcJV9e0L.mjs";import{S as v}from"./Subtitle-CV-2yKE4.mjs";import{T as j}from"./Title-BnzYV3Is.mjs";import C from"@heroicons/react/24/outline/WalletIcon";import{styled as w}from"styled-components";import{g as x}from"./getChainName-DjpPdUSc.mjs";import{C as k}from"./Chip-D2-wZOHJ.mjs";import{N}from"./NetworkIcon-B48ilzF8.mjs";import{B,a as T}from"./shared-FM0rljBt.mjs";import{Menu as S,MenuButton as A,MenuItems as I,MenuItem as E}from"@headlessui/react";import $ from"@heroicons/react/24/outline/ChevronDownIcon";import{f as F}from"./formatErc20TokenAmount-BuPk9xcy.mjs";import{g as P}from"./ethers-VpbQV-TA.mjs";import{F as L,a as M,b as D,c as R,d as U}from"./styles-ByUO8DsA.mjs";const W=({chains:o,appId:t,address:s,rpcConfig:c})=>Promise.all(o.map((async o=>{let l=e({chain:o,transport:r(i(o,c,t))}),m=await l.getBalance({address:s}).catch((()=>0n)),d=null,h=a[o.id];if(h){let{balance:e}=await n({address:s,chain:o,rpcConfig:c,appId:t,erc20Address:h});d=e}return{balance:m,erc20Balance:d,erc20Address:h,chain:o}}))),z=({balance:e,className:r,chain:a})=>/*#__PURE__*/t(B,{className:r,$state:void 0,children:/*#__PURE__*/t(H,{balance:e,chain:a})}),H=({balance:e,chain:r})=>/*#__PURE__*/s(c,{children:[/*#__PURE__*/s(Q,{children:[/*#__PURE__*/t(G,{chainId:"object"==typeof r?r.id:"solana"}),/*#__PURE__*/t(b,{children:"object"==typeof r?r.name:x(r)})]}),/*#__PURE__*/s(k,{isLoading:!1,isPulsing:!1,color:"gray",children:[/*#__PURE__*/t(V,{children:/*#__PURE__*/t(C,{})}),e]})]});let Q=w.div`
  display: flex;
  align-items: center;
`,V=w.div`
  height: 0.75rem;
  width: 0.75rem;
  margin-right: 0.2rem;
`,G=w(N)`
  height: 1.25rem;
  width: 1.25rem;
  display: inline-block;
  margin-right: 0.5rem;
  border-radius: 4px;
`;const J=({options:e,onSelect:r,selected:a,className:o})=>/*#__PURE__*/s(S,{as:O,children:[/*#__PURE__*/s(A,{as:X,children:[/*#__PURE__*/t(H,{balance:a.balance,chain:a.chain}),/*#__PURE__*/t(K,{height:16})]}),/*#__PURE__*/t(I,{as:Y,className:o,children:e.map(((e,a)=>/*#__PURE__*/t(E,{as:q,onClick:()=>r(a),children:/*#__PURE__*/t(H,{balance:e.balance,chain:e.chain})},a)))})]});let O=w.div`
  width: 100%;
  position: relative;
`,Y=w.div`
  width: 100%;
  margin-top: 0.5rem;
  position: absolute;
  background-color: var(--privy-color-background);
  border-radius: var(--privy-border-radius-md);
  overflow-x: hidden;
  overflow-y: auto;
  box-shadow: 0px 1px 2px 0px rgba(16, 24, 40, 0.05);
  max-height: 11.75rem;

  && {
    border: solid 1px var(--privy-color-foreground-4);
  }

  z-index: 1;
`,q=w.button`
  width: 100%;
  display: flex;
  justify-content: space-between;

  && {
    padding: 1rem;
  }

  :not(:last-child) {
    border-bottom: solid 1px var(--privy-color-foreground-4);
  }

  :hover {
    background: var(--privy-color-background-2);
  }
`,K=w($)`
  height: 1rem;
  margin-left: 0.5rem;
`,X=w.button`
  ${T}

  /* Push the chip all the way to the right */
  span {
    margin-left: auto;
  }

  ${K} {
    transition: rotate 100ms ease-in;
  }

  &[aria-expanded='true'] {
    ${K} {
      rotate: -180deg;
    }
  }
`;const Z=({displayName:e,errorMessage:r,configuredFundingChain:a,formattedBalance:i,fundingAmount:n,fundingCurrency:b,fundingAmountInUsd:C,options:w,selectedOption:k,isPreparing:N,isSubmitting:B,addressToFund:T,fundingWalletAddress:S,onSubmit:A,onSelect:I,onAmountChange:E})=>{let $=l(null);/*#__PURE__*/return s(c,{children:[/*#__PURE__*/t(u,{}),/*#__PURE__*/t(h,{}),/*#__PURE__*/t(j,{children:"Transfer from another network"}),/*#__PURE__*/s(v,{children:["You need more funds on the"," ","object"==typeof a?a.name:x(a)," ","network. Bridge from another blockchain network."]}),/*#__PURE__*/s(L,{style:{marginTop:"2rem"},children:[/*#__PURE__*/s(M,{onClick:()=>$.current?.focus(),children:[/*#__PURE__*/t(D,{ref:$,value:n,onChange:e=>{let r=e.target.value;if(/^[0-9.]*$/.test(r)&&r.split(".").length-1<=1){let e=/\.$/.test(r)?".":"",a=Number(r.replace(/\.$/,"")||"0");if(Number.isNaN(a))return void E("0");E(a.toString()+e)}}}),/*#__PURE__*/t(R,{children:b})]}),C&&/*#__PURE__*/t(U,{children:C})]}),/*#__PURE__*/s(g,{style:{marginTop:"1.5rem"},children:[/*#__PURE__*/t(y,{children:"From"}),/*#__PURE__*/t(y,{children:o(S)})]}),/*#__PURE__*/t(J,{selected:{chain:k.chain,balance:k.isErc20Quote?F({amount:k.erc20Balance??0n,decimals:6})+" USDC":P(k.balance,k.chain.nativeCurrency.symbol,3,!0)},options:w.map((({chain:e,balance:r,isErc20Quote:a,erc20Balance:o})=>({chain:e,balance:a?F({amount:o??0n,decimals:6})+" USDC":P(r,e.nativeCurrency.symbol,3,!0)}))),onSelect:I}),/*#__PURE__*/s(g,{style:{marginTop:"1.5rem"},children:[/*#__PURE__*/t(y,{children:"To"}),/*#__PURE__*/t(y,{children:o(T)})]}),/*#__PURE__*/t(z,{chain:a,balance:i}),/*#__PURE__*/t(f,{style:{marginTop:"1rem"},children:r}),/*#__PURE__*/s(m,{style:{marginTop:"1rem"},loading:B||N,disabled:N||B,onClick:A,children:["Confirm with ",e]}),/*#__PURE__*/t(p,{}),/*#__PURE__*/t(d,{})]})};export{Z as B,W as g};
//# sourceMappingURL=BridgeNetworkSelectionView-C9MwVnhb.mjs.map
