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

import { useUserStore } from '@vben/stores';

const userStore = useUserStore();

export const queryFormSchema: FormSchemaGetter = () => [
  {
    component: 'Select',
    fieldName: 'stationId',
    label: '油站',
    componentProps: {
      placeholder: '请选择油站',
      options: [
        { label: '油站1', value: 1 },
        { label: '油站2', value: 2 },
        { label: '油站3', value: 3 },
      ],
    },
  },
  {
    component: 'DatePicker',
    fieldName: 'operatedStartTime',
    label: '开始时间',
    componentProps: {
      placeholder: '请选择开始时间',
      type: 'date',
      format: 'YYYY-MM-DD',
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
      style: {
        width: '100%',
      },
    },
  },
  {
    component: 'DatePicker',
    fieldName: 'operatedEndTime',
    label: '结束时间',
    componentProps: {
      placeholder: '请选择结束时间',
      type: 'date',
      format: 'YYYY-MM-DD',
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
      style: {
        width: '100%',
      },
    },
  },
  {
    component: 'Input',
    fieldName: 'filterModel',
    label: '过滤器型号',
    componentProps: {
      placeholder: '请输入过滤器型号',
    },
  },
  {
    component: 'Input',
    fieldName: 'filterNumber',
    label: '过滤器编号',
    componentProps: {
      placeholder: '请输入过滤器编号',
    },
  },
];

export const tableColumns: VxeGridProps['columns'] = [
  {
    type: 'checkbox',
    width: 80,
  },
  {
    field: 'stationName',
    title: '油站',
    minWidth: 150,
  },
  {
    field: 'filterNumber',
    title: '过滤器编号',
    minWidth: 180,
  },
  {
    field: 'filterModel',
    title: '过滤器型号',
    minWidth: 150,
  },
  {
    field: 'oilMachineModel',
    title: '油机型号',
    minWidth: 150,
  },
  {
    field: 'relatedGuns',
    title: '关联油枪',
    minWidth: 120,
  },
  {
    field: 'relatedOilTypes',
    title: '关联油品',
    minWidth: 120,
  },
  {
    field: 'totalFilteredLiters',
    title: '累计过滤升数',
    minWidth: 180,
  },
  {
    field: 'nextReplacementDate',
    title: '下次更换日期',
    minWidth: 150,
  },
  {
    field: 'createBy',
    title: '创建人',
    minWidth: 120,
  },
  {
    field: 'createTime',
    title: '创建时间',
    minWidth: 180,
  },
  {
    field: 'action',
    fixed: 'right',
    slots: { default: 'action' },
    title: '操作',
    width: 150,
  },
];

export const drawerFormSchema: FormSchemaGetter = () => [
  {
    component: 'Input',
    dependencies: {
      show: () => false,
      triggerFields: [''],
    },
    fieldName: 'id',
  },
  {
    component: 'Select',
    componentProps: {
      placeholder: '请选择场站',
      options: (userStore.userInfo?.stations || []).map((item: any) => {
        return {
          label: item.stationName,
          value: item.id,
        };
      }),
    },
    fieldName: 'stationId',
    label: '场站',
    rules: 'required',
  },
  {
    component: 'Input',
    fieldName: 'filterNumber',
    label: '过滤器编号',
    componentProps: {
      placeholder: '请输入过滤器编号',
      maxlength: 100,
    },
    rules: 'required',
  },
  {
    component: 'Input',
    fieldName: 'filterModel',
    label: '过滤器型号',
    componentProps: {
      placeholder: '请输入过滤器型号',
      maxlength: 100,
    },
    rules: 'required',
  },
  {
    component: 'Input',
    fieldName: 'oilMachineModel',
    label: '油机型号',
    componentProps: {
      placeholder: '请输入油机型号',
      maxlength: 100,
    },
    rules: 'required',
  },
  {
    component: 'Input',
    fieldName: 'relatedGuns',
    label: '关联油枪',
    componentProps: {
      placeholder: '请输入关联油枪',
      maxlength: 50,
    },
    rules: 'required',
  },
  {
    component: 'Input',
    fieldName: 'relatedOilTypes',
    label: '关联油品',
    componentProps: {
      placeholder: '请输入关联油品',
      maxlength: 50,
    },
    rules: 'required',
  },

  {
    component: 'DatePicker',
    fieldName: 'nextReplacementDate',
    label: '下次更换日期',
    componentProps: {
      placeholder: '请选择下次更换日期',
      type: 'date',
      format: 'YYYY-MM-DD',
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
    },
    rules: 'required',
  },
  {
    component: 'Select',
    fieldName: 'maintenanceType',
    label: '维护类型',
    componentProps: {
      placeholder: '请选择维护类型',
      options: [
        { label: '检查', value: '检查' },
        { label: '更换', value: '更换' },
      ],
    },
    rules: 'required',
  },
  {
    component: 'InputNumber',
    fieldName: 'currentMeterReading',
    label: '现油表数(L)',
    componentProps: {
      placeholder: '请输入现油表走字数',
      min: 0,
      step: 0.1,
      style: {
        width: '100%',
      },
    },
  },
  {
    component: 'InputNumber',
    fieldName: 'lastMeterReading',
    label: '上次油表数(L)',
    componentProps: {
      placeholder: '请输入上次油表走字数',
      min: 0,
      step: 0.1,
      style: {
        width: '100%',
      },
    },
  },
  {
    component: 'InputNumber',
    fieldName: 'flowRateBefore',
    label: '更换前流速',
    componentProps: {
      placeholder: '请输入更换前流速(L/min)',
      min: 0,
      step: 0.1,
      style: {
        width: '100%',
      },
    },
  },
  {
    component: 'InputNumber',
    fieldName: 'flowRateAfter',
    label: '更换后流速',
    componentProps: {
      placeholder: '请输入更换后流速(L/min)',
      min: 0,
      step: 0.1,
      style: {
        width: '100%',
      },
    },
  },
];
