'use client';

import { NodeShell } from './node-shell';
import { PortRow } from './port-row';

interface ConditionNodeData {
  rules?: Array<{ condition: string; target: string }>;
  default?: string;
  isStart?: boolean;
  nodeId?: string;
  [key: string]: unknown;
}

export function ConditionNode({ data, id }: { data: ConditionNodeData; id: string }) {
  const rules = (data.rules ?? []) as Array<{ condition: string; target: string }>;
  const defaultTarget = data.default;
  const isStart = data.isStart;
  const nodeId = (data.nodeId as string) || id;

  return (
    <NodeShell
      accentColor="#ffa726"
      icon={'\uD83D\uDD00'}
      title="Условие"
      nodeId={nodeId}
      isStart={isStart}
    >
      {rules.length === 0 && !defaultTarget && (
        <p
          style={{
            fontSize: 10,
            fontStyle: 'italic',
            color: '#bdbdbd',
            margin: 0,
          }}
        >
          Нет условий
        </p>
      )}

      {/* Rule rows + default — as PortRows */}
      <div style={{ margin: '0 -10px' }}>
        {rules.map((rule, i) => (
          <PortRow key={`rule-${i}`} label={rule.condition} handleId={`source-rule-${i}`} />
        ))}
        {defaultTarget && <PortRow label="Иначе" handleId="source-default" dotColor="#ffa726" />}
      </div>
    </NodeShell>
  );
}
