import { Task } from "../models/task";

/*
#85c75c
#8fb645
#97a532
#9c9323
#9f811a
#a06f16
#9f5d18
#9b4b1c
#953921
#8d2626
*/

export const colorArray = [
    "#85c75c",
    "#8fb645",
    "#97a532",
    "#9c9323",
    "#9f811a",
    "#a06f16",
    "#9f5d18",
    "#9b4b1c",
    "#953921",
    "#8d2626"
];

export const GetTaskColor = (task: Task): string => {
    console.log(task);
    if (!!task.lastDone && !!task.daysToRedo) {
        const timeDifference = Date.now() - task.lastDone!;
        const colorIndex = ((timeDifference / (task.daysToRedo! * 24 * 3600 * 1000)) * colorArray.length); // Cycle through colors based on days difference
        if (colorIndex < 0) {
            return colorArray[0]; // Default color if negative index
        }
        else if (colorIndex >= colorArray.length) {
            return colorArray[colorArray.length - 1]; // Ensure we don't go out of bounds
        } else {
            return colorArray[Math.floor(colorIndex)];
        }

    }
    return colorArray[0]; // Default color if no last done date
}