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

import { DictEnum } from '@vben/constants';

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

export const queryFormSchema: FormSchemaGetter = () => [
  {
    component: 'Input',
    fieldName: 'name',
    label: '名称',
  },
  {
    component: 'Select',
    componentProps: {
      options: getDictOptions(DictEnum.OIL_LOCATION_TYPE),
    },
    fieldName: 'oilLocationType',
    label: '位置类型',
  },
  {
    component: 'Select',
    componentProps: {
      options: getDictOptions(DictEnum.OIL_LEVEL),
    },
    fieldName: 'oilLevel',
    label: '油站级别',
  },
  {
    component: 'Select',
    componentProps: {
      options: getDictOptions(DictEnum.OIL_NETWORK_TYPE),
    },
    fieldName: 'oilNetworkType',
    label: '网络类型',
  },
  // {
  //   component: 'DatePicker',
  //   componentProps: {
  //     type: 'daterange',
  //     format: 'YYYY-MM-DD',
  //     valueFormat: 'YYYY-MM-DD',
  //     startPlaceholder: '开始日期',
  //     endPlaceholder: '结束日期',
  //   },
  //   fieldName: 'createTime',
  //   label: '创建时间',
  // },
];

export const tableColumns: VxeGridProps['columns'] = [
  {
    type: 'checkbox',
    width: 80,
  },
  {
    field: 'oilId',
    title: '油站编号',
  },
  {
    field: 'name',
    title: '油站名称',
  },
  {
    field: 'level',
    title: '油站等级',
    slots: {
      default: ({ row }) => {
        return renderDict(row.level, DictEnum.OIL_LEVEL);
      },
    },
  },
  {
    field: 'locationType',
    title: '位置类型',
    slots: {
      default: ({ row }) => {
        return renderDict(row.locationType, DictEnum.OIL_LOCATION_TYPE);
      },
    },
  },
  {
    field: 'location',
    title: '位置',
  },
  {
    field: 'networkType',
    title: '网络类型',
    slots: {
      default: ({ row }) => {
        return renderDict(row.networkType, DictEnum.OIL_NETWORK_TYPE);
      },
    },
  },

  {
    field: 'createTime',
    title: '创建时间',
  },
  {
    field: 'remark',
    title: '备注',
  },
  {
    field: 'action',
    fixed: 'right',
    slots: { default: 'action' },
    title: '操作',
  },
];

export const drawerFormSchema: FormSchemaGetter = () => [
  {
    component: 'Input',
    dependencies: {
      show: () => false,
      triggerFields: [''],
    },
    fieldName: 'configId',
  },
  {
    component: 'Input',
    fieldName: 'configName',
    label: '参数名称',
    componentProps: {
      maxlength: 100,
    },
    rules: 'required',
  },
  {
    component: 'Input',
    fieldName: 'configKey',
    label: '参数键名',
    componentProps: {
      maxlength: 100,
    },
    rules: 'required',
  },
  {
    component: 'Input',
    fieldName: 'configValue',
    label: '参数键值',
    componentProps: {
      maxlength: 500,
      type: 'textarea',
      showWordLimit: true,
    },
  },
  {
    component: 'RadioGroup',
    componentProps: {
      options: getDictOptions(DictEnum.SYS_YES_NO),
      isButton: true,
    },
    fieldName: 'configType',
    defaultValue: 'Y',
    label: '状态',
  },
  {
    component: 'Input',
    fieldName: 'remark',
    label: '备注',
    componentProps: {
      maxlength: 500,
      type: 'textarea',
      showWordLimit: true,
    },
  },
];
