import React from 'react';
import { useStore } from '@xyflow/react';
// import styles from '@/pages/flowEditor/node/style/base.module.less';
import styles from '@/components/FlowEditor/node/style/baseOther.module.less';
import NodeContent from '@/pages/flowEditor/components/nodeContent';
import DynamicIcon from '@/components/DynamicIcon';
import NodeContentOther from '@/pages/flowEditor/components/nodeContentOther';


const setIcon = (nodeType: string) => {
  let type = 'IconApps';
  switch (nodeType) {
    case 'CONDITION':
      type = 'IconBranch';
      break;
    case 'AND':
      type = 'IconShareAlt';
      break;
    case 'OR':
      type = 'IconPause';
      break;
    case 'WAIT':
      type = 'IconClockCircle';
      break;
    case 'LOOP':
      type = 'IconSync';
      break;
    case 'CYCLE':
      type = 'IconSchedule';
      break;
    case 'EVENTLISTENE':
      type = 'IconImport';
      break;
    case 'EVENTSEND':
      type = 'IconExport';
      break;
    case 'JSON2STR':
      type = 'IconCodeBlock';
      break;
    case 'STR2JSON':
      type = 'IconCodeSquare';
      break;
    case 'JSONCONVERT':
      type = 'IconTranslate';
      break;
    case 'RESULT':
      type = 'IconInteraction';
      break;
    case 'IMAGE':
      type = 'IconImage';
      break;
    case 'CODE':
      type = 'IconCode';
      break;
    case 'REST':
      type = 'IconCloudDownload';
      break;
  }
  return <DynamicIcon type={type} style={{ fontSize: '16px', marginRight: '5px' }} />;
};

const LocalNode = ({ data, id }: { data: any; id: string }) => {
  const title = data.title || '系统组件';

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

  return (
    <div className={`${styles['node-container']} ${isSelected ? styles.selected : ''}`}>
      <div className={styles['node-header']} style={{ backgroundColor: '#1890ff' }}>
        {setIcon(data.type)}
        {title}
      </div>
      {/*<NodeContent data={data} />*/}
      <NodeContentOther data={data} />
    </div>
  );
};

export default LocalNode;