import type {NodeProps} from '@xyflow/react'
import React, {useCallback} from 'react'
import {useContextStore} from '../store/ContextStore.ts'
import {useDataStore} from '../store/DataStore.ts'
import {useFlowStore} from '../store/FlowStore.ts'
import AmisNode, {EndNodeHandler, inputsFormColumns} from './AmisNode.tsx'

const OutputNode = (props: NodeProps) => {
  const {getNodes, getEdges} = useFlowStore()
  const {getData} = useDataStore()
  const {getInputSchema} = useContextStore()
  const columnsSchema = useCallback(
    () => inputsFormColumns(props.id, getInputSchema(), getNodes(), getEdges(), getData()),
    [props.id],
  )

  return (
    <AmisNode
      nodeProps={props}
      columnSchema={columnsSchema}
      handler={<EndNodeHandler/>}
    />
  )
}

export default React.memo(OutputNode)