'use strict';

var core = require('@linaria/core');
var index = require('../Empty/index.js');
var index$1 = require('../ParrotTrans/index.js');
var useFormatDuration = require('../../hooks/useFormatDuration.js');
var formatDuration = require('../../utils/formatDuration.js');
var isEmpty = require('../../utils/isEmpty.js');
var React = require('react');
var index$2 = require('../Styled/index.js');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var React__default = /*#__PURE__*/_interopDefault(React);

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,
  "data-testid": dataTestId
}) => {
  const { parts } = useFormatDuration.useFormatDuration(rawValue != null ? rawValue : 0, {
    maxDisplayUnits,
    useAbbreviation: abbreviate,
    minUnit
  });
  if (isEmpty(rawValue)) {
    return /* @__PURE__ */ React__default.default.createElement(index, __spreadValues({ "data-testid": dataTestId }, emptyProps));
  }
  if (parts.length === 0) {
    return /* @__PURE__ */ React__default.default.createElement(index, __spreadValues({ "data-testid": dataTestId }, emptyProps));
  }
  if (contentRender) {
    const formatItems = formatDuration.formatDuration(rawValue, {
      maxDisplayUnits,
      minUnit
    });
    return /* @__PURE__ */ React__default.default.createElement(React__default.default.Fragment, null, contentRender(formatItems));
  }
  const allZero = parts.every((part) => part.value === 0);
  if (noUnitOnZero && allZero) {
    return /* @__PURE__ */ React__default.default.createElement("span", { "data-testid": dataTestId, className: core.cx("value", valueClassName) }, "0");
  }
  return /* @__PURE__ */ React__default.default.createElement(React__default.default.Fragment, null, parts.map((part, index) => /* @__PURE__ */ React__default.default.createElement(React__default.default.Fragment, { key: `${part.unit}-${index}` }, index > 0 && /* @__PURE__ */ React__default.default.createElement("span", null, " "), /* @__PURE__ */ React__default.default.createElement(
    index$1.ParrotTrans,
    {
      parent: "span",
      i18nKey: part.i18nKey,
      count: part.value
    },
    /* @__PURE__ */ React__default.default.createElement("span", { className: core.cx("value", valueClassName) }),
    /* @__PURE__ */ React__default.default.createElement("span", { className: core.cx("unit", index$2.UnitStyle, unitClassName) })
  ))));
};
var Duration$1 = Duration;

module.exports = Duration$1;
