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

import { getVipLevelList } from '../api';
import { VIP_TIER_GROUP_OPTIONS } from './constants';

export const gridOptions: VxeGridProps<any> = {
  checkboxConfig: { highlight: true, labelField: '' },
  columnConfig: { useKey: true },
  rowConfig: { useKey: true, isHover: true },
  columns: [
    { type: 'checkbox', width: 60 },
    { field: 'id', title: 'ID', width: 70 },
    { field: 'code', title: '编码', width: 120 },
    { field: 'name', title: '名称', minWidth: 120 },
    {
      field: 'tier_group',
      title: '等级组',
      width: 90,
      formatter: ({ cellValue }) =>
        VIP_TIER_GROUP_OPTIONS.find((o) => o.value === cellValue)?.label || '-',
    },
    { field: 'level_weight', title: '权重', width: 80 },
    { field: 'badge_url', title: '等级徽标', width: 100, slots: { default: 'badge' } },
    { field: 'price', title: '标价', width: 100 },
    { field: 'status_txt', title: '状态', width: 80 },
    { field: 'sort', title: '排序', width: 80 },
    { field: 'created_at', title: '创建时间', width: 170 },
    { title: '操作', slots: { default: 'action' }, width: 160, fixed: 'right' },
  ],
  keepSource: true,
  pagerConfig: {},
  proxyConfig: {
    ajax: {
      query: async ({ page }, formValues) => {
        return await getVipLevelList({
          page: page.currentPage,
          pageSize: page.pageSize,
          ...formValues,
        });
      },
    },
  },
  border: false,
  toolbarConfig: {
    search: true,
    refresh: true,
    zoom: true,
    slots: { buttons: 'toolbar-actions' },
  },
};
