import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { MesTraceCrossRegionApi } from '#/api/mes/trace/crossregion';

import { getRangePickerDefaultProps } from '#/utils';

/** 预警类型选项 */
export const WARNING_TYPE_OPTIONS = [
  { label: '跨省窜货', value: 'CROSS_PROVINCE' },
  { label: '跨市窜货', value: 'CROSS_CITY' },
];

/** 预警状态选项 */
export const WARNING_STATUS_OPTIONS = [
  { label: '待处理', value: 10 },
  { label: '已处理', value: 20 },
  { label: '误报', value: 30 },
];

/** 判定粒度选项 */
export const WARNING_LEVEL_OPTIONS = [
  { label: '跨省判定', value: 'PROVINCE' },
  { label: '跨市判定', value: 'CITY' },
];

/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'status',
      label: '状态',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: WARNING_STATUS_OPTIONS,
        placeholder: '请选择状态',
      },
    },
    {
      fieldName: 'warningType',
      label: '预警类型',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: WARNING_TYPE_OPTIONS,
        placeholder: '请选择预警类型',
      },
    },
    {
      fieldName: 'batchCode',
      label: '批次号',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入批次号',
      },
    },
    {
      fieldName: 'bagCode',
      label: '袋码',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入袋码',
      },
    },
    {
      fieldName: 'clientName',
      label: '经销商',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入经销商名称',
      },
    },
    {
      fieldName: 'eventTime',
      label: '预警时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
  ];
}

/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions<MesTraceCrossRegionApi.Warning>['columns'] {
  return [
    {
      field: 'warningNo',
      title: '预警编号',
      fixed: 'left',
      minWidth: 190,
    },
    {
      field: 'bagCode',
      title: '袋码',
      minWidth: 150,
      slots: { default: 'bagCode' },
    },
    {
      field: 'batchCode',
      title: '批次号',
      minWidth: 190,
    },
    {
      field: 'itemName',
      title: '物料名称',
      minWidth: 120,
    },
    {
      field: 'salesCode',
      title: '出库单号',
      minWidth: 150,
    },
    {
      field: 'clientName',
      title: '经销商',
      minWidth: 120,
    },
    {
      field: 'dealerProvince',
      title: '经销商地区',
      minWidth: 130,
      slots: { default: 'dealerRegion' },
    },
    {
      field: 'scanProvince',
      title: '扫码地区',
      minWidth: 130,
      slots: { default: 'scanRegion' },
    },
    {
      field: 'warningTypeName',
      title: '预警类型',
      width: 110,
      slots: { default: 'warningType' },
    },
    {
      field: 'statusName',
      title: '状态',
      width: 90,
      slots: { default: 'status' },
    },
    {
      field: 'eventTime',
      title: '预警时间',
      width: 170,
      formatter: 'formatDateTime',
    },
    {
      field: 'handleUserName',
      title: '处理人',
      width: 90,
    },
    {
      title: '操作',
      width: 120,
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}
