import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { MesMdVendorApi } from '#/api/mes/md/vendor';

import { DICT_TYPE } from '#/packages/constants/src';

/** 供应商选择弹窗搜索表单 */
export function useVendorSelectGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'code',
      label: '供应商编码',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入供应商编码',
      },
    },
    {
      fieldName: 'name',
      label: '供应商名称',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入供应商名称',
      },
    },
    {
      fieldName: 'nickname',
      label: '供应商简称',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入供应商简称',
      },
    },
    {
      fieldName: 'englishName',
      label: '英文名称',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入英文名称',
      },
    },
  ];
}

/** 供应商选择弹窗列表字段 */
export function useVendorSelectGridColumns(
  multiple = true,
): VxeTableGridOptions<MesMdVendorApi.Vendor>['columns'] {
  return [
    { type: multiple ? 'checkbox' : 'radio', width: 50 },
    {
      field: 'code',
      title: '供应商编码',
      minWidth: 160,
    },
    {
      field: 'name',
      title: '供应商名称',
      minWidth: 170,
    },
    {
      field: 'nickname',
      title: '供应商简称',
      width: 120,
    },
    {
      field: 'level',
      title: '供应商等级',
      width: 120,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_TYPE.MES_VENDOR_LEVEL },
      },
    },
    {
      field: 'score',
      title: '供应商评分',
      width: 110,
    },
    {
      field: 'telephone',
      title: '联系电话',
      width: 140,
    },
    {
      field: 'status',
      title: '状态',
      width: 100,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_TYPE.COMMON_STATUS },
      },
    },
    {
      field: 'remark',
      title: '备注',
      minWidth: 140,
    },
  ];
}
