import React from 'react'; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from '../../ui/dialog'; import { Button } from '../../ui/button'; import { Label } from '../../ui/label'; import { Input } from '../../ui/input'; import { Textarea } from '../../ui/textarea'; import { Switch } from '../../ui/switch'; import { Loader2, Play, Info, Copy, CheckCircle2, Settings, Edit2 } from 'lucide-react'; import { Badge } from '../../ui/badge'; interface TemplateDialogProps { isOpen: boolean; onOpenChange: (open: boolean) => void; editingTemplate: any; setEditingTemplate: (template: any) => void; testDataInput: string; setTestDataInput: (data: string) => void; previewLoading: boolean; handlePreviewTemplate: () => void; previewContent: any; handleSaveTemplate: () => void; } export const TemplateDialog: React.FC = ({ isOpen, onOpenChange, editingTemplate, setEditingTemplate, testDataInput, setTestDataInput, previewLoading, handlePreviewTemplate, previewContent, handleSaveTemplate }) => { const textareaRef = React.useRef(null); const insertPlaceholder = (placeholder: string) => { if (!textareaRef.current) return; const { selectionStart, selectionEnd } = textareaRef.current; const text = editingTemplate?.body || ''; const newText = text.substring(0, selectionStart) + `{{${placeholder}}}` + text.substring(selectionEnd); setEditingTemplate({ ...editingTemplate!, body: newText }); // Set focus back and move cursor setTimeout(() => { if (textareaRef.current) { textareaRef.current.focus(); textareaRef.current.setSelectionRange(selectionStart + placeholder.length + 4, selectionStart + placeholder.length + 4); } }, 0); }; const placeholders = editingTemplate?.placeholders || []; return ( {editingTemplate?.id ? 'Edit Email Template' : 'Add Email Template'} Configure automated email template with dynamic content
{/* Left Column: Template Configuration */}

General Settings

setEditingTemplate({ ...editingTemplate!, name: e.target.value })} />
setEditingTemplate({ ...editingTemplate!, templateCode: e.target.value })} />
setEditingTemplate({ ...editingTemplate!, description: e.target.value })} />
setEditingTemplate({ ...editingTemplate!, isActive: checked })} />
{editingTemplate?.isActive ? 'Template Enabled' : 'Template Disabled'}
{/* Placeholders Library */}

Available Placeholders

Click on a placeholder below to insert it at your current cursor position in the editor.

{placeholders.length > 0 ? placeholders.map((p: string) => ( )) : (

No placeholders defined for this trigger

)}
{/* Middle Column: Editor */}

Template Designer

setEditingTemplate({ ...editingTemplate!, subject: e.target.value })} />