import { rulesHelper } from '@/common';
import { Apis } from '@/gen/Apis';
import { ProColumns, ProFormColumnsType } from '@ant-design/pro-components';

type ReturnType = ProColumns<any, 'text'> & ProFormColumnsType<any, 'text'>;
type PropsType = { required?: boolean } & ReturnType;

export const SysSelects = {
  Companies(props?: PropsType): ReturnType {
    const {
      title = '机构',
      key = 'parent_id',
      required = false,
      hideInTable = true,
      ...rest
    } = props ?? {};

    return {
      title: title,
      key: key,
      valueType: 'select',
      hideInTable: hideInTable,
      formItemProps: { ...(required ? rulesHelper.number : {}) },
      fieldProps: {
        showSearch: true,
        fieldNames: {
          label: 'label',
          value: 'value',
        },
      },
      request: async (params) =>
        (
          await Apis.Company.Companies.Select({
            keywords: params?.KeyWords,
            ...params,
          })
        ).data,
      ...rest,
    };
  },
};
