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

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

interface RowType {
  id: number;
  order_no: string;
  status: number;
}

/**
 * 开票中心表格配置；statusFilter 由页面注入当前 Tab 状态
 */
export function createGridOptions(getStatus: () => string | number): VxeGridProps<RowType> {
  return {
    checkboxConfig: {
      highlight: true,
      labelField: '',
    },
    columns: [
      { field: 'id', title: 'ID', width: 70 },
      { field: 'order_no', title: '订单号', minWidth: 160 },
      { field: 'store_name', title: '诊所', minWidth: 140 },
      { field: 'title_type_text', title: '抬头类型', width: 90 },
      { field: 'title_name', title: '抬头名称', minWidth: 120 },
      { field: 'amount', title: '金额', width: 100 },
      { field: 'party_progress', title: '分账进度', width: 100, slots: { default: 'party_progress' } },
      { field: 'receive_type_text', title: '接收方式', width: 100 },
      { field: 'email', title: '邮箱', minWidth: 160 },
      { field: 'status_text', title: '状态', width: 90, slots: { default: 'status' } },
      { field: 'created_at', title: '申请时间', minWidth: 160 },
      {
        title: '操作',
        align: 'right',
        slots: { default: 'action' },
        width: 260,
        fixed: 'right',
      },
    ],
    keepSource: true,
    pagerConfig: {},
    columnConfig: { useKey: true },
    rowConfig: { useKey: true },
    proxyConfig: {
      ajax: {
        query: async ({ page }, formValues) => {
          const status = getStatus();
          return await getInvoiceCenterListApi({
            page: page.currentPage,
            pageSize: page.pageSize,
            status: status === '' || status === 'all' ? '' : status,
            ...formValues,
          });
        },
      },
    },
    height: 'auto',
    border: false,
    toolbarConfig: {
      // @ts-ignore
      search: true,
      refresh: true,
      print: false,
      export: false,
      zoom: true,
      slots: { buttons: 'toolbar-actions' },
    },
    showOverflow: false,
  };
}
