import { MyColumnsType } 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 MomentSelect = {
  MomentCategoriesTree(props?: PropsType): ReturnType {
    const { ...rest } = props ?? {};
    return {
      key: 'parent_id',
      title: '上级分类',
      valueType: 'treeSelect',
      request: async () => {
        return Apis.Customer.CustomerMomentCategories.SelectTree().then(
          (res) => res.data,
        );
      },
      fieldProps: {
        allowClear: true,
        autoClearSearchValue: true,
        bordered: true,
        fieldNames: {
          label: 'name',
          value: 'id',
        },
        filterTreeNode: true,
        showSearch: true,
        treeNodeFilterProp: 'title',
        treeDefaultExpandAll: true,
      },
      ...rest,
    };
  },
  MomentCategoriesSelect(props?: PropsType): MyColumnsType {
    const { ...rest } = props ?? {};
    return {
      title: '内容分类',
      dataIndex: 'moment_categories_ids',
      valueType: 'cascader',
      request: async () => {
        return Apis.Customer.CustomerMomentCategories.SelectTree().then(
          (res) => res.data,
        );
      },
      hideInTable: true,
      fieldProps: {
        showSearch: true,
        placeholder: '请选择 / 输入名称搜索',
        fieldNames: {
          label: 'name',
          value: 'id',
          children: 'children',
        },
      },
      ...rest,
    };
  },
};
