"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var _chunkWF7Z2VITcjs = require('./chunk-WF7Z2VIT.cjs');


var _chunkCDFVRIETcjs = require('./chunk-CDFVRIET.cjs');

// src/components/CurrencyAmount.tsx
var _styled = require('@emotion/styled'); var _styled2 = _interopRequireDefault(_styled);







var _core = require('@lightsparkdev/core');
var _jsxruntime = require('@emotion/react/jsx-runtime');
function CurrencyAmount({
  amount,
  displayUnit: displayUnitProp,
  shortNumber = false,
  showUnits = false,
  includeEstimatedIndicator = false,
  fullPrecision = false,
  id,
  ml = 0,
  typography,
  unitsPerBtc,
  showCurrencyIcon = true
}) {
  let value;
  let defaultFormattedNumber;
  let displayUnitStr;
  let currencyAmountForFormatting;
  if (_core.isUmaCurrencyAmount.call(void 0, amount)) {
    value = amount.value;
    defaultFormattedNumber = _core.formatCurrencyStr.call(void 0, amount);
    displayUnitStr = amount.currency.code === "SAT" ? _core.CurrencyUnit.SATOSHI : amount.currency.code;
    currencyAmountForFormatting = amount;
  } else {
    let amountMap;
    let displayUnit;
    if (_core.isCurrencyMap.call(void 0, amount)) {
      displayUnit = displayUnitProp || _core.CurrencyUnit.SATOSHI;
      amountMap = amount;
    } else {
      const resolvedCurrencyAmount = _core.getCurrencyAmount.call(void 0, amount);
      displayUnit = displayUnitProp || resolvedCurrencyAmount.unit;
      amountMap = _core.mapCurrencyAmount.call(void 0, amount, unitsPerBtc);
    }
    value = amountMap[displayUnit];
    defaultFormattedNumber = amountMap.formatted[displayUnit];
    displayUnitStr = displayUnit;
    currencyAmountForFormatting = { value: Number(value), unit: displayUnit };
  }
  const appendUnits = showUnits === false ? void 0 : showUnits === true ? {
    plural: false,
    lowercase: false,
    showForCurrentLocaleUnit: false
  } : showUnits;
  let formattedNumber = defaultFormattedNumber;
  if (shortNumber) {
    formattedNumber = _core.formatCurrencyStr.call(void 0, currencyAmountForFormatting, {
      precision: 1,
      compact: true,
      appendUnits
    });
  } else if (fullPrecision) {
    formattedNumber = _core.formatCurrencyStr.call(void 0, currencyAmountForFormatting, {
      precision: "full",
      appendUnits
    });
  } else if (appendUnits) {
    formattedNumber = _core.formatCurrencyStr.call(void 0, currencyAmountForFormatting, {
      appendUnits
    });
  }
  let content = formattedNumber;
  if (typography && typography.type) {
    content = _chunkCDFVRIETcjs.renderTypography.call(void 0, typography.type, {
      size: typography.size,
      color: typography.color,
      children: formattedNumber
    });
  }
  return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, StyledCurrencyAmount, { ml, id, children: [
    includeEstimatedIndicator && "Est. ",
    showCurrencyIcon ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, CurrencyIcon, { unit: displayUnitStr }) : null,
    content
  ] });
}
var CurrencyIcon = ({ unit }) => {
  switch (unit) {
    case _core.CurrencyUnit.BITCOIN:
      return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkWF7Z2VITcjs.Icon, { name: "BitcoinB", width: 8, verticalAlign: -2, mr: 2 });
    case _core.CurrencyUnit.SATOSHI:
      return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkWF7Z2VITcjs.Icon, { name: "Satoshi", width: 8, verticalAlign: -2, mr: 2 });
    default:
      return null;
  }
};
var StyledCurrencyAmount = _styled2.default.span`
  color: inherit !important;
  white-space: nowrap;
  font-feature-settings:
    "tnum" on,
    "lnum" on;
  margin-left: ${({ ml }) => ml}px;
`;




exports.CurrencyAmount = CurrencyAmount; exports.CurrencyIcon = CurrencyIcon;
