import { useState } from 'react' import BreedSelect from './BreedSelect' const STATUS_OPTIONS = [ { value: 'active', label: 'Active' }, { value: 'for_sale', label: 'For Sale' }, { value: 'on_hold', label: 'On Hold' }, { value: 'sold', label: 'Sold' }, { value: 'deceased', label: 'Deceased' }, { value: 'other', label: 'Other' }, ] const SEX_OPTIONS = [ { value: 'buck', label: 'Buck' }, { value: 'doe', label: 'Doe' }, { value: 'unknown', label: 'Unknown' }, ] function lbsToOz(decimalLbs) { if (decimalLbs === null || decimalLbs === undefined || decimalLbs === '') return { lbs: '', oz: '' } const total = Number(decimalLbs) if (Number.isNaN(total)) return { lbs: '', oz: '' } const lbs = Math.floor(total) const oz = Math.round((total - lbs) * 16) return { lbs: String(lbs), oz: String(oz) } } function ozToLbs(lbs, oz) { const l = Number(lbs) || 0 const o = Number(oz) || 0 return l + o / 16 } function RabbitDetailsForm({ value, onChange, onPhotoChange, weightUnit = 'decimal_lbs', showValidation = false }) { const [photoPreview, setPhotoPreview] = useState(null) const { lbs: ozLbs, oz: ozOz } = lbsToOz(value.weight_lbs) function setField(field, fieldValue) { onChange({ [field]: fieldValue }) } function handlePhotoSelect(e) { const file = e.target.files?.[0] if (!file) return onPhotoChange?.(file) setPhotoPreview(URL.createObjectURL(file)) } const nameInvalid = showValidation && !value.name?.trim() return (
setField('name', e.target.value)} className={`mt-1 w-full rounded-md border px-3 py-2 font-body text-sm focus:outline-none focus:ring-2 focus:ring-accent ${ nameInvalid ? 'border-danger' : 'border-border' }`} /> {nameInvalid &&

Name is required

}
setField('farm', e.target.value)} className="mt-1 w-full rounded-md border border-border px-3 py-2 font-body text-sm focus:outline-none focus:ring-2 focus:ring-accent" />
{SEX_OPTIONS.map((opt) => ( ))}
setField('dob', e.target.value)} className="mt-1 w-full rounded-md border border-border px-3 py-2 font-body text-sm focus:outline-none focus:ring-2 focus:ring-accent" />
setField('acquired_date', e.target.value || null)} className="mt-1 w-full rounded-md border border-border px-3 py-2 font-body text-sm focus:outline-none focus:ring-2 focus:ring-accent" />

If added to the herd after birth

setField('death_date', e.target.value || null)} className="mt-1 w-full rounded-md border border-border px-3 py-2 font-body text-sm focus:outline-none focus:ring-2 focus:ring-accent" />
{weightUnit === 'lbs_oz' ? (
setField('weight_lbs', ozToLbs(e.target.value, ozOz))} placeholder="lbs" className="w-1/2 rounded-md border border-border px-3 py-2 font-body text-sm focus:outline-none focus:ring-2 focus:ring-accent" /> setField('weight_lbs', ozToLbs(ozLbs, e.target.value))} placeholder="oz" className="w-1/2 rounded-md border border-border px-3 py-2 font-body text-sm focus:outline-none focus:ring-2 focus:ring-accent" />
) : ( setField('weight_lbs', e.target.value === '' ? null : Number(e.target.value))} placeholder="decimal lbs" className="mt-1 w-full rounded-md border border-border px-3 py-2 font-body text-sm focus:outline-none focus:ring-2 focus:ring-accent" /> )}
setField('ear_number', e.target.value.toUpperCase())} className="mt-1 w-full rounded-md border border-border px-3 py-2 font-body text-sm uppercase focus:outline-none focus:ring-2 focus:ring-accent" />
setField('location', e.target.value)} className="mt-1 w-full rounded-md border border-border px-3 py-2 font-body text-sm focus:outline-none focus:ring-2 focus:ring-accent" />
setField('breed', breed)} />
setField('color_name', e.target.value)} placeholder="e.g. Broken Black Tort" className="mt-1 w-full rounded-md border border-border px-3 py-2 font-body text-sm focus:outline-none focus:ring-2 focus:ring-accent" />
{photoPreview && ( Preview )}
) } export default RabbitDetailsForm