import { useCallback, useEffect, useState } from "react"; import { api } from "../api"; import type { DogDetailResult } from "../types"; import { estimatedBreeds } from "./MatchCard"; interface Props { kind: "known" | "unknown"; id: number; onClose: () => void; onChanged?: () => void; // called after an admin status change so parent lists can refresh } // Valid statuses per dog kind (admin can set these — e.g. a found dog "at_shelter" vs "reunited"). const STATUS_OPTIONS: Record<"known" | "unknown", string[]> = { known: ["home", "lost", "reunited"], unknown: ["pending", "at_shelter", "claimed", "reunited"], }; // Modal showing a dog's profile + ALL of its photos (full images). Admin-only, so it also lets the // admin change the dog's status. export default function DogPhotosModal({ kind, id, onClose, onChanged }: Props) { const [data, setData] = useState(null); const [error, setError] = useState(null); const [savingStatus, setSavingStatus] = useState(false); const load = useCallback(() => { setError(null); return api .getDogDetail(kind, id) .then(setData) .catch((e) => setError(e instanceof Error ? e.message : "Failed to load")); }, [kind, id]); useEffect(() => { setData(null); load(); }, [load]); async function changeStatus(status: string) { setSavingStatus(true); setError(null); try { await api.setDogStatus(kind, id, status); await load(); onChanged?.(); } catch (e) { setError(e instanceof Error ? e.message : "Could not update status"); } finally { setSavingStatus(false); } } return (
e.stopPropagation()} > {error &&

{error}

} {!data && !error ? (

Loading…

) : data ? ( <>

{data.profile.name}

{data.profile.kind} #{data.profile.id} {" · "} {estimatedBreeds(data.profile.predicted_breeds)} {data.profile.zip ? ` · ${data.profile.zip}` : ""} {data.profile.dataset_name ? ` · ${data.profile.dataset_name}` : ""}

{savingStatus && Saving…}

{data.photos.length} photo(s)

{data.photos.map((p) => ( {data.profile.name} ))} {data.photos.length === 0 && (

No photos.

)}
) : null}
); }