'use client'; import React from 'react'; import { useParams } from 'next/navigation'; import { useCollectionProducts } from '@/hooks/use-shopify-collections'; import ProductCard from './product-card'; import { Button } from '@/components/ui/button'; const GRID_CLASSES = 'grid grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-x-8 gap-y-16'; const CollectionTitle: React.FC<{ title: string }> = ({ title }) => (

{title}

); const CollectionDetail: React.FC = () => { const params = useParams(); const handle = params?.handle as string; const { collection, loading, error, refetch } = useCollectionProducts(handle); // Format title from handle const formattedTitle = handle ? handle.replace(/-/g, ' ').replace(/\b\w/g, (l) => l.toUpperCase()) : 'Collection'; if (loading) { return (
{/* Loading Skeleton */}
{Array.from({ length: 8 }).map((_, index) => (
))}
); } if (error) { return (

{error}

); } const products = collection?.products || []; const title = collection?.title || formattedTitle; return (
{products.length === 0 ? (

This collection doesn't have any products yet.

) : (
{products.map((product) => ( ))}
)}
); }; export default CollectionDetail;