import { c as _c } from "react/compiler-runtime";
import { memo } from "react";
export default memo(Duration);
/**
 * Constants will be folded by the bundler
 *
 * Values taken from:
 * https://tc39.es/proposal-unified-intl-numberformat/section6/locales-currencies-tz_proposed_out.html#sec-issanctionedsimpleunitidentifier
 *
 * TODO: Maybe use https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DurationFormat one day
 */
const durationFormatters = {
  year: 1000 * 60 * 60 * 24 * 365,
  month: 1000 * 60 * 60 * 24 * 30,
  week: 1000 * 60 * 60 * 24 * 7,
  day: 1000 * 60 * 60 * 24,
  hour: 1000 * 60 * 60,
  minute: 1000 * 60,
  second: 1000,
  millisecond: 1
};
function Duration(t0) {
  const $ = _c(7);
  const {
    seconds,
    display,
    maxDigits
  } = t0;
  const t1 = `${seconds}s`;
  const t2 = maxDigits ?? 0;
  let t3;
  if ($[0] !== display || $[1] !== seconds || $[2] !== t2) {
    t3 = formatDuration(seconds, display, t2);
    $[0] = display;
    $[1] = seconds;
    $[2] = t2;
    $[3] = t3;
  } else {
    t3 = $[3];
  }
  let t4;
  if ($[4] !== t1 || $[5] !== t3) {
    t4 = <time dateTime={t1}>{t3}</time>;
    $[4] = t1;
    $[5] = t3;
    $[6] = t4;
  } else {
    t4 = $[6];
  }
  return t4;
}
function formatDuration(seconds, unitDisplay, maxDigits) {
  const ms = seconds * 1000;
  for (const [unit, thresholdStr] of Object.entries(durationFormatters)) {
    const threshold = Number(thresholdStr);
    if (ms >= threshold) {
      return getFormatter(unit, unitDisplay, maxDigits).format(ms / threshold);
    }
  }
  return getFormatter("second", unitDisplay, maxDigits).format(ms);
}
const formatterCache = {};
function getFormatter(unit, unitDisplay, maxDigits) {
  // biome-ignore lint/suspicious/noAssignInExpressions: Ok here
  const fu = formatterCache[unitDisplay] ??= {};
  // biome-ignore lint/suspicious/noAssignInExpressions: Ok here
  const fun = fu[unit] ??= {};
  // biome-ignore lint/suspicious/noAssignInExpressions: Ok here
  return fun[maxDigits] ??= new Intl.NumberFormat("de-DE", {
    style: "unit",
    unit,
    unitDisplay,
    maximumFractionDigits: maxDigits
  });
}
//# sourceMappingURL=Duration.jsx.map