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

import { selectAllSysStationAreaList } from '#/api/system/infoEntry/stationInfo/stationInfo';

export const queryFormSchema: FormSchemaGetter = () => [
  {
    component: 'ApiSelect',
    fieldName: 'stationId',
    label: '油站',
    componentProps: {
      placeholder: '请选择油站',
      api: async () => {
        const resp = await selectAllSysStationAreaList();
        const data = resp || [];
        return Array.isArray(data)
          ? data.map((item: any) => ({
              label: item.stationName,
              value: item.id.toString(),
            }))
          : [];
      },
    },
  },
  {
    component: 'Input',
    fieldName: 'gunNo',
    label: '油枪编号',
    componentProps: {
      placeholder: '请输入油枪编号',
    },
  },
  {
    component: 'Input',
    fieldName: 'oilType',
    label: '油品种类',
    componentProps: {
      placeholder: '请输入油品种类',
    },
  },
];

export const tableColumns: VxeGridProps['columns'] = [
  {
    type: 'checkbox',
    width: 80,
  },
  {
    field: 'gunNo',
    title: '油枪编号',
    minWidth: 120,
  },
  {
    field: 'oilType',
    title: '油品种类',
    minWidth: 120,
  },
  {
    field: 'stationName',
    title: '油站名称',
    minWidth: 150,
  },
  {
    field: 'remark',
    title: '备注',
    minWidth: 150,
  },
  {
    field: 'action',
    fixed: 'right',
    slots: { default: 'action' },
    title: '操作',
    width: 150,
  },
];

export const drawerFormSchema: FormSchemaGetter = () => [
  {
    component: 'Input',
    dependencies: {
      show: () => false,
      triggerFields: [''],
    },
    fieldName: 'id',
  },
  {
    component: 'ApiSelect',
    fieldName: 'stationId',
    label: '油站',
    componentProps: {
      placeholder: '请选择油站',
      api: async () => {
        const resp = await selectAllSysStationAreaList();
        const data = resp || [];
        return Array.isArray(data)
          ? data.map((item: any) => ({
              label: item.stationName,
              value: item.id.toString(),
            }))
          : [];
      },
    },
    rules: 'required',
  },
  {
    component: 'Input',
    fieldName: 'gunNo',
    label: '油枪编号',
    componentProps: {
      placeholder: '请输入油枪编号',
      maxlength: 100,
    },
    rules: 'required',
  },
  {
    component: 'Input',
    fieldName: 'oilType',
    label: '油品种类',
    componentProps: {
      placeholder: '请输入油品种类',
      maxlength: 100,
    },
    rules: 'required',
  },
  {
    component: 'Input',
    fieldName: 'remark',
    label: '备注',
    componentProps: {
      placeholder: '请输入备注',
      maxlength: 200,
      type: 'textarea',
      showWordLimit: true,
    },
  },
];
