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

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

/** 客户选择弹窗搜索表单 */
export function useClientSelectGridFormSchema(): 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 useClientSelectGridColumns(
  multiple = true,
): VxeTableGridOptions<MesMdClientApi.Client>['columns'] {
  return [
    { type: multiple ? 'checkbox' : 'radio', width: 50 },
    {
      field: 'code',
      title: '客户编码',
      minWidth: 160,
    },
    {
      field: 'name',
      title: '客户名称',
      minWidth: 160,
    },
    {
      field: 'nickname',
      title: '客户简称',
      width: 120,
    },
    {
      field: 'type',
      title: '客户类型',
      width: 110,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_TYPE.MES_CLIENT_TYPE },
      },
    },
    {
      field: 'contact1Name',
      title: '联系人',
      width: 120,
    },
    {
      field: 'telephone',
      title: '联系电话',
      width: 140,
    },
    {
      field: 'contact1Telephone',
      title: '联系人电话',
      width: 140,
    },
    {
      field: 'status',
      title: '状态',
      width: 100,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_TYPE.COMMON_STATUS },
      },
    },
  ];
}
