import { DropdownItem } from "@komi-app/creator-ui";

export const generateTimeSlots = ({
  lowerHourBound = 0,
  upperHourBound = 23,
  lowerMinuteBound = 0,
  upperMinuteBound = 45,
}): DropdownItem[] => {
  const timeSlots: DropdownItem[] = [];

  for (let hour = lowerHourBound; hour <= upperHourBound; hour++) {
    const isLowerBoundHour = hour === lowerHourBound;
    const isUpperBoundHour = hour === upperHourBound;
    const minuteStart = isLowerBoundHour ? lowerMinuteBound : 0;
    const minuteEnd = isUpperBoundHour ? upperMinuteBound : 45;

    const labelHour = hour % 12 || 12;
    const labelPeriod = hour < 12 ? "AM" : "PM";
    const valueHour = hour.toString().padStart(2, "0");

    for (let minute = minuteStart; minute <= minuteEnd; minute += 15) {
      const formattedMinute = minute.toString().padStart(2, "0");

      timeSlots.push({
        label: `${labelHour}:${formattedMinute} ${labelPeriod}`,
        value: `${valueHour}:${formattedMinute}`,
        suffixTagProps: { text: "ET", variant: "default" },
      });
    }
  }

  return timeSlots;
};
