import React from 'react'; import { Plus, Mail, Pencil, Trash2, Lock } from 'lucide-react'; const EmailTemplateList = ({ templates, onCreateNew, onEdit, onDelete, isProActive, freeLimit }) => { const [searchTerm, setSearchTerm] = React.useState(''); const atFreeLimit = !isProActive && templates.length >= freeLimit; const filteredTemplates = (Array.isArray(templates) ? templates : []).filter(t => t.name && t.name.toLowerCase().includes(searchTerm.toLowerCase()) ); if (!Array.isArray(templates)) { return null; } const handleDelete = async (id) => { if (!window.confirm('Are you sure you want to delete this template?')) return; try { const response = await fetch(`${window.wpbotAutomator.apiUrl}/email-templates/${id}`, { method: 'DELETE', headers: { 'X-WP-Nonce': window.wpbotAutomator.nonce, }, }); const data = await response.json(); if (data.success) { onDelete(); } else { alert('Failed to delete template.'); } } catch (error) { console.error('Error deleting template:', error); } }; return (

Email Templates

Manage and design your transactional and automated emails.

{atFreeLimit ? ( <>
Create New Template PRO

Free plan includes {freeLimit} templates.{' '} Upgrade to Pro {' '} for unlimited.

) : (
{!isProActive && (

{templates.length} / {freeLimit} free templates used

)}
)}
setSearchTerm(e.target.value)} className="w-full pl-10 pr-4 py-2 border border-border rounded-md bg-background focus:outline-none focus:ring-2 focus:ring-primary/20 transition-all text-sm" />
{filteredTemplates.length === 0 ? (

No templates found

{searchTerm ? `No templates matching "${searchTerm}"` : "You haven't created any email templates yet."}

{!searchTerm && !atFreeLimit && ( )}
) : (
{filteredTemplates.map((template) => (

onEdit(template)}> {template.name}

ID: {template.id}

))}
)}
); }; export default EmailTemplateList;