import React from 'react'; import { ExternalLink } from 'lucide-react'; import { useI18n } from '../../application/i18n/I18nProvider'; import { pluginAuthenticationChallengeMessage, usePluginAuthenticationChallenges, } from '../../application/state/usePluginAuthenticationChallenges'; import { Button } from '../ui/button'; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from '../ui/dialog'; import { Input } from '../ui/input'; import { Label } from '../ui/label'; export const PluginAuthenticationHost: React.FC = () => { const { t } = useI18n(); const state = usePluginAuthenticationChallenges(); const { challenge, busy, externalUrl } = state; if (!challenge) return null; const message = pluginAuthenticationChallengeMessage(challenge); return ( { if (!open) void state.complete(undefined, true); }}> {challenge.title} {message || t('plugins.authentication.description')} {state.isText && (
state.setTextValue(event.target.value)} onKeyDown={(event) => { if (event.key === 'Enter' && state.canSubmit) state.submit(); }} autoFocus />
)} {challenge.kind === 'choice' && (
{challenge.choices.map((choice) => { const selected = state.selectedChoices.includes(choice.id); return ( ); })}
)} {(challenge.kind === 'browser' || challenge.kind === 'deviceCode') && (
{challenge.kind === 'deviceCode' && (
{t('plugins.authentication.deviceCode')}
{challenge.userCode}
)} {externalUrl ? ( ) : (

{t('plugins.authentication.invalidUrl')}

)}
)} {state.responseError !== null && (

{state.responseError ? t('plugins.authentication.responseFailedWithMessage', { message: state.responseError }) : t('plugins.authentication.responseFailed')}

)} {challenge.kind === 'confirmation' ? ( ) : ( )}
); };