"use client";

import { Skeleton } from "@heroui/react";
import { ProductListTileSkeleton } from "@/components/product/ProductListTileSkeleton";
import { PRODUCT_DETAIL_SECTION_IDS } from "@/lib/product-detail/constants";

const RELATED_SKELETON_COUNT = 4;

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 mt-6 h-px w-full bg-[var(--separator)]" />
      <Skeleton className="mt-4 h-10 w-full rounded-lg" />
    </div>
  );
}

/**
 * Skeleton for the Related products section. Matches ShopProductGrid layout:
 * mobile list of tiles, md+ grid of cards.
 */
export function ProductDetailRelatedSkeleton() {
  return (
    <section
      id={PRODUCT_DETAIL_SECTION_IDS.related}
      aria-label="Related products"
      className="py-6 md:py-8"
    >
      <Skeleton className="mb-4 h-6 w-48 rounded md:mb-6 md:h-7" />
      <>
        <ul className="flex flex-col gap-3 md:hidden" aria-hidden>
          {Array.from({ length: RELATED_SKELETON_COUNT }, (_, i) => (
            <li key={i}>
              <ProductListTileSkeleton />
            </li>
          ))}
        </ul>
        <div className="hidden md:grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4 md:gap-6">
          {Array.from({ length: RELATED_SKELETON_COUNT }, (_, i) => (
            <ProductCardSkeleton key={i} />
          ))}
        </div>
      </>
    </section>
  );
}
