import React from "react"; import { Check, Clock, User } from "lucide-react"; type TimelineStatus = "open" | "waiting_staff" | "waiting_client" | "closed"; interface TimelineProps { currentStatus: TimelineStatus; lastMessageBy?: "client" | "staff"; } const TIMELINE_STEPS = [ { id: "open", label: "Ticket ouvert", icon: Check }, { id: "waiting_staff", label: "Attente retour Odentas", icon: Clock }, { id: "waiting_client", label: "Attente retour client", icon: User }, { id: "closed", label: "Résolu", icon: Check }, ] as const; function getStepStatus(stepId: string, currentStatus: TimelineStatus, lastMessageBy?: "client" | "staff") { if (stepId === "open") { return "completed"; // Toujours complété car le ticket existe } if (stepId === "waiting_staff") { // Complété si on a dépassé cette étape if (currentStatus === "waiting_client" || currentStatus === "closed") return "completed"; // En cours si on attend le staff if (currentStatus === "waiting_staff") return "current"; // En cours si ticket ouvert et dernier message du client if (currentStatus === "open" && lastMessageBy === "client") return "current"; return "upcoming"; } if (stepId === "waiting_client") { // Complété si on a atteint la fermeture if (currentStatus === "closed") return "completed"; // En cours si on attend le client if (currentStatus === "waiting_client") return "current"; // En cours si ticket ouvert et dernier message du staff if (currentStatus === "open" && lastMessageBy === "staff") return "current"; return "upcoming"; } if (stepId === "closed") { return currentStatus === "closed" ? "current" : "upcoming"; } return "upcoming"; } export default function TicketTimeline({ currentStatus, lastMessageBy }: TimelineProps) { return (
{/* Version mobile : vertical */}
{TIMELINE_STEPS.map((step, index) => { const status = getStepStatus(step.id, currentStatus, lastMessageBy); const Icon = step.icon; return (
{/* Icône */}
{status === "current" && (
)}
{/* Label */}
{step.label}
{/* Connecteur vertical */} {index < TIMELINE_STEPS.length - 1 && (
)} ); })}
{/* Version desktop : horizontal */}
{TIMELINE_STEPS.map((step, index) => { const status = getStepStatus(step.id, currentStatus, lastMessageBy); const Icon = step.icon; return (
{/* Icône */}
{status === "current" && (
)}
{/* Label */}
{step.label}
{/* Connecteur horizontal */} {index < TIMELINE_STEPS.length - 1 && (
)} ); })}
); }