'use strict';

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

var vue = require('vue');
var useCellClassName = require('../../hooks/useCellClassName.cjs');
var dateUtil = require('../../utils/dateUtil.cjs');
var RangeContext = require('../../RangeContext.cjs');
var PanelBody = require('../PanelBody.cjs');
var useMergeProps = require('../../hooks/useMergeProps.cjs');
var constant = require('./constant.cjs');

const YEAR_COL_COUNT = 3;
const YEAR_ROW_COUNT = 4;
function YearBody(_props) {
  const props = useMergeProps.default(_props);
  const {
    prefixCls,
    value,
    viewDate,
    locale,
    generateConfig
  } = props;
  const {
    rangedValue,
    hoverRangedValue
  } = RangeContext.useInjectRange();
  const yearPrefixCls = `${prefixCls}-cell`;
  const yearNumber = generateConfig.getYear(viewDate);
  const startYear = Math.floor(yearNumber / constant.YEAR_DECADE_COUNT) * constant.YEAR_DECADE_COUNT;
  const endYear = startYear + constant.YEAR_DECADE_COUNT - 1;
  const baseYear = generateConfig.setYear(viewDate, startYear - Math.ceil((YEAR_COL_COUNT * YEAR_ROW_COUNT - constant.YEAR_DECADE_COUNT) / 2));
  const isInView = (date) => {
    const currentYearNumber = generateConfig.getYear(date);
    return startYear <= currentYearNumber && currentYearNumber <= endYear;
  };
  const getCellClassName = useCellClassName.default({
    cellPrefixCls: yearPrefixCls,
    value,
    generateConfig,
    rangedValue: rangedValue.value,
    hoverRangedValue: hoverRangedValue.value,
    isSameCell: (current, target) => dateUtil.isSameYear(generateConfig, current, target),
    isInView,
    offsetCell: (date, offset) => generateConfig.addYear(date, offset)
  });
  return vue.createVNode(PanelBody.default, {
    ...props,
    "rowNum": YEAR_ROW_COUNT,
    "colNum": YEAR_COL_COUNT,
    "baseDate": baseYear,
    "getCellText": generateConfig.getYear,
    "getCellClassName": getCellClassName,
    "getCellDate": generateConfig.addYear,
    "titleCell": (date) => dateUtil.formatValue(date, {
      locale,
      format: "YYYY",
      generateConfig
    })
  }, null);
}
YearBody.displayName = "YearBody";
YearBody.inheritAttrs = false;

exports.YEAR_COL_COUNT = YEAR_COL_COUNT;
exports.default = YearBody;
//# sourceMappingURL=YearBody.cjs.map
