import React__default from 'react';
import { cx } from '@linaria/core';
import Empty from '../Empty/index.js';
import { ParrotTrans } from '../ParrotTrans/index.js';
import { useFormatDuration } from '../../hooks/useFormatDuration.js';
import isEmpty from '../../utils/isEmpty.js';
import { formatDuration } from '../../utils/formatDuration.js';
import { UnitStyle } from '../Styled/index.js';

var __defProp = Object.defineProperty;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
  for (var prop in b || (b = {}))
    if (__hasOwnProp.call(b, prop))
      __defNormalProp(a, prop, b[prop]);
  if (__getOwnPropSymbols)
    for (var prop of __getOwnPropSymbols(b)) {
      if (__propIsEnum.call(b, prop))
        __defNormalProp(a, prop, b[prop]);
    }
  return a;
};
const Duration = ({
  rawValue,
  valueClassName,
  unitClassName,
  abbreviate,
  emptyProps,
  maxDisplayUnits = 2,
  minUnit = "second",
  noUnitOnZero = false,
  contentRender
}) => {
  const { parts } = useFormatDuration(rawValue != null ? rawValue : 0, {
    maxDisplayUnits,
    useAbbreviation: abbreviate,
    minUnit
  });
  if (isEmpty(rawValue)) {
    return /* @__PURE__ */ React__default.createElement(Empty, __spreadValues({}, emptyProps));
  }
  if (parts.length === 0) {
    return /* @__PURE__ */ React__default.createElement(Empty, __spreadValues({}, emptyProps));
  }
  if (contentRender) {
    const formatItems = formatDuration(rawValue, {
      maxDisplayUnits,
      minUnit
    });
    return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, contentRender(formatItems));
  }
  const allZero = parts.every((part) => part.value === 0);
  if (noUnitOnZero && allZero) {
    return /* @__PURE__ */ React__default.createElement("span", { className: cx("value", valueClassName) }, "0");
  }
  return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, parts.map((part, index) => /* @__PURE__ */ React__default.createElement(React__default.Fragment, { key: `${part.unit}-${index}` }, index > 0 && /* @__PURE__ */ React__default.createElement("span", null, " "), /* @__PURE__ */ React__default.createElement(
    ParrotTrans,
    {
      parent: "span",
      i18nKey: part.i18nKey,
      count: part.value
    },
    /* @__PURE__ */ React__default.createElement("span", { className: cx("value", valueClassName) }),
    /* @__PURE__ */ React__default.createElement("span", { className: cx("unit", UnitStyle, unitClassName) })
  ))));
};
var Duration$1 = Duration;

export { Duration$1 as default };
