import { Handle, Position } from 'reactflow'

/**
 * AnalysisNode - KI-Prompt Knoten
 *
 * Properties:
 * - data.label: Node-Label
 * - data.prompt_slug: Slug des referenzierten Basis-Prompts (Reference Mode)
 * - data.inline_template: Inline Prompt-Template (Inline Mode)
 * - data.prompt_name: Name des Prompts (optional, für Display)
 * - data.questions: Array von Question Augmentations
 * - selected: Boolean
 */
export function AnalysisNode({ data, selected }) {
  const hasQuestions = data.questions?.length > 0
  const questionCount = data.questions?.length || 0

  // Part 3: Inline Prompts - Zeige "Inline-Template" oder Prompt-Namen
  const isInlineMode = data.inline_template !== null && data.inline_template !== undefined
  const promptName = isInlineMode
    ? '✏️ Inline-Template'
    : (data.prompt_name || (data.prompt_slug ? `Prompt: ${data.prompt_slug}` : 'Kein Prompt'))

  return (
    <div className={`workflow-node analysis-node ${selected ? 'selected' : ''}`}>
      <div className="node-header">
        <div className="node-icon">🤖</div>
        <div className="node-label">{data.label || 'Analyse'}</div>
      </div>

      <div className="node-body">
        <div className="prompt-name" title={promptName}>
          {promptName}
        </div>

        {hasQuestions && (
          <div className="questions-indicator">
            📋 {questionCount} {questionCount === 1 ? 'Frage' : 'Fragen'}
          </div>
        )}
      </div>

      <Handle
        type="target"
        position={Position.Top}
        id="in"
        style={{ background: 'var(--accent)' }}
      />
      <Handle
        type="source"
        position={Position.Bottom}
        id="out"
        style={{ background: 'var(--accent)' }}
      />
    </div>
  )
}
