import { Link } from "@tanstack/react-router";
import type { EventRow } from "@/lib/events.functions";
import { formatDateFr } from "@/lib/format";
import { fallbackEventImage } from "@/lib/site";

export function EventCard({ event }: { event: EventRow }) {
  const { day, monthShort } = formatDateFr(event.event_date);
  return (
    <Link to="/evenements" className="group block">
      <div className="relative mb-6 aspect-[3/4] overflow-hidden bg-secondary">
        <img
          src={event.image_url || fallbackEventImage(event.category)}
          alt={event.title}
          width={800}
          height={1200}
          loading="lazy"
          className="h-full w-full object-cover grayscale transition-all duration-700 group-hover:scale-105 group-hover:grayscale-0"
        />
        <div className="absolute left-4 top-4 bg-primary px-3 py-1 font-mono text-[10px] uppercase tracking-tight text-white">
          {day} {monthShort}
        </div>
        {event.is_featured && (
          <div className="absolute right-4 top-4 bg-accent px-3 py-1 font-mono text-[10px] uppercase tracking-tight text-accent-foreground">
            À ne pas manquer
          </div>
        )}
      </div>
      <span className="font-mono text-[10px] uppercase tracking-[0.3em] text-accent">
        {event.category}
      </span>
      <h4 className="mt-2 font-display text-xl italic">{event.title}</h4>
      {event.time_label && (
        <p className="mt-1 font-mono text-[10px] uppercase tracking-tight text-muted-foreground">
          {event.time_label}
        </p>
      )}
      {event.description && (
        <p className="mt-2 text-sm leading-relaxed text-muted-foreground">{event.description}</p>
      )}
    </Link>
  );
}
