"use client";

import { Skeleton } from "@heroui/react";
import { ProductListTileSkeleton } from "@/components/product/ProductListTileSkeleton";

/**
 * Loading state for the product grid/list. Mobile-first:
 * - Mobile: list of ProductListTileSkeleton.
 * - md+: grid of card skeletons (2/3/4 columns).
 */
const SKELETON_COUNT = 8;

function ProductCardSkeleton() {
  return (
    <div className="flex flex-col rounded-[var(--radius)] border border-[var(--border)] bg-[var(--surface)] p-5">
      <Skeleton className="aspect-square w-full rounded-lg" />
      <div className="mt-4 flex gap-2">
        <Skeleton className="h-4 w-16 rounded" />
        <Skeleton className="h-4 w-12 rounded" />
      </div>
      <Skeleton className="mt-3 h-4 w-full rounded" />
      <Skeleton className="mt-2 h-4 w-3/4 rounded" />
      <div className="mt-auto h-px w-full bg-[var(--separator)] mt-6" />
      <Skeleton className="mt-4 h-10 w-full rounded-lg" />
    </div>
  );
}

export function ShopProductGridSkeleton() {
  return (
    <>
      {/* Mobile: list skeleton */}
      <ul className="flex flex-col gap-3 md:hidden" aria-hidden>
        {Array.from({ length: SKELETON_COUNT }, (_, i) => (
          <li key={i}>
            <ProductListTileSkeleton />
          </li>
        ))}
      </ul>
      {/* Tablet and up: grid skeleton */}
      <div className="hidden md:grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4 md:gap-6">
        {Array.from({ length: SKELETON_COUNT }, (_, i) => (
          <ProductCardSkeleton key={i} />
        ))}
      </div>
    </>
  );
}
