import { DragEvent } from "react"; import { useIsMobile, useIsTablet } from "../../hooks/useResponsive"; import { ResponsiveContainer } from "../ui/Responsive"; // Définition des éléments WooCommerce (migration depuis l'ancien éditeur) const WOOCOMMERCE_ELEMENTS = [ { type: "product_table", label: "Tableau Produits", icon: "📋", description: "Tableau des produits commandés avec quantités et prix", category: "woocommerce", defaultProps: { x: 50, y: 50, width: 500, height: 200, showHeaders: true, showBorders: true, showAlternatingRows: true, showSku: false, showDescription: false, showQuantity: true, showShipping: false, showTax: false, showGlobalDiscount: false, fontSize: 11, fontFamily: "Arial", fontWeight: "normal", fontStyle: "normal", textDecoration: "none", textTransform: "none", wordSpacing: "normal", lineHeight: "1.1", currency: "€", tableStyle: "default", textAlign: "left", verticalAlign: "top", // ===== STYLES GLOBAUX ===== globalFontSize: 11, globalFontFamily: "Arial", globalFontWeight: "normal", globalFontStyle: "normal", // ===== STYLES ENTÊTE ===== headerFontSize: 12, headerFontFamily: "Arial", headerFontWeight: "bold", headerFontStyle: "normal", // ===== STYLES LIGNES ===== rowFontSize: 11, rowFontFamily: "Arial", rowFontWeight: "normal", rowFontStyle: "normal", rowTextColor: "#374151", // ===== STYLES TOTAUX ===== totalFontSize: 12, totalFontFamily: "Arial", totalFontWeight: "bold", totalFontStyle: "normal", totalTextColor: "#111827", backgroundColor: "#ffffff", headerBackgroundColor: "#f9fafb", headerTextColor: "#111827", alternateRowColor: "#f9fafb", borderColor: "#e5e7eb", borderWidth: 1, textColor: "#374151", rotation: 0, shadowColor: "#000000", shadowOffsetX: 0, shadowOffsetY: 0, shadowBlur: 0, visible: true, }, }, { type: "customer_info", label: "Fiche Client", icon: "👤", description: "Informations détaillées du client (nom, adresse, email)", category: "woocommerce", defaultProps: { x: 50, y: 220, width: 250, height: 120, showHeaders: true, showBackground: true, showBorders: false, showName: true, showFullName: true, showAddress: true, showEmail: true, showPhone: true, showPaymentMethod: false, showTransactionId: false, layout: "vertical", fontSize: 12, fontFamily: "Arial", fontWeight: "normal", fontStyle: "normal", // ===== STYLES ENTÊTE ===== headerFontSize: 14, headerFontFamily: "Arial", headerFontWeight: "bold", headerFontStyle: "normal", // ===== STYLES CORPS ===== bodyFontSize: 12, bodyFontFamily: "Arial", bodyFontWeight: "normal", bodyFontStyle: "normal", textDecoration: "none", textTransform: "none", wordSpacing: "normal", lineHeight: "1.1", backgroundColor: "#e5e7eb", borderColor: "#e5e7eb", borderWidth: 0, textColor: "#374151", headerTextColor: "#111827", rotation: 0, shadowColor: "#000000", shadowOffsetX: 0, shadowOffsetY: 0, shadowBlur: 0, visible: true, }, }, { type: "company_info", label: "Informations Entreprise", icon: "[D]", description: "Nom, adresse, contact et TVA de l'entreprise", category: "woocommerce", defaultProps: { x: 50, y: 340, width: 250, height: 120, showBorders: false, showFullName: true, showAddress: true, showEmail: true, showPhone: true, showSiret: true, showVat: true, showRcs: true, showCapital: true, showCompanyName: true, layout: "vertical", fontSize: 12, fontFamily: "Arial", fontWeight: "normal", fontStyle: "normal", // ===== STYLES ENTÊTE ===== headerFontSize: 14, headerFontFamily: "Arial", headerFontWeight: "bold", headerFontStyle: "normal", // ===== STYLES CORPS ===== bodyFontSize: 12, bodyFontFamily: "Arial", bodyFontWeight: "normal", bodyFontStyle: "normal", textDecoration: "none", textTransform: "none", wordSpacing: "normal", lineHeight: "1.1", backgroundColor: "#e5e7eb", borderColor: "#e5e7eb", borderWidth: 0, textColor: "#374151", headerTextColor: "#111827", rotation: 0, shadowColor: "#000000", shadowOffsetX: 0, shadowOffsetY: 0, shadowBlur: 0, showBackground: true, visible: true, // ✅ NEW: Propriétés d'icônes showIcons: false, iconsPosition: "left", iconsSize: 16, iconsColor: "#374151", }, }, { type: "company_logo", label: "Logo Entreprise", icon: "🏢", description: "Logo et identité visuelle de l'entreprise", category: "woocommerce", defaultProps: { x: 350, y: 50, width: 150, height: 80, fit: "contain", objectFit: "contain", alignment: "left", src: "", // URL du logo à définir backgroundColor: "transparent", borderColor: "#e5e7eb", borderWidth: 1, borderRadius: 0, opacity: 1, rotation: 0, shadowColor: "#000000", shadowOffsetX: 0, shadowOffsetY: 0, shadowBlur: 0, visible: true, }, }, { type: "woocommerce_order_date", label: "Date de Commande", icon: "📅", description: "Date de création de la commande", category: "woocommerce", defaultProps: { x: 350, y: 160, width: 100, height: 30, fontSize: 12, fontFamily: "Arial", fontWeight: "normal", fontStyle: "normal", textDecoration: "none", textTransform: "none", wordSpacing: "normal", lineHeight: "1.1", textAlign: "right", backgroundColor: "transparent", borderColor: "#e5e7eb", borderWidth: 0, textColor: "#374151", rotation: 0, shadowColor: "#000000", shadowOffsetX: 0, shadowOffsetY: 0, shadowBlur: 0, visible: true, dateFormat: "d/m/Y", showTime: false, showLabel: true, labelText: "Date de la facture :", labelPosition: "left", labelFontFamily: "Arial", labelFontSize: 12, labelFontWeight: "normal", labelFontStyle: "normal", labelColor: "#374151", labelSpacing: 8, }, }, { type: "woocommerce_invoice_number", label: "Numéro de Facture", icon: "📄", description: "Numéro de facture généré", category: "woocommerce", defaultProps: { x: 350, y: 190, width: 100, height: 30, fontSize: 12, fontFamily: "Arial", fontWeight: "normal", fontStyle: "normal", textDecoration: "none", textTransform: "none", wordSpacing: "normal", lineHeight: "1.1", textAlign: "right", backgroundColor: "transparent", borderColor: "#e5e7eb", borderWidth: 0, textColor: "#374151", rotation: 0, shadowColor: "#000000", shadowOffsetX: 0, shadowOffsetY: 0, shadowBlur: 0, visible: true, prefix: "", suffix: "", showLabel: true, labelText: "Numéro de facture :", labelPosition: "left", labelFontFamily: "Arial", labelFontSize: 12, labelFontWeight: "normal", labelFontStyle: "normal", labelColor: "#374151", labelSpacing: 8, }, }, { type: "document_type", label: "Type de Document", icon: "📄", description: "Type du document (Facture, Devis, Bon de commande, etc.)", category: "woocommerce", defaultProps: { x: 50, y: 430, width: 150, height: 40, title: "FACTURE", fontSize: 18, fontFamily: "Arial", fontWeight: "bold", fontStyle: "normal", textDecoration: "none", textTransform: "none", wordSpacing: "normal", lineHeight: "1.1", textAlign: "left", backgroundColor: "transparent", borderColor: "#e5e7eb", borderWidth: 0, textColor: "#111827", rotation: 0, shadowColor: "#000000", shadowOffsetX: 0, shadowOffsetY: 0, shadowBlur: 0, visible: true, }, }, { type: "dynamic_text", label: "Texte Dynamique", icon: "📝", description: "Texte avec variables dynamiques", category: "woocommerce", defaultProps: { x: 50, y: 550, width: 200, height: 40, text: "Texte personnalisable", textTemplate: "custom", autoWrap: true, theme: "clean", fontSize: 14, fontFamily: "Arial", fontWeight: "normal", fontStyle: "normal", textDecoration: "none", textTransform: "none", wordSpacing: "normal", lineHeight: "1.1", backgroundColor: "transparent", rotation: 0, shadowColor: "#000000", shadowOffsetX: 0, shadowOffsetY: 0, shadowBlur: 0, visible: true, }, }, { type: "mentions", label: "Mentions légales", icon: "📄", description: "Informations légales (email, SIRET, téléphone, etc.)", category: "woocommerce", defaultProps: { x: 50, y: 480, width: 500, height: 60, // ===== OPTIONS DE CONTENU ===== showEmail: true, showPhone: true, showSiret: true, showVat: true, separator: " • ", text: "", // Contenu personnalisé (vide par défaut = génération automatique) mentionType: "dynamic", // Type: "dynamic", "custom", "medley" selectedMentions: [], // Pour type "medley" - liste des mentions sélectionnées medleySeparator: "\n\n", // Séparateur entre mentions pour medley // ===== OPTIONS VISUELLES ===== showSeparator: true, // Affiche la barre horizontale separatorStyle: "solid", // Style: "solid" ou "dashed" separatorColor: "#e5e7eb", // Couleur du séparateur separatorWidth: 1, // Épaisseur du séparateur en px showBackground: false, // ===== STYLES TEXTE ===== fontSize: 10, fontFamily: "Arial", fontWeight: "normal", fontStyle: "normal", textDecoration: "none", textTransform: "none", wordSpacing: "normal", lineHeight: "1.1", textAlign: "left", textColor: "#6b7280", // ===== STYLES FOND & BORDURES ===== backgroundColor: "transparent", borderColor: "#e5e7eb", borderWidth: 0, borderStyle: "solid", borderRadius: 0, // ===== EFFETS & VISIBILITÉ ===== rotation: 0, opacity: 100, shadowColor: "#000000", shadowOffsetX: 0, shadowOffsetY: 0, shadowBlur: 0, visible: true, locked: false, }, }, ]; interface ElementLibraryProps { onElementSelect?: (elementType: string) => void; className?: string; } export function ElementLibrary({ onElementSelect, className, }: ElementLibraryProps) { const isMobile = useIsMobile(); const isTablet = useIsTablet(); const handleElementClick = (elementType: string) => { if (onElementSelect) { onElementSelect(elementType); } }; const handleDragStart = (e: DragEvent, element: Record) => { // Stocker les données de l'élément dans le transfert const dragData = { type: element.type, label: element.label, defaultProps: element.defaultProps, }; const jsonData = JSON.stringify(dragData); e.dataTransfer?.setData("application/json", jsonData); if (e.dataTransfer) { e.dataTransfer.effectAllowed = "copy"; } }; const handleDragEnd = (_e: DragEvent) => { // Drag terminé }; return (
{/* Header de la sidebar */}

📦 Éléments WooCommerce

Glissez les éléments sur le canvas

{/* Liste des éléments */}
{WOOCOMMERCE_ELEMENTS.map((element) => (
handleElementClick(element.type)} onDragStart={(e) => handleDragStart(e, element)} onDragEnd={handleDragEnd} style={{ padding: "12px", backgroundColor: "#ffffff", border: "1px solid #dee2e6", borderRadius: "6px", cursor: "grab", transition: "all 0.2s ease", display: "flex", alignItems: "center", gap: "12px", userSelect: "none", }} onMouseEnter={(e) => { e.currentTarget.style.borderColor = "#007acc"; e.currentTarget.style.boxShadow = "0 2px 4px rgba(0, 122, 204, 0.1)"; e.currentTarget.style.cursor = "grabbing"; }} onMouseLeave={(e) => { e.currentTarget.style.borderColor = "#dee2e6"; e.currentTarget.style.boxShadow = "none"; e.currentTarget.style.cursor = "grab"; }} > {/* Icône */}
{element.icon}
{/* Contenu */}
{element.label}
{element.description}
))}
{/* Footer avec info */}
Cliquez sur un élément pour l'ajouter
); }