// ============================================ // components/admin/ProductDetailsModal.tsx // ============================================ // ✅ Modal d'affichage détaillé d'un produit // ✅ Galerie de médias (images/vidéos) // ✅ Informations complètes import React, { useState } from "react"; import { X, Package, DollarSign, Box, Calendar, ChevronLeft, ChevronRight, Image as ImageIcon, Video as VideoIcon, Play, } from "lucide-react"; import type { Product, ProductPrice } from "../api/api_types"; import { getMediaUrl } from "../api/api"; import "./ProductModal.css"; interface ProductDetailsModalProps { product: Product; onClose: () => void; } const ProductDetailsModal: React.FC = ({ product, onClose, }) => { // ============================================ // 📝 STATE // ============================================ const [currentMediaIndex, setCurrentMediaIndex] = useState(0); // ============================================ // 🎨 HELPER FUNCTIONS // ============================================ const getCategoryLabel = (category: string): string => { switch (category) { case "weed&hash": return "Weed & Hash"; case "zipette&co": return "Zipette & Co"; case "gros&semi": return "Gros & Semi"; default: return category; } }; const formatDate = (dateString?: string): string => { if (!dateString) return "N/A"; const date = new Date(dateString); return date.toLocaleDateString("fr-FR", { day: "2-digit", month: "long", year: "numeric", hour: "2-digit", minute: "2-digit", }); }; const hasMedia = product.media && product.media.length > 0; const currentMedia = hasMedia && product.media ? product.media[currentMediaIndex] : null; const nextMedia = () => { if ( hasMedia && product.media && currentMediaIndex < product.media.length - 1 ) { setCurrentMediaIndex(currentMediaIndex + 1); } }; const prevMedia = () => { if (hasMedia && currentMediaIndex > 0) { setCurrentMediaIndex(currentMediaIndex - 1); } }; // ============================================ // 🎨 RENDER // ============================================ return ( <>
{/* Header */}

{product.name}

{getCategoryLabel(product.category)}

{/* Content */}
{/* Galerie de médias */} {hasMedia && (
{currentMedia?.type === "image" ? ( {product.name} ) : currentMedia?.type === "video" ? (
) : (

Aucun média disponible

)} {/* Navigation */} {product.media && product.media.length > 1 && ( <> )} {/* Compteur */}
{currentMediaIndex + 1} /{" "} {product.media?.length || 0}
{/* Miniatures */} {product.media && product.media.length > 1 && (
{product.media.map((media: { url: string; type: string }, index: number) => ( ))}
)}
)} {/* Pas de médias */} {!hasMedia && (

Aucun média disponible pour ce produit

)} {/* Informations détaillées */}
{/* Description */}

Description

{product.description}

{/* Stock */}

Stock Disponible

0 ? "in-stock" : "out-of-stock"}`} > {product.stock}g
{/* Catégorie */}

Catégorie

{getCategoryLabel(product.category)}
{/* Prix */}

Tarifs

{product.prices && product.prices.length > 0 ? ( product.prices.map((price: ProductPrice, index: number) => (
{price.quantity}g
{price.price.toFixed(2)}€
)) ) : (

Aucun tarif défini

)}
{/* Statistiques médias */} {hasMedia && product.media && (

Médias

{ product.media.filter( (m: { url: string; type: string }) => m.type === "image", ).length }{" "} Image {product.media.filter( (m: { url: string; type: string }) => m.type === "image", ).length > 1 ? "s" : ""}
{ product.media.filter( (m: { url: string; type: string }) => m.type === "video", ).length }{" "} Vidéo {product.media.filter( (m: { url: string; type: string }) => m.type === "video", ).length > 1 ? "s" : ""}
)} {/* Dates */} {product.created_at && (

Créé le

{formatDate(product.created_at)}

)} {product.updated_at && (

Modifié le

{formatDate(product.updated_at)}

)}
{/* Footer */}
); }; export default ProductDetailsModal;