import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { EnergyHydrogenDetailApi } from '#/api/energy/hydrogen-detail';

import { useActionColumn } from '#/utils/table';
import { getRangePickerDefaultProps } from '#/utils';

export const AUDIT_STATUS_OPTIONS = [
  { label: '待审核', value: 0, color: 'orange' },
  { label: '已审核', value: 1, color: 'green' },
  { label: '审核驳回', value: 2, color: 'red' },
];

export const DEDUCTION_STATUS_OPTIONS = [
  { label: '未扣款', value: 0, color: 'default' },
  { label: '已扣款', value: 1, color: 'green' },
  { label: '扣款失败', value: 2, color: 'red' },
];

export const SETTLEMENT_STATUS_OPTIONS = [
  { label: '未结算', value: 0, color: 'default' },
  { label: '已结算', value: 1, color: 'green' },
];

/** 搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'stationName',
      label: '加氢站',
      component: 'Input',
      componentProps: {
        placeholder: '请输入加氢站',
        allowClear: true,
      },
    },
    {
      fieldName: 'customerName',
      label: '客户名称',
      component: 'Input',
      componentProps: {
        placeholder: '请输入客户名称',
        allowClear: true,
      },
    },
    {
      fieldName: 'plateNumber',
      label: '车牌号',
      component: 'Input',
      componentProps: {
        placeholder: '请输入车牌号',
        allowClear: true,
      },
    },
    {
      fieldName: 'hydrogenDate',
      label: '加氢日期',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        class: 'w-full',
      },
    },
    {
      fieldName: 'auditStatus',
      label: '审核状态',
      component: 'Select',
      componentProps: {
        options: AUDIT_STATUS_OPTIONS,
        placeholder: '请选择审核状态',
        allowClear: true,
      },
    },
    {
      fieldName: 'deductionStatus',
      label: '扣款状态',
      component: 'Select',
      componentProps: {
        options: DEDUCTION_STATUS_OPTIONS,
        placeholder: '请选择扣款状态',
        allowClear: true,
      },
    },
    {
      fieldName: 'settlementStatus',
      label: '结算状态',
      component: 'Select',
      componentProps: {
        options: SETTLEMENT_STATUS_OPTIONS,
        placeholder: '请选择结算状态',
        allowClear: true,
      },
    },
  ];
}

/** 表格列配置 */
export function useGridColumns(): VxeTableGridOptions<EnergyHydrogenDetailApi.Detail>['columns'] {
  return [
    {
      type: 'checkbox',
      width: 60,
      fixed: 'left',
    },
    {
      field: 'stationName',
      title: '加氢站',
      minWidth: 150,
      fixed: 'left',
    },
    {
      field: 'customerName',
      title: '客户名称',
      minWidth: 150,
    },
    {
      field: 'plateNumber',
      title: '车牌号',
      minWidth: 120,
    },
    {
      field: 'hydrogenDate',
      title: '加氢日期',
      minWidth: 120,
      formatter: 'formatDate',
      align: 'center',
    },
    {
      field: 'hydrogenQuantity',
      title: '加氢量',
      minWidth: 80,
      align: 'right',
    },
    {
      field: 'costPrice',
      title: '成本单价',
      minWidth: 80,
      align: 'right',
    },
    {
      field: 'costAmount',
      title: '成本金额',
      minWidth: 100,
      align: 'right',
    },
    {
      field: 'customerPrice',
      title: '对客单价',
      minWidth: 80,
      align: 'right',
    },
    {
      field: 'customerAmount',
      title: '对客金额',
      minWidth: 100,
      align: 'right',
    },
    {
      field: 'auditStatus',
      title: '审核状态',
      minWidth: 100,
      align: 'center',
      slots: { default: 'auditStatus' },
    },
    {
      field: 'deductionStatus',
      title: '扣款状态',
      minWidth: 100,
      align: 'center',
      slots: { default: 'deductionStatus' },
    },
    {
      field: 'settlementStatus',
      title: '结算状态',
      minWidth: 100,
      align: 'center',
      slots: { default: 'settlementStatus' },
    },
    useActionColumn(2),
  ];
}
