import dayjs from 'dayjs'

interface Date{
    day?: number;
    list?: Array<any>;
}

interface GetDate{
    date: Array<Array<Date>>;
    year: number;
    yue: number;
    day: number;
    zhou: number;
    start: string;
    end: string;
}

export function getdate(yue: number,id: string): GetDate{
     /* eslint-disable */
     const utc = require('dayjs/plugin/utc') // dependent on utc plugin
     /* eslint-disable */
     const timezone = require('dayjs/plugin/timezone')
     dayjs.extend(utc)
     dayjs.extend(timezone)
     const days: any = dayjs;
    let now = days().tz(id)
    now = now.month(now.month() + yue);
    yue = now.month() + 1;
    const day = now.date() // 当前天
    const zhou = now.day(); // 当前周
    now = now.date(1)
    const week = now.day(); // 第一天是星期几
    now = now.month(now.month() + 1);
    now = now.date(0);
    const month = now.date(); // 当前月有几天
    const year = now.year()
    const start = year + "-" + yue + '-01';
    const end = year + "-" + yue + '-' + month;
    console.log(day,week,month)
    let i = 0;
    let w = 0;

    
    const date: Array<Array<Date>> = [[]];
    
    while(i < month){
        
        for(w = 0; w < week; w++){
            date[0][w] = {list:[]};
        }
        i++;
        const zhou =  Math.floor((i + w - 1) / 7)
        const d = {
            day: i,
            list: [],
            time: now.date(i).toISOString()
        }
        if(date[zhou] == undefined){
            date[zhou] = []
        }
        date[zhou].push(d)
    }
    while(date[date.length - 1].length < 7){
        date[date.length - 1].push({list:[]})
    }
    console.log(date)

    return {date, year, yue, day, zhou, start, end};
}


export function getweek(time: string, id: string,zhou?: number){
    /* eslint-disable */
    const utc = require('dayjs/plugin/utc') // dependent on utc plugin
    /* eslint-disable */
    const timezone = require('dayjs/plugin/timezone')
    dayjs.extend(utc)
    dayjs.extend(timezone)
    const days: any = dayjs;
    console.log(id, 11111)
    let now;
    try {
        now = days((!time ? undefined : time)).tz(id)
    } catch (error) {
        now = days(undefined).tz(id)
    }
    console.log(now, 11111)

    if(zhou != undefined){
        now = now.day(now.day() + (zhou * 7));
    }
    const yue = (now.month() + 1 < 10 ? '0' + (now.month() + 1)  : (now.month() + 1));
    const day = now.date() // 当前天
    zhou = now.day(); // 当前周几
    const year = now.year()
    const startd = now.day(0);
    const start = `${startd.year()}-${(startd.month() + 1 < 10 ? '0' + (startd.month() + 1)  : (startd.month() + 1))}-${startd.date() > 9 ? startd.date() : '0' + startd.date()}`
    interface Date{
        day: string;
        list?: Array<any>;
    }
    const date: Array<Date> = [];
   
    for(let i = 0; i < 7; i++){
        console.log(i);
        now = now.day(i)
        date[i] = {day: ""};
        date[i].day = now.year() + "-" + (now.month() + 1 < 10 ? '0' + (now.month() + 1)  : (now.month() + 1)) + "-" + (now.date() < 10 ? '0' + now.date() : now.date())
        date[i].list = []
        for(let j = 0;j < 24; j++){
            date[i].list?.push({
                start:"",
                num:"",
                title: "",
                time:""
            })
        }
    }
    const end = `${now.year()}-${(now.month() + 1 < 10 ? '0' + (now.month() + 1)  : (now.month() + 1))}-${now.date()}`
    console.log(date)
    return {date, year, yue, day, zhou, start, end}
}


export function getDay(date: string){
    const now = dayjs(date)
    console.log(now.date())
    return now.date();
}

export function gethour(date: string){
    const now = dayjs(date)
    console.log(now.hour(), now.date(), now.minute())
    return now.hour();
}

export function getminute(date: string){
    const now = dayjs(date)
    // console.log(now.hour(), now.date(), now.minute())
    return now.minute();
}

export function gettime(date: string, num: number){
    let now = dayjs(date)
    const start = `${now.hour() > 9 ? now.hour() : '0' + now.hour()}:${now.minute() > 9 ? now.minute() : '0' + now.minute()}`
    now = now.minute(now.minute() + num);
    const end = `${now.hour() > 9 ? now.hour() : '0' + now.hour()}:${now.minute() > 9 ? now.minute() : '0' + now.minute()}`
    return  start + "-" + end;
}