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

import { getDictOptions } from '#/utils/dict';

// 字典标识常量
const DICT_KEYS = {
  // 损溢类型字典标识
  LOSS_GAIN_TYPE: 'loss_gain_type',
};

// 获取损溢类型字典选项
const getLossGainTypeOptions = () => getDictOptions(DICT_KEYS.LOSS_GAIN_TYPE);

export const queryFormSchema: FormSchemaGetter = () => [];

export const tableColumns: VxeGridProps['columns'] = [
  {
    type: 'checkbox',
    width: 80,
  },
  {
    field: 'lossGainType',
    title: '损益计算值',
    minWidth: 120,
    align: 'center',
    formatter: (params: { cellValue: string; column: any; row: any }) => {
      const options = getLossGainTypeOptions();
      const option = options.find((item) => item.value === params.cellValue);
      return option ? option.label : params.cellValue;
    },
  },
  {
    field: 'oilProduct',
    title: '油品',
    minWidth: 150,
    align: 'center',
  },
  {
    field: 'greaterThan',
    title: '大于',
    minWidth: 100,
    align: 'center',
  },
  {
    field: 'lessThan',
    title: '小于',
    minWidth: 100,
    align: 'center',
  },
  {
    field: 'source',
    title: '来源',
    minWidth: 100,
    align: 'center',
    formatter: ({ cellValue }) => {
      return cellValue === 0 ? '默认' : '新增';
    },
  },
  {
    field: 'action',
    fixed: 'right',
    slots: { default: 'action' },
    title: '操作',
    width: 150,
    align: 'center',
  },
];

export const drawerFormSchema: FormSchemaGetter = () => [
  {
    component: 'Input',
    dependencies: {
      show: () => false,
      triggerFields: [''],
    },
    fieldName: 'id',
  },
  {
    component: 'Select',
    fieldName: 'lossGainType',
    label: '损益计算值',
    componentProps: {
      placeholder: '请选择损益计算值',
      options: getLossGainTypeOptions(),
    },
    rules: 'required',
  },
  {
    component: 'Input',
    fieldName: 'oilProduct',
    label: '油品',
    componentProps: {
      placeholder: '请输入油品',
      maxlength: 100,
      
    },
    rules: 'required',
  },
  {
    component: 'InputNumber',
    fieldName: 'greaterThan',
    label: '大于',
    componentProps: {
      placeholder: '请输入大于值',
      step: 0.01,
      style: {
        width: '100%',
      },
    },
    rules: 'required',
  },
  {
    component: 'InputNumber',
    fieldName: 'lessThan',
    label: '小于',
    componentProps: {
      placeholder: '请输入小于值',
      step: 0.01,
      style: {
        width: '100%',
      },
    },
    rules: 'required',
  },
  {
    component: 'Input',
    dependencies: {
      show: () => false,
      triggerFields: [''],
    },
    fieldName: 'source',
    defaultValue: 1,
  },
];


