import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import { z } from '#/adapter/form';
import { useActionColumn } from '#/utils/table';

/** 新增/修改的表单 - 基本信息 */
export function useBasicFormSchema(): VbenFormSchema[] {
  return [
    {
      component: 'Input',
      fieldName: 'id',
      dependencies: {
        triggerFields: [''],
        show: () => false,
      },
    },
    {
      fieldName: 'brand',
      label: '品牌',
      component: 'Input',
      componentProps: {
        placeholder: '请输入品牌，如：帕力安牌',
      },
      rules: z.string().min(1, { message: '请输入品牌' }),
    },
    {
      fieldName: 'model',
      label: '型号',
      component: 'Input',
      componentProps: {
        placeholder: '请输入型号，如：XDQ504LXCFCEV01',
      },
      rules: z.string().min(1, { message: '请输入型号' }),
    },
    {
      fieldName: 'vehicleType',
      label: '车辆类型',
      component: 'Input',
      componentProps: {
        placeholder: '请输入车辆类型，如：轻型箱式货车',
      },
      rules: z.string().min(1, { message: '请输入车辆类型' }),
    },
    {
      fieldName: 'modelLabel',
      label: '型号标签',
      component: 'Input',
      componentProps: {
        placeholder: '请输入型号标签，如：4.5T冷链车',
      },
      rules: z.string().min(1, { message: '请输入型号标签' }),
    },
    {
      fieldName: 'fuelType',
      label: '燃料种类',
      component: 'Select',
      componentProps: {
        placeholder: '请选择燃料种类',
        options: [
          { label: '氢', value: '氢' },
          { label: '电', value: '电' },
          { label: '柴油', value: '柴油' },
          { label: '氢电混合', value: '氢电混合' },
        ],
      },
      rules: z.string().min(1, { message: '请选择燃料种类' }),
    },
    {
      fieldName: 'plateColor',
      label: '车牌颜色',
      component: 'Select',
      componentProps: {
        placeholder: '请选择车牌颜色',
        options: [
          { label: '绿牌', value: '绿牌' },
          { label: '黄牌', value: '黄牌' },
          { label: '黄绿牌', value: '黄绿牌' },
        ],
      },
      rules: z.string().min(1, { message: '请选择车牌颜色' }),
    },
  ];
}

/** 新增/修改的表单 - 车辆尺寸 */
export function useSizeFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'truckSize_x',
      label: '车辆长度(mm)',
      component: 'Input',
      componentProps: {
        placeholder: '请输入车辆长度',
      },
    },
    {
      fieldName: 'truckSize_y',
      label: '车辆宽度(mm)',
      component: 'Input',
      componentProps: {
        placeholder: '请输入车辆宽度',
      },
    },
    {
      fieldName: 'truckSize_z',
      label: '车辆高度(mm)',
      component: 'Input',
      componentProps: {
        placeholder: '请输入车辆高度',
      },
    },
    {
      fieldName: 'tireSize',
      label: '轮胎规格',
      component: 'Input',
      componentProps: {
        placeholder: '请输入轮胎规格',
      },
    },
    {
      fieldName: 'tireNumber',
      label: '轮胎数量',
      component: 'InputNumber',
      componentProps: {
        placeholder: '请输入轮胎数量',
        min: 1,
        style: { width: '100%' },
      },
    },
  ];
}

/** 新增/修改的表单 - 电池信息 */
export function useBatteryFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'batteryType',
      label: '电池类型',
      component: 'Select',
      componentProps: {
        placeholder: '请选择电池类型',
        options: [
          { label: '磷酸铁锂', value: '磷酸铁锂' },
          { label: '三元锂', value: '三元锂' },
        ],
      },
    },
    {
      fieldName: 'batteryFactory',
      label: '电池厂家',
      component: 'Input',
      componentProps: {
        placeholder: '请输入电池厂家',
      },
    },
    {
      fieldName: 'reserveElectricity',
      label: '储电量(kwh)',
      component: 'InputNumber',
      componentProps: {
        placeholder: '请输入储电量',
        min: 0,
        precision: 2,
        style: { width: '100%' },
      },
    },
    {
      fieldName: 'electricityMileage',
      label: '电续航里程(KM)',
      component: 'InputNumber',
      componentProps: {
        placeholder: '请输入电续航里程',
        min: 0,
        style: { width: '100%' },
      },
    },
  ];
}

