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

'use strict';

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

var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var vue = require('vue');
var dayjs = require('dayjs');
var remove = require('lodash/remove');
var isFunction = require('lodash/isFunction');
var isArray = require('lodash/isArray');
var configProvider_useConfig = require('../config-provider/useConfig.js');
var hooks_tnode = require('../hooks/tnode.js');
var select_index = require('../select/index.js');
var radio_index = require('../radio/index.js');
var button_index = require('../button/index.js');
var tag_index = require('../tag/index.js');
var calendar_const = require('./const.js');
var calendar_utils = require('./utils.js');
var calendar_props = require('./props.js');
var calendar_calendarCell = require('./calendar-cell.js');
var calendar_hook_useState = require('./hook/useState.js');
var calendar_hook_useCalendarClass = require('./hook/useCalendarClass.js');
var calendar_hook_useColHeaders = require('./hook/useColHeaders.js');
var calendar_hook_useController = require('./hook/useController.js');
require('lodash/cloneDeep');
require('lodash/isString');
require('../config-provider/context.js');
require('lodash/mergeWith');
require('lodash/merge');
require('../_common/js/global-config/default-config.js');
require('../_common/js/global-config/locale/zh_CN.js');
require('@babel/runtime/helpers/typeof');
require('../_chunks/dep-f4db2590.js');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../utils/render-tnode.js');
require('lodash/isEmpty');
require('lodash/isObject');
require('../utils/withInstall.js');
require('../select/select.js');
require('@babel/runtime/helpers/objectWithoutProperties');
require('@babel/runtime/helpers/toConsumableArray');
require('lodash/pick');
require('lodash/debounce');
require('lodash/get');
require('lodash/intersection');
require('../common-components/fake-arrow.js');
require('../hooks/useConfig.js');
require('../select-input/index.js');
require('../select-input/select-input.js');
require('../popup/index.js');
require('../popup/popup.js');
require('@popperjs/core');
require('../utils/dom.js');
require('../utils/easing.js');
require('../_common/js/utils/set-style.js');
require('../hooks/useVModel.js');
require('../popup/props.js');
require('../popup/container.js');
require('lodash/isUndefined');
require('../hooks/useResizeObserver.js');
require('../select-input/props.js');
require('../select-input/useSingle.js');
require('../input/index.js');
require('../input/input.js');
require('@ldesign/icons-vue-next');
require('../form/hooks.js');
require('../hooks/useGlobalIcon.js');
require('../input/props.js');
require('../input/useInput.js');
require('../form/const.js');
require('../input/useLengthLimit.js');
require('lodash/isNumber');
require('../_common/js/log/log.js');
require('../_common/js/utils/helper.js');
require('lodash/isNull');
require('../input/useInputEventHandler.js');
require('../input/useInputWidth.js');
require('../input/input-group.js');
require('../input/input-group-props.js');
require('../loading/index.js');
require('../loading/directive.js');
require('../loading/plugin.js');
require('../loading/loading.js');
require('../hooks/useTeleport.js');
require('../loading/props.js');
require('../loading/icon/gradient.js');
require('../_common/js/loading/circle-adapter.js');
require('../hooks/useDefaultValue.js');
require('../select-input/useMultiple.js');
require('../tag-input/index.js');
require('../tag-input/tag-input.js');
require('../tag-input/props.js');
require('../tag-input/hooks/useTagScroll.js');
require('../tag-input/useTagList.js');
require('../tag-input/hooks/useHover.js');
require('../tag-input/hooks/useDragSorter.js');
require('../tag/tag.js');
require('../tag/props.js');
require('../tag/check-tag.js');
require('../tag/check-tag-props.js');
require('../select-input/useOverlayInnerStyle.js');
require('../select/props.js');
require('../select/select-panel.js');
require('lodash/omit');
require('../select/option.js');
require('../checkbox/index.js');
require('../checkbox/checkbox.js');
require('../hooks/useRipple.js');
require('../utils/set-style.js');
require('../hooks/useKeepAnimation.js');
require('../checkbox/props.js');
require('../checkbox/constants.js');
require('../checkbox/group.js');
require('../hooks/slot.js');
require('../checkbox/checkbox-group-props.js');
require('../select/option-props.js');
require('../select/helper.js');
require('../select/optionGroup.js');
require('../select/option-group-props.js');
require('../select/hooks/usePanelVirtualScroll.js');
require('../hooks/useVirtualScroll.js');
require('../select/hooks/useSelectOptions.js');
require('../radio/radio.js');
require('../utils/helper.js');
require('../radio/constants.js');
require('../radio/props.js');
require('../radio/group.js');
require('@babel/runtime/helpers/asyncToGenerator');
require('@babel/runtime/regenerator');
require('lodash/isNil');
require('../radio/radio-group-props.js');
require('../radio/useKeyboard.js');
require('../radio/radio-button.js');
require('../button/button.js');
require('../button/props.js');
require('lodash/isBoolean');

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

