/** @format */

import * as React from 'react'
import Select, {SelectProps} from './select'
import {useProvideApi} from '../../service/provider'

interface IproviderSelect extends SelectProps {
    provider_id?: number | string;
}

export default React.forwardRef((props: IproviderSelect, ref) => {
    const {provider_id, ...rest} = props
    const [providerState, requestProvider] = useProvideApi()
    React.useEffect(() => {
        requestProvider(provider_id)
    }, [provider_id])
    return (
        <Select
            ref={ref}
            allowClear
            showSearch
            options={providerState.dataSource.sort((pre, next) => {
                return pre.label.localeCompare(next.label)
            })}
            placeholder='请选择供应商接口'
            loading={providerState.loading}
            {...rest}
        />
    )
})
