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

import { h } from "vue";
import dayjs from "dayjs";
import { userGroupProps, shareTypes } from "./configs";
import { statusList } from "/@/utils/status";
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 => Number(t.value) === Number(row[userGroupProps.status]))?.label || "--" }
      );
    }
  },
  {
    label: "共享类型",
    prop: userGroupProps.type,
    cellRenderer({ row }) {
      return h(ElTag, null, {
        default: () =>
          shareTypes.find(t => Number(t.value) === Number(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: 50,
    slot: "operation"
  }
];

const contentConfig: ContentConfig = {
  title: "用户组",
  columns,
  apis: {
    httpList,
  }
};

export default contentConfig;
