export default function(){

    function generateTimeSlots(
        intervalHours: number,
        startTime?: string | null,
        endTime?: string | null
        ): TTimeSlotOption[] {
        if (!intervalHours || intervalHours <= 0) {
            throw new Error("Interval must be greater than 0");
        }

        const intervalMinutes = intervalHours * 60;
        const startMinutes = toMinutes(startTime ?? "00:00");
        const endMinutes = toMinutes(endTime ?? "24:00");

        const slots: TTimeSlotOption[] = [];
        let key = 1;

        let current = startMinutes + intervalMinutes;

        for (; current <= endMinutes; current += intervalMinutes) {
            slots.push({
            key: key++,
            time: toTimeString(current),
            disabled: false
            });
        }

        return slots;
}

const toMinutes = (time: string): number => {
            const [h, m] = time.split(":").map(Number);
            return h * 60 + m;
};

const toTimeString = (minutes: number): string => {
            const hours = Math.floor(minutes / 60);
            const mins = minutes % 60;
            return `${hours.toString().padStart(2, "0")}:${mins.toString().padStart(2, "0")}`;
};

function generateTimeSlotsFromStart(
            intervalHours: number,
            startTime?: string | null,
            endTime?: string | null
            ): TTimeSlotOption[] {
            if (!intervalHours || intervalHours <= 0) {
                throw new Error("Interval must be greater than 0");
            }

            const intervalMinutes = intervalHours * 60;
            const startMinutes = toMinutes(startTime ?? "00:00");
            const endMinutes = toMinutes(endTime ?? "24:00");

            const slots: TTimeSlotOption[] = [];
            let key = 1;

            let current = startMinutes

            for (; current <= endMinutes; current += intervalMinutes) {
                slots.push({
                key: key++,
                time: toTimeString(current),
                disabled: false
                });
            }

            return slots;
}

// 24/11/2025, 09:05 format
function toLocalTimeNumeric(utcString: string) {
  return new Date(utcString).toLocaleString("en-GB", {
    year: "numeric",
    month: "2-digit",
    day: "2-digit",
    hour: "2-digit",
    minute: "2-digit",
    hour12: false,
  })
}



const monthlyOptions = [
    { value: 1, title: "1st" },
    { value: 2, title: "2nd" },
    { value: 3, title: "3rd" },
    { value: 4, title: "4th" },
    { value: 5, title: "5th" },
    { value: 6, title: "6th" },
    { value: 7, title: "7th" },
    { value: 8, title: "8th" },
    { value: 9, title: "9th" },
    { value: 10, title: "10th" },
    { value: 11, title: "11th" },
    { value: 12, title: "12th" },
    { value: 13, title: "13th" },
    { value: 14, title: "14th" },
    { value: 15, title: "15th" },
    { value: 16, title: "16th" },
    { value: 17, title: "17th" },
    { value: 18, title: "18th" },
    { value: 19, title: "19th" },
    { value: 20, title: "20th" },
    { value: 21, title: "21st" },
    { value: 22, title: "22nd" },
    { value: 23, title: "23rd" },
    { value: 24, title: "24th" },
    { value: 25, title: "25th" },
    { value: 26, title: "26th" },
    { value: 27, title: "27th" },
    { value: 28, title: "28th" },
    { value: "Last Day", title: "Last Day" }
];

       
function defaultCurrencyObject (){

    return { 
            symbol: "S$",
            code: "SGD",
            taxType: "GST",
        }
}


return {
    generateTimeSlots,
    toMinutes,
    toTimeString,
    generateTimeSlotsFromStart,
    monthlyOptions,
    toLocalTimeNumeric,
    defaultCurrencyObject
    
}

}
