import { CurrentDot, RealRing, RingCommon, TargetRing } from "@/components/view/Rings"
import { ColorType } from "@/context/themes/color";








const startArc = (time: number) => {
    var date = new Date(time);
    var hour = date.getHours();
    var minute = date.getMinutes();
    var second = date.getSeconds();
    return (hour * 3600 + minute * 60 + second) / (24 * 3600) * 2 * Math.PI - Math.PI / 2.0;
}

const durationArc = (start_time: number, end_time: number) => {
    var duration = (end_time - start_time) / 1000;
    return duration / (24 * 3600) * 2 * Math.PI;
}



export const haveSmallRing = (data: any) => {
    if (data.scenario == 'FAST_SLEEP')
        return true
    return false
}

export const getCommon = (data: any, isBigRing: boolean) => {
    const commonBig: RingCommon = {
        useCase: 'Record',
        radius: 50,
        lineWidth: 8,
        isFast: true,
        status: 'WAIT_FOR_START'
    }

    const commonSmall: RingCommon = {
        useCase: 'Record',
        radius: 40,
        lineWidth: 8,
        isFast: true,
        status: 'WAIT_FOR_START'
    }

    if (isBigRing) {
        return commonBig
    }
    return commonSmall
}

export const getBgRing = () => {
    return {
        color: ColorType.ring
    }
}

export const getDot = (data: any, isBigRing: boolean) => {
    const currentDotBig: CurrentDot = {
        color: global.fastColor ? global.fastColor : ColorType.fast,
        lineWidth: 8,
        borderColor: 'black'
    }

    const currentDotSmall: CurrentDot = {
        color: global.sleepColor?global.sleepColor:ColorType.sleep,
        lineWidth: 8,
        borderColor: 'black'
    }

    if (isBigRing) {
        if (data && data.scenario == 'SLEEP') {
            currentDotBig.color = global.sleepColor?global.sleepColor:ColorType.sleep
        }
        return currentDotBig
    }
    else {
        return currentDotSmall
    }
}

export const getTarget = (data: any, isBigRing: boolean) => {
    const targetRingBig: TargetRing = {
        color: '#FF0000',
        startArc: 0,
        durationArc: 0
    }

    const targetRingSmall: TargetRing = {
        color: '#FF0000',
        startArc: 0,
        durationArc: 0
    }

    if (isBigRing) {
        if (data.scenario == 'SLEEP') {
            targetRingBig.color = global.sleepColor?global.sleepColor:ColorType.sleep
            targetRingBig.startArc = startArc(data.sleep.target_start_time)
            targetRingBig.durationArc = durationArc(data.sleep.start_time, data.sleep.target_end_time)
        }
        else {
            targetRingBig.startArc = startArc(data.fast.target_start_time)
            targetRingBig.durationArc = durationArc(data.fast.target_start_time, data.fast.target_end_time)
        }
        return targetRingBig
    }
    else {
        targetRingSmall.startArc = startArc(data.sleep.target_start_time)
        targetRingSmall.durationArc = durationArc(data.sleep.target_start_time, data.sleep.target_end_time)
        return targetRingSmall
    }
}

export const getReal = (data: any, isBigRing: boolean, isRecord: boolean) => {
    const realRingBig: RealRing = {
        color: global.fastColor ? global.fastColor : ColorType.fast,
        startArc: 0,
        durationArc: 0
    }

    const realRingSmall: RealRing = {
        color: global.sleepColor?global.sleepColor:ColorType.sleep,
        startArc: 0,
        durationArc: 0
    }

    if (isBigRing) {
        if (data.scenario == 'SLEEP') {
            realRingBig.color = global.sleepColor?global.sleepColor:ColorType.sleep
            realRingBig.startArc = startArc(data.sleep.real_start_time)
            realRingBig.durationArc = durationArc(data.sleep.real_start_time, isRecord ? (data.sleep.real_end_time ? data.sleep.real_end_time : new Date().getTime()) : new Date().getTime())
        }
        else {
            realRingBig.startArc = startArc(data.fast.real_start_time)
            realRingBig.durationArc = durationArc(data.fast.real_start_time, isRecord ? (data.fast.real_end_time ? data.fast.real_end_time : new Date().getTime()) : new Date().getTime())
        }
        return realRingBig
    }
    else {
        realRingSmall.startArc = startArc(data.sleep.real_start_time)
        realRingSmall.durationArc = durationArc(data.sleep.real_start_time, isRecord ? (data.sleep.real_end_time ? data.sleep.real_end_time : new Date().getTime()) : new Date().getTime())
        // if (isRecord && !isBigRing){
        //     debugger
        // }
        return realRingSmall
    }


}
