import { ContentConfig } from "/@/components/PageContent";
import { httpList, httpStatus } from "/@/api/interest/dataShare";

import { h } from "vue";
import dayjs from "dayjs";
import { statusList } from "/@/utils/status";
import { userGroupProps, shareTypes } from "./configs";
import { ElTag } from "element-plus";

const columns = [
  {
    type: "selection",
    width: 40,
    align: "center",
    hide: ({ checkList }) => !checkList.includes("勾选列")
  },
  {
    label: "序号",
    type: "index",
    width: 70,
    hide: ({ checkList }) => !checkList.includes("序号列")
  },
  {
    label: "菜单数据",
    prop: userGroupProps.menu,
    cellRenderer({ row }) {
      return h("span", null, {
        default: () => row.menu_list.map(({ menu_name }) => menu_name).join(",")
      });
    }
  },
  {
    label: "数据源用户",
    width: 130,
    prop: "source_nickname"
  },
  {
    label: "数据源用户组",
    width: 130,
    prop: "source_group_title"
  },
  {
    label: "数据共享用户",
    width: 130,
    prop: "nickname"
  },
  {
    label: "数据共享用户组",
    width: 130,
    prop: "group_title"
  },
  {
    label: "状态",
    prop: userGroupProps.status,
    cellRenderer({ row }) {
      return h(
        ElTag,
        {
          type: row[userGroupProps.status] === "0" ? "warning" : ""
        },
        {
          default: () =>
            statusList.find(t => t.value === row.status)?.label || "--"
        }
      );
    }
  },
  {
    label: "共享权限",
    prop: userGroupProps.share,
    cellRenderer({ row }) {
      return h(ElTag, null, {
        default: () => shareTypes.find(t => t.value === row.type)?.label || "--"
      });
    }
  },
  {
    label: "创建时间",
    prop: "addTime",
    formatter: ({ addtime }) => dayjs(addtime).format("YYYY-MM-DD HH:mm:ss")
  },
  {
    label: "操作",
    fixed: "right",
    width: 120,
    slot: "operation"
  }
];

const contentConfig: ContentConfig = {
  title: "数据共享",
  powers: ["001", "002", "003", "004", "005", "006", "007", "008"],
  columns,
  isRequestArray: true,
  apis: {
    httpList,
    httpStatus,
    httpUpdate: true,
    httpAdd: true
  }
};

export default contentConfig;
