"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 (
{/* Main View */}
{isEditing ? "Mode Édition Actif" : "Mode Visualisation"}
{isEditing ? ( <> ) : ( )}
{/* Sidebar Info & Labeling */}
{/* Labeling Section (Only if editing or has impacts) */}

Étiquetage (Impacts)

{impacts.length} TOTAL
{impacts.map((impact: any, index: number) => (
Impact #{impact.id} {isEditing && ( )}
{isEditing ? ( ) : (
{impact.label}
)}
{isEditing ? ( updateScore(index, parseInt(e.target.value) || 0)} className="w-full bg-slate-900 border border-slate-800 rounded px-2 py-1 text-xs outline-none focus:border-indigo-500" /> ) : (
{impact.score}
)}
))} {impacts.length === 0 && (

Aucun impact détecté. {isEditing ? "Cliquez sur l'image pour en ajouter." : ""}

)}
{/* Metadata Card (Read Only) */}

Métadonnées Session

} label="Date" value={photoData ? new Date(photoData.timestamp).toLocaleString() : 'Inconnue'} /> } label="Contributeur" value={photoData?.wallet_hash || 'Anonyme'} isMono /> } label="Appareil" value={photoData?.device_info?.model || 'Inconnu'} />
); } function InfoItem({ icon, label, value, isMono = false }: any) { return (
{icon} {label}

{value}

); }