import { memo, useCallback, useMemo, } from 'react' import { useTranslation } from 'react-i18next' import { RiEqualizer2Line, } from '@remixicon/react' import { Button, } from '@/app/components/base/button' import type { CustomConfigurationModelFixedFields, ModelProvider, } from '@/app/components/header/account-setting/model-provider-page/declarations' import { ConfigurationMethodEnum } from '@/app/components/header/account-setting/model-provider-page/declarations' import Authorized from './authorized' import { useAuth, useCredentialStatus } from './hooks' import Tooltip from '@/app/components/base/tooltip' import cn from '@/utils/classnames' type ConfigProviderProps = { provider: ModelProvider, configurationMethod: ConfigurationMethodEnum, currentCustomConfigurationModelFixedFields?: CustomConfigurationModelFixedFields, } const ConfigProvider = ({ provider, configurationMethod, currentCustomConfigurationModelFixedFields, }: ConfigProviderProps) => { const { t } = useTranslation() const { handleOpenModal, } = useAuth(provider, configurationMethod, currentCustomConfigurationModelFixedFields) const { hasCredential, authorized, current_credential_id, current_credential_name, available_credentials, } = useCredentialStatus(provider) const notAllowCustomCredential = provider.allow_custom_token === false const handleClick = useCallback(() => { if (!hasCredential && !notAllowCustomCredential) handleOpenModal() }, [handleOpenModal, hasCredential, notAllowCustomCredential]) const ButtonComponent = useMemo(() => { const Item = ( ) if (notAllowCustomCredential) { return ( {Item} ) } return Item }, [handleClick, authorized, notAllowCustomCredential, t]) if (!hasCredential) return ButtonComponent return ( ) } export default memo(ConfigProvider)