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

import { d as dayjs } from '../../_chunks/dep-9888611c.mjs';
import { i as isObject_1 } from '../../_chunks/dep-a8bcacea.mjs';
import { i as isArray_1 } from '../../_chunks/dep-b57180d0.mjs';
import { i as isFunction_1 } from '../../_chunks/dep-5717e263.mjs';
import '../../_chunks/dep-255303ba.mjs';
import '../../_chunks/dep-eba0ea6e.mjs';
import '../../_chunks/dep-469b4ae0.mjs';

function useDisableDate(props) {
  return {
    disableDate: function disableDate(value) {
      return !isEnabled({
        disableDate: props.disableDate,
        format: props.format,
        mode: props.mode,
        value: value
      });
    },
    minDate: isObject_1(props.disableDate) && "before" in props.disableDate ? new Date(props.disableDate.before) : props.start,
    maxDate: isObject_1(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_1(props.disableDate)) return !props.disableDate(props.value);
  if (isArray_1(props.disableDate)) {
    var isIncludes = false;
    var formatedDisabledDate = props.disableDate.map(function (item) {
      return dayjs(item, props.format);
    });
    formatedDisabledDate.forEach(function (item) {
      if (item.isSame(dayjs(props.value))) isIncludes = true;
    });
    return !isIncludes;
  }
  if (props.disableDate.from && props.disableDate.to) {
    var compareMin = dayjs(new Date(props.disableDate.from));
    var compareMax = dayjs(new Date(props.disableDate.to));
    return !dayjs(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(new Date(min));
    var _compareMax = dayjs(new Date(max));
    isEnabled2 = dayjs(props.value).isBetween(_compareMin, _compareMax, props.mode, "[]");
  } else if (min) {
    var _compareMin2 = dayjs(new Date(min));
    isEnabled2 = !dayjs(props.value).isBefore(_compareMin2, props.mode);
  } else if (max) {
    var _compareMax2 = dayjs(new Date(max));
    isEnabled2 = !dayjs(props.value).isAfter(_compareMax2, props.mode);
  }
  return isEnabled2;
}

export { useDisableDate as default };
//# sourceMappingURL=useDisableDate.mjs.map
