"use client";

import Image from "next/image";
import Link from "next/link";
import { ArrowRight } from "lucide-react";

import { SectionHeading } from "@/components/section-heading";
import { useLanguage } from "@/lib/i18n";
import { menuItems } from "@/lib/data";

export function Popular() {
  const { t } = useLanguage();

  const popular = menuItems
    .filter((item) => item.popular)
    .slice(0, 4);

  return (
    <section className="mx-auto max-w-7xl px-4 py-20 md:px-8 md:py-24">
      <SectionHeading
        tag={t("popular.tag")}
        title={t("popular.title")}
      />

      <div className="mt-12 grid gap-5 sm:grid-cols-2 lg:grid-cols-4">
        {popular.map((item) => (
          <article
            key={item.id}
            className="group flex flex-col overflow-hidden rounded-xl border border-border bg-card transition-colors hover:border-primary/50"
          >
            {/* IMAGE */}
            <div className="relative aspect-[4/3] overflow-hidden">
              <Image
                src={item.image || "/placeholder.svg"}
                alt={item.name}
                fill
                sizes="(max-width: 768px) 100vw, 25vw"
                className="object-cover transition-transform duration-500 group-hover:scale-105"
              />

              {/* BADGE */}
              <span className="absolute left-3 top-3 rounded-full bg-primary px-2.5 py-1 text-[10px] font-bold uppercase tracking-wider text-primary-foreground">
                Top
              </span>
            </div>

            {/* INFORMATIONS */}
            <div className="flex flex-1 flex-col p-4">
              <div className="flex items-start justify-between gap-2">
                <h3 className="font-serif text-lg font-semibold leading-tight text-foreground">
                  {item.name}
                </h3>

                <span className="whitespace-nowrap font-semibold text-primary">
                  {item.price.toLocaleString("fr-FR")}

                  <span className="ml-1 text-xs text-muted-foreground">
                    {t("common.currency")}
                  </span>
                </span>
              </div>

              <p className="mt-1.5 flex-1 text-sm leading-relaxed text-muted-foreground">
                {item.description}
              </p>
            </div>
          </article>
        ))}
      </div>

      {/* BOUTON MENU */}
      <div className="mt-10 text-center">
        <Link
          href="/menu"
          className="inline-flex items-center gap-2 rounded-full border border-primary px-7 py-3 text-sm font-semibold text-primary transition-colors hover:bg-primary hover:text-primary-foreground"
        >
          {t("popular.viewMenu")}

          <ArrowRight
            className="h-4 w-4"
            aria-hidden="true"
          />
        </Link>
      </div>
    </section>
  );
}