'use strict';

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

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

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 / constants.YEAR_DECADE_COUNT) * constants.YEAR_DECADE_COUNT;
  const endYear = startYear + constants.YEAR_DECADE_COUNT - 1;
  const baseYear = generateConfig.setYear(viewDate, startYear - Math.ceil((constants.YEAR_COL_COUNT * YEAR_ROW_COUNT - constants.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, vue.mergeProps(props, {
    "rowNum": YEAR_ROW_COUNT,
    "colNum": constants.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.default = YearBody;
//# sourceMappingURL=YearBody.js.map
