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

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, computed, createVNode } from 'vue';
import dayjs from 'dayjs';
import isFunction from 'lodash/isFunction';
import { getDefaultFormat, formatDate, parseToDayjs } from '../_common/js/date-picker/format.js';
import { subtractMonth, addMonth, extractTimeObj } from '../_common/js/date-picker/utils.js';
import useSingleValue from './hooks/useSingleValue.js';
import datePickerPanelProps from './date-picker-panel-props.js';
import datePickerProps from './props.js';
import TSinglePanel from './panel/SinglePanel.js';
import 'lodash/isString';
import '../_common/js/log/log.js';
import '@babel/runtime/helpers/slicedToArray';
import '@babel/runtime/helpers/objectDestructuringEmpty';
import '@babel/runtime/helpers/extends';
import '../_chunks/dep-e041f5b0.js';
import '../_chunks/dep-e86e320e.js';
import 'lodash/chunk';
import '../hooks/useVModel.js';
import 'lodash/kebabCase';
import '../hooks/useConfig.js';
import '../config-provider/useConfig.js';
import 'lodash/cloneDeep';
import '../config-provider/context.js';
import 'lodash/mergeWith';
import 'lodash/merge';
import 'lodash/isArray';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/zh_CN.js';
import '@babel/runtime/helpers/typeof';
import './hooks/useTableData.js';
import './hooks/useDisableDate.js';
import 'lodash/isObject';
import './panel/ExtraContent.js';
import './base/Footer.js';
import '../button/index.js';
import '../utils/withInstall.js';
import '../button/button.js';
import '@babel/runtime/helpers/toConsumableArray';
import '../loading/index.js';
import '../loading/directive.js';
import '../loading/plugin.js';
import '../utils/dom.js';
import '../utils/easing.js';
import '../loading/loading.js';
import '../utils/render-tnode.js';
import 'lodash/isEmpty';
import 'lodash/camelCase';
import '../hooks/useTeleport.js';
import '../loading/props.js';
import '../loading/icon/gradient.js';
import '../_common/js/loading/circle-adapter.js';
import '../_common/js/utils/set-style.js';
import '../_common/js/utils/helper.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import 'lodash/isNull';
import 'lodash/isUndefined';
import 'lodash/isNumber';
import '../hooks/useRipple.js';
import '../utils/set-style.js';
import '../hooks/useKeepAnimation.js';
import '../form/hooks.js';
import '../hooks/tnode.js';
import '../button/props.js';
import './panel/PanelContent.js';
import './base/Header.js';
import '../pagination/index.js';
import '../pagination/pagination.js';
import 'lodash/isNaN';
import '@ldesign/icons-vue-next';
import '../hooks/useGlobalIcon.js';
import '../input-number/index.js';
import '../input-number/input-number.js';
import '../input/index.js';
import '../input/input.js';
import '../input/props.js';
import '../input/useInput.js';
import '../form/const.js';
import '../input/useLengthLimit.js';
import '../input/useInputEventHandler.js';
import '../input/useInputWidth.js';
import '../input/input-group.js';
import '../input/input-group-props.js';
import '../input-number/props.js';
import '../input-number/useInputNumber.js';
import '../hooks/useCommonClassName.js';
import '../_common/js/input-number/number.js';
import 'lodash/isNil';
import '../_common/js/input-number/large-number.js';
import '../select/index.js';
import '../select/select.js';
import 'lodash/pick';
import 'lodash/debounce';
import 'lodash/get';
import 'lodash/intersection';
import '../common-components/fake-arrow.js';
import '../select-input/index.js';
import '../select-input/select-input.js';
import '../popup/index.js';
import '../popup/popup.js';
import '@popperjs/core';
import '../popup/props.js';
import '../popup/container.js';
import '../hooks/useResizeObserver.js';
import '../select-input/props.js';
import '../select-input/useSingle.js';
import '../hooks/useDefaultValue.js';
import '../select-input/useMultiple.js';
import '../tag-input/index.js';
import '../tag-input/tag-input.js';
import '../tag-input/props.js';
import '../tag-input/hooks/useTagScroll.js';
import '../tag-input/useTagList.js';
import '../tag/index.js';
import '../tag/tag.js';
import '../tag/props.js';
import '../tag/check-tag.js';
import '../tag/check-tag-props.js';
import '../tag-input/hooks/useHover.js';
import '../tag-input/hooks/useDragSorter.js';
import '../select-input/useOverlayInnerStyle.js';
import '../select/props.js';
import '../select/select-panel.js';
import 'lodash/omit';
import '../select/option.js';
import '../checkbox/index.js';
import '../checkbox/checkbox.js';
import '../checkbox/props.js';
import '../checkbox/constants.js';
import '../checkbox/group.js';
import '../hooks/slot.js';
import '../checkbox/checkbox-group-props.js';
import '../select/option-props.js';
import '../select/helper.js';
import '../select/optionGroup.js';
import '../select/option-group-props.js';
import '../select/hooks/usePanelVirtualScroll.js';
import '../hooks/useVirtualScroll.js';
import '../select/hooks/useSelectOptions.js';
import '../input-adornment/index.js';
import '../input-adornment/input-adornment.js';
import '../input-adornment/props.js';
import '../pagination/props.js';
import '../pagination/usePaginationClasses.js';
import '../pagination/useMoreAction.js';
import '../pagination/pagination-mini.js';
import '../pagination/pagination-mini-props.js';
import './base/Table.js';
import './base/Cell.js';
import '../time-picker/panel/time-picker-panel.js';
import '../_common/js/time-picker/const.js';
import '../time-picker/panel/props.js';
import 'lodash/isBoolean';
import '../time-picker/props.js';
import '../time-picker/panel/single-panel.js';
import 'lodash/range';
import 'lodash/padStart';
import '../_common/js/time-picker/utils.js';

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(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; }
var _DatePickerPanel = defineComponent({
  name: "TDatePickerPanel",
  props: _objectSpread({
    value: datePickerProps.value,
    defaultValue: datePickerProps.defaultValue,
    modelValue: datePickerProps.modelValue,
    disabled: datePickerProps.disabled,
    disableDate: datePickerProps.disableDate,
    enableTimePicker: datePickerProps.enableTimePicker,
    firstDayOfWeek: datePickerProps.firstDayOfWeek,
    format: datePickerProps.format,
    mode: datePickerProps.mode,
    presets: datePickerProps.presets,
    presetsPlacement: datePickerProps.presetsPlacement,
    timePickerProps: datePickerProps.timePickerProps
  }, datePickerPanelProps),
  setup: function setup(props) {
    var _useSingleValue = useSingleValue(props),
      cacheValue = _useSingleValue.cacheValue,
      value = _useSingleValue.value,
      year = _useSingleValue.year,
      month = _useSingleValue.month,
      time = _useSingleValue.time,
      onChange = _useSingleValue.onChange;
    var formatRef = computed(function () {
      return getDefaultFormat({
        mode: props.mode,
        format: props.format,
        enableTimePicker: props.enableTimePicker
      });
    });
    function onCellClick(date, _ref) {
      var _props$onCellClick;
      var e = _ref.e;
      (_props$onCellClick = props.onCellClick) === null || _props$onCellClick === void 0 ? void 0 : _props$onCellClick.call(props, {
        date: date,
        e: e
      });
      if (props.mode === "date") {
        year.value = date.getFullYear();
        month.value = date.getMonth();
      }
      if (props.enableTimePicker) {
        cacheValue.value = formatDate(date, {
          format: formatRef.value.format
        });
      } else {
        onChange === null || onChange === void 0 ? void 0 : onChange(formatDate(date, {
          format: formatRef.value.format
        }), {
          dayjsValue: parseToDayjs(date, formatRef.value.format),
          trigger: "pick"
        });
      }
    }
    function onJumperClick(_ref2) {
      var trigger = _ref2.trigger;
      var triggerMap = {
        prev: "arrow-previous",
        next: "arrow-next"
      };
      var monthCountMap = {
        date: 1,
        week: 1,
        month: 12,
        quarter: 12,
        year: 120
      };
      var monthCount = monthCountMap[props.mode] || 0;
      var current = new Date(year.value, month.value);
      var next = null;
      if (trigger === "prev") next = subtractMonth(current, monthCount);else if (trigger === "current") next = new Date();else if (trigger === "next") next = addMonth(current, monthCount);
      var nextYear = next.getFullYear();
      var nextMonth = next.getMonth();
      if (year.value !== nextYear) {
        var _props$onYearChange;
        (_props$onYearChange = props.onYearChange) === null || _props$onYearChange === void 0 ? void 0 : _props$onYearChange.call(props, {
          year: nextYear,
          date: dayjs(value.value).toDate(),
          trigger: trigger === "current" ? "today" : "year-".concat(triggerMap[trigger])
        });
      }
      if (month.value !== nextMonth) {
        var _props$onMonthChange;
        (_props$onMonthChange = props.onMonthChange) === null || _props$onMonthChange === void 0 ? void 0 : _props$onMonthChange.call(props, {
          month: nextMonth,
          date: dayjs(value.value).toDate(),
          trigger: trigger === "current" ? "today" : "month-".concat(triggerMap[trigger])
        });
      }
      year.value = nextYear;
      month.value = nextMonth;
    }
    function onTimePickerChange(val) {
      var _props$onTimeChange;
      time.value = val;
      var _extractTimeObj = extractTimeObj(val),
        hours = _extractTimeObj.hours,
        minutes = _extractTimeObj.minutes,
        seconds = _extractTimeObj.seconds,
        milliseconds = _extractTimeObj.milliseconds,
        meridiem = _extractTimeObj.meridiem;
      var nextHours = hours;
      if (/am/i.test(meridiem) && nextHours === 12) nextHours -= 12;
      if (/pm/i.test(meridiem) && nextHours < 12) nextHours += 12;
      var currentDate = !dayjs(cacheValue.value, formatRef.value.format).isValid() ? dayjs() : dayjs(cacheValue.value, formatRef.value.format);
      var nextDate = currentDate.hour(nextHours).minute(minutes).second(seconds).millisecond(milliseconds).toDate();
      cacheValue.value = formatDate(nextDate, {
        format: formatRef.value.format
      });
      (_props$onTimeChange = props.onTimeChange) === null || _props$onTimeChange === void 0 ? void 0 : _props$onTimeChange.call(props, {
        time: val,
        date: dayjs(value.value).toDate(),
        trigger: "time-hour"
      });
    }
    function onConfirmClick(_ref3) {
      var _props$onConfirm;
      var e = _ref3.e;
      onChange === null || onChange === void 0 ? void 0 : onChange(formatDate(cacheValue.value, {
        format: formatRef.value.format
      }), {
        dayjsValue: parseToDayjs(cacheValue.value, formatRef.value.format),
        trigger: "confirm"
      });
      (_props$onConfirm = props.onConfirm) === null || _props$onConfirm === void 0 ? void 0 : _props$onConfirm.call(props, {
        date: dayjs(cacheValue.value).toDate(),
        e: e
      });
    }
    function onPresetClick(presetValue, _ref4) {
      var _props$onPresetClick;
      var e = _ref4.e,
        preset = _ref4.preset;
      var presetVal = isFunction(presetValue) ? presetValue() : presetValue;
      onChange === null || onChange === void 0 ? void 0 : onChange(formatDate(presetVal, {
        format: formatRef.value.format
      }), {
        dayjsValue: parseToDayjs(presetVal, formatRef.value.format),
        trigger: "preset"
      });
      (_props$onPresetClick = props.onPresetClick) === null || _props$onPresetClick === void 0 ? void 0 : _props$onPresetClick.call(props, {
        e: e,
        preset: preset
      });
    }
    function onYearChange(nextYear) {
      var _props$onYearChange2;
      year.value = nextYear;
      (_props$onYearChange2 = props.onYearChange) === null || _props$onYearChange2 === void 0 ? void 0 : _props$onYearChange2.call(props, {
        year: year.value,
        date: dayjs(value.value).toDate(),
        trigger: "year-select"
      });
    }
    function onMonthChange(nextMonth) {
      var _props$onMonthChange2;
      month.value = nextMonth;
      (_props$onMonthChange2 = props.onMonthChange) === null || _props$onMonthChange2 === void 0 ? void 0 : _props$onMonthChange2.call(props, {
        month: month.value,
        date: dayjs(value.value).toDate(),
        trigger: "month-select"
      });
    }
    var panelProps = computed(function () {
      return {
        value: cacheValue.value,
        year: year.value,
        month: month.value,
        mode: props.mode,
        format: formatRef.value.format,
        presets: props.presets,
        time: time.value,
        disableDate: props.disableDate,
        firstDayOfWeek: props.firstDayOfWeek,
        timePickerProps: props.timePickerProps,
        enableTimePicker: props.enableTimePicker,
        presetsPlacement: props.presetsPlacement,
        panelClick: props.onPanelClick,
        onCellClick: onCellClick,
        onJumperClick: onJumperClick,
        onConfirmClick: onConfirmClick,
        onPresetClick: onPresetClick,
        onYearChange: onYearChange,
        onMonthChange: onMonthChange,
        onTimePickerChange: onTimePickerChange
      };
    });
    return function () {
      return createVNode(TSinglePanel, panelProps.value, null);
    };
  }
});

export { _DatePickerPanel as default };
//# sourceMappingURL=DatePickerPanel.js.map
