import type { PluginPayload } from './types'
import { cn } from '@langgenius/dify-ui/cn'
import { memo } from 'react'
import { useTranslation } from 'react-i18next'
import { ACCOUNT_SETTING_TAB } from '@/app/components/header/account-setting/constants'
import { useModalContext } from '@/context/modal-context'
import Authorize from './authorize'
import Authorized from './authorized'
import { usePluginAuth } from './hooks/use-plugin-auth'
import { AuthCategory } from './types'
type PluginAuthProps = {
pluginPayload: PluginPayload
children?: React.ReactNode
className?: string
}
const PluginAuth = ({ pluginPayload, children, className }: PluginAuthProps) => {
const { t } = useTranslation()
const { setShowAccountSettingModal } = useModalContext()
const {
isAuthorized,
canOAuth,
canApiKey,
credentials,
invalidPluginCredentialInfo,
notAllowCustomCredential,
} = usePluginAuth(pluginPayload, !!pluginPayload.provider)
const showPermissionHint =
!isAuthorized &&
!notAllowCustomCredential &&
pluginPayload.category === AuthCategory.tool &&
(canOAuth || canApiKey)
const authorizeContent = (