import React, { useState } from 'react'; interface Item { [key: string]: any; } interface FieldConfig { key: string; label: string; type: 'text' | 'textarea'; } interface EditableCardProps { title: string; items: T[]; onItemsChange: (items: T[]) => void; fieldConfigs: FieldConfig[]; newItemTemplate: T; renderDisplay: (item: T, index: number) => React.ReactNode; showAddButton?: boolean; t: { add: string; cancel: string; save: string; } } const PencilIcon = () => ( ); const TrashIcon = () => ( ); export const EditableCard = ({ title, items, onItemsChange, fieldConfigs, newItemTemplate, renderDisplay, showAddButton, t }: EditableCardProps) => { const [editingIndex, setEditingIndex] = useState(null); const [editItem, setEditItem] = useState(null); const handleEdit = (index: number) => { setEditingIndex(index); setEditItem({ ...items[index] }); }; const handleSave = () => { if (editingIndex !== null && editItem) { const newItems = [...items]; newItems[editingIndex] = editItem; onItemsChange(newItems); setEditingIndex(null); setEditItem(null); } }; const handleCancel = () => { setEditingIndex(null); setEditItem(null); }; const handleRemove = (index: number) => { onItemsChange(items.filter((_, i) => i !== index)); }; const handleAdd = () => { onItemsChange([...items, newItemTemplate]); setEditingIndex(items.length); setEditItem(newItemTemplate); }; const handleInputChange = (key: string, value: string) => { if (editItem) { setEditItem({ ...editItem, [key]: value }); } }; const inputClasses = "w-full bg-light-secondary dark:bg-brand-secondary text-light-text dark:text-brand-text border border-light-accent dark:border-brand-accent rounded-md px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-brand-highlight"; return (

{title}

{(showAddButton ?? true) && ( )}
{items.map((item, index) => (
{editingIndex === index && editItem ? (
{fieldConfigs.map(field => (
{field.type === 'textarea' ? (