/**
 * ldesign v0.2.14
 * (c) 2022/11/2 16:16 built by swimly
 * @license MIT
 */

'use strict';

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

var dayjs = require('dayjs');
var _commonjsHelpers = require('../../../chunks/_commonjsHelpers.js');
var isObject = require('lodash/isObject');

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 isBetween$1 = {exports: {}};

(function (module, exports) {
  !function (e, i) {
    module.exports = i() ;
  }(_commonjsHelpers.commonjsGlobal, function () {

    return function (e, i, t) {
      i.prototype.isBetween = function (e, i, s, f) {
        var n = t(e),
          o = t(i),
          r = "(" === (f = f || "()")[0],
          u = ")" === f[1];
        return (r ? this.isAfter(n, s) : !this.isBefore(n, s)) && (u ? this.isBefore(o, s) : !this.isAfter(o, s)) || (r ? this.isBefore(n, s) : !this.isAfter(n, s)) && (u ? this.isAfter(o, s) : !this.isBefore(o, s));
      };
    };
  });
})(isBetween$1);
var isBetween = isBetween$1.exports;

dayjs__default["default"].extend(isBetween);
function useDisableDate(props) {
  return {
    disableDate: value => !isEnabled({
      disableDate: props.disableDate,
      format: props.format,
      mode: props.mode,
      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;
  let isEnabled2 = true;
  if (typeof props.disableDate === "function") return !props.disableDate(props.value);
  if (Array.isArray(props.disableDate)) {
    let isIncludes = false;
    const formattedDisabledDate = props.disableDate.map(item => dayjs__default["default"](item, props.format));
    formattedDisabledDate.forEach(item => {
      if (item.isSame(dayjs__default["default"](props.value))) isIncludes = true;
    });
    return !isIncludes;
  }
  if (props.disableDate.from && props.disableDate.to) {
    const compareMin = dayjs__default["default"](new Date(props.disableDate.from));
    const compareMax = dayjs__default["default"](new Date(props.disableDate.to));
    return !dayjs__default["default"](props.value).isBetween(compareMin, compareMax, props.mode, "[]");
  }
  const min = props.disableDate.before ? new Date(props.disableDate.before) : null;
  const max = props.disableDate.after ? new Date(props.disableDate.after) : null;
  if (max && min) {
    const compareMin = dayjs__default["default"](new Date(min));
    const compareMax = dayjs__default["default"](new Date(max));
    isEnabled2 = dayjs__default["default"](props.value).isBetween(compareMin, compareMax, props.mode, "[]");
  } else if (min) {
    const compareMin = dayjs__default["default"](new Date(min));
    isEnabled2 = !dayjs__default["default"](props.value).isBefore(compareMin, props.mode);
  } else if (max) {
    const compareMax = dayjs__default["default"](new Date(max));
    isEnabled2 = !dayjs__default["default"](props.value).isAfter(compareMax, props.mode);
  }
  return isEnabled2;
}

exports["default"] = useDisableDate;
//# sourceMappingURL=use-disabled-date.js.map
