"use client";
import { Clock } from "lucide-react";
import type { TimelineEvent } from "@/lib/services/analysis-schema";

const IMPACT_DOT: Record<string, string> = {
  negative: "bg-red-500", positive: "bg-green-500", neutral: "bg-slate-300",
};

export function TimelineSection({ events }: { events: TimelineEvent[] }) {
  return (
    <div className="bg-white rounded-xl border border-slate-200 overflow-hidden">
      <div className="px-4 py-3 border-b border-slate-100 flex items-center gap-2">
        <Clock className="w-3.5 h-3.5 text-brand-600" />
        <h3 className="text-sm font-bold text-slate-800">Event Timeline</h3>
        <span className="ml-auto text-[10px] text-slate-400">{events.length} event{events.length !== 1 ? "s" : ""}</span>
      </div>
      <div className="px-4 py-3">
        <div className="relative pl-4 border-l-2 border-slate-100 space-y-4">
          {events.map((e, i) => (
            <div key={i} className="relative">
              <div className={`absolute -left-[21px] top-1.5 w-2.5 h-2.5 rounded-full border-2 border-white ${IMPACT_DOT[e.impact ?? "neutral"]}`} />
              <p className="text-[10px] text-slate-400 font-mono">{e.date}</p>
              <p className="text-xs font-semibold text-slate-800 mt-0.5">{e.title}</p>
              <p className="text-[11px] text-slate-500 leading-relaxed">{e.description}</p>
              <p className="text-[9px] text-slate-300 mt-0.5">{e.source}</p>
            </div>
          ))}
        </div>
      </div>
    </div>
  );
}
