import Link from "next/link";
import { Heart, AlertTriangle } from "lucide-react";
import type { MySupport } from "@/lib/store";
import ArtistPortrait from "@/components/cards/ArtistPortrait";
import { cn } from "@/lib/cn";

export default function MyFanSupport({ supports }: { supports: MySupport[] }) {
  if (supports.length === 0) {
    return (
      <div className="rounded-xl border border-dashed border-white/10 p-8 text-center text-white/45 text-sm">
        还没有应援的艺人 ·{" "}
        <Link href="/" className="text-purple-300 hover:underline">
          去发现
        </Link>
      </div>
    );
  }

  return (
    <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3">
      {supports.map(({ artist, votedCount }) => {
        const inTop12 = artist.rank <= 12 && artist.votes > 0;
        return (
          <Link
            key={artist.id}
            href={`/artist/${artist.id}`}
            className={cn(
              "flex items-center gap-3 p-3 rounded-xl border transition-all",
              "bg-surface/60 hover:bg-surface/80",
              inTop12 ? "border-purple-500/35" : "border-white/[0.08]",
            )}
          >
            <div
              className={cn(
                "w-12 h-12 rounded-full overflow-hidden border-2 flex-shrink-0",
                inTop12 ? "border-purple-500/70" : "border-white/15",
              )}
            >
              <ArtistPortrait
                artist={artist}
                rounded="rounded-full"
                className="w-full h-full"
              />
            </div>
            <div className="flex-1 min-w-0">
              <div className="text-sm font-semibold text-white truncate">
                {artist.name}
              </div>
              <div className="inline-flex items-center gap-1 text-[11px] text-purple-300 mt-0.5 font-display tabular-nums">
                <Heart size={10} fill="currentColor" />
                已投 {votedCount} 票
              </div>
              <div
                className={cn(
                  "text-[11px] mt-0.5 inline-flex items-center gap-1",
                  inTop12 ? "text-white/55" : "text-pink-400",
                )}
              >
                当前 #{artist.rank}
                {!inTop12 && <AlertTriangle size={10} />}
              </div>
            </div>
          </Link>
        );
      })}
    </div>
  );
}
