import { jsx as u, Fragment as g } from "@emotion/react/jsx-runtime";
import y, { useMemo as f } from "react";
import { clsx as F } from "clsx";
import { getPropertyByString as d } from "@m4l/core";
import { useFormatter as S } from "@m4l/graphics";
import { getComponentSlotRoot as N } from "../../../utils/getComponentSlotRoot.js";
import { getPropDataTestId as P } from "../../../test/getNameDataTestId.js";
import { useComponentSize as b } from "../../../hooks/useComponentSize/index.js";
import { PriceFormatterRootStyled as D } from "./slots/PriceFormatterSlots.js";
import { PRICE_FORMATTER_KEY_COMPONENT as s } from "./constants.js";
import { PriceFormatterSlots as x } from "./slots/PriceFormatterEnum.js";
function R(n, i, t, r) {
  let e = "";
  const o = d(n, i);
  try {
    if (isNaN(Number(o)))
      return 0 .toLocaleString(navigator.language, {
        currency: t,
        style: "currency",
        currencyDisplay: "symbol",
        useGrouping: !0,
        maximumFractionDigits: r
      });
    e = Number(o).toLocaleString(navigator.language, {
      currency: t,
      style: "currency",
      currencyDisplay: "symbol",
      useGrouping: !0,
      maximumFractionDigits: r
    }) || "";
  } catch {
    e = Number(o).toLocaleString("en-US", {
      style: "currency",
      currency: "USD",
      currencyDisplay: "symbol",
      useGrouping: !0,
      maximumFractionDigits: r
    }) || "";
  }
  return e;
}
function I(n) {
  const { obProps: i, fieldValue: t, Component: r = D, size: e = "medium", color: o, dataTestid: a, className: l } = n, { currentSize: p } = b(e), { currencyFormatter: m } = S(), c = f(
    () => R(i, t, m.code, m.decimalDigits),
    [i, t, m.code, m.decimalDigits]
  );
  return r === y.Fragment ? /* @__PURE__ */ u(g, { children: c }) : /* @__PURE__ */ u(
    r,
    {
      variant: "body",
      size: p,
      color: o,
      className: F(N(s), l),
      ...P(s, x.root, a),
      children: c
    }
  );
}
export {
  I as PriceFormatter,
  R as getFormatPrice
};
