/** @format */
// 商户选择
import * as React from 'react';

import Select, {SelectProps} from './select';
import {userMerchantList} from '../../service/merchant';
interface MerchantSelectProps extends SelectProps {
    api_ids?: number | string; //baseApi id
    data_api_id?: number | ''; // dataApi id
    merchantId?:any
}
/**
 * 商户下拉选择框
 */
const MerchantSelect = React.forwardRef((props: MerchantSelectProps, ref) => {
    const {api_ids = '', data_api_id = '',merchantId, ...rest} = props;
    const [merchantState, requestMerchant] = userMerchantList();
    React.useEffect(() => {
        requestMerchant({
            data_api_id,
            api_ids,
        });
    }, [api_ids, data_api_id]);
    React.useEffect(()=>{
        requestMerchant({
            data_api_id,
            api_ids,
        });
    },[merchantId])
    const filterDataSource = merchantState.dataSource.filter(element => {
        return element.label.includes('hj-test') || element.label.includes('GD');
    });
    const newData = merchantState.dataSource
        .filter(element => {
            return !element.label.includes('hj-test') && !element.label.includes('GD');
        })
        .concat(...filterDataSource);

    return (
        <Select
            ref={ref}
            showSearch
            placeholder='请选择商户'
            allowClear
            loading={merchantState.loading}
            options={newData}
            {...rest}
        />
    );
});
export default MerchantSelect;
