// @ts-ignore: 忽略
import type { FormSchemaGetter } from '#/adapter/form';
// @ts-ignore: 忽略
import type { VxeGridProps } from '#/adapter/vxe-table';

// @ts-ignore: 忽略
import { DictEnum } from '@vben/constants';

import { ElInputNumber } from 'element-plus';

import { getDictOptions } from '#/utils/dict';
/**
 * 量缸试水抽屉表单配置
 */
export const drawerFormSchema: any | FormSchemaGetter = () => [
  {
    component: 'DatePicker',
    fieldName: 'measurementStartTime',
    label: '开始测量时间',
    componentProps: {
      placeholder: '请选择开始测量时间',
      type: 'datetime',
      format: 'YYYY-MM-DD HH:mm:ss',
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
    },
    rules: 'required',
  },
  {
    component: 'Input',
    fieldName: 'abnormalDescription',
    label: '异常记录',
    componentProps: {
      placeholder: '请输入异常记录',
      type: 'textarea',
      rows: 4,
    },
  },
  {
    fieldName: 'tankWaterDetailList',
    label: '测量信息',
    hideLabel: true,
    renderComponentContent: () => {
      return {
        default: () => [],
      };
    },
  },
];

/**
 * 默认表格列配置
 */
export const defautTableColumns: VxeGridProps['columns'] = [
  {
    field: 'tankNumber',
    title: '罐号',
    width: 100,
    fixed: 'left',
    editRender: { name: 'input' },
  },
  {
    field: 'oilProduct',
    title: '油品名称',
    width: 120,
    editRender: {
      name: 'select',
      options: getDictOptions(DictEnum.OIL_PRODUCT),
      optionProps: {
        label: 'label',
        value: 'label',
      },
    },
  },
  {
    field: 'levelGauge',
    title: '液位仪',
    width: 200,
    children: [
      {
        field: 'levelGaugeOilHeightH1',
        title: '油高h1(mm)',
        width: 150,
        editRender: {
          name: 'input',
          immediate: true,
        },
        slots: {
          default: (data: any) => {
            return data.row.levelGaugeOilHeightH1;
          },
          edit: (data: any) => {
            const change = () => {
              const { row } = data;
              row.heightDifference =
                row.manualTankOilHeightH2 - row.levelGaugeOilHeightH1;
            };
            return (
              <ElInputNumber
                controls-position="right" // 改为驼峰命名
                max={1_000_000}
                min={0}
                onChange={change}
                step={1}
                v-model={data.row.levelGaugeOilHeightH1}
              />
            );
          },
        },
      },
      {
        field: 'levelGaugeWaterHeight',
        title: '水高(mm)',
        width: 150,
        editRender: { name: 'input' },
        slots: {
          default: (data: any) => {
            return data.row.levelGaugeWaterHeight;
          },
          edit: (data: any) => {
            return (
              <ElInputNumber
                controls-position="right" // 改为驼峰命名
                max={1_000_000}
                min={0}
                step={1}
                v-model={data.row.levelGaugeWaterHeight}
              />
            );
          },
        },
      },
    ],
  },
  {
    field: 'manualTank',
    title: '手工量缸',
    width: 250,
    children: [
      {
        field: 'manualTankOilHeightH2',
        title: '油高h2(mm)',
        width: 150,

        editRender: {
          name: 'input',
          immediate: true,
        },
        slots: {
          default: (data: any) => {
            return data.row.manualTankOilHeightH2;
          },
          edit: (data: any) => {
            const change = () => {
              const { row } = data;
              row.heightDifference =
                row.manualTankOilHeightH2 - row.levelGaugeOilHeightH1;
            };
            return (
              <ElInputNumber
                controls-position="right" // 改为驼峰命名
                max={1_000_000}
                min={0}
                onChange={change}
                step={1}
                v-model={data.row.manualTankOilHeightH2}
              />
            );
          },
        },
      },
      {
        field: 'manualTankWaterHeight',
        title: '水高(mm)',
        width: 150,
        editRender: { name: 'input' },
        slots: {
          default: (data: any) => {
            return data.row.manualTankWaterHeight;
          },
          edit: (data: any) => {
            return (
              <ElInputNumber
                controls-position="right" // 改为驼峰命名
                max={1_000_000}
                min={0}
                step={1}
                v-model={data.row.manualTankWaterHeight}
              />
            );
          },
        },
      },
    ],
  },
  {
    field: 'heightDifference',
    title: '高度差(mm)(h2-h1)',
    width: 250,
  },
  {
    field: 'tankTemperature',
    title: '油罐温度（℃）',
    width: 100,
    editRender: { name: 'input' },
    slots: {
      default: (data: any) => {
        return data.row.tankTemperature;
      },
      edit: (data: any) => {
        return (
          <ElInputNumber
            controls-position="right" // 改为驼峰命名
            max={1_000_000}
            min={0}
            step={1}
            v-model={data.row.tankTemperature}
          />
        );
      },
    },
  },
  {
    field: 'action',
    title: '操作',
    width: 100,
    fixed: 'right',
    slots: { default: 'action' },
  },
];
