import { useEffect, useState } from 'react' import { Activity, Plus, Edit2, Trash2, ChevronRight } from 'lucide-react' import { useNavigate } from 'react-router-dom' import axios from 'axios' import LitterForm from '../components/LitterForm' function LitterList() { const [litters, setLitters] = useState([]) const [loading, setLoading] = useState(true) const [showForm, setShowForm] = useState(false) const [editingLitter, setEditingLitter] = useState(null) const [prefill, setPrefill] = useState(null) const navigate = useNavigate() useEffect(() => { fetchLitters() }, []) const fetchLitters = async () => { try { const res = await axios.get('/api/litters') setLitters(res.data) } catch (error) { console.error('Error fetching litters:', error) } finally { setLoading(false) } } const handleCreate = () => { setEditingLitter(null) setPrefill(null) setShowForm(true) } const handleEdit = (e, litter) => { e.stopPropagation() setEditingLitter(litter) setPrefill(null) setShowForm(true) } const handleDelete = async (e, id) => { e.stopPropagation() if (!window.confirm('Delete this litter record? Puppies will be unlinked but not deleted.')) return try { await axios.delete(`/api/litters/${id}`) fetchLitters() } catch (error) { console.error('Error deleting litter:', error) } } const handleSave = () => { fetchLitters() } if (loading) { return
Create a litter after a breeding cycle to track puppies
{litter.notes}
)}