var _slicedToArray__default = /*#__PURE__*/_interopDefaultLegacy(_slicedToArray);
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
var dayjs__default = /*#__PURE__*/_interopDefaultLegacy(dayjs);
var remove__default = /*#__PURE__*/_interopDefaultLegacy(remove);
var isFunction__default = /*#__PURE__*/_interopDefaultLegacy(isFunction);
var isArray__default = /*#__PURE__*/_interopDefaultLegacy(isArray);

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
function _isSlot(s) {
  return typeof s === 'function' || Object.prototype.toString.call(s) === '[object Object]' && !vue.isVNode(s);
}
var _Calendar = vue.defineComponent({
  name: "TCalendar",
  props: _objectSpread({}, calendar_props["default"]),
  setup: function setup(props2, _ref) {
    var slots = _ref.slots;
    var renderContent = hooks_tnode.useContent();
    var _useConfig = configProvider_useConfig.useConfig(calendar_const.COMPONENT_NAME),
      t = _useConfig.t,
      globalConfig = _useConfig.globalConfig;
    var _useState = calendar_hook_useState.useState(props2),
      state = _useState.state,
      toToday = _useState.toToday,
      checkDayVisible = _useState.checkDayVisible;
    var cls = calendar_hook_useCalendarClass.useCalendarClass(props2, state);
    var _useColHeaders = calendar_hook_useColHeaders.useColHeaders(props2, state),
      cellColHeaders = _useColHeaders.cellColHeaders;
    var controller = calendar_hook_useController.userController(props2, state);
    var rangeFromTo = vue.computed(function () {
      if (!props2.range || props2.range.length < 2) return null;
      var _props2$range = _slicedToArray__default["default"](props2.range, 2),
        v1 = _props2$range[0],
        v2 = _props2$range[1];
      if (dayjs__default["default"](v1).isBefore(dayjs__default["default"](v2))) {
        return {
          from: v1,
          to: v2
        };
      }
      return {
        from: v2,
        to: v1
      };
    });
    function checkMonthAndYearSelectedDisabled(year, month) {
      var disabled = false;
      if (rangeFromTo.value && rangeFromTo.value.from && rangeFromTo.value.to) {
        var beginYear = dayjs__default["default"](rangeFromTo.value.from).year();
        var endYear = dayjs__default["default"](rangeFromTo.value.to).year();
        if (year === beginYear) {
          var beginMon = parseInt(dayjs__default["default"](rangeFromTo.value.from).format("M"), 10);
          disabled = month < beginMon;
        } else if (year === endYear) {
          var endMon = parseInt(dayjs__default["default"](rangeFromTo.value.to).format("M"), 10);
          disabled = month > endMon;
        }
      }
      return disabled;
    }
    vue.watch(function () {
      return {
        year: "".concat(state.curSelectedYear),
        month: "".concat(state.curSelectedMonth)
      };
    }, function (v) {
      isFunction__default["default"](props2.onMonthChange) && props2.onMonthChange(_objectSpread({}, v));
      controller.emitControllerChange();
    });
    var dateSelect = {
      yearSelectOptionList: vue.computed(function () {
        var re = [];
        var begin = state.curSelectedYear - 10;
        var end = state.curSelectedYear + 10;
        if (rangeFromTo.value && rangeFromTo.value.from && rangeFromTo.value.to) {
          begin = dayjs__default["default"](rangeFromTo.value.from).year();
          end = dayjs__default["default"](rangeFromTo.value.to).year();
        }
        if (begin < calendar_const.MIN_YEAR) begin = calendar_const.MIN_YEAR;
        if (end < calendar_const.MIN_YEAR) end = calendar_const.MIN_YEAR;
        for (var i = begin; i <= end; i++) {
          var disabled = checkMonthAndYearSelectedDisabled(i, state.curSelectedMonth);
          re.push({
            value: i,
            label: t(globalConfig.value.yearSelection, {
              year: i
            }),
            disabled: disabled
          });
        }
        return re;
      }),
      isYearSelectVisible: vue.computed(function () {
        return controller.checkControllerVisible("year");
      }),
      isYearSelectDisabled: vue.computed(function () {
        return controller.checkControllerDisabled("year", "selectProps");
      }),
      monthSelectOptionList: vue.computed(function () {
        var re = [];
        for (var i = calendar_const.FIRST_MONTH_OF_YEAR; i <= calendar_const.LAST_MONTH_OF_YEAR; i++) {
          var disabled = checkMonthAndYearSelectedDisabled(state.curSelectedYear, i);
          re.push({
            value: i,
            label: t(globalConfig.value.monthSelection, {
              month: i
            }),
            disabled: disabled
          });
        }
        return re;
      }),
      isMonthSelectVisible: vue.computed(function () {
        return state.curSelectedMode === "month" && controller.checkControllerVisible("month");
      }),
      isMonthSelectDisabled: vue.computed(function () {
        return controller.checkControllerDisabled("month", "selectProps");
      })
    };
    var modeSelect = {
      optionList: vue.computed(function () {
        return [{
          value: "month",
          label: t(globalConfig.value.monthRadio)
        }, {
          value: "year",
          label: t(globalConfig.value.yearRadio)
        }];
      }),
      isVisible: vue.computed(function () {
        return controller.checkControllerVisible("mode");
      }),
      isDisabled: vue.computed(function () {
        return controller.checkControllerDisabled("mode", "radioGroupProps");
      })
    };
    var weekendBtn = {
      text: vue.computed(function () {
        return state.isShowWeekend ? t(globalConfig.value.hideWeekend) : t(globalConfig.value.showWeekend);
      }),
      vBind: vue.computed(function () {
        var c = controller.configData.value.weekend;
        return state.isShowWeekend ? c.hideWeekendButtonProps : c.showWeekendButtonProps;
      }),
      isVisible: vue.computed(function () {
        return props2.theme === "full" && controller.checkControllerVisible("current") && controller.checkControllerVisible("weekend");
      }),
      isDisabled: vue.computed(function () {
        var p = state.isShowWeekend ? "hideWeekendButtonProps" : "showWeekendButtonProps";
        return controller.checkControllerDisabled("weekend", p);
      })
    };
    var currentBtn = {
      text: vue.computed(function () {
        return state.curSelectedMode === "month" ? t(globalConfig.value.today) : t(globalConfig.value.thisMonth);
      }),
      vBind: vue.computed(function () {
        var c = controller.configData.value.current;
        return state.curSelectedMode === "month" ? c.currentDayButtonProps : c.currentMonthButtonProps;
      }),
      isVisible: vue.computed(function () {
        return props2.theme === "full" && controller.checkControllerVisible("current");
      }),
      isDisabled: vue.computed(function () {
        var p = state.curSelectedMode === "month" ? "currentDayButtonProps" : "currentMonthButtonProps";
        return controller.checkControllerDisabled("current", p);
      })
    };
    var renderControl = function renderControl() {
      var _slot;
      return vue.createVNode("div", {
        "class": cls.control.value
      }, [vue.createVNode("div", {
        "class": cls.title.value
      }, [renderContent("head", void 0, {
        params: _objectSpread({}, controller.options.value)
      })]), vue.createVNode("div", {
        "class": cls.controlSection.value
      }, [dateSelect.isYearSelectVisible.value && vue.createVNode("div", {
        "class": cls.controlSectionCell.value
      }, [vue.createVNode(select_index.Select, vue.mergeProps({
        "modelValue": state.curSelectedYear,
        "onUpdate:modelValue": function onUpdateModelValue($event) {
          return state.curSelectedYear = $event;
        },
        "size": state.controlSize,
        "autoWidth": true
      }, controller.configData.value.year.selectProps, {
        "disabled": dateSelect.isYearSelectDisabled.value,
        "options": dateSelect.yearSelectOptionList.value
      }), null)]), dateSelect.isMonthSelectVisible.value && vue.createVNode("div", {
        "class": cls.controlSectionCell.value
      }, [vue.createVNode(select_index.Select, vue.mergeProps({
        "autoWidth": true,
        "modelValue": state.curSelectedMonth,
        "onUpdate:modelValue": function onUpdateModelValue($event) {
          return state.curSelectedMonth = $event;
        },
        "size": state.controlSize
      }, controller.configData.value.month.selectProps, {
        "disabled": dateSelect.isMonthSelectDisabled.value,
        "options": dateSelect.monthSelectOptionList.value
      }), null)]), modeSelect.isVisible.value && vue.createVNode("div", {
        "class": cls.controlSectionCell.value,
        "style": "height: auto"
      }, [vue.createVNode(radio_index.RadioGroup, vue.mergeProps({
        "modelValue": state.curSelectedMode,
        "onUpdate:modelValue": function onUpdateModelValue($event) {
          return state.curSelectedMode = $event;
        },
        "variant": "default-filled",
        "size": state.controlSize
      }, controller.configData.value.mode.radioGroupProps, {
        "disabled": modeSelect.isDisabled.value,
        "onChange": controller.emitControllerChange
      }), _isSlot(_slot = modeSelect.optionList.value.map(function (item) {
        return vue.createVNode(radio_index.RadioButton, {
          "key": item.value,
          "value": item.value
        }, {
          "default": function _default() {
            return [item.label];
          }
        });
      })) ? _slot : {
        "default": function _default() {
          return [_slot];
        }
      })]), weekendBtn.isVisible.value && vue.createVNode("div", {
        "class": cls.controlSectionCell.value
      }, [vue.createVNode(tag_index.CheckTag, vue.mergeProps({
        "class": cls.controlTag.value,
        "theme": state.isShowWeekend ? "default" : "primary",
        "size": "large"
      }, weekendBtn.vBind.value, {
        "disabled": weekendBtn.isDisabled.value,
        "onClick": function onClick() {
          state.isShowWeekend = !state.isShowWeekend;
          controller.emitControllerChange();
        }
      }), {
        "default": function _default() {
          return [weekendBtn.text.value];
        }
      })]), currentBtn.isVisible.value && vue.createVNode("div", {
        "class": cls.controlSectionCell.value
      }, [vue.createVNode(button_index.Button, vue.mergeProps({
        "size": state.controlSize
      }, currentBtn.vBind.value, {
        "disabled": currentBtn.isDisabled.value,
        "onClick": function onClick() {
          toToday();
        }
      }), {
        "default": function _default() {
          return [currentBtn.text.value];
        }
      })])])]);
    };
    var cellClickEmit = function cellClickEmit(eventPropsName, e, cellData) {
      if (isFunction__default["default"](props2[eventPropsName])) {
        var options = {
          cell: _objectSpread(_objectSpread({}, cellData), controller.options.value),
          e: e
        };
        props2[eventPropsName](options);
      }
    };
    var clickCell = function clickCell(e, cellData) {
      var d = dayjs__default["default"](cellData.date);
      if (props2.multiple) {
        if (state.curDateList.find(function (item) {
          return item.isSame(d);
        })) state.curDateList = remove__default["default"](state.curDateList, function (item) {
          return !item.isSame(d);
        });else state.curDateList.push(d);
      } else {
        state.curDate = d;
      }
      cellClickEmit("onCellClick", e, cellData);
    };
    var doubleClickCell = function doubleClickCell(e, cellData) {
      cellClickEmit("onCellDoubleClick", e, cellData);
    };
    var rightClickCell = function rightClickCell(e, cellData) {
      if (props2.preventCellContextmenu) e.preventDefault();
      cellClickEmit("onCellRightClick", e, cellData);
    };
    var monthCellsData = vue.computed(function () {
      var daysArr = calendar_utils.createMonthCellsData(props2, state);
      return daysArr;
    });
    var renderMonthBody = function renderMonthBody() {
      return vue.createVNode("table", {
        "class": cls.table.value
      }, [vue.createVNode("thead", {
        "class": cls.tableHead.value
      }, [vue.createVNode("tr", {
        "class": cls.tableHeadRow.value
      }, [cellColHeaders.value.map(function (item, index) {
        return checkDayVisible(item.num) && vue.createVNode("th", {
          "class": cls.tableHeadCell.value
        }, [isArray__default["default"](props2.week) ? props2.week[index] : renderContent("week", void 0, {
          defaultNode: vue.createVNode("span", null, [item.display]),
          params: {
            day: item.num
          }
        })]);
      })])]), vue.createVNode("tbody", {
        "class": cls.tableBody.value
      }, [monthCellsData.value.map(function (week, weekIndex) {
        return vue.createVNode("tr", {
          "class": cls.tableBodyRow.value
        }, [week.map(function (item, itemIndex) {
          return (state.isShowWeekend || item.day < 6) && vue.createVNode(calendar_calendarCell["default"], {
            "key": "d-".concat(weekIndex, "-").concat(itemIndex),
            "item": item,
            "theme": props2.theme,
            "t": t,
            "global": globalConfig.value,
            "cell": props2.cell,
            "cellAppend": props2.cellAppend,
            "fillWithZero": props2.fillWithZero,
            "onClick": function onClick(e) {
              return clickCell(e, item);
            },
            "onDblclick": function onDblclick(e) {
              return doubleClickCell(e, item);
            },
            "onRightclick": function onRightclick(e) {
              return rightClickCell(e, item);
            }
          }, _objectSpread({}, slots));
        })]);
      })])]);
    };
    var yearCellsData = vue.computed(function () {
      var re = [];
      var monthsArr = calendar_utils.createYearCellsData(props2, state);
      var rowCount = Math.ceil(monthsArr.length / calendar_const.DEFAULT_YEAR_CELL_NUMINROW);
      var index = 0;
      for (var i = 1; i <= rowCount; i++) {
        var row = [];
        for (var j = 1; j <= calendar_const.DEFAULT_YEAR_CELL_NUMINROW; j++) {
          row.push(monthsArr[index]);
          index += 1;
        }
        re.push(row);
      }
      return re;
    });
    var renderYearBody = function renderYearBody() {
      return vue.createVNode("table", {
        "class": cls.table.value
      }, [vue.createVNode("tbody", {
        "class": cls.tableBody.value
      }, [yearCellsData.value.map(function (cell, cellIndex) {
        return vue.createVNode("tr", {
          "class": cls.tableBodyRow.value
        }, [cell.map(function (item, itemIndex) {
          return vue.createVNode(calendar_calendarCell["default"], {
            "key": "m-".concat(cellIndex, "-").concat(itemIndex),
            "item": item,
            "theme": props2.theme,
            "t": t,
            "global": globalConfig.value,
            "cell": props2.cell,
            "cellAppend": props2.cellAppend,
            "fillWithZero": props2.fillWithZero,
            "onClick": function onClick(e) {
              return clickCell(e, item);
            },
            "onDblclick": function onDblclick(e) {
              return doubleClickCell(e, item);
            },
            "onRightclick": function onRightclick(e) {
              return rightClickCell(e, item);
            }
          }, _objectSpread({}, slots));
        })]);
      })])]);
    };
    return function () {
      return vue.createVNode("div", {
        "class": cls.body.value
      }, [controller.visible.value && renderControl(), vue.createVNode("div", {
        "class": cls.panel.value
      }, [state.curSelectedMode === "month" ? renderMonthBody() : renderYearBody()])]);
    };
  }
});

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