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

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.name
  },
  {
    label: "组成员",
    prop: "nickname"
  },
  {
    label: "状态",
    prop: userGroupProps.status,
    cellRenderer({ row }) {
      return h(
        ElTag,
        {
          type: row.status === "0" ? "warning" : ""
        },
        {
          default: () =>
            statusList.find(t => t.value === row[userGroupProps.status])
              ?.label || "--"
        }
      );
    }
  },
  {
    label: "共享类型",
    prop: userGroupProps.type,
    cellRenderer({ row }) {
      return h(ElTag, null, {
        default: () =>
          shareTypes.find(t => t.value === row[userGroupProps.type])?.label ||
          "--"
      });
    }
  },
  {
    label: "备注",
    prop: userGroupProps.remark
  },
  {
    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"],
  isRequesetArray: true,
  columns,
  apis: {
    httpList,
    httpStatus,
    httpUpdate: true,
    httpAdd: true
  }
};

export default contentConfig;
