/** @format */

import * as React from 'react';
import Select, {SelectProps} from './select';
import {useProviders} from '../../service/provider';
interface IproviderSelect extends SelectProps {
    provider_api_id?: number | string;
}

export default React.forwardRef((props: IproviderSelect, ref) => {
    const {provider_api_id} = props;
    const [providersState, requestProviders] = useProviders();
    React.useEffect(() => {
        requestProviders({
            provider_api_id: provider_api_id,
            is_all: true,
        });
    }, [provider_api_id]);
    return (
        <Select
            ref={ref}
            showSearch
            options={providersState.dataSource.sort((pre, next) => {
                return pre.label.localeCompare(next.label);
            })}
            loading={providersState.loading}
            placeholder='请选择供应商'
            {...props}
        />
    );
});
