"use client"; import React, { useState } from 'react'; import { useCollectionProducts } from '@/hooks/use-shopify-collections'; import ProductCard from './ProductCard'; import ProductModal from './ProductModal'; import { Button } from './ui/button'; interface ProductImage { url: string; altText?: string; } interface ProductPrice { amount: string; currencyCode: string; } interface ProductVariant { id: string; title: string; price: ProductPrice; availableForSale: boolean; } interface Product { id: string; title: string; description?: string; handle: string; images: { edges: Array<{ node: ProductImage; }>; }; priceRange: { minVariantPrice: ProductPrice; }; compareAtPriceRange?: { minVariantPrice: ProductPrice; }; variants: { edges: Array<{ node: ProductVariant; }>; }; } interface CollectionDetailProps { collectionHandle?: string; } const CollectionDetail: React.FC = ({ collectionHandle }) => { const { collection, loading, error } = useCollectionProducts(collectionHandle || null, { first: 20, sortKey: 'BEST_SELLING', reverse: false }); const [selectedProduct, setSelectedProduct] = useState(null); const [isModalOpen, setIsModalOpen] = useState(false); if (loading) { return (

Collection

{/* Loading Skeleton */}
{Array.from({ length: 8 }).map((_, index) => (
))}
); } if (error || !collection) { return (

Collection Not Found

{error || "We couldn't find the collection you're looking for. It may have been removed or the link might be incorrect."}

); } return (
{/* Hero Banner */} {collection.image && (
{collection.image.altText

{collection.title}

)} {/* Products Section */}
{collection.products.length === 0 ? (

No Products in Collection

This collection doesn't have any products yet.

) : (
{collection.products.map((product) => ( { setSelectedProduct(product); setIsModalOpen(true); }} /> ))}
)}
{/* Product Modal */} {selectedProduct && ( { setIsModalOpen(false); setSelectedProduct(null); }} /> )}
); }; export default CollectionDetail;