"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.generateDatePickerColumns = exports.convertStringArrayToDate = exports.convertDateToStringArray = void 0;
var dateUtils = _interopRequireWildcard(require("./date-picker-date-utils"));
var quarterUtils = _interopRequireWildcard(require("./date-picker-quarter-utils"));
var weekUtils = _interopRequireWildcard(require("./date-picker-week-utils"));
var _util = require("./util");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
const precisionLengthRecord = {
  year: 1,
  month: 2,
  day: 3,
  hour: 4,
  minute: 5,
  second: 6
};
const convertDateToStringArray = (date, precision) => {
  if (precision.includes('week')) {
    return weekUtils.convertDateToStringArray(date);
  } else if (precision.includes('quarter')) {
    return quarterUtils.convertDateToStringArray(date);
  } else {
    const datePrecision = precision;
    const stringArray = dateUtils.convertDateToStringArray(date);
    return stringArray.slice(0, precisionLengthRecord[datePrecision]);
  }
};
exports.convertDateToStringArray = convertDateToStringArray;
const convertStringArrayToDate = (value, precision) => {
  // Special case for DATE_NOW
  if ((value === null || value === void 0 ? void 0 : value[0]) === _util.TILL_NOW) {
    const now = new Date();
    now.tillNow = true;
    return now;
  }
  if (precision.includes('week')) {
    return weekUtils.convertStringArrayToDate(value);
  } else if (precision.includes('quarter')) {
    return quarterUtils.convertStringArrayToDate(value);
  } else {
    return dateUtils.convertStringArrayToDate(value);
  }
};
exports.convertStringArrayToDate = convertStringArrayToDate;
const generateDatePickerColumns = (selected, min, max, precision, renderLabel, filter, tillNow) => {
  if (precision.startsWith('week')) {
    return weekUtils.generateDatePickerColumns(selected, min, max, precision, renderLabel, filter);
  } else if (precision.startsWith('quarter')) {
    return quarterUtils.generateDatePickerColumns(selected, min, max, precision, renderLabel, filter);
  } else {
    return dateUtils.generateDatePickerColumns(selected, min, max, precision, renderLabel, filter, tillNow);
  }
};
exports.generateDatePickerColumns = generateDatePickerColumns;