'use strict';

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

var vue = require('vue');
require('../../../../../utils/index.cjs');
var dateUtil = require('../../utils/dateUtil.cjs');
var uiUtil = require('../../utils/uiUtil.cjs');
var useMergeProps = require('../../hooks/useMergeProps.cjs');
var DateHeader = require('./DateHeader.cjs');
var DateBody = require('./DateBody.cjs');
var _class = require('../../../../../utils/dom/class.cjs');

const DATE_ROW_COUNT = 6;
function DatePanel(_props) {
  const props = useMergeProps.default(_props);
  const {
    prefixCls,
    panelName = "date",
    keyboardConfig,
    active,
    operationRef,
    generateConfig,
    value,
    viewDate,
    onViewDateChange,
    onPanelChange,
    onSelect
  } = props;
  const panelPrefixCls = `${prefixCls}-${panelName}-panel`;
  operationRef.value = {
    onKeydown: (event) => uiUtil.createKeydownHandler(event, {
      onLeftRight: (diff) => {
        onSelect(generateConfig.addDate(value || viewDate, diff), "key");
      },
      onCtrlLeftRight: (diff) => {
        onSelect(generateConfig.addYear(value || viewDate, diff), "key");
      },
      onUpDown: (diff) => {
        onSelect(generateConfig.addDate(value || viewDate, diff * dateUtil.WEEK_DAY_COUNT), "key");
      },
      onPageUpDown: (diff) => {
        onSelect(generateConfig.addMonth(value || viewDate, diff), "key");
      },
      ...keyboardConfig
    })
  };
  const onYearChange = (diff) => {
    const newDate = generateConfig.addYear(viewDate, diff);
    onViewDateChange(newDate);
    onPanelChange(null, newDate);
  };
  const onMonthChange = (diff) => {
    const newDate = generateConfig.addMonth(viewDate, diff);
    onViewDateChange(newDate);
    onPanelChange(null, newDate);
  };
  return vue.createVNode("div", {
    "class": _class.classNames(panelPrefixCls, {
      [`${panelPrefixCls}-active`]: active
    })
  }, [vue.createVNode(DateHeader.default, {
    ...props,
    "prefixCls": prefixCls,
    "value": value,
    "viewDate": viewDate,
    "onPrevYear": () => {
      onYearChange(-1);
    },
    "onNextYear": () => {
      onYearChange(1);
    },
    "onPrevMonth": () => {
      onMonthChange(-1);
    },
    "onNextMonth": () => {
      onMonthChange(1);
    },
    "onMonthClick": () => {
      onPanelChange("month", viewDate);
    },
    "onYearClick": () => {
      onPanelChange("year", viewDate);
    }
  }, null), vue.createVNode(DateBody.default, {
    ...props,
    "onSelect": (date) => onSelect(date, "mouse"),
    "prefixCls": prefixCls,
    "value": value,
    "viewDate": viewDate,
    "rowCount": DATE_ROW_COUNT
  }, null)]);
}
DatePanel.displayName = "DatePanel";
DatePanel.inheritAttrs = false;

exports.default = DatePanel;
//# sourceMappingURL=index.cjs.map
