import { ref } from "vue";
import dayjs from "dayjs";
import { useRenderIcon } from "/@/components/ReIcon/src/hooks";

export function useColumns() {
  const columns = ref([
    {
      type: "selection",
      minWidth: 55,
      align: "left",
      hide: ({ checkList }) => !checkList.includes("勾选列")
    },
    {
      label: "序号",
      type: "index",
      minWidth: 60,
      align: "left",
      hide: ({ checkList }) => !checkList.includes("序号列")
    },
    {
      label: "名称",
      prop: "menu_name",
      minWidth: 180,
      align: "left"
    },
    {
      label: "图标",
      prop: "menu_img",
      minWidth: 80,
      cellRenderer: ({ row, props }) => (
        <IconifyIconOnline icon={row.menu_img} />
      )
    },
    {
      label: "path",
      prop: "menu_route",
      minWidth: 180,
      align: "left"
    },
    {
      label: "权重",
      prop: "weight",
      minWidth: 60
    },
    {
      label: "类型",
      prop: "menu_type",
      minWidth: 80,
      cellRenderer: ({ row, props }) => (
        <el-tag
          size={props.size}
          type={row.menu_type + "" === "1" ? "success" : "danger"}
          effect="plain"
        >
          {row.menu_type + "" === "1" ? "菜单" : "页面"}
        </el-tag>
      )
    },
    {
      label: "状态",
      prop: "status",
      minWidth: 80,
      cellRenderer: ({ row, props }) => (
        <el-tag
          size={props.size}
          type={row.status + "" === "1" ? "success" : "danger"}
          effect="plain"
        >
          {row.status + "" === "0" ? "禁用" : "启用"}
        </el-tag>
      )
    },
    {
      label: "页面路径",
      prop: "menu_url",
      minWidth: 180,
      align: "left"
    },
    {
      label: "创建时间",
      width: 155,
      prop: "createTime",
      formatter: ({ createTime }) =>
        dayjs(createTime).format("YYYY-MM-DD HH:mm:ss")
    },
    {
      label: "操作",
      fixed: "right",
      width: 180,
      slot: "operation"
    }
  ]);

  return {
    columns
  };
}
