import { Card, CardHeader, CardBody } from '../ui/wp-card'; import { TextareaControl } from "../ui/textarea-control"; import { InputControl } from '../ui/input-control'; import { Divider } from '../ui/divider'; import { Heading } from '../ui/heading'; import { Flex, FlexItem, FlexBlock } from '../ui/flex'; import { Spacer } from '../ui/spacer'; import { Controller, useFormContext } from 'react-hook-form'; import { IValueSet, useValueSetServiceContext } from '../../services'; import { PractitionerRoleAvailableTime } from 'fhir/r4'; import React from 'react'; // - WordPress's ToggleControl, swapped for the ui/* adapter. Same props, same JSX; // only `__nextHasNoMarginBottom` is dropped, which means nothing outside WordPress. import { ToggleControl } from '../ui/toggle-control'; interface FhirOperationalHoursProps { hours: any; label: string; context?: string; startKey?: string; endKey?: string; showAvailabilityExceptions?: boolean; submitting?: boolean; } const FhirOperationalHours = ({ hours, label, context = 'availableTime', startKey = 'availableStartTime', endKey = 'availableEndTime', showAvailabilityExceptions = true, submitting = false }: FhirOperationalHoursProps) => { const { control, watch } = useFormContext(); const { daysOfWeek } = useValueSetServiceContext(); const getDayOfWeekDisplay = (availableTime: PractitionerRoleAvailableTime): string => daysOfWeek.find((day: IValueSet) => day.code === availableTime.daysOfWeek?.[0])?.display ?? ''; const spacerMargin = '24px'; return ( <> {label} {hours.fields.map((availableTime: any, index: number) => { return ( {getDayOfWeekDisplay(availableTime)} ( )}/> {watch(`${context}.${index}.available`) && ( <> {/* allDay */} ( )}/> {!watch(`${context}.${index}.allDay`) && ( {/* start */} ( )}/> {/* end */} ( )}/> )} )} ); })} {/* availabilityExceptions */} {showAvailabilityExceptions && ( <> Availability Exceptions ( )}/> )} ); }; export default FhirOperationalHours; // import { Controller, useFormContext, useFieldArray } from 'react-hook-form'; // import { IValueSet, useValueSetServiceContext } from '../../services'; // import { PractitionerRoleAvailableTime } from 'fhir/r4'; // import React from 'react'; // // interface FhirOperationalHoursProps { // hours: any; // label: string; // context?: string; // startKey?: string; // endKey?: string; // showAvailabilityExceptions?: boolean; // submitting?: boolean; // } // // interface TimeInterval { // id: string; // start: string; // end: string; // } // // const FhirOperationalHours = ({ // hours, // label, // context = 'availableTime', // startKey = 'availableStartTime', // endKey = 'availableEndTime', // showAvailabilityExceptions = true, // submitting = false // }: FhirOperationalHoursProps) => { // const { control, watch, setValue, getValues } = useFormContext(); // const { daysOfWeek } = useValueSetServiceContext(); // const getDayOfWeekDisplay = (availableTime: PractitionerRoleAvailableTime): string => // daysOfWeek.find((day: IValueSet) => day.code === availableTime.daysOfWeek?.[0])?.display ?? ''; // // const spacerMargin = '24px'; // // // Create a field array for each day's time intervals // const timeIntervalsArrays = hours.fields.map((_: any, index: number) => { // return useFieldArray({ // control, // name: `${context}.${index}.timeIntervals` // }); // }); // // // Initialize time intervals if they don't exist // React.useEffect(() => { // hours.fields.forEach((availableTime: any, index: number) => { // const timeIntervals = getValues(`${context}.${index}.timeIntervals`); // // if (!timeIntervals || timeIntervals.length === 0) { // // Initialize with a single interval using the existing start/end times // setValue(`${context}.${index}.timeIntervals`, [ // { // start: getValues(`${context}.${index}.${startKey}`) || '09:00', // end: getValues(`${context}.${index}.${endKey}`) || '17:00' // } // ]); // } // }); // }, [hours.fields, context, startKey, endKey, setValue, getValues]); // // // Add a new time interval for a specific day // const addTimeInterval = (dayIndex: number) => { // const timeIntervals = timeIntervalsArrays[dayIndex]; // timeIntervals.append({ // start: '09:00', // end: '17:00' // }); // }; // // // Remove a time interval for a specific day // const removeTimeInterval = (dayIndex: number, intervalIndex: number) => { // const timeIntervals = timeIntervalsArrays[dayIndex]; // timeIntervals.remove(intervalIndex); // }; // // return ( // <> // // {label} // // // // {hours.fields.map((availableTime: any, dayIndex: number) => { // const dayAvailable = watch(`${context}.${dayIndex}.available`); // const allDay = watch(`${context}.${dayIndex}.allDay`); // const timeIntervals = timeIntervalsArrays[dayIndex]; // // return ( // // // // {getDayOfWeekDisplay(availableTime)} // // // // // {/* available */} // ( // // )} // /> // // // // {dayAvailable && ( // <> // {/* allDay */} // ( // // )} // /> // // // // {!allDay && timeIntervals.fields.map((interval: any, intervalIndex: number) => ( //
// // // {intervalIndex === 0 ? 'Hours': `Additional Hours ${intervalIndex}`} // // // {intervalIndex > 0 && ( //
// ))} // // {!allDay && ( // // // // )} // // )} //
//
// // //
// ); // })} // // {/* availabilityExceptions */} // {showAvailabilityExceptions && ( // <> // // Availability Exceptions // // // // ( // // )} // /> // // )} // // ); // }; // // export default FhirOperationalHours;