import React, { useState } from 'react'; import type { Variable, VariableType } from '../../types/project'; import { formatVariableDefault, parseVariableDefault, validateVariableName } from './configurationUtils'; import styles from './ActionInspector.module.css'; type Props = { name: string; variable: Variable; variables: Record; isNew?: boolean; onSave: (name: string, variable: Variable) => void; onCancel: () => void; }; const TYPES: VariableType[] = ['string', 'number', 'boolean', 'object', 'array']; export default function VariableEditor({ name, variable, variables, isNew = false, onSave, onCancel }: Props): React.ReactElement { const [nameDraft, setNameDraft] = useState(name); const [type, setType] = useState(variable.type); const [defaultDraft, setDefaultDraft] = useState(() => formatVariableDefault(variable)); const [description, setDescription] = useState(variable.description ?? ''); const nameError = validateVariableName(nameDraft, variables, isNew ? undefined : name); let defaultValue: unknown; let defaultError: string | null = null; try { defaultValue = parseVariableDefault(type, defaultDraft); } catch (error) { defaultError = error instanceof Error ? error.message : String(error); } const valid = !nameError && !defaultError; return (