import {
  Icon
} from "./chunk-RWIZ7Q74.js";

// src/components/CurrencyAmount.tsx
import { gql } from "@apollo/client";
import styled from "@emotion/styled";
import {
  CurrencyUnit,
  formatCurrencyStr,
  isCurrencyMap,
  mapCurrencyAmount
} from "@lightsparkdev/core";
import { jsx, jsxs } from "@emotion/react/jsx-runtime";
function CurrencyAmount({
  amount,
  displayUnit = CurrencyUnit.SATOSHI,
  shortNumber = false,
  showUnits = false,
  includeEstimatedIndicator = false,
  /* Product has voted to hide msats from end users.
     showSubSatDigits should only be used in ops tools: */
  showSubSatDigits = false,
  ml = 0
}) {
  const unit = displayUnit;
  const amountMap = isCurrencyMap(amount) ? amount : mapCurrencyAmount(amount);
  const value = amountMap[unit];
  const defaultFormattedNumber = amountMap.formatted[unit];
  let formattedNumber = defaultFormattedNumber;
  if (shortNumber) {
    formattedNumber = formatCurrencyStr(
      { value: Number(value), unit },
      1,
      true
    );
  } else if (showSubSatDigits) {
    formattedNumber = formatCurrencyStr(
      { value: Number(value), unit: CurrencyUnit.SATOSHI },
      3
    );
  }
  if (showUnits) {
    formattedNumber += ` ${shorttext(unit, value)}`;
  }
  return /* @__PURE__ */ jsxs(StyledCurrencyAmount, { ml, children: [
    includeEstimatedIndicator && "Est. ",
    /* @__PURE__ */ jsx(CurrencyIcon, { unit }),
    formattedNumber
  ] });
}
var CurrencyIcon = ({ unit }) => {
  switch (unit) {
    case CurrencyUnit.BITCOIN:
      return /* @__PURE__ */ jsx(Icon, { name: "BitcoinB", width: 8, verticalAlign: -2, mr: 2 });
    case CurrencyUnit.SATOSHI:
      return /* @__PURE__ */ jsx(Icon, { name: "Satoshi", width: 8, verticalAlign: -2, mr: 2 });
    default:
      return null;
  }
};
var shorttext = (unit, value) => {
  const pl = value !== 1;
  switch (unit) {
    case CurrencyUnit.BITCOIN:
      return "BTC";
    case CurrencyUnit.MILLIBITCOIN:
      return "mBTC";
    case CurrencyUnit.MICROBITCOIN:
      return "\u03BCBTC";
    case CurrencyUnit.SATOSHI:
      return `sat${pl ? "s" : ""}`;
    case CurrencyUnit.MILLISATOSHI:
      return `msat${pl ? "s" : ""}`;
  }
  return unit;
};
var StyledCurrencyAmount = styled.span`
  color: inherit !important;
  white-space: nowrap;
  font-feature-settings:
    "tnum" on,
    "lnum" on;
  margin-left: ${({ ml }) => ml}px;
`;
CurrencyAmount.fragments = {
  amount: gql`
    fragment CurrencyAmount_amount on CurrencyAmount {
      original_value
      original_unit
      preferred_currency_unit
      preferred_currency_value_rounded
      preferred_currency_value_approx
    }
  `
};

export {
  CurrencyAmount,
  CurrencyIcon
};
