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

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

const userStore = useUserStore();

// 获取状态字典选项
const getStatusOptions = () => [
  { label: '启用', value: '1' },
  { label: '禁用', value: '0' },
];

export const queryFormSchema: FormSchemaGetter = () => [
  {
    component: 'Select',
    fieldName: 'stationId',
    label: '我方油站',
    componentProps: {
      placeholder: '请输入我方油站名称',
      options: (userStore.userInfo?.stations || []).map((item: any) => {
        return {
          label: item.stationName,
          value: item.id,
        };
      }),
    },
  },
  {
    component: 'Input',
    fieldName: 'personName',
    label: '人员姓名',
    componentProps: {
      placeholder: '请输入人员姓名',
    },
  },
  {
    component: 'Input',
    fieldName: 'vehicleNumber',
    label: '车辆号码',
    componentProps: {
      placeholder: '请输入车辆号码',
    },
  },
  {
    component: 'Select',
    componentProps: {
      placeholder: '请选择状态',
      options: getStatusOptions(),
    },
    fieldName: 'statusCode',
    label: '状态',
  },
];

export const tableColumns: VxeGridProps['columns'] = [
  {
    type: 'checkbox',
    width: 80,
  },
  {
    field: 'stationName',
    title: '我方油站',
    minWidth: 120,
  },
  {
    field: 'personName',
    title: '人员姓名',
    minWidth: 100,
  },
  {
    field: 'vehicleNumber',
    title: '车辆号码',
    minWidth: 120,
  },
  {
    field: 'updateBy',
    title: '操作人姓名',
    minWidth: 120,
  },
  {
    field: 'updateTime',
    title: '操作时间',
    minWidth: 150,
  },
  {
    field: 'statusCode',
    title: '状态',
    minWidth: 100,
    formatter: ({ row }) => {
      const status = getStatusOptions().find(
        (item) => item.value === row.statusCode,
      );
      return status?.label || '-';
    },
  },
  {
    field: 'action',
    fixed: 'right',
    slots: { default: 'action' },
    title: '操作',
    width: 150,
  },
];

export const drawerFormSchema: FormSchemaGetter = () => [
  {
    component: 'Input',
    dependencies: {
      show: () => false,
      triggerFields: [''],
    },
    fieldName: 'id',
  },
  {
    component: 'Select',
    fieldName: 'stationId',
    label: '油站',
    componentProps: {
      placeholder: '请输入油站名称',
      maxlength: 100,
      options: (userStore.userInfo?.stations || []).map((item: any) => {
        return {
          label: item.stationName,
          value: item.id,
        };
      }),
    },
    rules: 'required',
  },
  {
    component: 'Input',
    fieldName: 'personName',
    label: '人员姓名',
    componentProps: {
      placeholder: '请输入人员姓名',
      maxlength: 50,
    },
    rules: 'required',
  },
  {
    component: 'Input',
    fieldName: 'vehicleNumber',
    label: '车辆号码',
    componentProps: {
      placeholder: '请输入车辆号码',
      maxlength: 20,
    },
    rules: 'required',
  },

  {
    component: 'Upload',
    fieldName: 'driverLicensePath',
    label: '驾驶证图片',
    componentProps: {
      action: '#',
      multiple: false,
    },
  },
  {
    component: 'Upload',
    fieldName: 'vehicleLicensePath',
    label: '行驶证图片',
    componentProps: {
      action: '#',
      multiple: false,
    },
  },
  {
    component: 'Upload',
    fieldName: 'trafficRouteBookPath',
    label: '交通路书图片',
    componentProps: {
      action: '#',
      multiple: false,
    },
  },
  {
    component: 'Upload',
    fieldName: 'vehicleFullViewPath',
    label: '车辆全貌图片',
    componentProps: {
      action: '#',
      multiple: false,
    },
  },
  {
    component: 'Input',
    componentProps: {
      options: getStatusOptions(),
      isButton: true,
    },
    fieldName: 'desc',
    defaultValue: '',
    label: '',
    description: '',
    slots: {
      default: 'desc',
    },
  },
  {
    component: 'RadioGroup',
    componentProps: {
      options: getStatusOptions(),
      isButton: true,
    },
    fieldName: 'statusCode',
    defaultValue: 1,
    label: '状态',
  },
];
