---
// @design-system: domain/DealsBrowser/DealsGrid
// SSR deal grid — renders DealCard list or empty state.

import DealCard from '@/components/ui/domain/DealCard/DealCard.astro';

interface DealRow {
  id: string;
  title: string;
  originalPrice: number | string;
  discountedPrice: number | string;
  discountPercent?: number | string | null;
  /** Raw R2 key or absolute URL — NOT pre-built /api/img/... */
  imageUrl?: string | null;
}

interface Props {
  deals: DealRow[];
  gridLabel: string;
  emptyLabel: string;
}
const { deals, gridLabel, emptyLabel } = Astro.props as Props;
---

{
  deals.length === 0 ? (
    <div class="flex flex-col items-center justify-center py-16 text-center">
      <p class="text-text-muted text-lg">{emptyLabel}</p>
    </div>
  ) : (
    <div
      class="grid gap-3"
      style="grid-template-columns: repeat(auto-fill, minmax(min(11rem, 100%), 1fr));"
      aria-label={gridLabel}
    >
      {deals.map((d) => (
        <DealCard
          id={d.id}
          title={d.title}
          originalPrice={d.originalPrice}
          discountedPrice={d.discountedPrice}
          discountPercent={d.discountPercent ?? null}
          imageUrl={d.imageUrl ?? null}
        />
      ))}
    </div>
  )
}
