/*
*  应用编排处理
* */

import { convertAppFlowData } from '@/utils/convertAppFlowData';
import { convertFlowData } from '@/utils/convertFlowData';
import { Edge } from '@xyflow/react';
import { updateCanvasDataMap } from '@/store/ideContainer';

export const appFLowHandle = (initialData, useDefault, setNodes, setEdges, dispatch) => {
  const {
    nodes: convertedNodes,
    edges: convertedEdges
  } = convertAppFlowData(initialData);


  // 为所有边添加类型
  const initialEdges: Edge[] = convertedEdges.map(edge => ({
    ...edge,
    type: 'custom'
  }));

  setNodes(convertedNodes);
  setEdges(initialEdges);

  // if (initialData?.appId) {
  //   dispatch(updateCanvasDataMap({
  //     ...canvasDataMap,
  //     [initialData.appId]: { nodes: convertedNodes, edges: initialEdges }
  //   }));
  // }
};