import { useForm } from 'react-hook-form' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' import { Label } from '@/components/ui/label' import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select' import type { InventoryUnit, UnitCondition, UnitStatus } from '@/types/inventory' const CONDITIONS: { value: UnitCondition; label: string }[] = [ { value: 'new', label: 'New' }, { value: 'excellent', label: 'Excellent' }, { value: 'good', label: 'Good' }, { value: 'fair', label: 'Fair' }, { value: 'poor', label: 'Poor' }, ] const STATUSES: { value: UnitStatus; label: string }[] = [ { value: 'available', label: 'Available' }, { value: 'sold', label: 'Sold' }, { value: 'rented', label: 'Rented' }, { value: 'on_trial', label: 'On Trial' }, { value: 'in_repair', label: 'In Repair' }, { value: 'layaway', label: 'Layaway' }, { value: 'lost', label: 'Lost' }, { value: 'retired', label: 'Retired' }, ] interface Props { defaultValues?: Partial onSubmit: (data: Record) => void loading?: boolean } export function InventoryUnitForm({ defaultValues, onSubmit, loading }: Props) { const { register, handleSubmit, setValue, watch } = useForm({ defaultValues: { serialNumber: defaultValues?.serialNumber ?? '', condition: (defaultValues?.condition ?? 'new') as UnitCondition, status: (defaultValues?.status ?? 'available') as UnitStatus, purchaseDate: defaultValues?.purchaseDate ?? '', purchaseCost: defaultValues?.purchaseCost ?? '', notes: defaultValues?.notes ?? '', }, }) const condition = watch('condition') const status = watch('status') function handleFormSubmit(data: Record) { onSubmit({ serialNumber: (data.serialNumber as string) || undefined, condition: data.condition, status: data.status, purchaseDate: (data.purchaseDate as string) || undefined, purchaseCost: (data.purchaseCost as string) || undefined, notes: (data.notes as string) || undefined, }) } return (