import { jsx as c, Fragment as d } from "@emotion/react/jsx-runtime";
import F, { useMemo as u } from "react";
import { useFormatter as D } from "@m4l/graphics";
import { DateFormatterRootStyled as T } from "./slots/DateFormatterSlots.js";
import { DateFormatterSlots as g } from "./slots/DateFormatterEnum.js";
import y from "clsx";
import { getComponentSlotRoot as R } from "../../../utils/getComponentSlotRoot.js";
import { getPropDataTestId as b } from "../../../test/getNameDataTestId.js";
import { DATE_FORMATTER_KEY_COMPONENT as f } from "./constants.js";
function h(n, t, e, r) {
  let o = r || e.datetimeFormat, m, a;
  if (t == null)
    return "-";
  switch (n) {
    case "datetime":
      o = r || e.datetimeFormat;
      break;
    case "date":
      o = r || e.dateFormat;
      break;
    case "time":
      o = r || e.timeFormat;
      break;
  }
  try {
    return typeof t == "number" || typeof t == "string" ? a = new Date(t) : a = t, m = e.formatDate(a, o), m;
  } catch {
    return m = "-", m;
  }
}
function S(n) {
  const {
    presentationType: t,
    value: e,
    format: r,
    Component: o = T,
    dataTestId: m,
    className: a,
    componentProps: i
  } = n, { dateFormatter: l } = D(), s = h(t, e, l, r), p = u(() => s, [s]);
  return o === F.Fragment ? /* @__PURE__ */ c(d, { children: p }) : /* @__PURE__ */ c(
    o,
    {
      className: y(R(f), a),
      ...b(f, g.root, m),
      role: "dateFormatter-role",
      ...i,
      children: p
    }
  );
}
export {
  S as DateFormatter,
  h as getFormatDate
};
