import { jsx as s, Fragment as L } from "@emotion/react/jsx-runtime";
import E, { useMemo as A } from "react";
import { useModuleDictionary as P, useModuleSkeleton as k } from "@m4l/core";
import { PERIOD_FORMATTER_KEY_COMPONENT as l } from "./constants.js";
import _ from "clsx";
import { getComponentSlotRoot as $ } from "../../../utils/getComponentSlotRoot.js";
import { getPropDataTestId as F } from "../../../test/getNameDataTestId.js";
import { useComponentSize as R } from "../../../hooks/useComponentSize/index.js";
import { dictionary as m } from "./dictionary.js";
import { PeriodFormatterRootStyled as b, PeriodFormatterSkeletonStyled as M } from "./slots/PeriodFormatterSlots.js";
import { PeriodFormatterSlots as T } from "./slots/PeriodFomatterEnum.js";
function z(o, i, a) {
  const { getLabel: t } = P();
  let e = "";
  const r = ", ";
  switch (o) {
    case 0:
      break;
    case 1:
      e = `1 ${t(m.LABEL_YEAR)}`;
      break;
    default:
      e = `${o} ${t(m.LABEL_YEARS)}`;
  }
  switch (i) {
    case 0:
      break;
    case 1:
      o > 0 && (e += r), e += `1 ${t(m.LABEL_MONTH)}`;
      break;
    default:
      o > 0 && (e += r), e += `${i} ${t(m.LABEL_MONTHS)}`;
  }
  switch (a) {
    case 0:
      break;
    case 1:
      (o > 0 || i > 0) && (e += r), e += `1 ${t(m.LABEL_DAY)}`;
      break;
    default:
      (o > 0 || i > 0) && (e += r), e += `${a} ${t(m.LABEL_DAYS)}`;
  }
  return e === "" && (e = "-"), e;
}
function H(o) {
  const { size: i = "medium", years: a = 0, months: t = 0, days: e = 0, Component: r = b, dataTestId: p, className: u, componentProps: S } = o, { currentSize: n } = R(i), c = k(), d = z(a, t, e), f = A(() => c ? /* @__PURE__ */ s(M, { variant: "text" }) : d, [d, c]);
  return r === E.Fragment ? /* @__PURE__ */ s(L, { children: f }) : /* @__PURE__ */ s(
    r,
    {
      size: n === "small" || n === "medium" ? n : "medium",
      className: _($(l), u),
      ...F(l, T.root, p),
      role: "period-formatter-role",
      ...S,
      children: f
    }
  );
}
export {
  H as PeriodFormatter,
  z as useFormatPeriod
};
