-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrecommended-brand-client.tsx
More file actions
45 lines (39 loc) · 1.28 KB
/
recommended-brand-client.tsx
File metadata and controls
45 lines (39 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
'use client';
import { useState } from 'react';
import { BrandWithProducts } from '@/types/domain/brand';
import RecommendedBrandHeader from './recommended-brand-header';
import RecommendedBrandGridCard from './recommended-brand-grid-card';
interface RecommendedBrandClientProps {
brands: BrandWithProducts[];
}
export default function RecommendedBrandClient({
brands,
}: RecommendedBrandClientProps) {
const [selectedIndex, setSelectedIndex] = useState<number>(0);
const currentBrand = brands[selectedIndex];
const currentProducts = currentBrand?.products || [];
return (
<div className="flex w-full flex-col p-5">
<RecommendedBrandHeader
brands={brands}
onClick={setSelectedIndex}
selectedIndex={selectedIndex}
/>
<div className="mt-4">
<div className="mt-2 w-full">
{currentProducts.length > 0 ? (
<ul className="grid w-full grid-cols-2 justify-items-center gap-4">
{currentProducts.map((product) => (
<li key={product.id}>
<RecommendedBrandGridCard product={product} />
</li>
))}
</ul>
) : (
<p>No products available for this brand.</p>
)}
</div>
</div>
</div>
);
}