;(function () {
/* PortfolioCard — total portfolio value + 3 action pills (Deposit / Withdraw / Transfer). */

const EyeOff = ({ width, height, color, opacity }) => (
  <svg width={width} height={height} viewBox="0 0 19.688 18" fill="none" style={{ color, opacity }}>
    <path d="M 19.424 8.287 L 20.27 7.753 L 20.27 7.753 L 19.424 8.287 Z M 8.44 1.103 C 7.894 1.184 7.517 1.692 7.597 2.239 C 7.678 2.785 8.187 3.162 8.733 3.082 L 8.587 2.092 L 8.44 1.103 Z M 19.423 9.716 L 20.268 10.25 L 20.268 10.25 L 19.423 9.716 Z M 17.294 10.938 C 16.939 11.362 16.995 11.993 17.418 12.347 C 17.842 12.702 18.472 12.646 18.827 12.222 L 18.06 11.58 L 17.294 10.938 Z M 19.667 8.777 L 18.692 9 L 18.692 9 L 19.667 8.777 Z M 19.667 9.224 L 20.642 9.447 L 20.642 9.447 L 19.667 9.224 Z M 0.264 9.713 L 1.109 9.179 L 1.109 9.179 L 0.264 9.713 Z M 0.265 8.285 L -0.581 7.751 L -0.581 7.751 L 0.265 8.285 Z M 5.129 4.543 C 5.587 4.233 5.706 3.611 5.396 3.154 C 5.086 2.697 4.464 2.577 4.007 2.887 L 4.568 3.715 L 5.129 4.543 Z M 15.695 15.103 C 16.152 14.793 16.27 14.171 15.959 13.714 C 15.649 13.258 15.027 13.139 14.57 13.45 L 15.133 14.277 L 15.695 15.103 Z M 0.021 9.223 L 0.996 9 L 0.996 9 L 0.021 9.223 Z M 0.021 8.776 L -0.953 8.553 L -0.953 8.553 L 0.021 8.776 Z M 1.551 -0.707 C 1.161 -1.098 0.528 -1.098 0.137 -0.707 C -0.253 -0.317 -0.253 0.317 0.137 0.707 L 0.844 0 L 1.551 -0.707 Z M 18.137 18.707 C 18.528 19.098 19.161 19.098 19.551 18.707 C 19.942 18.317 19.942 17.683 19.551 17.293 L 18.844 18 L 18.137 18.707 Z M 8.43 7.586 C 8.82 7.195 8.82 6.562 8.43 6.172 C 8.039 5.781 7.406 5.781 7.016 6.172 L 7.723 6.879 L 8.43 7.586 Z M 12.673 11.828 C 13.063 11.438 13.063 10.805 12.673 10.414 C 12.282 10.024 11.649 10.024 11.258 10.414 L 11.965 11.121 L 12.673 11.828 Z M 9.844 2 L 9.844 3 C 12.087 3 13.982 3.988 15.486 5.243 C 16.992 6.5 18.046 7.977 18.579 8.821 L 19.424 8.287 L 20.27 7.753 C 19.677 6.814 18.494 5.148 16.767 3.707 C 15.039 2.265 12.706 1 9.844 1 L 9.844 2 Z M 8.587 2.092 L 8.733 3.082 C 9.092 3.028 9.462 3 9.844 3 L 9.844 2 L 9.844 1 C 9.362 1 8.894 1.036 8.44 1.103 L 8.587 2.092 Z M 19.423 9.716 L 18.578 9.181 C 18.296 9.627 17.865 10.256 17.294 10.938 L 18.06 11.58 L 18.827 12.222 C 19.467 11.458 19.95 10.754 20.268 10.25 L 19.423 9.716 Z M 19.424 8.287 L 18.579 8.821 C 18.614 8.877 18.639 8.916 18.66 8.95 C 18.68 8.983 18.69 9.001 18.695 9.011 C 18.7 9.02 18.699 9.019 18.696 9.012 C 18.695 9.009 18.694 9.006 18.693 9.004 C 18.692 9.001 18.692 9 18.692 9 L 19.667 8.777 L 20.642 8.553 C 20.559 8.193 20.39 7.943 20.27 7.753 L 19.424 8.287 Z M 19.423 9.716 L 20.268 10.25 C 20.389 10.059 20.559 9.808 20.642 9.447 L 19.667 9.224 L 18.692 9 C 18.692 9 18.692 8.999 18.693 8.996 C 18.694 8.993 18.695 8.99 18.696 8.987 C 18.699 8.981 18.7 8.98 18.695 8.989 C 18.69 8.999 18.679 9.018 18.659 9.051 C 18.638 9.086 18.613 9.125 18.578 9.181 L 19.423 9.716 Z M 19.667 8.777 L 18.692 9 C 18.689 8.988 18.688 8.98 18.688 8.977 C 18.687 8.974 18.687 8.973 18.687 8.975 C 18.688 8.977 18.688 8.98 18.688 8.985 C 18.688 8.99 18.688 8.995 18.688 9 C 18.688 9.005 18.688 9.011 18.688 9.015 C 18.688 9.02 18.688 9.023 18.687 9.025 C 18.687 9.027 18.687 9.026 18.688 9.023 C 18.688 9.02 18.689 9.012 18.692 9 L 19.667 9.224 L 20.642 9.447 C 20.704 9.175 20.704 8.825 20.642 8.553 L 19.667 8.777 Z M 9.844 16 L 9.844 15 C 7.601 15 5.706 14.012 4.202 12.757 C 2.696 11.5 1.642 10.023 1.109 9.179 L 0.264 9.713 L -0.582 10.247 C 0.011 11.186 1.195 12.852 2.921 14.293 C 4.65 15.735 6.982 17 9.844 17 L 9.844 16 Z M 0.265 8.285 L 1.11 8.819 C 1.752 7.804 3.132 5.898 5.129 4.543 L 4.568 3.715 L 4.007 2.887 C 1.68 4.466 0.124 6.635 -0.581 7.751 L 0.265 8.285 Z M 15.133 14.277 L 14.57 13.45 C 13.235 14.358 11.655 15 9.844 15 L 9.844 16 L 9.844 17 C 12.15 17 14.116 16.177 15.695 15.103 L 15.133 14.277 Z M 0.264 9.713 L 1.109 9.179 C 1.074 9.123 1.049 9.084 1.029 9.05 C 1.009 9.017 0.999 8.999 0.993 8.989 C 0.989 8.98 0.99 8.981 0.992 8.988 C 0.993 8.991 0.994 8.994 0.995 8.996 C 0.996 8.999 0.996 9 0.996 9 L 0.021 9.223 L -0.953 9.447 C -0.871 9.807 -0.702 10.057 -0.582 10.247 L 0.264 9.713 Z M 0.265 8.285 L -0.581 7.751 C -0.701 7.942 -0.871 8.192 -0.953 8.553 L 0.021 8.776 L 0.996 9 C 0.996 9 0.996 9.001 0.995 9.004 C 0.994 9.007 0.993 9.01 0.992 9.013 C 0.99 9.019 0.989 9.02 0.993 9.011 C 0.999 9.001 1.009 8.983 1.029 8.949 C 1.05 8.915 1.075 8.876 1.11 8.819 L 0.265 8.285 Z M 0.021 9.223 L 0.996 9 C 0.999 9.012 1 9.02 1.001 9.023 C 1.001 9.026 1.001 9.027 1.001 9.025 C 1.001 9.023 1.001 9.02 1 9.015 C 1 9.01 1 9.005 1 9 C 1 8.995 1 8.989 1 8.985 C 1.001 8.98 1.001 8.977 1.001 8.975 C 1.001 8.973 1.001 8.974 1.001 8.977 C 1 8.98 0.999 8.988 0.996 9 L 0.021 8.776 L -0.953 8.553 C -1.016 8.825 -1.016 9.175 -0.953 9.447 L 0.021 9.223 Z M 0.844 0 L 0.137 0.707 L 18.137 18.707 L 18.844 18 L 19.551 17.293 L 1.551 -0.707 L 0.844 0 Z M 9.844 12 L 9.844 11 C 8.74 11 7.844 10.105 7.844 9 L 6.844 9 L 5.844 9 C 5.844 11.209 7.635 13 9.844 13 L 9.844 12 Z M 6.844 9 L 7.844 9 C 7.844 8.447 8.067 7.949 8.43 7.586 L 7.723 6.879 L 7.016 6.172 C 6.293 6.894 5.844 7.896 5.844 9 L 6.844 9 Z M 11.965 11.121 L 11.258 10.414 C 10.895 10.777 10.397 11 9.844 11 L 9.844 12 L 9.844 13 C 10.948 13 11.95 12.551 12.673 11.828 L 11.965 11.121 Z" fill="currentColor" fillRule="nonzero"/>
  </svg>
);

const CreditCardDown = ({ width, height }) => (
  <svg width={width} height={height} viewBox="0 0 20 20" fill="none">
    <path d="M18.3341 7.50065H1.66748M4.58415 15.0006H4.33415C3.40073 15.0006 2.93402 15.0006 2.5775 14.819C2.26389 14.6592 2.00893 14.4042 1.84914 14.0906C1.66748 13.7341 1.66748 13.2674 1.66748 12.334V6.00065C1.66748 5.06723 1.66748 4.60052 1.84914 4.244C2.00893 3.9304 2.26389 3.67543 2.5775 3.51564C2.93402 3.33398 3.40073 3.33398 4.33415 3.33398H15.6675C16.6009 3.33398 17.0676 3.33398 17.4241 3.51564C17.7377 3.67543 17.9927 3.9304 18.1525 4.244C18.3341 4.60052 18.3341 5.06723 18.3341 6.00065V12.334C18.3341 13.2674 18.3341 13.7341 18.1525 14.0906C17.9927 14.4042 17.7377 14.6592 17.4241 14.819C17.0676 15.0007 16.6009 15.0007 15.6675 15.0007H15.4175" stroke="#344054" strokeWidth="1.25" strokeLinecap="round" strokeLinejoin="round"/>
    <path d="M12.5 14.1667L10 16.6667L7.5 14.1667M10 16.6667V10.8334" stroke="#00AFAB" strokeWidth="1.25" strokeLinecap="round" strokeLinejoin="round"/>
  </svg>
);

const CreditCardUp = ({ width, height }) => (
  <svg width={width} height={height} viewBox="0 0 20 20" fill="none">
    <path d="M12.5008 13.3331L10.0008 10.8331L7.50081 13.3331M10.0008 10.8331V16.6665M18.3341 7.4998H1.66748M4.58415 14.9998H4.33415C3.40073 14.9998 2.93402 14.9998 2.5775 14.8181C2.26389 14.6584 2.00893 14.4034 1.84914 14.0898C1.66748 13.7333 1.66748 13.2665 1.66748 12.3331V5.9998C1.66748 5.06638 1.66748 4.59967 1.84914 4.24315C2.00893 3.92954 2.26389 3.67457 2.5775 3.51479C2.93402 3.33313 3.40073 3.33313 4.33415 3.33313H15.6675C16.6009 3.33313 17.0676 3.33313 17.4241 3.51479C17.7377 3.67458 17.9927 3.92954 18.1525 4.24315C18.3341 4.59967 18.3341 5.06638 18.3341 5.9998V12.3331C18.3341 13.2666 18.3341 13.7333 18.1525 14.0898C17.9927 14.4034 17.7377 14.6584 17.4241 14.8181C17.0676 14.9998 16.6009 14.9998 15.6675 14.9998H15.4175" stroke="#344054" strokeWidth="1.25" strokeLinecap="round" strokeLinejoin="round"/>
    <path d="M12.5 13.3331L10 10.8331L7.5 13.3331M10 10.8331V16.6665" stroke="#00AFAB" strokeWidth="1.25" strokeLinecap="round" strokeLinejoin="round"/>
  </svg>
);

const CreditCardRefresh = ({ width, height }) => (
  <svg width={width} height={height} viewBox="0 0 20 20" fill="none">
    <path d="M18.3334 8.33333H1.66675M9.16675 15.8333L15.6667 15.8333C16.6002 15.8333 17.0669 15.8333 17.4234 15.6517C17.737 15.4919 17.992 15.2369 18.1518 14.9233C18.3334 14.5668 18.3334 14.1001 18.3334 13.1667V6.83333C18.3334 5.89991 18.3334 5.4332 18.1518 5.07668C17.992 4.76308 17.737 4.50811 17.4234 4.34832C17.0669 4.16667 16.6002 4.16667 15.6667 4.16667H14.1667M10.8334 14.1667L9.16675 15.8333L10.8334 17.5M5.83341 15.8333H4.33341C3.39999 15.8333 2.93328 15.8333 2.57676 15.6517C2.26316 15.4919 2.00819 15.2369 1.8484 14.9233C1.66675 14.5668 1.66675 14.1001 1.66675 13.1667V6.83333C1.66675 5.89991 1.66675 5.4332 1.8484 5.07668C2.00819 4.76308 2.26316 4.50811 2.57676 4.34832C2.93328 4.16667 3.39999 4.16667 4.33342 4.16667H10.8334M9.16675 2.5L10.8334 4.16667L9.16675 5.83333" stroke="#475467" strokeWidth="1.25" strokeLinecap="round" strokeLinejoin="round"/>
  </svg>
);

/* Icon already has its own stroke colors (teal arrow + dark card), so no tint applied.
   iconSize prop allows callers to bump the icon up from the RN default of 20 — useful
   on web where vector strokes anti-alias thinner than they do at native iOS pixel density.
   The icon is wrapped in a div with flexShrink:0 because CSS flex-shrinks SVGs without
   min-width constraints all the way to 0 when content overflows; the longer "Withdraw"
   label hits min-content:auto first and absorbs zero shrink, leaving the SVG to disappear
   entirely. RN's flex layout doesn't have this quirk. */
const ActionPill = ({ Icon, label, onPress, iconSize = 20 }) => (
  <button
    onClick={onPress}
    style={{
      border: 'none', background: 'transparent', padding: 0, margin: 0,
      cursor: 'pointer', font: 'inherit', color: 'inherit', textAlign: 'inherit',
      ...styles.pill,
    }}
  >
    <span style={{ display:'inline-flex', flexShrink:0, lineHeight:0 }}>
      <Icon width={iconSize} height={iconSize} />
    </span>
    <span style={styles.pillLabel}>{label}</span>
  </button>
);

const PortfolioCard = () => {
  const { total } = window.useTradingNumbers();
  /* Open the global cash-flow sheet via the App-level trigger.
     PortfolioCard doesn't need to know which modal renders — it
     just signals intent. */
  const openFlow = (mode) => () => {
    if (window.openCashFlow) window.openCashFlow(mode);
  };
  const onDeposit = openFlow('deposit');
  const onWithdraw = openFlow('withdraw');
  const onTransfer = openFlow('transfer');
  return (
    <div style={styles.card}>
      {/* Label row — title + eye-off, mirroring the wallet hero where
         the eye-off sits next to the "Total Available Funds" caption
         rather than at the end of the value. */}
      <div style={styles.labelRow}>
        <span style={styles.label}>Total Portfolio Value</span>
        <EyeOff width={16} height={16} color={colors.muted2} opacity={0.55} />
      </div>
      <div style={styles.valueRow}>
        {/* Total value comes from the shared portfolio data module — same
           sum used by the Wallet hero, so the two screens always agree.
           Layout mirrors the wallet hero: large bold whole, smaller
           regular-weight fraction, semibold USD tag. */}
        {(function () {
          const parts = formatAmount(total);
          return (
            <React.Fragment>
              <span style={styles.value}>{'$' + parts.amount}</span>
              <span style={styles.valueFraction}>{parts.fraction}</span>
              <span style={styles.valueCurrency}>USD</span>
            </React.Fragment>
          );
        })()}
      </div>
      <div style={styles.actions}>
        <ActionPill Icon={CreditCardDown} label="Deposit" onPress={onDeposit} iconSize={18} />
        <ActionPill Icon={CreditCardUp} label="Withdraw" onPress={onWithdraw} iconSize={18} />
        <ActionPill Icon={CreditCardRefresh} label="Transfer" onPress={onTransfer} iconSize={18} />
      </div>
    </div>
  );
};

const styles = {
  card: {
    backgroundColor: '#fff',
    borderRadius: '20px',
    paddingLeft: '20px',
    paddingRight: '20px',
    paddingTop: '16px',
    paddingBottom: '16px',
    /* Strengthened lg-modal shadow — same boost as Card primitive. */
    boxShadow: '0px 24px 28px rgba(14, 20, 32, 0.16)',
  },
  labelRow: {
    display: 'flex',
    flexDirection: 'row',
    alignItems: 'center',
    gap: '8px',
  },
  label: {
    fontFamily: 'Inter',
    fontWeight: 400,
    fontSize: '14px',
    lineHeight: '18px',
    color: colors.muted,
  },
  valueRow: {
    display: 'flex',
    flexDirection: 'row',
    /* baseline-aligned so the smaller fraction + currency tag sit on
       the bottom edge of the big whole-amount glyphs (wallet-hero
       parity). */
    alignItems: 'flex-end',
    gap: '10px',
    marginTop: '2px',
  },
  value: {
    fontFamily: 'Gilroy',
    fontWeight: 700,
    fontSize: '36px',
    lineHeight: '44px',
    color: colors.ink,
    letterSpacing: '-0.7px',
  },
  valueFraction: {
    fontFamily: 'Gilroy',
    fontWeight: 400,
    fontSize: '18px',
    lineHeight: '32px',
    color: colors.ink,
    /* tighten the visual gap between '$124,670' and '.18'; the parent
       row's gap:10px is intended for the eye-icon spacing, not the
       intra-number spacing. */
    marginLeft: '-6px',
  },
  valueCurrency: {
    fontFamily: 'Gilroy',
    fontWeight: 600,
    fontSize: '20px',
    lineHeight: '36px',
    color: colors.ink,
    marginLeft: '-4px',
  },
  actions: {
    display: 'flex',
    flexDirection: 'row',
    gap: '8px',
    marginTop: '12px',
  },
  pill: {
    flex: 1,
    /* CSS default `min-width: auto` on flex items prevents shrinking below
       intrinsic content. RN doesn't have this quirk; set explicitly so
       three pills + gaps fit inside the card. */
    minWidth: 0,
    height: '42px',
    /* RN spec is paddingHorizontal:14, but that pushes the longer "Withdraw"
       label past the available width. Reduce to 10 so all three labels +
       icons fit comfortably without flex-shrinking. */
    paddingLeft: '10px',
    paddingRight: '10px',
    border: `1px solid ${colors.line}`,
    borderRadius: '32px',
    backgroundColor: '#fff',
    display: 'flex',
    flexDirection: 'row',
    alignItems: 'center',
    justifyContent: 'center',
    gap: '6px',
  },
  pillLabel: {
    fontFamily: 'Gilroy',
    fontWeight: 600,
    fontSize: '14px',
    color: colors.ink2,
  },
};

Object.assign(window, { PortfolioCard });
})();
