import { useState } from 'react'; import { TextareaControl } from "../ui/textarea-control"; import { Card, CardBody, CardHeader } from '../ui/wp-card'; import { Divider } from '../ui/divider'; import { Heading } from '../ui/heading'; import { Flex, FlexItem } from '../ui/flex'; import { Text } from '../ui/text'; import { Spacer } from '../ui/spacer'; import { PlusCircle, Trash2 } from 'lucide-react'; import { Controller, useFormContext } from 'react-hook-form'; import { FhirPeriod } from '../index.ts'; interface FhirOperationalHoursNotAvailableProps { notAvailable: any; label: string; context?: string; submitting?: boolean; } const FhirOperationalHoursNotAvailable = ({ notAvailable, label, context = 'notAvailable', submitting = false }: FhirOperationalHoursNotAvailableProps) => { const { control, getValues } = useFormContext(); const [confirmIndex, setConfirmIndex] = useState(null); const spacerMargin = '24px'; const addNotAvailable = () => { if (canAddNotAvailable()) { notAvailable.append({ description: '', during: { start: '', end: '' } }); } }; const requestRemove = (index: number) => { setConfirmIndex(index); }; const confirmRemove = () => { if (confirmIndex !== null) { notAvailable.remove(confirmIndex); setConfirmIndex(null); } }; const cancelRemove = () => setConfirmIndex(null); const canAddNotAvailable = (): boolean => { if (notAvailable.fields.length === 0) return true; const lastDescription = getValues(`${context}.${notAvailable.fields.length - 1}.description`) ?? ''; return lastDescription.trim() !== ''; }; return ( <> {label} {notAvailable.fields.map((period: any, periodIndex: number) => (
Description {confirmIndex === periodIndex ? ( Remove? {/* Yes/No are an INLINE confirm, not a modal — there is no X doing the same thing, so "No" stays. The hardcoded #cc1818 goes: btn-red-ghost is the house treatment for exactly this. */} ) : ( )} ( )} />
))} ); }; export default FhirOperationalHoursNotAvailable;