// 这里是 vue-flow 自定义的组件的types集合
import { markRaw } from "vue";
import type { Node, Edge } from "@vue-flow/core";

import CommonEdge from "../edges/commonEdge.vue";

import CommonNode from "../nodes/CommonNode.vue";
import NestNode from "../nodes/NestNode.vue";
import NumberInputNode from "../nodes/NumberInputNode.vue";
import NumberFunctionNode from "../nodes/NumberFunNode.vue";
import NumberResultNode from "../nodes/NumberResultNode.vue";

import UniversalNode from "../nodes/universal/UniversalNode.vue";
// 工作流相关
import WorkFlowNode from "../nodes/workflow/WorkFlowNode.vue";

export enum HJNodeType {
  custom = "custom",
  nest = "nest",
  //   算数相关
  numberInput = "number-input",
  numberFunction = "number-function",
  numberResult = "number-result",
  //   工作流相关
  workFlow = "work-flow",
  //   公共 通用 上面是header 下面是content
  universal = "universal",
}

export const nodeTypes = {
  [HJNodeType.custom]: markRaw(CommonNode),
  [HJNodeType.nest]: markRaw(NestNode),
  //   算数相关
  [HJNodeType.numberInput]: markRaw(NumberInputNode),
  [HJNodeType.numberFunction]: markRaw(NumberFunctionNode),
  [HJNodeType.numberResult]: markRaw(NumberResultNode),
  [HJNodeType.workFlow]: markRaw(WorkFlowNode),

  [HJNodeType.universal]: markRaw(UniversalNode),
};

export const edgeTypes = {
  default: markRaw(CommonEdge),
};

// 用于Handle
export enum HJPosition {
  Left = "left",
  Top = "top",
  Right = "right",
  Bottom = "bottom",
}

export interface HJHandle {
  type: "source" | "target";
  position: HJPosition;
  style?: any; //如果同一侧有多个handle，可以用style调整位置
  other?: string; //预留字段，以后看可能不同的node类型需要不同的handle样式，通过这个引入不同的Handlevue 文件
}

// 用于Node 类型中的data，方便拓展选中 拖拽等数据
export interface HJNodeDataModel {
  label: string;
  isSelected?: boolean;
  isDragging?: boolean;
  handles?: HJHandle[];
  information?: any; //点击node节点 弹出drawer编辑的数据
}

// 用于<VueFlow>组件的nodes属性的类型定义 从外部导入数据需要使用
export interface HJNodeData extends Partial<Node> {
  jsonData?: string; //经实验发现nodeTypes这种方法无法传递 Node之外的key，给props扩展也没有用， 也就是自定义的nodes里面拿不到这个key
  data: HJNodeDataModel;
}

// 这个类型用于自定义node节点内部的数据结构，忽略一些数据能提升渲染时候的性能，
export type HJInterNodeData = Omit<HJNodeData, "jsonData">;

// 在顶层组件订一个方法，通过provide方法提供给其他组件使用
export const HJMethodProvideName = "hjMethodProvideName";
export const CurrentHeaderOperationProvideName =
  "hjCurrentHeaderOperationProvideName";
export const CurrentSelectedEdgeProvideName =
  "hjCurrentSelectedEdgeProvideName";
export class HJMethodName {
  static AddNode = "hjAddNode";
  static EditNode = "hjEditNode";
  static SaveTemplate = "hjSaveTemplate";
}
export type GrandparentMethod = (name: HJMethodName, param: HJNodeData) => void;

// Panel相关 HJPanelFunName添加一个  就在数组种写一个
export type HJPanelFunName =
  | "addNode"
  | "reset"
  | "layoutLR"
  | "layoutTB"
  | "toSnake"
  | "back"
  | "saveTemplate";
export const HJPanelFunNameArray = [
  "addNode",
  "reset",
  "layoutLR",
  "layoutTB",
  "toSnake",
  "back",
];

// 外面会传给HJFlow的props
export interface HJFlowProps {
  // Pannel相关
  panelBtns?: HJPanelFunName[]; //自定义面板按钮 默认空
  showPanel?: boolean; // 默认为false，不显示面板
}

export interface HJFlowInstance {
  updateNodeData: (node: HJNodeData) => void;
  initFlow: (nodes: HJNodeData[], edges: any[]) => void;
  clearStatus: () => void;
  getChangedStatus: () => boolean;
}
