'use strict';

var React = require('react');
var formatDuration = require('../utils/formatDuration.js');

function useFormatDuration(milliseconds, options = {
  maxDisplayUnits: 2,
  useAbbreviation: false,
  minUnit: "second"
}) {
  const {
    maxDisplayUnits = 2,
    useAbbreviation = false,
    minUnit = "second"
  } = options;
  const result = React.useMemo(() => {
    const items = formatDuration.formatDuration(milliseconds, { maxDisplayUnits, minUnit });
    const shouldUseAbbreviation = items.length > 1 && useAbbreviation;
    const parts = items.map((item) => {
      const suffix = shouldUseAbbreviation ? "_abbreviation" : "";
      const i18nKey = `unit.${item.unit}${suffix}`;
      return {
        value: item.value,
        unit: item.unit,
        i18nKey
      };
    });
    return {
      parts
    };
  }, [milliseconds, maxDisplayUnits, useAbbreviation, minUnit]);
  return result;
}

exports.useFormatDuration = useFormatDuration;
