"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.calcFromDate = void 0;
var _locale = require("@mirai/locale");
var _helpers = require("../../../helpers");
const FIRST_FORTNIGHT = 14;
const calcFromDate = function () {
  let dates = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  if (!Array.isArray(dates) || !dates[0]) return;
  const date = (0, _locale.parseDate)(dates[0], _helpers.CALENDAR_FORMAT);
  const month = date.getMonth() - (date.getDate() <= FIRST_FORTNIGHT && (0, _locale.dateDiff)((0, _locale.UTC)(new Date()), new Date(date.getFullYear(), date.getMonth(), 0)).days > 0 ? 1 : 0);
  const value = (0, _locale.UTC)(new Date(date.getFullYear(), month, 1));
  return (0, _locale.dateFormat)(value, {
    format: _helpers.CALENDAR_FORMAT
  });
};
exports.calcFromDate = calcFromDate;
//# sourceMappingURL=calcFromDate.js.map