import type { VxeGridProps } from '#/adapter/vxe-table';

import { getOaChatList } from '#/views/system/oa-chat/api';

interface RowType {
  id: number;
  platform_code: string;
  name: string;
  external_id: string;
  icon: string;
  sort: number;
  status: number;
  created_at: string;
}

/**
 * 群聊列表表格配置
 * 列表展示：ID、平台（slot 渲染中文名）、群聊名称、外部 ID、排序、状态、创建时间、操作
 */
export const gridOptions: VxeGridProps<RowType> = {
  checkboxConfig: {
    highlight: true,
    labelField: '',
  },
  columnConfig: {
    useKey: true,
  },
  rowConfig: {
    useKey: true,
  },
  columns: [
    { type: 'checkbox', width: 60 },
    { field: 'id', align: 'left', title: 'ID', width: 80 },
    {
      field: 'platform_code',
      align: 'left',
      title: '平台',
      width: 120,
      slots: { default: 'platform_code' },
    },
    { field: 'name', align: 'left', title: '群聊名称' },
    {
      field: 'chat_kind',
      align: 'left',
      title: '群类型',
      width: 110,
      slots: { default: 'chat_kind' },
    },
    { field: 'external_id', align: 'left', title: '外部群 ID', width: 180 },
    { field: 'owner_userid', align: 'left', title: '群主', width: 120 },
    { field: 'sort', align: 'left', title: '排序', width: 80 },
    {
      field: 'status',
      align: 'left',
      title: '状态',
      width: 100,
      slots: { default: 'status' },
    },
    { field: 'created_at', align: 'left', title: '创建时间', width: 180 },
    {
      type: 'html',
      title: '操作',
      slots: { default: 'action' },
      width: 200,
      fixed: 'right',
    },
  ],
  keepSource: true,
  pagerConfig: {},
  proxyConfig: {
    ajax: {
      query: async ({ page }, formValues) => {
        return await getOaChatList({
          page: page.currentPage,
          pageSize: page.pageSize,
          ...formValues,
        });
      },
    },
  },
  border: false,
  toolbarConfig: {
    search: true,
    refresh: true,
    print: false,
    export: false,
    zoom: true,
    slots: {
      buttons: 'toolbar-actions',
    },
    custom: {
      icon: 'vxe-icon-menu',
    },
  },
  showOverflow: false,
};
