import React from 'react';
import styles from '@/components/FlowEditor/node/style/baseOther.module.less';
import NodeContentOther from '@/pages/flowEditor/components/nodeContentOther';
import { useStore } from '@xyflow/react';
import { defaultNodeTypes } from '@/components/FlowEditor/node/types/defaultType';
import NodeStatusIndicator, { NodeStatus } from '@/components/FlowEditor/NodeStatusIndicator';
import { useStore as useFlowStore } from '@xyflow/react';

const EndNode = ({ data, id }: { data: defaultNodeTypes; id: string }) => {
  const title = data.title || '结束';

  // 获取节点选中状态 - 适配React Flow v12 API
  const isSelected = useStore((state) =>
    state.nodeLookup.get(id)?.selected || false
  );

  // 获取节点运行状态
  const nodeStatus: NodeStatus = useFlowStore((state) => 
    (state.nodeLookup.get(id)?.data?.status as NodeStatus) || 'waiting'
  );
  
  // 获取运行状态可见性
  const isStatusVisible = useFlowStore((state) => 
    !!state.nodeLookup.get(id)?.data?.isStatusVisible
  );

  return (
    <div className={`${styles['node-container']} ${isSelected ? styles.selected : ''}`}>
      <div className={styles['node-header']} style={{ backgroundColor: '#c05144' }}>
        {title}
        <NodeStatusIndicator status={nodeStatus} isVisible={isStatusVisible} />
      </div>
      <NodeContentOther data={{ ...data, type: 'end' }} />
    </div>
  );
};

export default EndNode;