import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { EnergyStationConfigApi } from '#/api/energy/station-config';

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

export const DEDUCT_MODE_OPTIONS = [
  { label: '审核即扣款', value: true },
  { label: '出账单后扣款', value: false },
];

export const AUTO_MATCH_OPTIONS = [
  { label: '开启', value: true },
  { label: '关闭', value: false },
];

export const COOPERATION_TYPE_OPTIONS = [
  { label: '预充值', value: 1 },
  { label: '月结算', value: 2 },
];

/** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] {
  return [
    {
      component: 'Input',
      fieldName: 'id',
      dependencies: {
        triggerFields: [''],
        show: () => false,
      },
    },
    {
      fieldName: 'stationId',
      label: '加氢站',
      component: 'InputNumber',
      componentProps: {
        placeholder: '请输入加氢站ID',
        style: { width: '100%' },
      },
      rules: 'required',
    },
    {
      fieldName: 'cooperationType',
      label: '合作模式',
      component: 'RadioGroup',
      componentProps: {
        options: COOPERATION_TYPE_OPTIONS,
        buttonStyle: 'solid',
        optionType: 'button',
      },
      rules: 'required',
    },
    {
      fieldName: 'autoDeduct',
      label: '扣款模式',
      component: 'RadioGroup',
      componentProps: {
        options: DEDUCT_MODE_OPTIONS,
        buttonStyle: 'solid',
        optionType: 'button',
      },
      rules: 'required',
    },
    {
      fieldName: 'autoMatch',
      label: '自动匹配',
      component: 'Select',
      componentProps: {
        options: AUTO_MATCH_OPTIONS,
        placeholder: '请选择是否开启自动匹配',
      },
      rules: 'required',
    },
    {
      fieldName: 'remark',
      label: '备注',
      component: 'Textarea',
      componentProps: {
        placeholder: '请输入备注',
        rows: 3,
      },
    },
  ];
}

/** 搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'stationName',
      label: '站点名称',
      component: 'Input',
      componentProps: {
        placeholder: '请输入站点名称',
        allowClear: true,
      },
    },
    {
      fieldName: 'autoDeduct',
      label: '扣款模式',
      component: 'Select',
      componentProps: {
        options: DEDUCT_MODE_OPTIONS,
        placeholder: '请选择扣款模式',
        allowClear: true,
      },
    },
  ];
}

/** 表格列配置 */
export function useGridColumns(): VxeTableGridOptions<EnergyStationConfigApi.Config>['columns'] {
  return [
    {
      field: 'stationName',
      title: '站点名称',
      minWidth: 150,
      fixed: 'left',
    },
    {
      field: 'cooperationType',
      title: '合作模式',
      minWidth: 120,
      slots: { default: 'cooperationType' },
    },
    {
      field: 'autoDeduct',
      title: '扣款模式',
      minWidth: 130,
      slots: { default: 'autoDeduct' },
    },
    {
      field: 'autoMatch',
      title: '自动匹配',
      minWidth: 100,
      slots: { default: 'autoMatch' },
    },
    {
      field: 'createTime',
      title: '创建时间',
      minWidth: 180,
      formatter: 'formatDateTime',
    },
    useActionColumn(1),
  ];
}
