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 (
Manage and design your transactional and automated emails.
Free plan includes {freeLimit} templates.{' '} Upgrade to Pro {' '} for unlimited.
> ) : ({templates.length} / {freeLimit} free templates used
)}{searchTerm ? `No templates matching "${searchTerm}"` : "You haven't created any email templates yet."}
{!searchTerm && !atFreeLimit && ( )}ID: {template.id}