import { DynamicTextElement } from '../../types/elements'; import { NumericPropertyInput } from '../ui/NumericPropertyInput'; import { ColorPropertyInput } from '../ui/ColorPropertyInput'; import { getEditorFeatureFlags, getPdfBuilderData } from '../../utils/editorFeatures'; type DynamicTextTemplateOption = { id: string; label: string; template: string; }; // 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', transition: 'background-color 0.2s ease', border: 'none' }} >
{description}
); interface DynamicTextPropertiesProps { element: DynamicTextElement; onChange: (elementId: string, property: string, value: unknown) => void; activeTab: { [key: string]: 'fonctionnalites' | 'personnalisation' | 'positionnement' }; setActiveTab: (tabs: { [key: string]: 'fonctionnalites' | 'personnalisation' | 'positionnement' }) => void; } export function DynamicTextProperties({ element, onChange, activeTab, setActiveTab }: DynamicTextPropertiesProps) { const dynamicCurrentTab = activeTab[element.id] || 'fonctionnalites'; const setDynamicCurrentTab = (tab: 'fonctionnalites' | 'personnalisation' | 'positionnement') => { setActiveTab({ ...activeTab, [element.id]: tab }); }; const { canUseEditorThemes } = getEditorFeatureFlags(); const freeTextExamples: DynamicTextTemplateOption[] = [ { id: 'document_title', label: 'Titre de document', template: 'CONTRAT DE PRESTATION DE SERVICES' }, { id: 'document_subtitle', label: 'Sous-titre de document', template: 'Entre les parties ci-dessous désignées' }, { id: 'date_today', label: 'Date du jour', template: 'Fait à [Ville], le [date]' } ]; const customTemplate: DynamicTextTemplateOption = { id: 'custom', label: 'Personnalisé', template: '' }; const pdfBuilderData = getPdfBuilderData(); const premiumTextExamples = ((pdfBuilderData.dynamicTextTemplatesPremium ?? []) as DynamicTextTemplateOption[]); const allTextExamples = [customTemplate, ...freeTextExamples, ...premiumTextExamples]; // Détecter le template actuel const currentText = element.text || ''; const currentTemplate = (() => { if (element.textTemplate && allTextExamples.some((example) => example.id === element.textTemplate)) { return element.textTemplate; } return allTextExamples.find((example) => example.template === currentText)?.id || 'custom'; })(); // Fonction pour changer de template const handleTemplateChange = (templateId: string) => { const selectedExample = allTextExamples.find((ex) => ex.id === templateId); if (selectedExample) { onChange(element.id, 'text', selectedExample.template); onChange(element.id, 'textTemplate', selectedExample.id); } }; const dynamicTextThemes = [ { id: 'clean', name: 'Propre', preview: (
), styles: { backgroundColor: '#ffffff', borderColor: '#f3f4f6', textColor: '#374151', headerTextColor: '#111827' } }, { id: 'subtle', name: 'Discret', preview: (
), styles: { backgroundColor: '#f9fafb', borderColor: '#e5e7eb', textColor: '#6b7280', headerTextColor: '#374151' } }, { id: 'highlighted', name: 'Surligné', preview: (
), styles: { backgroundColor: '#eff6ff', borderColor: '#dbeafe', textColor: '#1e40af', headerTextColor: '#1e3a8a' } } ]; const availableVariables = [ { key: '{{customer_name}}', label: 'Nom du client' }, { key: '{{customer_first_name}}', label: 'Prénom du client' }, { key: '{{customer_last_name}}', label: 'Nom du client' }, { key: '{{customer_email}}', label: 'Email du client' }, { key: '{{customer_phone}}', label: 'Téléphone du client' }, { key: '{{order_number}}', label: 'Numéro de commande' }, { key: '{{order_date}}', label: 'Date de commande' }, { key: '{{order_total}}', label: 'Total de la commande' }, { key: '{{company_name}}', label: 'Nom de l\'entreprise' }, { key: '{{company_email}}', label: 'Email de l\'entreprise' }, { key: '{{company_phone}}', label: 'Téléphone de l\'entreprise' }, { key: '{{company_address}}', label: 'Adresse de l\'entreprise' }, { key: '{{current_date}}', label: 'Date actuelle' }, { key: '{{current_time}}', label: 'Heure actuelle' } ]; return ( <> {/* Système d'onglets pour Dynamic Text */}
{/* Onglet Fonctionnalités */} {dynamicCurrentTab === 'fonctionnalites' && ( <>