/** 排班网格的日期工具 */

const WEEK_LABELS = ['日', '一', '二', '三', '四', '五', '六'];

/** 返回某月天数数组，如 2026-08 → [1..31] */
export function getDaysOfMonth(yearMonth: string): number[] {
  const [yearStr, monthStr] = yearMonth.split('-');
  const days = new Date(Number(yearStr), Number(monthStr), 0).getDate();
  return Array.from({ length: days }, (_, i) => i + 1);
}

/** 返回某日的星期中文标签（日/一/二…） */
export function getWeekLabel(yearMonth: string, day: number): string {
  const date = new Date(`${yearMonth}-${String(day).padStart(2, '0')}`);
  return WEEK_LABELS[date.getDay()] ?? '';
}

/** 判断某日是否为周末 */
export function isWeekend(yearMonth: string, day: number): boolean {
  const date = new Date(`${yearMonth}-${String(day).padStart(2, '0')}`);
  const week = date.getDay();
  return week === 0 || week === 6;
}

/** 生成某月某日的日期字符串 yyyy-MM-dd */
export function formatDate(yearMonth: string, day: number): string {
  return `${yearMonth}-${String(day).padStart(2, '0')}`;
}

/** 自动排班休息模式 */
export const REST_MODE = {
  /** 双休：周六、周日休息 */
  DOUBLE: 'double',
  /** 单休：周日休息 */
  SINGLE: 'single',
  /** 不休息：每天排班 */
  NONE: 'none',
} as const;

export type RestMode = (typeof REST_MODE)[keyof typeof REST_MODE];

export const REST_MODE_OPTIONS: { label: string; value: RestMode }[] = [
  { label: '双休（六日休）', value: REST_MODE.DOUBLE },
  { label: '单休（周日休）', value: REST_MODE.SINGLE },
  { label: '不休息', value: REST_MODE.NONE },
];
