import dayjs from 'dayjs';
import { nanoid } from 'nanoid';
import isSameOrBefore from 'dayjs/plugin/isSameOrBefore';
dayjs.extend(isSameOrBefore);
const WEEKINFO = {
  Mo: '星期一',
  Tu: '星期二',
  We: '星期三',
  Th: '星期四',
  Fr: '星期五',
  Sa: '星期六',
};

export const COUNT = ['空班', '第一班', '第二班', '第三班', '第四班'];
// 默认头部
export function defaultHead() {
  const res = [];
  for (let i = 1; i < 7; i++) {
    const date = dayjs().day(i).format('YYYY-MM-DD');
    res.push({
      monthDay: dayjs(date).format('MM-DD'),
      week: WEEKINFO[dayjs(date).format('dd')],
      current: dayjs().isSame(date, 'day'),
      // 班次
      count: ['第一班', '第二班', '第三班'],
    });
  }
  return res;
}
const defaultBedCount = 55;
// 默认床位
export function defaultBed() {
  const res = [];
  for (let i = 0; i < defaultBedCount; i++) {
    res.push({
      bed: i < 10 ? '0' + i : '' + i,
      regionName: 'A区',
      regionCode: 'A',
      robot: '4008s',
      // 双机位
      double: i % 2 == 0 ? true : false,
    });
  }
  return res;
}

// 默认数据
export function defaultData() {
  const res = [];
  for (let i = 0; i < defaultBedCount; i++) {
    const obj = {
      id: nanoid(5),
      bed: i < 10 ? '0' + i : '' + i,
      regionCode: 'A',
      sailings: [],
    };

    for (let w = 1; w < 7; w++) {
      const week = [];
      const date = dayjs().day(w).format('YYYY-MM-DD');
      // console.log(dayjs().isAfter(date, 'day'));
      // console.log('date', date);
      for (let s = 0; s < 3; s++) {
        const bool = Math.round(Math.random() * 100) > 50;
        week.push({
          id: nanoid(5),
          key: nanoid(8),
          name: bool ? '范' + nanoid(3) : '',
          date: date,
          old: dayjs().isSame(date, 'day') ? false : dayjs().isAfter(date, 'day'),
          show: true,
          empty: !bool,
          edit: false,
          error: false,
          selected: false,
          actived: false,
          disabled: false,
          // 床位
          x: i,
          // 时间
          y: w,
          // 具体班次
          z: s,
        });
      }
      obj.sailings.push(week);
    }
    res.push(obj);
  }
  return res;
}
