import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { MesWmStockWarningApi } from '#/api/mes/wm/stock-warning';

/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'itemCode',
      label: '品种编码',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入品种编码',
      },
    },
    {
      fieldName: 'batchCode',
      label: '批次号',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入批次号',
      },
    },
    {
      fieldName: 'warningType',
      label: '预警类型',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: [
          { label: '低库存', value: 10 },
          { label: '临期', value: 20 },
          { label: '库龄', value: 30 },
        ],
        placeholder: '请选择预警类型',
      },
    },
    {
      fieldName: 'status',
      label: '处理状态',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: [
          { label: '未处理', value: 10 },
          { label: '已处理', value: 20 },
        ],
        placeholder: '请选择处理状态',
      },
    },
  ];
}

/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions<MesWmStockWarningApi.StockWarning>['columns'] {
  return [
    {
      field: 'itemCode',
      title: '品种编码',
      minWidth: 120,
    },
    {
      field: 'itemName',
      title: '品种名称',
      minWidth: 140,
    },
    {
      field: 'batchCode',
      title: '批次号',
      minWidth: 140,
    },
    {
      field: 'warehouseName',
      title: '仓库',
      minWidth: 100,
    },
    {
      field: 'warningType',
      title: '预警类型',
      width: 100,
      cellRender: {
        name: 'CellTag',
        props: {
          options: [
            { label: '低库存', value: 10, color: 'orange' },
            { label: '临期', value: 20, color: 'gold' },
            { label: '库龄', value: 30, color: 'purple' },
          ],
        },
      },
    },
    {
      field: 'thresholdValue',
      title: '阈值',
      width: 100,
    },
    {
      field: 'currentValue',
      title: '当前值',
      width: 100,
    },
    {
      field: 'expireDate',
      title: '过期日期',
      width: 180,
      formatter: 'formatDateTime',
    },
    {
      field: 'receiptTime',
      title: '入库时间',
      width: 180,
      formatter: 'formatDateTime',
    },
    {
      field: 'status',
      title: '处理状态',
      width: 100,
      cellRender: {
        name: 'CellTag',
        props: {
          options: [
            { label: '未处理', value: 10, color: 'red' },
            { label: '已处理', value: 20, color: 'green' },
          ],
        },
      },
    },
    {
      field: 'handleTime',
      title: '处理时间',
      width: 180,
      formatter: 'formatDateTime',
    },
    {
      field: 'handleRemark',
      title: '处理备注',
      minWidth: 140,
    },
    {
      title: '操作',
      width: 80,
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}

/** 实时计算面板的字段 */
export function useCurrentGridColumns(): VxeTableGridOptions<MesWmStockWarningApi.StockWarning>['columns'] {
  return [
    {
      field: 'itemCode',
      title: '品种编码',
      minWidth: 120,
    },
    {
      field: 'itemName',
      title: '品种名称',
      minWidth: 140,
    },
    {
      field: 'batchCode',
      title: '批次号',
      minWidth: 140,
    },
    {
      field: 'warehouseName',
      title: '仓库',
      minWidth: 100,
    },
    {
      field: 'warningType',
      title: '预警类型',
      width: 100,
      cellRender: {
        name: 'CellTag',
        props: {
          options: [
            { label: '低库存', value: 10, color: 'orange' },
            { label: '临期', value: 20, color: 'gold' },
            { label: '库龄', value: 30, color: 'purple' },
          ],
        },
      },
    },
    {
      field: 'thresholdValue',
      title: '阈值',
      width: 100,
    },
    {
      field: 'currentValue',
      title: '当前值',
      width: 100,
    },
    {
      field: 'expireDate',
      title: '过期日期',
      width: 180,
      formatter: 'formatDateTime',
    },
    {
      field: 'receiptTime',
      title: '入库时间',
      width: 180,
      formatter: 'formatDateTime',
    },
  ];
}
