'use client'; import React from 'react'; import { useCollectionProducts } from '@/hooks/use-shopify-collections'; import ProductCard from './product-card'; import { Skeleton } from '@/components/ui/skeleton'; const CollectionDetail: React.FC<{ handle?: string }> = ({ handle: handleProp }) => { const handle = handleProp ?? ''; 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 || !handle) { return (
{Array.from({ length: 8 }).map((_, index) => (
))}
); } if (error) { return (

Could not load collection

{error}

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

{title}

{products.length === 0 ? (

No Products in Collection

This collection doesn't have any products yet.

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