import type { Stream, StreamType } from '../../types/stream'; import './StreamEditor.css'; interface Props { id?: string; stream: Stream; onChange: (updated: Stream) => void; onDelete: () => void; } const ALL_VARS = [ 'Tin', 'Tout', 'ṁ', 'cp', 'CP', 'Water Content In', 'Water Content Out', 'Density', 'Pressure', ]; const DEFAULT_VARS: Record = { product: ['Tin', 'Tout', 'ṁ', 'cp'], steam: ['Tin', 'ṁ'], water: ['Tin', 'ṁ', 'Water Content In', 'Water Content Out'], air: ['Tin', 'ṁ'], }; const STREAM_TYPES: StreamType[] = ['product', 'steam', 'air', 'water']; export default function StreamEditor({ id, stream, onChange, onDelete }: Props) { const displayVars = stream.display_vars?.length ? stream.display_vars : DEFAULT_VARS[stream.type] || DEFAULT_VARS.product; const update = (partial: Partial) => { onChange({ ...stream, ...partial }); }; const handleTypeChange = (type: StreamType) => { update({ type, display_vars: DEFAULT_VARS[type], }); }; const toggleVar = (varName: string) => { const current = [...displayVars]; const idx = current.indexOf(varName); if (idx >= 0) { current.splice(idx, 1); } else { current.push(varName); } update({ display_vars: current }); }; const updateValue = (key: string, value: string) => { const sv = { ...(stream.stream_values || {}) }; sv[key] = value; update({ stream_values: sv }); }; return (
{/* Header row */}
update({ name: e.target.value })} placeholder="Stream name" />
{/* Variable selector */}
{ALL_VARS.map((v) => { const isSelected = displayVars.includes(v); return ( ); })}
{/* Value inputs */}
{displayVars.map((v) => (
updateValue(v, e.target.value)} placeholder="—" />
))}
); }