import { FORMAT_WITH_TIME } from './constants.js';
import dayjs from './dayjs.js';
import defaultFormats from './dayjsFormatOverrides/default.js';
import { getLocaleFormatOverrides } from './localePlugin.js';
import '../../defineProperty-CrCYjjU3.js';
import '../../typeof-D-UKOauR.js';
import '../../toConsumableArray-B7CFjjkW.js';
import '../../unsupportedIterableToArray-Dqz8Y8_I.js';
import '../../createClass-C1MbpvOB.js';
import 'dayjs';
import '../../asyncToGenerator-CPKhuIh2.js';
import 'i18next';

/* eslint-disable @bigbinary/neeto/use-standard-date-time-formats */
var getDefaultDateFormat = function getDefaultDateFormat() {
  var _window$globalProps$u, _window$globalProps;
  return (_window$globalProps$u = (_window$globalProps = window.globalProps) === null || _window$globalProps === void 0 || (_window$globalProps = _window$globalProps.user) === null || _window$globalProps === void 0 ? void 0 : _window$globalProps.dateFormat) !== null && _window$globalProps$u !== void 0 ? _window$globalProps$u : "DD/MM/YYYY";
};
var getDefaultTimeFormat = function getDefaultTimeFormat() {
  var _window$globalProps$u2, _window$globalProps2;
  return (_window$globalProps$u2 = (_window$globalProps2 = window.globalProps) === null || _window$globalProps2 === void 0 || (_window$globalProps2 = _window$globalProps2.user) === null || _window$globalProps2 === void 0 ? void 0 : _window$globalProps2.timeFormat) !== null && _window$globalProps$u2 !== void 0 ? _window$globalProps$u2 : "12h";
}; // "12h" | "24h"

var is12h = function is12h() {
  return getDefaultTimeFormat() === "12h";
};
var getDateFormat = function getDateFormat(key, locale, hourFormatOverride) {
  var _overrides$resolvedKe;
  var resolvedLocale = locale;
  var overrides = getLocaleFormatOverrides(resolvedLocale);
  var use12h = hourFormatOverride ? hourFormatOverride === "12h" : is12h();
  var resolvedKey = FORMAT_WITH_TIME.includes(key) ? key + (use12h ? "12" : "24") : key;
  return (_overrides$resolvedKe = overrides === null || overrides === void 0 ? void 0 : overrides[resolvedKey]) !== null && _overrides$resolvedKe !== void 0 ? _overrides$resolvedKe : defaultFormats[resolvedKey];
};
var createTimeFormat = function createTimeFormat(dayjs) {
  var locale = dayjs.locale();
  return {
    // Relative
    fromNow: function fromNow(time) {
      return dayjs(time).fromNow();
    },
    // Time only
    time: function time(_time) {
      var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
        hourFormat = _ref.hourFormat;
      return dayjs(_time).format(getDateFormat("time", locale, hourFormat));
    },
    timeWithSeconds: function timeWithSeconds(time) {
      var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
        hourFormat = _ref2.hourFormat;
      return dayjs(time).format(getDateFormat("timeWithSeconds", locale, hourFormat));
    },
    // Date only
    date: function date(time) {
      return dayjs(time).format(getDateFormat("date", locale));
    },
    dateWeek: function dateWeek(time) {
      return dayjs(time).format(getDateFormat("dateWeek", locale));
    },
    dateWeekDayExtended: function dateWeekDayExtended(time) {
      return dayjs(time).format(getDateFormat("dateWeekDayExtended", locale));
    },
    dateWeekWithoutYear: function dateWeekWithoutYear(time) {
      return dayjs(time).format(getDateFormat("dateWeekWithoutYear", locale));
    },
    dateWeekWithoutYearDayExtended: function dateWeekWithoutYearDayExtended(time) {
      return dayjs(time).format(getDateFormat("dateWeekWithoutYearDayExtended", locale));
    },
    // Date + time
    dateTime: function dateTime(time) {
      var _ref3 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
        hourFormat = _ref3.hourFormat;
      return dayjs(time).format(getDateFormat("dateTime", locale, hourFormat));
    },
    dateTimeWithSeconds: function dateTimeWithSeconds(time) {
      var _ref4 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
        hourFormat = _ref4.hourFormat;
      return dayjs(time).format(getDateFormat("dateTimeWithSeconds", locale, hourFormat));
    },
    dateWeekTime: function dateWeekTime(time) {
      var _ref5 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
        hourFormat = _ref5.hourFormat;
      return dayjs(time).format(getDateFormat("dateWeekTime", locale, hourFormat));
    },
    dateWeekTimeDayExtended: function dateWeekTimeDayExtended(time) {
      var _ref6 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
        hourFormat = _ref6.hourFormat;
      return dayjs(time).format(getDateFormat("dateWeekTimeDayExtended", locale, hourFormat));
    },
    // Time + weekday
    timeWeekday: function timeWeekday(time) {
      var _ref7 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
        hourFormat = _ref7.hourFormat;
      return dayjs(time).format(getDateFormat("timeWeekday", locale, hourFormat));
    },
    // Month formats
    monthDay: function monthDay(time) {
      return dayjs(time).format(getDateFormat("monthDay", locale));
    },
    monthYear: function monthYear(time) {
      return dayjs(time).format(getDateFormat("monthYear", locale));
    },
    // Extended
    extended: function extended(time) {
      var _ref8 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
        hourFormat = _ref8.hourFormat;
      var date = dayjs(time);
      var dateTime = date.format(getDateFormat("extended", locale, hourFormat));
      var fromNow = date.fromNow();
      return "".concat(dateTime, " (").concat(fromNow, ")");
    },
    "default": function _default(time) {
      return dayjs(time).format(getDefaultDateFormat());
    },
    defaultWithTime: function defaultWithTime(time) {
      var _ref9 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
        hourFormat = _ref9.hourFormat;
      return dayjs(time).format("".concat(getDefaultDateFormat(), " ").concat(getDateFormat("time", locale, hourFormat)));
    }
  };
};
var timeFormat = createTimeFormat(dayjs);
var createDateFormat = createTimeFormat;
var dateFormat = timeFormat;

export { createDateFormat, createTimeFormat, dateFormat, timeFormat };
//# sourceMappingURL=datetime.js.map
