import React, { useState } from 'react'; const OPERATORS = [ { value: 'lt', label: '< (less than)' }, { value: 'lte', label: '≤ (less than or equal)' }, { value: 'eq', label: '= (equal to)' }, { value: 'gte', label: '≥ (greater than or equal)' }, { value: 'gt', label: '> (greater than)' }, ]; const ACTIONS = [ { value: 'seek_fulfillment', label: 'Seek Fulfillment' }, { value: 'alert', label: 'Trigger Alert' }, { value: 'change_state', label: 'Change Character State' }, { value: 'generate_event', label: 'Generate Roleplay Event' }, { value: 'activate_rule', label: 'Activate Other Rule' }, ]; export default function BrainRuleEditor({ brainRules, needs, onAdd, onUpdate, onDelete }) { const [editingId, setEditingId] = useState(null); const [editForm, setEditForm] = useState({}); const startEdit = (rule) => { setEditingId(rule.id); const condition = typeof rule.condition === 'string' ? JSON.parse(rule.condition) : rule.condition; const action = typeof rule.action === 'string' ? JSON.parse(rule.action) : rule.action; setEditForm({ ...rule, condition, action }); }; const cancelEdit = () => { setEditingId(null); setEditForm({}); }; const saveEdit = () => { onUpdate(editingId, { condition: editForm.condition, action: editForm.action, priority: editForm.priority, enabled: editForm.enabled, }); setEditingId(null); }; const handleAdd = () => { const newRule = { condition: { need: needs?.[0]?.name || '', operator: 'lt', value: 30 }, action: { type: 'seek_fulfillment', target: '' }, priority: 0, enabled: true, }; onAdd(newRule); }; return (
No brain rules defined. Rules define how your character reacts to changing needs.
) : (