import { ContentConfig } from "/@/components/PageContent";

import dayjs from "dayjs";
import {
  httpList,
  httpAdd,
  httpStatus,
  httpDelete
} from "/@/api/parameter/setActionProcess";
import { h } from "vue";
import { ElTag } from "element-plus";
import { actionTypes, operactionTypes } from "./configs";

const columns = [
  {
    type: "selection",
    width: 40,
    align: "center",
    hide: ({ checkList }) => !checkList.includes("勾选列")
  },
  {
    label: "序号",
    type: "index",
    width: 70,
    hide: ({ checkList }) => !checkList.includes("序号列")
  },
  {
    label: "节点名称",
    prop: "status_name"
  },
  {
    label: "节点值",
    prop: "order_process"
  },
  {
    label: "节点类型",
    prop: "status",
    cellRenderer({ row }) {
      return h(ElTag, null, {
        default: () =>
          actionTypes.find(type => type.value === row.action_type)?.label
      });
    }
  },
  {
    label: "操作类型",
    prop: "status",
    cellRenderer({ row }) {
      return h(ElTag, null, {
        default: () =>
          operactionTypes.find(type => type.value === row.operation_type)?.label
      });
    }
  },
  {
    label: "状态",
    prop: "status",
    cellRenderer({ row }) {
      return h(
        ElTag,
        {
          type: row.status === "0" ? "danger" : "success"
        },
        {
          default: () => (row.status === "1" ? "启用" : "禁用")
        }
      );
    }
  },
  {
    label: "下一节点",
    prop: "status",
    width: "200px",
    cellRenderer({ row }) {
      return h("div", null, {
        default: () =>
          row.next_actions.map(n =>
            h(
              ElTag,
              {
                style: {
                  marginRight: "10px"
                }
              },
              {
                default: () => n
              }
            )
          )
      });
    }
  },
  {
    label: "创建人",
    prop: "creater"
  },
  {
    label: "创建时间",
    prop: "addtime",
    formatter: ({ addtime }) => dayjs(addtime).format("YYYY-MM-DD HH:mm:ss")
  },
  {
    label: "操作",
    fixed: "right",
    width: 150,
    slot: "operation"
  }
];

const contentConfig: ContentConfig = {
  title: "流程节点设置",
  notNeedCompanyFilter: true,
  columns,
  notReuqiredInit: true,
  apis: {
    httpAdd,
    httpList,
    httpStatus,
    httpUpdate: true,
    httpDelete
  }
};

export default contentConfig;
