import { createVNode } from 'vue';
import { createKeydownHandler } from '../../utils/uiUtil.mjs';
import useMergeProps from '../../hooks/useMergeProps.mjs';
import YearBody, { YEAR_COL_COUNT } from './YearBody.mjs';
import YearHeader from './YearHeader.mjs';
import { YEAR_DECADE_COUNT } from './constant.mjs';

function YearPanel(_props) {
  const props = useMergeProps(_props);
  const {
    prefixCls,
    operationRef,
    onViewDateChange,
    generateConfig,
    value,
    viewDate,
    sourceMode,
    onSelect,
    onPanelChange
  } = props;
  const panelPrefixCls = `${prefixCls}-year-panel`;
  operationRef.value = {
    onKeydown: (event) => createKeydownHandler(event, {
      onLeftRight: (diff) => {
        onSelect(generateConfig.addYear(value || viewDate, diff), "key");
      },
      onCtrlLeftRight: (diff) => {
        onSelect(generateConfig.addYear(value || viewDate, diff * YEAR_DECADE_COUNT), "key");
      },
      onUpDown: (diff) => {
        onSelect(generateConfig.addYear(value || viewDate, diff * YEAR_COL_COUNT), "key");
      },
      onEnter: () => {
        onPanelChange(sourceMode === "date" ? "date" : "month", value || viewDate);
      }
    })
  };
  const onDecadeChange = (diff) => {
    const newDate = generateConfig.addYear(viewDate, diff * 10);
    onViewDateChange(newDate);
    onPanelChange(null, newDate);
  };
  return createVNode("div", {
    "class": panelPrefixCls
  }, [createVNode(YearHeader, {
    ...props,
    "prefixCls": prefixCls,
    "onPrevDecade": () => {
      onDecadeChange(-1);
    },
    "onNextDecade": () => {
      onDecadeChange(1);
    },
    "onDecadeClick": () => {
      onPanelChange("decade", viewDate);
    }
  }, null), createVNode(YearBody, {
    ...props,
    "prefixCls": prefixCls,
    "onSelect": (date) => {
      onPanelChange(sourceMode === "date" ? "date" : "month", date);
      onSelect(date, "mouse");
    }
  }, null)]);
}
YearPanel.displayName = "YearPanel";
YearPanel.inheritAttrs = false;

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