import { useState } from 'react' import { ChevronDown, ChevronRight, GripVertical, Trash2, Plus, X } from 'lucide-react' import { Input } from '@/components/ui/Input' import type { ScriptParameter, ScriptParameterOption, ScriptParameterValidation } from '@/types' const PARAM_TYPES = [ { value: 'text', label: 'Text' }, { value: 'password', label: 'Password' }, { value: 'textarea', label: 'Textarea' }, { value: 'number', label: 'Number' }, { value: 'boolean', label: 'Boolean' }, { value: 'select', label: 'Select' }, { value: 'multi_text', label: 'Multi-text' }, ] as const interface Props { param: ScriptParameter index: number onChange: (index: number, updated: ScriptParameter) => void onRemove: (index: number) => void onMoveUp: (index: number) => void onMoveDown: (index: number) => void isFirst: boolean isLast: boolean disabled?: boolean } export function ParameterCard({ param, index, onChange, onRemove, onMoveUp, onMoveDown, isFirst, isLast, disabled, }: Props) { const [expanded, setExpanded] = useState(true) const update = (patch: Partial) => { onChange(index, { ...param, ...patch }) } const updateOption = (optIndex: number, patch: Partial) => { const options = [...(param.options ?? [])] options[optIndex] = { ...options[optIndex], ...patch } update({ options }) } const addOption = () => { const options = [...(param.options ?? []), { value: '', label: '' }] update({ options }) } const removeOption = (optIndex: number) => { const options = (param.options ?? []).filter((_, i) => i !== optIndex) update({ options }) } const updateValidation = (patch: Partial) => { update({ validation: { ...(param.validation ?? {}), ...patch } }) } return (
{/* Header */} {/* Body */} {expanded && (
{/* Row 1: key + label */}
update({ key: e.target.value.replace(/[^a-zA-Z0-9_]/g, '') })} placeholder="param_key" disabled={disabled} />
update({ label: e.target.value })} placeholder="Display Label" disabled={disabled} />
{/* Row 2: type + group */}
update({ group: e.target.value || null })} placeholder="e.g. User Identity" disabled={disabled} />
{/* Row 3: placeholder + help text */}
update({ placeholder: e.target.value || null })} placeholder="Placeholder text" disabled={disabled} />
update({ help_text: e.target.value || null })} placeholder="Help text shown below field" disabled={disabled} />
{/* Row 4: toggles */}
{/* Default value */}
update({ default: e.target.value || null })} placeholder="Default value" disabled={disabled} />
{/* Select options (only for select type) */} {param.type === 'select' && (
{(param.options ?? []).map((opt, i) => (
updateOption(i, { value: e.target.value })} placeholder="value" disabled={disabled} /> updateOption(i, { label: e.target.value })} placeholder="label" disabled={disabled} />
))}
)} {/* Validation (for text/number types) */} {(param.type === 'text' || param.type === 'number' || param.type === 'textarea') && (
{param.type === 'number' ? ( <>
updateValidation({ min_value: e.target.value ? Number(e.target.value) : undefined })} disabled={disabled} />
updateValidation({ max_value: e.target.value ? Number(e.target.value) : undefined })} disabled={disabled} />
) : ( <>
updateValidation({ min_length: e.target.value ? Number(e.target.value) : undefined })} disabled={disabled} />
updateValidation({ max_length: e.target.value ? Number(e.target.value) : undefined })} disabled={disabled} />
)}
updateValidation({ pattern: e.target.value || undefined })} placeholder="^[a-z]+$" disabled={disabled} />
)} {/* Actions row */}
)}
) }