/** 新增/修改的表单 - 氢能信息 */
export function useHydrogenFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'hydrogenCapacity',
      label: '氢瓶容量(L)',
      component: 'InputNumber',
      componentProps: {
        placeholder: '请输入氢瓶容量',
        min: 0,
        style: { width: '100%' },
      },
    },
    {
      fieldName: 'hydrogenFactory',
      label: '供氢系统厂家',
      component: 'Input',
      componentProps: {
        placeholder: '请输入供氢系统厂家',
      },
    },
    {
      fieldName: 'hydrogenUnit',
      label: '仪表盘氢气单位',
      component: 'Select',
      componentProps: {
        placeholder: '请选择氢气单位',
        options: [
          { label: '%', value: '%' },
          { label: 'MPa', value: 'MPa' },
          { label: 'Kg', value: 'Kg' },
        ],
      },
    },
    {
      fieldName: 'hydrogenMileage',
      label: '氢续航里程(KM)',
      component: 'InputNumber',
      componentProps: {
        placeholder: '请输入氢续航里程',
        min: 0,
        style: { width: '100%' },
      },
    },
  ];
}

/** 新增/修改的表单 - 其他信息 */
export function useOtherFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'refrigeratorFactory',
      label: '冷机厂家',
      component: 'Input',
      componentProps: {
        placeholder: '请输入冷机厂家',
      },
    },
    {
      fieldName: 'onlineSpreadEnterprise',
      label: '电堆厂家',
      component: 'Input',
      componentProps: {
        placeholder: '请输入电堆厂家',
      },
    },
  ];
}

/** 搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'brand',
      label: '品牌',
      component: 'Input',
      componentProps: {
        placeholder: '请输入品牌',
      },
    },
    {
      fieldName: 'model',
      label: '型号',
      component: 'Input',
      componentProps: {
        placeholder: '请输入型号',
      },
    },
    {
      fieldName: 'fuelType',
      label: '燃料种类',
      component: 'Select',
      componentProps: {
        placeholder: '请选择燃料种类',
        allowClear: true,
        options: [
          { label: '氢', value: '氢' },
          { label: '电', value: '电' },
          { label: '柴油', value: '柴油' },
          { label: '氢电混合', value: '氢电混合' },
        ],
      },
    },
  ];
}

/** 表格列配置 */
export function useGridColumns(): VxeTableGridOptions['columns'] {
  return [
    { type: 'checkbox', width: 60, fixed: 'left' },
    {
      field: 'brand',
      title: '品牌',
      minWidth: 120,
      fixed: 'left',
    },
    {
      field: 'model',
      title: '型号',
      minWidth: 150,
    },
    {
      field: 'modelLabel',
      title: '型号标签',
      minWidth: 120,
    },
    {
      field: 'vehicleType',
      title: '车辆类型',
      minWidth: 120,
    },
    {
      field: 'fuelType',
      title: '燃料种类',
      minWidth: 100,
    },
    {
      field: 'plateColor',
      title: '车牌颜色',
      minWidth: 100,
    },
    {
      field: 'tireNumber',
      title: '轮胎数量',
      minWidth: 80,
      align: 'center',
    },
    {
      field: 'tireSize',
      title: '轮胎规格',
      minWidth: 100,
    },
    {
      field: 'batteryType',
      title: '电池类型',
      minWidth: 100,
    },
    {
      field: 'reserveElectricity',
      title: '储电量(kWh)',
      minWidth: 110,
      align: 'right',
    },
    {
      field: 'hydrogenCapacity',
      title: '氢瓶容量(L)',
      minWidth: 110,
      align: 'right',
    },
    {
      field: 'electricityMileage',
      title: '电续航(KM)',
      minWidth: 100,
      align: 'right',
    },
    {
      field: 'hydrogenMileage',
      title: '氢续航(KM)',
      minWidth: 100,
      align: 'right',
    },
    {
      field: 'createTime',
      title: '创建时间',
      minWidth: 180,
      formatter: 'formatDateTime',
    },
    useActionColumn(3),
  ];
}

/** 维保项目表格列配置 */
export function useMaintainItemColumns(): VxeTableGridOptions['columns'] {
  return [
    { type: 'seq', width: 60, title: '序号' },
    {
      field: 'maintainItem',
      title: '保养项目名称',
      minWidth: 150,
      editRender: { name: 'input' },
    },
    {
      field: 'kilometerCycle',
      title: '保养公里周期(KM)',
      minWidth: 150,
      editRender: { name: 'input', props: { type: 'number' } },
    },
    {
      field: 'timeCycle',
      title: '保养时间周期(月)',
      minWidth: 150,
      editRender: { name: 'input', props: { type: 'number' } },
    },
    {
      field: 'hourFee',
      title: '工时费(元)',
      minWidth: 120,
      editRender: { name: 'input', props: { type: 'number' } },
    },
    {
      field: 'materialFee',
      title: '材料费(元)',
      minWidth: 120,
      editRender: { name: 'input', props: { type: 'number' } },
    },
    {
      field: 'totalFee',
      title: '费用合计(元)',
      minWidth: 120,
      editRender: { name: 'input', props: { type: 'number' } },
    },
    useActionColumn(1, false, 'operate'),
  ];
}
