import { useState, ReactNode } from 'react'; import { BaseElement } from '../../types/elements'; import { NumericPropertyInput } from '../ui/NumericPropertyInput'; import { ColorPropertyInput } from '../ui/ColorPropertyInput'; import { getEditorFeatureFlags } from '../../utils/editorFeatures'; interface ProductTableElement extends BaseElement { showHeaders?: boolean; showBorders?: boolean; showAlternatingRows?: boolean; showShipping?: boolean; showTax?: boolean; showGlobalDiscount?: boolean; columns?: { image?: boolean; name?: boolean; quantity?: boolean; price?: boolean; total?: boolean; [key: string]: boolean | undefined }; globalFontSize?: number; globalFontFamily?: string; globalFontWeight?: string; globalFontStyle?: string; globalFontEnabled?: boolean; headerFontSize?: number; headerFontFamily?: string; headerFontWeight?: string; headerFontStyle?: string; headerTextColor?: string; headerBackgroundColor?: string; rowFontSize?: number; rowFontFamily?: string; rowFontWeight?: string; rowFontStyle?: string; rowTextColor?: string; totalFontSize?: number; totalFontFamily?: string; totalFontWeight?: string; totalFontStyle?: string; totalTextColor?: string; backgroundColor?: string; alternateRowColor?: string; borderColor?: string; textColor?: string; textAlign?: string; verticalAlign?: string; } // Composant Accordion personnalisé const Accordion = ({ title, children, defaultOpen = false }: { title: string; children: ReactNode; defaultOpen?: boolean; }) => { const [isOpen, setIsOpen] = useState(defaultOpen); return (
setIsOpen(!isOpen)} style={{ padding: '12px', backgroundColor: '#f8f9fa', cursor: 'pointer', display: 'flex', justifyContent: 'space-between', alignItems: 'center', borderBottom: isOpen ? '1px solid #e9ecef' : 'none' }} >

{title}

