import React, { useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useQuery } from '@tanstack/react-query'; import { X, Search, Eye, Check, Sparkles, Smile, Minus, ChevronRight } from 'lucide-react'; import api from '../api/client'; import { EmailTemplateCategory } from '../types'; interface TemplatePreset { name: string; description: string; style: string; subject: string; html_content: string; text_content: string; } interface PresetsResponse { presets: Record; } interface EmailTemplatePresetSelectorProps { category: EmailTemplateCategory; onSelect: (preset: TemplatePreset) => void; onClose: () => void; } const styleIcons: Record = { professional: , friendly: , minimalist: , }; const styleColors: Record = { professional: 'bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-300', friendly: 'bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-300', minimalist: 'bg-gray-100 text-gray-700 dark:bg-gray-700 dark:text-gray-300', }; const EmailTemplatePresetSelector: React.FC = ({ category, onSelect, onClose, }) => { const { t } = useTranslation(); const [searchQuery, setSearchQuery] = useState(''); const [selectedPreview, setSelectedPreview] = useState(null); const [selectedStyle, setSelectedStyle] = useState('all'); // Fetch presets const { data: presetsData, isLoading } = useQuery({ queryKey: ['email-template-presets'], queryFn: async () => { const { data } = await api.get('/email-templates/presets/'); return data; }, }); const presets = presetsData?.presets[category] || []; // Filter presets const filteredPresets = presets.filter(preset => { const matchesSearch = searchQuery.trim() === '' || preset.name.toLowerCase().includes(searchQuery.toLowerCase()) || preset.description.toLowerCase().includes(searchQuery.toLowerCase()); const matchesStyle = selectedStyle === 'all' || preset.style === selectedStyle; return matchesSearch && matchesStyle; }); // Get unique styles from presets const availableStyles = Array.from(new Set(presets.map(p => p.style))); const handleSelectPreset = (preset: TemplatePreset) => { onSelect(preset); onClose(); }; return (
{/* Header */}

{t('emailTemplates.selectPreset', 'Choose a Template')}

{t('emailTemplates.presetDescription', 'Select a pre-designed template to customize')}

{/* Search and Filters */}
{/* Search */}
setSearchQuery(e.target.value)} placeholder={t('emailTemplates.searchPresets', 'Search templates...')} className="w-full pl-9 pr-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white text-sm focus:ring-2 focus:ring-brand-500 focus:border-brand-500" />
{/* Style Filter */}
{availableStyles.map(style => ( ))}
{/* Content */}
{isLoading ? (
) : filteredPresets.length === 0 ? (

{t('emailTemplates.noPresets', 'No templates found matching your criteria')}

) : (
{filteredPresets.map((preset, index) => (
{/* Preview Image Placeholder */}