import { useState, ReactNode } from "react";
import { CustomerInfoElement } from "../../types/elements";
import { NumericPropertyInput } from "../ui/NumericPropertyInput";
import { ColorPropertyInput } from "../ui/ColorPropertyInput";
import { getEditorFeatureFlags } from "../../utils/editorFeatures";
// 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}
▼
{isOpen && (
{children}
)}
);
};
// Composant Toggle personnalisé
const Toggle = ({
checked,
onChange,
label,
description,
}: {
checked: boolean;
onChange: (checked: boolean) => void;
label: string;
description: string;
}) => (
{label}
onChange(!checked)}
style={{
position: "relative",
width: "44px",
height: "24px",
backgroundColor: checked ? "#007bff" : "#ccc",
borderRadius: "12px",
cursor: "pointer",
transition: "background-color 0.2s ease",
border: "none",
}}
>
{description}
);
interface CustomerInfoPropertiesProps {
element: CustomerInfoElement;
onChange: (elementId: string, property: string, value: unknown) => void;
activeTab: {
[key: string]: "fonctionnalites" | "personnalisation" | "positionnement";
};
setActiveTab: (tabs: {
[key: string]: "fonctionnalites" | "personnalisation" | "positionnement";
}) => void;
}
export function CustomerInfoProperties({
element,
onChange,
activeTab,
setActiveTab,
}: CustomerInfoPropertiesProps) {
const customerCurrentTab = activeTab[element.id] || "fonctionnalites";
const setCustomerCurrentTab = (
tab: "fonctionnalites" | "personnalisation" | "positionnement",
) => {
setActiveTab({ ...activeTab, [element.id]: tab });
};
const { canUseEditorThemes } = getEditorFeatureFlags();
return (
<>
{/* Système d'onglets pour Customer Info */}
setCustomerCurrentTab("fonctionnalites")}
style={{
flex: "1 1 30%",
padding: "8px 6px",
backgroundColor:
customerCurrentTab === "fonctionnalites" ? "#007bff" : "#f0f0f0",
color: customerCurrentTab === "fonctionnalites" ? "#fff" : "#333",
border: "none",
cursor: "pointer",
fontSize: "11px",
fontWeight: "bold",
borderRadius: "3px 3px 0 0",
minWidth: "0",
whiteSpace: "nowrap",
overflow: "hidden",
textOverflow: "ellipsis",
}}
title="Fonctionnalités"
>
Fonctionnalités
setCustomerCurrentTab("personnalisation")}
style={{
flex: "1 1 30%",
padding: "8px 6px",
backgroundColor:
customerCurrentTab === "personnalisation" ? "#007bff" : "#f0f0f0",
color: customerCurrentTab === "personnalisation" ? "#fff" : "#333",
border: "none",
cursor: "pointer",
fontSize: "11px",
fontWeight: "bold",
borderRadius: "3px 3px 0 0",
minWidth: "0",
whiteSpace: "nowrap",
overflow: "hidden",
textOverflow: "ellipsis",
}}
title="Personnalisation"
>
Personnalisation
setCustomerCurrentTab("positionnement")}
style={{
flex: "1 1 30%",
padding: "8px 6px",
backgroundColor:
customerCurrentTab === "positionnement" ? "#007bff" : "#f0f0f0",
color: customerCurrentTab === "positionnement" ? "#fff" : "#333",
border: "none",
cursor: "pointer",
fontSize: "11px",
fontWeight: "bold",
borderRadius: "3px 3px 0 0",
minWidth: "0",
whiteSpace: "nowrap",
overflow: "hidden",
textOverflow: "ellipsis",
}}
title="Positionnement"
>
Positionnement
{/* Onglet Fonctionnalités */}
{customerCurrentTab === "fonctionnalites" && (
<>
{/* Section Structure de l'information */}
Structure des informations
onChange(element.id, "showHeaders", checked)
}
label="Afficher les en-têtes"
description="Affiche les titres des sections"
/>
onChange(element.id, "showBackground", checked)
}
label="Afficher le fond"
description="Affiche un fond coloré derrière les informations"
/>
onChange(element.id, "showBorders", checked)
}
label="Afficher les bordures"
description="Affiche les bordures autour des sections"
/>
{/* Section Informations personnelles */}
Informations personnelles
onChange(element.id, "showFullName", checked)
}
label="Afficher le nom complet"
description="Prénom et nom du client"
/>
{/* Section Coordonnées */}
Coordonnées
onChange(element.id, "showAddress", checked)
}
label="Afficher l'adresse"
description="Adresse complète du client"
/>
onChange(element.id, "showEmail", checked)
}
label="Afficher l'email"
description="Adresse email du client"
/>
onChange(element.id, "showPhone", checked)
}
label="Afficher le téléphone"
description="Numéro de téléphone du client"
/>
{/* Section Informations de paiement */}
Informations de paiement
onChange(element.id, "showPaymentMethod", checked)
}
label="Afficher le moyen de paiement"
description="Méthode de paiement utilisée"
/>
onChange(element.id, "showTransactionId", checked)
}
label="Afficher l'ID de transaction"
description="Identifiant unique de la transaction"
/>
>
)}
{/* Onglet Personnalisation */}
{customerCurrentTab === "personnalisation" && (
<>
{/* Accordéon Disposition */}
Type de disposition
{
onChange(element.id, "layout", e.target.value);
}}
style={{
width: "100%",
padding: "4px 8px",
border: "1px solid #ccc",
borderRadius: "3px",
fontSize: "12px",
}}
>
Verticale
Horizontale
Compacte
{canUseEditorThemes && (
{[
{
id: "clean",
name: "Propre",
preview: (
),
styles: {
backgroundColor: "#ffffff",
borderColor: "#f3f4f6",
textColor: "#374151",
headerTextColor: "#111827",
},
},
{
id: "subtle",
name: "Discret",
preview: (
),
styles: {
backgroundColor: "#fafbfc",
borderColor: "#f1f5f9",
textColor: "#475569",
headerTextColor: "#334155",
},
},
{
id: "elegant",
name: "Élégant",
preview: (
),
styles: {
backgroundColor: "#fefefe",
borderColor: "#f3e8ff",
textColor: "#6b21a8",
headerTextColor: "#581c87",
},
},
{
id: "corporate",
name: "Corporate",
preview: (
),
styles: {
backgroundColor: "#ffffff",
borderColor: "#e5e7eb",
textColor: "#374151",
headerTextColor: "#111827",
},
},
{
id: "warm",
name: "Chaleureux",
preview: (
),
styles: {
backgroundColor: "#fff8f0",
borderColor: "#fed7aa",
textColor: "#9a3412",
headerTextColor: "#78350f",
},
},
{
id: "minimal",
name: "Minimal",
preview: (
),
styles: {
backgroundColor: "transparent",
borderColor: "transparent",
textColor: "#6b7280",
headerTextColor: "#374151",
},
},
].map((theme) => (
{
// Appliquer toutes les propriétés du thème
Object.entries(theme.styles).forEach(
([property, value]) => {
onChange(element.id, property, value);
},
);
}}
style={{
padding: "6px",
border: "2px solid transparent",
borderRadius: "6px",
backgroundColor: "#ffffff",
cursor: "pointer",
textAlign: "center",
transition: "all 0.2s ease",
minHeight: "70px",
display: "flex",
flexDirection: "column",
alignItems: "center",
gap: "4px",
}}
onMouseEnter={(e) => {
e.currentTarget.style.borderColor = "#007bff";
e.currentTarget.style.backgroundColor = "#f8f9fa";
e.currentTarget.style.transform = "translateY(-1px)";
}}
onMouseLeave={(e) => {
e.currentTarget.style.borderColor = "transparent";
e.currentTarget.style.backgroundColor = "#ffffff";
e.currentTarget.style.transform = "translateY(0)";
}}
title={`Appliquer le thème ${theme.name}`}
>
{theme.name}
{theme.preview}
))}
)}
{/* Accordéon Police de l'en-tête */}
{element.showHeaders !== false && (
onChange(element.id, "headerFontSize", value)
}
/>
Famille de police
onChange(element.id, "headerFontFamily", e.target.value)
}
style={{
width: "100%",
padding: "4px 8px",
border: "1px solid #ccc",
borderRadius: "3px",
fontSize: "12px",
}}
>
Arial
Helvetica
Times New Roman
Georgia
Verdana
Tahoma
Trebuchet MS
Calibri
Cambria
Segoe UI
Épaisseur de police
onChange(element.id, "headerFontWeight", e.target.value)
}
style={{
width: "100%",
padding: "4px 8px",
border: "1px solid #ccc",
borderRadius: "3px",
fontSize: "12px",
}}
>
Normal (400)
Gras (700)
Fin (300)
Très gras (900)
Style de police
onChange(element.id, "headerFontStyle", e.target.value)
}
style={{
width: "100%",
padding: "4px 8px",
border: "1px solid #ccc",
borderRadius: "3px",
fontSize: "12px",
}}
>
Normal
Italique
Oblique
onChange(element.id, "headerTextColor", value)
}
/>
)}
{/* Accordéon Police du corps du texte */}
onChange(element.id, "bodyFontSize", value)
}
/>
Famille de police
onChange(element.id, "bodyFontFamily", e.target.value)
}
style={{
width: "100%",
padding: "4px 8px",
border: "1px solid #ccc",
borderRadius: "3px",
fontSize: "12px",
}}
>
Arial
Helvetica
Times New Roman
Georgia
Verdana
Tahoma
Trebuchet MS
Calibri
Cambria
Segoe UI
Épaisseur de police
onChange(element.id, "bodyFontWeight", e.target.value)
}
style={{
width: "100%",
padding: "4px 8px",
border: "1px solid #ccc",
borderRadius: "3px",
fontSize: "12px",
}}
>
Normal (400)
Gras (700)
Fin (300)
Très gras (900)
Style de police
onChange(element.id, "bodyFontStyle", e.target.value)
}
style={{
width: "100%",
padding: "4px 8px",
border: "1px solid #ccc",
borderRadius: "3px",
fontSize: "12px",
}}
>
Normal
Italique
Oblique
onChange(element.id, "textColor", value)}
/>
{/* Accordéon Couleurs */}
onChange(element.id, "headerTextColor", value)
}
/>
onChange(element.id, "textColor", value)}
/>
{element.showBackground !== false && (
onChange(element.id, "backgroundColor", value)
}
/>
)}
{element.showBorders !== false && (
onChange(element.id, "borderColor", value)
}
/>
)}
{element.showBorders !== false && (
onChange(element.id, "borderWidth", value)
}
/>
)}
>
)}
{/* Onglet Positionnement */}
{customerCurrentTab === "positionnement" && (
<>
Position X: {element.x}px
onChange(element.id, "x", parseInt(e.target.value))
}
style={{
width: "100%",
height: "6px",
borderRadius: "3px",
background: "#ddd",
outline: "none",
cursor: "pointer",
}}
/>
Position Y: {element.y}px
onChange(element.id, "y", parseInt(e.target.value))
}
style={{
width: "100%",
height: "6px",
borderRadius: "3px",
background: "#ddd",
outline: "none",
cursor: "pointer",
}}
/>
Largeur: {element.width}px
onChange(element.id, "width", parseInt(e.target.value))
}
style={{
width: "100%",
height: "6px",
borderRadius: "3px",
background: "#ddd",
outline: "none",
cursor: "pointer",
}}
/>
Hauteur: {element.height}px
onChange(element.id, "height", parseInt(e.target.value))
}
style={{
width: "100%",
height: "6px",
borderRadius: "3px",
background: "#ddd",
outline: "none",
cursor: "pointer",
}}
/>
Alignement horizontal
onChange(element.id, "textAlign", e.target.value)
}
style={{
width: "100%",
padding: "4px 8px",
border: "1px solid #ccc",
borderRadius: "3px",
fontSize: "12px",
}}
>
Gauche
Centre
Droite
Alignement vertical
onChange(element.id, "verticalAlign", e.target.value)
}
style={{
width: "100%",
padding: "4px 8px",
border: "1px solid #ccc",
borderRadius: "3px",
fontSize: "12px",
}}
>
Haut
Milieu
Bas
Espacement des lettres{" "}
({(element.letterSpacing ?? 0).toFixed(2)}px)
onChange(
element.id,
"letterSpacing",
parseFloat(e.target.value),
)
}
style={{
width: "100%",
height: "6px",
borderRadius: "3px",
background: "#ddd",
outline: "none",
cursor: "pointer",
}}
/>
>
)}
>
);
}