import { memo } from 'react';
import NodeShell from '../components/NodeShell.jsx';
import { NodeDraftInput } from '../components/NodeDraftField.jsx';
import { useWorkflow } from '../context/WorkflowContext.jsx';
import { getNodeAccent } from '../lib/nodeRegistry.js';

function ClassifierFlowNode({ id, data, selected, type }) {
  const { getNodeHandles, patchNodeData } = useWorkflow();
  const handles = getNodeHandles(type, data);
  const runtime = data.runtime || {};

  return (
    <NodeShell
      nodeId={id}
      title={data.title}
      accent={getNodeAccent(type)}
      selected={selected}
      status={runtime.status}
      inputs={handles.inputs}
      outputs={handles.outputs}
    >
      <div className="field-stack">
        <label className="field-label" htmlFor={`classifier-options-${id}`}>
          Options
        </label>
        <NodeDraftInput
          id={`classifier-options-${id}`}
          className="nodrag node-input"
          type="text"
          value={data.options || ''}
          onCommit={(value) => patchNodeData(id, { options: value })}
        />
        <div className="node-preview">{runtime.result || 'После Run здесь будет выбранный вариант.'}</div>
        {runtime.error ? <div className="node-error">{runtime.error}</div> : null}
      </div>
    </NodeShell>
  );
}

export default memo(ClassifierFlowNode);