{children}
); }; // Composant Toggle personnalisé const Toggle = ({ checked, onChange, label, description }: { checked: boolean; onChange: (checked: boolean) => void; label: string; description: string; }) => (
onChange(!checked)} style={{ position: 'relative', width: '44px', height: '24px', backgroundColor: checked ? '#007bff' : '#ccc', borderRadius: '12px', cursor: 'pointer', border: 'none' }} >
{description}
); interface ProductTablePropertiesProps { element: ProductTableElement; onChange: (elementId: string, property: string, value: unknown) => void; activeTab: { [key: string]: 'fonctionnalites' | 'personnalisation' | 'positionnement' }; setActiveTab: (tabs: { [key: string]: 'fonctionnalites' | 'personnalisation' | 'positionnement' }) => void; } export function ProductTableProperties({ element, onChange, activeTab, setActiveTab }: ProductTablePropertiesProps) { const currentTab = activeTab[element.id] || 'fonctionnalites'; const setCurrentTab = (tab: 'fonctionnalites' | 'personnalisation' | 'positionnement') => { setActiveTab({ ...activeTab, [element.id]: tab }); }; const { canUseEditorThemes } = getEditorFeatureFlags(); return ( <> {/* Système d'onglets pour Product Table */}
{/* Onglet Fonctionnalités */} {currentTab === 'fonctionnalites' && ( <> {/* Section Structure du tableau */}
Structure du tableau
onChange(element.id, 'showHeaders', checked)} label="Afficher les en-têtes" description="Affiche les noms des colonnes" /> onChange(element.id, 'showBorders', checked)} label="Afficher les bordures" description="Affiche les bordures du tableau" /> onChange(element.id, 'showAlternatingRows', checked)} label="Lignes alternées" description="Alterne les couleurs des lignes" />
{/* Section Colonnes produits */}
Colonnes produits
onChange(element.id, 'columns', { ...(element.columns || {}), image: checked })} label="Afficher les images" description="Colonne des images produits" /> onChange(element.id, 'columns', { ...(element.columns || {}), name: checked })} label="Afficher les noms" description="Colonne des noms de produits" /> onChange(element.id, 'columns', { ...(element.columns || {}), quantity: checked })} label="Afficher la quantité" description="Colonne quantité des produits" /> onChange(element.id, 'columns', { ...(element.columns || {}), price: checked })} label="Afficher les prix" description="Colonne prix unitaire" /> onChange(element.id, 'columns', { ...(element.columns || {}), total: checked })} label="Afficher les totaux" description="Colonne montants totaux" />
{/* Section Éléments de calcul */}
Éléments de calcul
onChange(element.id, 'showShipping', checked)} label="Afficher les frais de port" description="Affiche les frais de livraison" /> onChange(element.id, 'showTax', checked)} label="Afficher la TVA" description="Affiche les taxes sur le total" /> onChange(element.id, 'showGlobalDiscount', checked)} label="Afficher la remise globale" description="Affiche la remise globale appliquée" />
)} {/* Onglet Personnalisation */} {currentTab === 'personnalisation' && ( <> {/* Accordéon Police globale du tableau */}
onChange(element.id, 'globalFontSize', value)} />
Ces paramètres s'appliquent à tout le tableau. Vous pouvez les personnaliser par zone ci-dessous.
{/* Accordéons Police par zone - seulement si !globalFontEnabled */} {!element.globalFontEnabled && ( <> {/* Accordéon Police de l'entête */}
onChange(element.id, 'headerFontSize', value)} />
Défaut: {element.globalFontSize || 11}px
Défaut: {element.globalFontFamily || 'Arial'}
Défaut: {element.globalFontWeight || 'normal'}
Défaut: {element.globalFontStyle || 'normal'}
onChange(element.id, 'headerTextColor', value)} />
{/* Accordéon Police des lignes */}
onChange(element.id, 'rowFontSize', value)} />
Défaut: {element.globalFontSize || 11}px
Défaut: {element.globalFontFamily || 'Arial'}
Défaut: {element.globalFontWeight || 'normal'}
Défaut: {element.globalFontStyle || 'normal'}
onChange(element.id, 'rowTextColor', value)} />
{/* Accordéon Police des totaux */}
onChange(element.id, 'totalFontSize', value)} />
Défaut: {element.globalFontSize || 12}px
Défaut: {element.globalFontFamily || 'Arial'}
Défaut: {element.globalFontWeight || 'bold'}
Défaut: {element.globalFontStyle || 'normal'}
onChange(element.id, 'totalTextColor', value)} />
)} {canUseEditorThemes && (
{[ { id: 'classic', name: 'Classique', preview: (
), styles: { backgroundColor: '#ffffff', headerBackgroundColor: '#f9fafb', alternateRowColor: '#f9fafb', borderColor: '#e5e7eb', textColor: '#111827', headerTextColor: '#374151' } }, { id: 'modern', name: 'Moderne', preview: (
), styles: { backgroundColor: '#f8fafc', headerBackgroundColor: '#3b82f6', headerTextColor: '#ffffff', alternateRowColor: '#f1f5f9', borderColor: '#cbd5e1', textColor: '#334155' } }, { id: 'elegant', name: 'Élégant', preview: (
), styles: { backgroundColor: '#fefefe', headerBackgroundColor: '#8b5cf6', headerTextColor: '#ffffff', alternateRowColor: '#faf5ff', borderColor: '#c4b5fd', textColor: '#581c87' } }, { id: 'minimal', name: 'Minimal', preview: (
), styles: { backgroundColor: '#ffffff', headerBackgroundColor: '#f9fafb', alternateRowColor: '#f9fafb', borderColor: '#f3f4f6', textColor: '#374151', headerTextColor: '#111827' } }, { id: 'corporate', name: 'Corporate', preview: (
), styles: { backgroundColor: '#ffffff', headerBackgroundColor: '#1f2937', headerTextColor: '#ffffff', alternateRowColor: '#f9fafb', borderColor: '#374151', textColor: '#111827' } }, { id: 'warm', name: 'Chaud', preview: (
), styles: { backgroundColor: '#fff7ed', headerBackgroundColor: '#ea580c', headerTextColor: '#ffffff', alternateRowColor: '#ffedd5', borderColor: '#fed7aa', textColor: '#9a3412' } }, { id: 'nature', name: 'Nature', preview: (
), styles: { backgroundColor: '#f0fdf4', headerBackgroundColor: '#16a34a', headerTextColor: '#ffffff', alternateRowColor: '#dcfce7', borderColor: '#bbf7d0', textColor: '#14532d' } }, { id: 'dark', name: 'Sombre', preview: (
), styles: { backgroundColor: '#1f2937', headerBackgroundColor: '#111827', headerTextColor: '#ffffff', alternateRowColor: '#374151', borderColor: '#4b5563', textColor: '#f9fafb' } }, { id: 'ocean', name: 'Océan', preview: (
), styles: { backgroundColor: '#f0f9ff', headerBackgroundColor: '#0284c7', headerTextColor: '#ffffff', alternateRowColor: '#bae6fd', borderColor: '#0ea5e9', textColor: '#0c4a6e' } }, { id: 'sunset', name: 'Coucher', preview: (
), styles: { backgroundColor: '#fff7ed', headerBackgroundColor: '#ea580c', headerTextColor: '#ffffff', alternateRowColor: '#fed7aa', borderColor: '#f97316', textColor: '#9a3412' } }, { id: 'forest', name: 'Forêt', preview: (
), styles: { backgroundColor: '#f0fdf4', headerBackgroundColor: '#16a34a', headerTextColor: '#ffffff', alternateRowColor: '#bbf7d0', borderColor: '#22c55e', textColor: '#14532d' } }, { id: 'royal', name: 'Royal', preview: (
), styles: { backgroundColor: '#fef2f2', headerBackgroundColor: '#991b1b', headerTextColor: '#ffffff', alternateRowColor: '#fecaca', borderColor: '#7c2d12', textColor: '#450a0a' } }, { id: 'clean', name: 'Propre', preview: (
), styles: { backgroundColor: '#ffffff', headerBackgroundColor: '#f3f4f6', alternateRowColor: '#f9fafb', borderColor: '#d1d5db', textColor: '#374151', headerTextColor: '#111827' } }, { id: 'tech', name: 'Tech', preview: (
), styles: { backgroundColor: '#f8fafc', headerBackgroundColor: '#4f46e5', headerTextColor: '#ffffff', alternateRowColor: '#e0e7ff', borderColor: '#6366f1', textColor: '#312e81' } }, { id: 'vintage', name: 'Vintage', preview: (
), styles: { backgroundColor: '#fef3c7', headerBackgroundColor: '#b45309', headerTextColor: '#ffffff', alternateRowColor: '#fde68a', borderColor: '#92400e', textColor: '#78350f' } }, { id: 'berry', name: 'Baies', preview: (
), styles: { backgroundColor: '#fdf2f8', headerBackgroundColor: '#db2777', headerTextColor: '#ffffff', alternateRowColor: '#fce7f3', borderColor: '#be185d', textColor: '#831843' } }, { id: 'mint', name: 'Menthe', preview: (
), styles: { backgroundColor: '#ecfdf5', headerBackgroundColor: '#047857', headerTextColor: '#ffffff', alternateRowColor: '#a7f3d0', borderColor: '#059669', textColor: '#064e3b' } }, { id: 'lavender', name: 'Lavande', preview: (
), styles: { backgroundColor: '#faf5ff', headerBackgroundColor: '#6d28d9', headerTextColor: '#ffffff', alternateRowColor: '#e9d5ff', borderColor: '#7c3aed', textColor: '#581c87' } }, { id: 'stone', name: 'Pierre', preview: (
), styles: { backgroundColor: '#f9fafb', headerBackgroundColor: '#4b5563', headerTextColor: '#ffffff', alternateRowColor: '#e5e7eb', borderColor: '#6b7280', textColor: '#111827' } }, { id: 'sunshine', name: 'Soleil', preview: (
), styles: { backgroundColor: '#fffbeb', headerBackgroundColor: '#d97706', headerTextColor: '#ffffff', alternateRowColor: '#fef3c7', borderColor: '#f59e0b', textColor: '#92400e' } } ].map(theme => ( ))}
)}
{/* Accordéon Couleurs */}
onChange(element.id, 'backgroundColor', e.target.value)} style={{ width: '100%', height: '32px', border: '1px solid #ccc', borderRadius: '3px' }} />
onChange(element.id, 'headerBackgroundColor', value)} /> onChange(element.id, 'alternateRowColor', value)} /> onChange(element.id, 'borderColor', value)} />
onChange(element.id, 'textColor', e.target.value)} style={{ width: '100%', height: '32px', border: '1px solid #ccc', borderRadius: '3px' }} />
)} {/* Onglet Positionnement */} {currentTab === 'positionnement' && ( <>
onChange(element.id, 'x', value)} /> Valeur en pixels
onChange(element.id, 'y', value)} /> Valeur en pixels
onChange(element.id, 'width', value)} /> Valeur en pixels
onChange(element.id, 'height', value)} /> Valeur en pixels
)} ); }