import type { VxeTableGridOptions } from '@vben/plugins/vxe-table';

import type { VbenFormSchema } from '#/adapter/form';

import { DICT_TYPE } from '@vben/constants';
import { getDictOptions } from '@vben/hooks';

import { getRangePickerDefaultProps } from '#/utils';

/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'userId',
      label: '用户编号',
      component: 'Input',
      componentProps: {
        placeholder: '请输入用户编号',
      },
    },
    {
      fieldName: 'userType',
      label: '用户类型',
      component: 'Select',
      componentProps: {
        options: getDictOptions(DICT_TYPE.USER_TYPE, 'number'),
        placeholder: '请选择用户类型',
      },
    },
    {
      fieldName: 'createTime',
      label: '创建时间',
      component: 'RangePicker',
      componentProps: {
        allowClear: true,
        ...getRangePickerDefaultProps(),
        placeholder: ['开始日期', '结束日期'],
      },
    },
  ];
}

/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions['columns'] {
  return [
    {
      title: '编号',
      field: 'id',
    },
    {
      title: '用户编号',
      field: 'userId',
    },
    {
      title: '用户类型',
      field: 'userType',
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_TYPE.USER_TYPE },
      },
    },
    {
      title: '余额',
      field: 'balance',
      formatter: 'formatAmount2',
    },
    {
      title: '累计支出',
      field: 'totalExpense',
      formatter: 'formatAmount2',
    },
    {
      title: '累计充值',
      field: 'totalRecharge',
      formatter: 'formatAmount2',
    },
    {
      title: '冻结金额',
      field: 'freezePrice',
      formatter: 'formatAmount2',
    },
    {
      title: '创建时间',
      field: 'createTime',
      formatter: 'formatDateTime',
    },
    {
      title: '操作',
      field: 'actions',
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}
