import React, {FC} from "react"; import {Container} from "./Container"; import {__} from "../../globals"; import {Button} from "./Button"; import {TimeSlot, TimeSlotField, TimeSlotProps} from "./TimeSlotField"; import {EmulatedButton} from "../EmulatedButton"; export type WeeklyScheduleFieldsProps = { timeSlots: TimeSlot[], onNewTimeSlot: () => void, onTimeSlotChange: (index, timeSlot: TimeSlot) => void, onRemoveTimeSlot: (index: number) => void } export const WeeklyScheduleFields: FC = ({ timeSlots, onNewTimeSlot, onTimeSlotChange, onRemoveTimeSlot }) => { return {timeSlots.length === 0 &&

{__('Add time slots to restrict this coupon based on the day and time of the week')}

} {timeSlots.map((timeSlot, index) =>
{__('Time Slot')} #{index + 1} onRemoveTimeSlot(index)} className="active:scale-100 hover:scale-110 transition-transform">
{ onTimeSlotChange(index, { ...timeSlot, days: [...days] }) }} onAddDay={(day) => { onTimeSlotChange(index, { ...timeSlot, days: [...timeSlot.days, day] }) }} onRemoveDay={(day) => { onTimeSlotChange(index, { ...timeSlot, days: timeSlot.days.filter(d => d !== day) }) }} onTimeTypeChange={(type) => { onTimeSlotChange(index, { ...timeSlot, time: { ...timeSlot.time, type, // lets update the value from __local to prevent value corruption value: timeSlot.time.__local[type === 'range' ? 'value_range' : 'value_hours'] || [] } }) }} onTimeValueChange={(timeValue) => { onTimeSlotChange(index, { ...timeSlot, time: { ...timeSlot.time, value: timeValue, // update the __local value __local: { ...timeSlot.time.__local, [timeSlot.time.type === 'range' ? 'value_range' : 'value_hours']: timeValue } as Partial } }) }} autoOpenDaysPopupOnMount={timeSlot.time.__local?.open_days_popup_on_mount === true} onAutoOpenDaysPopupHandled={() => { if (timeSlot.time.__local?.open_days_popup_on_mount === true) { onTimeSlotChange(index, { ...timeSlot, time: { ...timeSlot.time, __local: { ...timeSlot.time.__local, open_days_popup_on_mount: false } } }) } }} />
)}
}