"use client";
import { useState } from "react";
import { Star, ChevronLeft, Check } from "lucide-react";
import { Button } from "@/components/ui/button";
import { useLanguage } from "@/contexts/LanguageContext";
import { useCart } from "@/contexts/CartContext";
import { products } from "@/data/products";
import ProductCard from "@/components/ProductCard";
import Link from "next/link";
import { useParams } from "next/navigation";
import { toast } from "sonner";
export default function ProductDetail() {
const { id } = useParams();
const { t } = useLanguage();
const { addItem } = useCart();
const product = products.find((p) => p.id === id);
const [selectedImage, setSelectedImage] = useState(0);
const [selectedColor, setSelectedColor] = useState("");
const [selectedLength, setSelectedLength] = useState("");
if (!product) {
return (
);
}
const similar = products.filter((p) => p.category === product.category && p.id !== product.id).slice(0, 4);
const handleAddToCart = () => {
const color = selectedColor || product.colors[0];
const length = selectedLength || product.lengths[0];
addItem(product, color, length);
toast.success(`Ajouté au panier - ${product.name} - ${color}, ${length}`);
};
return (
{t("nav.shop")}
{/* Images */}
{product.images.length > 1 && (
{product.images.map((img, i) => (
))}
)}
{/* Details */}
{product.name}
{Array.from({ length: 5 }).map((_, i) => (
))}
({product.reviewCount} avis)
{product.price} €
{product.originalPrice && (
{product.originalPrice} €
)}
{product.description}
{/* Color selector */}
{t("product.color")}
{product.colors.map((color) => (
))}
{/* Length selector */}
{t("product.length")}
{product.lengths.map((length) => (
))}
{/* Features */}
{t("product.features")}
{product.features.map((feature) => (
-
{feature}
))}
{/* Similar */}
{similar.length > 0 && (
{t("product.similar")}
{similar.map((p) => (
))}
)}
);
};