"use client"; import React, { useState } from "react"; import type { KidsChild } from "@/lib/kids"; export type ChildInput = { firstName: string; lastName: string; dateOfBirth: string; gender: string; allergies: string; medicalNotes: string; custodyNotes?: string; }; const inputCls = "w-full border rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-brand-500"; export function childToInput(c?: KidsChild | null): ChildInput { return { firstName: c?.firstName || "", lastName: c?.lastName || "", dateOfBirth: c?.dateOfBirth ? c.dateOfBirth.slice(0, 10) : "", gender: c?.gender || "", allergies: c?.allergies || "", medicalNotes: c?.medicalNotes || "", custodyNotes: c?.custodyNotes || "", }; } type Props = { initial?: KidsChild | null; /** Show the custody notes box (parents, supervisors and admins). */ custody: boolean; busy?: boolean; onSave: (input: ChildInput) => void; onCancel?: () => void; saveLabel?: string; }; /** Add or change a child: name, date of birth, allergies, medical and (optionally) custody notes. */ export function ChildForm({ initial, custody, busy, onSave, onCancel, saveLabel = "Save" }: Props) { const [v, setV] = useState(() => childToInput(initial)); const set = (k: keyof ChildInput) => (e: React.ChangeEvent) => setV(prev => ({ ...prev, [k]: e.target.value })); return (
{ e.preventDefault(); const out = { ...v }; if (!custody) delete out.custodyNotes; onSave(out); }} >