"use client";

import Link from "next/link";
import { useTranslations } from "next-intl";
import { AlertTriangle } from "lucide-react";
import { Badge } from "@/components/ui/badge";

type Leftover = {
  recipeId: string;
  dishName: string;
  recipeTitle: string;
  expiresAt: string;
  daysLeft: number;
};

export function ExpiringLeftovers({ leftovers }: { leftovers: Leftover[] }) {
  const t = useTranslations("pantry");

  if (leftovers.length === 0) return null;

  return (
    <div className="rounded-xl border p-4 space-y-3">
      <h2 className="font-semibold flex items-center gap-2">
        <AlertTriangle className="h-4 w-4 text-orange-500" />
        {t("expiringLeftoversTitle")}
      </h2>
      <div className="space-y-2">
        {leftovers.map((l) => (
          <Link
            key={`${l.recipeId}-${l.dishName}`}
            href={`/recipes/${l.recipeId}`}
            className="flex items-center justify-between gap-3 rounded-lg border p-2.5 hover:bg-accent transition-colors"
          >
            <div className="min-w-0">
              <p className="text-sm font-medium truncate">{l.dishName}</p>
              <p className="text-xs text-muted-foreground truncate">{l.recipeTitle}</p>
            </div>
            <Badge
              variant="outline"
              className={l.daysLeft <= 0 ? "text-destructive border-destructive shrink-0" : "text-orange-500 border-orange-500 shrink-0"}
            >
              {l.daysLeft <= 0
                ? t("expiringToday")
                : t("expiringInDays", { days: l.daysLeft })}
            </Badge>
          </Link>
        ))}
      </div>
    </div>
  );
}
