import { DND_RENDER_ID, NODE_WIDTH, NODE_HEIGHT } from './constant';
import { NsGraph } from '@antv/xflow';
import { NsGraphCmd } from '@antv/xflow';
import { queryBoomFlowDetail } from '@/services/boom';

/** mock 后端接口调用 */
export namespace MockApi {
  export const NODE_COMMON_PROPS = {
    renderKey: DND_RENDER_ID,
    width: NODE_WIDTH,
    height: NODE_HEIGHT,
  } as const;

  /** 查图的meta元信息 */
  export const queryGraphMeta: NsGraphCmd.GraphMeta.IArgs['graphMetaService'] = async (
    args: any
  ) => {
    // console.log('queryMeta', args);
    return { ...args, flowId: args.meta.flowId };
  };
  /** 加载图数据的api */
  export const loadGraphData = async (meta: NsGraph.IGraphMeta) => {
    const { data } = await queryBoomFlowDetail({ id: meta.flowId });

    
    // graphData.nodes = graphData.nodes.map(item => {
    //   item.ports.groups = groups;
    //   return item;
    // });
    // // graphData.edges = []
    // graphData.edges = graphData.edges.map(item => {
    //   item.attrs = attrs;
    //   return item;
    // });

    return {
      // nodes,
      // edges,
    };
  };
  /** 保存图数据的api */
  export const saveGraphData: NsGraphCmd.SaveGraphData.IArgs['saveGraphDataService'] = async (
    meta: NsGraph.IGraphMeta,
    graphData: NsGraph.IGraphData
  ) => {
    console.log('saveGraphData api', meta, graphData);
    localStorage.graphData = JSON.stringify(graphData);
    return null;
  };
}
