import React, { useState } from 'react'; const ELEMENT_TYPES = [ { value: 'progress_bar', label: 'Progress Bar' }, { value: 'gauge', label: 'Gauge' }, { value: 'icon', label: 'Icon' }, { value: 'text_label', label: 'Text Label' }, { value: 'radial', label: 'Radial Dial' }, { value: 'waveform', label: 'Waveform' }, ]; const COLORS = ['#e74c3c', '#f39c12', '#3498db', '#8e44ad', '#e91e63', '#ff6b6b', '#2ecc71', '#1abc9c']; export default function UIElementEditor({ uiElements, needs, onAdd, onUpdate, onDelete }) { const [editingId, setEditingId] = useState(null); const [editForm, setEditForm] = useState({}); const startEdit = (el) => { setEditingId(el.id); setEditForm({ ...el, config: typeof el.config === 'string' ? JSON.parse(el.config) : el.config }); }; const cancelEdit = () => { setEditingId(null); setEditForm({}); }; const saveEdit = () => { onUpdate(editingId, editForm); setEditingId(null); }; const handleAdd = () => { onAdd({ need_id: needs?.[0]?.id || null, element_type: 'progress_bar', config: { color: '#3498db', label: 'New Element', animation: 'smooth' }, }); }; return (

UI Elements

{(!uiElements || uiElements.length === 0) ? (

No UI elements defined. These represent how needs will visually appear.

) : (
{uiElements.map((el) => { const config = typeof el.config === 'string' ? JSON.parse(el.config) : el.config; const need = needs?.find((n) => n.id === el.need_id); return (
{editingId === el.id ? (
{COLORS.map((c) => (
setEditForm({ ...editForm, config: { ...editForm.config, label: e.target.value } })} />
) : ( <>

{config?.label || el.element_type}

{ELEMENT_TYPES.find(t => t.value === el.element_type)?.label || el.element_type}
Linked to: {need?.name || 'None'} Animation: {config?.animation || 'none'}
{el.element_type === 'progress_bar' && (
)} {el.element_type === 'gauge' && (
75%
)} {el.element_type === 'radial' && (
60%
)} {(el.element_type === 'icon' || el.element_type === 'text_label') && (
{config?.label || el.element_type}
)} {el.element_type === 'waveform' && (
~ ~ ~
)}
)}
); })}
)}
); }