import React from 'react'
import { Code2 } from 'lucide-react'
import { createNodeTypeBuilder } from '@/lib/graph/nodeTypeBuilder'
import { NODE_HELP } from '@/lib/graph/nodeHelp'
import type { NodeTypeDescriptor } from '@/lib/graph/nodeRegistry'
import FunctionNode from './FunctionNode'

const ICON_CLASS = 'mr-2 h-4 w-4'

const DEFAULT_BODY = `function(num, kwargs) {
  return num + (kwargs.bar || 0);
}`

export function getFunctionNodeDescriptor(): NodeTypeDescriptor {
  return createNodeTypeBuilder('function', FunctionNode, { width: 288, height: 260 }, { body: DEFAULT_BODY })
    .idPrefix('fn_')
    .withInputOutput(true, true)
    .classification('psyche')
    .allowedSourceTypes(['config', 'variable', 'function'])
    .allowedTargetTypes(['config', 'function'])
    .help(NODE_HELP.function)
    .menu('Function', <Code2 className={ICON_CLASS} />)
    .getResetData(() => ({ body: '' }))
    .connectionLabelByStatus({ default: 'adding input', updating: 'running', paused: 'pending', error: 'corrupted' })
    .withFullscreen()
    .build()
}
