/** 数据模型填报统计年份：最低 2021，最高当年（降序） */

export const DATA_MODEL_YEAR_MIN = 2021

/**
 * @param {number} [endYear=new Date().getFullYear()]
 * @returns {number[]}
 */
export function buildDataModelYearOptions(endYear = new Date().getFullYear()) {
  const end = Number(endYear)
  const start = DATA_MODEL_YEAR_MIN
  if (!Number.isFinite(end) || end < start) {
    return [start]
  }
  const years = []
  for (let y = end; y >= start; y--) {
    years.push(y)
  }
  return years
}

/**
 * el-date-picker type=year 禁用：不在 2021～当年
 * @param {Date} time
 * @returns {boolean}
 */
export function isDataModelYearDisabled(time) {
  if (!time || typeof time.getFullYear !== "function") {
    return true
  }
  const y = time.getFullYear()
  const end = new Date().getFullYear()
  return y < DATA_MODEL_YEAR_MIN || y > end
}
