"use client"; import { useState } from "react"; import PhotoOverlay from "./PhotoOverlay"; import { Info, Calendar, User, Smartphone, Cpu, Save, Edit2, X, Trash2, Check, Tag } from "lucide-react"; import { API_BASE_URL } from "@/lib/api"; import { useRouter } from "next/navigation"; interface PhotoEditorProps { initialPhoto: any; } const PREDEFINED_LABELS = ["bullet_hole", "tear", "miss", "rebound", "other"]; export default function PhotoEditor({ initialPhoto }: PhotoEditorProps) { const router = useRouter(); const [isEditing, setIsEditing] = useState(false); const [photoData, setPhotoData] = useState(initialPhoto.data); const [isSaving, setIsSaving] = useState(false); const handleImpactsChange = (newImpacts: any[]) => { setPhotoData({ ...photoData, plotting: { ...photoData.plotting, impacts: newImpacts } }); }; const updateLabel = (index: number, label: string) => { const newImpacts = [...photoData.plotting.impacts]; newImpacts[index] = { ...newImpacts[index], label }; handleImpactsChange(newImpacts); }; const updateScore = (index: number, score: number) => { const newImpacts = [...photoData.plotting.impacts]; newImpacts[index] = { ...newImpacts[index], score }; handleImpactsChange(newImpacts); }; const handleSave = async () => { setIsSaving(true); try { const response = await fetch(`${API_BASE_URL}/api/data/${initialPhoto.filename}`, { method: "PUT", headers: { "Content-Type": "application/json" }, body: JSON.stringify(photoData), }); if (response.ok) { setIsEditing(false); router.refresh(); } else { alert("Erreur lors de la sauvegarde"); } } catch (error) { console.error("Save error:", error); alert("Erreur réseau"); } finally { setIsSaving(false); } }; const impacts = photoData?.plotting?.impacts || []; return (
Aucun impact détecté. {isEditing ? "Cliquez sur l'image pour en ajouter." : ""}
)}{value}