/**
 * ldesign v0.3.13
 * (c) 2023 ldesign
 * @license MIT
 */

'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var dayjs = require('dayjs');
var isObject = require('lodash/isObject');
var isArray = require('lodash/isArray');
var isFunction = require('lodash/isFunction');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var dayjs__default = /*#__PURE__*/_interopDefaultLegacy(dayjs);
var isObject__default = /*#__PURE__*/_interopDefaultLegacy(isObject);
var isArray__default = /*#__PURE__*/_interopDefaultLegacy(isArray);
var isFunction__default = /*#__PURE__*/_interopDefaultLegacy(isFunction);

function useDisableDate(props) {
  return {
    disableDate: function disableDate(value) {
      return !isEnabled({
        disableDate: props.disableDate,
        format: props.format,
        mode: props.mode,
        value: value
      });
    },
    minDate: isObject__default["default"](props.disableDate) && "before" in props.disableDate ? new Date(props.disableDate.before) : props.start,
    maxDate: isObject__default["default"](props.disableDate) && "after" in props.disableDate ? new Date(props.disableDate.after) : props.end
  };
}
function isEnabled(props) {
  if (!props.disableDate) return true;
  var isEnabled2 = true;
  if (isFunction__default["default"](props.disableDate)) return !props.disableDate(props.value);
  if (isArray__default["default"](props.disableDate)) {
    var isIncludes = false;
    var formatedDisabledDate = props.disableDate.map(function (item) {
      return dayjs__default["default"](item, props.format);
    });
    formatedDisabledDate.forEach(function (item) {
      if (item.isSame(dayjs__default["default"](props.value))) isIncludes = true;
    });
    return !isIncludes;
  }
  if (props.disableDate.from && props.disableDate.to) {
    var compareMin = dayjs__default["default"](new Date(props.disableDate.from));
    var compareMax = dayjs__default["default"](new Date(props.disableDate.to));
    return !dayjs__default["default"](props.value).isBetween(compareMin, compareMax, props.mode, "[]");
  }
  var min = props.disableDate.before ? new Date(props.disableDate.before) : null;
  var max = props.disableDate.after ? new Date(props.disableDate.after) : null;
  if (max && min) {
    var _compareMin = dayjs__default["default"](new Date(min));
    var _compareMax = dayjs__default["default"](new Date(max));
    isEnabled2 = dayjs__default["default"](props.value).isBetween(_compareMin, _compareMax, props.mode, "[]");
  } else if (min) {
    var _compareMin2 = dayjs__default["default"](new Date(min));
    isEnabled2 = !dayjs__default["default"](props.value).isBefore(_compareMin2, props.mode);
  } else if (max) {
    var _compareMax2 = dayjs__default["default"](new Date(max));
    isEnabled2 = !dayjs__default["default"](props.value).isAfter(_compareMax2, props.mode);
  }
  return isEnabled2;
}

exports["default"] = useDisableDate;
//# sourceMappingURL=useDisableDate.js.map
