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 TreeSelects = {
  TreeSelectDepartment(props?: PropsType): ReturnType {
    const { required = false, ...rest } = props ?? {};
    return {
      title: '签约部门',
      dataIndex: 'sign_department_id',
      valueType: 'treeSelect',
      hideInTable: true,
      formItemProps: { ...(required ? rulesHelper.text : {}) },
      request: async () => (await Apis.Company.Organizations.SelectTree()).data,
      ...rest,
      fieldProps: {
        showSearch: true,
        allowClear: true,
        treeDefaultExpandAll: true,
        fieldNames: {
          label: 'name',
          value: 'id',
          children: 'children',
        },
        ...rest?.fieldProps,
      },
    };
  },
  TreeSelectEventCategories(props?: PropsType): ReturnType {
    const { required = false, ...rest } = props ?? {};
    return {
      title: '上级分类',
      dataIndex: 'parent_id',
      valueType: 'treeSelect',
      hideInTable: true,
      formItemProps: { ...(required ? rulesHelper.text : {}) },
      request: async () =>
        (await Apis.Emergency.EmergencyEventCategories.SelectTree()).data,
      ...rest,
      fieldProps: {
        showSearch: true,
        allowClear: true,
        treeDefaultExpandAll: true,
        fieldNames: {
          label: 'name',
          value: 'id',
          children: 'children',
        },
        ...rest?.fieldProps,
      },
    };
  },
  TreeSelecTassetItemCategories(props?: PropsType): ReturnType {
    const { required = false, ...rest } = props ?? {};
    return {
      title: '上级分类',
      dataIndex: 'parent_id',
      valueType: 'treeSelect',
      hideInTable: true,
      formItemProps: { ...(required ? rulesHelper.text : {}) },
      request: async () =>
        (await Apis.Asset.AssetItemCategories.SelectTree()).data,
      ...rest,
      fieldProps: {
        showSearch: true,
        allowClear: true,
        treeDefaultExpandAll: true,
        fieldNames: {
          label: 'name',
          value: 'id',
          children: 'children',
        },
        ...rest?.fieldProps,
      },
    };
  },
};
