/*
 * @Author: Nian Yi
 * @Date: 2022-04-11 09:54:53
 * @LastEditTime: 2022-04-11 10:25:16
 * @LastEditors: Nian Yi
 * @Description: nodes context
 * @FilePath: /easyvadmin/src/scripts/containers/nodes-edit/Context/index.tsx
 * 奥利给
 */
import React, { createContext, useMemo } from 'react';
import { ReactFlowInstance } from '@easyv/react-flow-renderer';
import { CustomEvent } from 'models/queue.type';
const NodesContext = createContext<{
  canvas?: ReactFlowInstance;
  activatedState: string;
  eventNodes: string[];
  changeLayerStatus: (x: string) => void;
  setEventNode: (x: string[]) => void;
  setActivatedState: (t: string) => void;
  setCanvas: (c: ReactFlowInstance) => void;
  setCustomEvents: (data: CustomEvent[]) => void;
  onRoutingSwitch: (id: string) => void;
  clearCurrentNode: () => void;
  setCurrentNode: (id: string | string[]) => void;
  updateLayerNode: (ids: string[]) => void;
  updateLayerEdge: (ids: string[]) => void;
  onContextMenu: ({ event, id }: { event: React.MouseEvent<Element, MouseEvent>; id: string; visible?: boolean }) => void;
}>({
  activatedState: '',
  eventNodes: [],
  changeLayerStatus: (s) => {
    //
  },
  onRoutingSwitch: (id) => {
    //
  },
  setCustomEvents: (data) => {
    //
  },
  setEventNode: (x) => {
    //
  },
  onContextMenu: (t) => {
    //
  },
  setCurrentNode: (t) => {
    //
  },
  updateLayerNode: (t) => {
    //
  },
  updateLayerEdge: (t) => {
    //
  },
  clearCurrentNode: () => {
    //
  },
  setActivatedState: (t) => {
    //
  },
  setCanvas: (c) => {
    //
  }
});

function NodesProvider({
  setCanvas,
  setCurrentNode,
  setEventNode,
  updateLayerNode,
  updateLayerEdge,
  clearCurrentNode,
  setActivatedState,
  onRoutingSwitch,
  changeLayerStatus,
  setCustomEvents,
  activatedState,
  eventNodes,
  canvas,
  onContextMenu,
  ...props
}: Record<string, any>) {
  const value = useMemo(() => {
    return {
      eventNodes,
      activatedState,
      setCurrentNode,
      updateLayerNode,
      updateLayerEdge,
      changeLayerStatus,
      setCustomEvents,
      onContextMenu,
      onRoutingSwitch,
      clearCurrentNode,
      setEventNode,
      setActivatedState,
      setCanvas,
      canvas
    };
  }, [canvas, activatedState]);

  return <NodesContext.Provider value={value} {...props} />;
}

export { NodesContext, NodesProvider };
