import { Skeleton } from "@/components/ui/skeleton";
import { trpc } from "@/lib/trpc";
import { assetUrl } from "@/lib/asset";
import { Link } from "wouter";

export default function MusicaArtistas() {
  const { data, isLoading } = trpc.musica.getArtistas.useQuery({ page: 1, limit: 60 });

  return (
    <div className="pb-32">
      <h1 className="text-4xl font-bold font-display text-sof-text mb-2">Artistas</h1>
      <p className="text-sof-text-3 mb-8">Artistas do SpotOnFide Música</p>

      {isLoading ? (
        <div className="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-6 gap-8">
          {Array(8)
            .fill(0)
            .map((_, i) => (
              <div key={i} className="space-y-3">
                <Skeleton className="aspect-square rounded-full bg-sof-surface" />
                <Skeleton className="h-4 w-3/4 mx-auto bg-sof-surface" />
              </div>
            ))}
        </div>
      ) : data && data.artistas.length > 0 ? (
        <div className="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-6 gap-8">
          {data.artistas.map(a => (
            <Link key={a.id} href={`/musica/artista/${a.id}`}>
              <div className="text-center group cursor-pointer">
                <div className="relative aspect-square mb-4 overflow-hidden rounded-full border-2 border-transparent group-hover:border-sof-gold transition-all shadow-lg">
                  <img
                    src={assetUrl(a.foto) ?? assetUrl("/placeholder-user.svg")}
                    alt={a.nome}
                    className="object-cover w-full h-full grayscale group-hover:grayscale-0 transition-all duration-500"
                  />
                </div>
                <p className="text-sm font-bold text-sof-text group-hover:text-sof-gold transition-colors truncate">
                  {a.nome}
                </p>
              </div>
            </Link>
          ))}
        </div>
      ) : (
        <p className="text-sof-text-3">Nenhum artista encontrado.</p>
      )}
    </div>
  );
}