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

import { formatVipExpireAt } from '#/utils/vip';

import { getVipStoreList } from '../api';

export const gridOptions: VxeGridProps<any> = {
  columnConfig: { useKey: true },
  rowConfig: { useKey: true, isHover: true },
  columns: [
    { field: 'store_id', title: '门店ID', width: 90 },
    { field: 'store_name', title: '门店名称', minWidth: 160 },
    {
      field: 'vip_badge',
      title: 'VIP徽标',
      width: 100,
      slots: { default: 'vip_badge' },
    },
    {
      field: 'duration_label',
      title: '会员类型',
      width: 110,
      formatter: ({ row }) => row.vip?.duration_label || '-',
    },
    {
      field: 'level_name',
      title: '会员等级',
      minWidth: 140,
      formatter: ({ row }) =>
        row.vip
          ? `${row.vip.level_name || ''}（${row.vip.level_code || ''}）`
          : '-',
    },
    {
      field: 'expire_at',
      title: '到期时间',
      width: 180,
      formatter: ({ row }) =>
        formatVipExpireAt(row.vip, { emptyText: '-', lifetimeText: '终身' }) ||
        '-',
    },
    { title: '操作', slots: { default: 'action' }, width: 100, fixed: 'right' },
  ],
  keepSource: true,
  pagerConfig: {},
  proxyConfig: {
    ajax: {
      query: async ({ page }, formValues) => {
        return await getVipStoreList({
          page: page.currentPage,
          pageSize: page.pageSize,
          ...formValues,
        });
      },
    },
  },
  border: false,
  toolbarConfig: { search: true, refresh: true, zoom: true },
};
