import React from 'react'; import { Button } from '@/components/ui/button'; import { Icon } from "@/components/icon/Icon"; import { useI18n } from '@/lib/i18n'; import { cn } from '@/lib/utils'; import { redactSensitiveUrl } from '@/lib/desktopHosts'; import { getDesktopRecoveryConfig, type RecoveryVariant, } from './desktopRecoveryConfig'; export type { RecoveryVariant } from './desktopRecoveryConfig'; export type DesktopConnectionRecoveryProps = { variant: RecoveryVariant; hostLabel?: string; hostUrl?: string; onRetry?: () => void; onUseLocal?: () => void; onUseRemote?: () => void; isRetrying?: boolean; }; /** Maps iconKey from config to actual icon component */ function getRecoveryIcon(iconKey: 'local' | 'remote'): React.ReactNode { switch (iconKey) { case 'local': return ; case 'remote': return ; } } export function DesktopConnectionRecovery({ variant, hostLabel, hostUrl, onRetry, onUseLocal, onUseRemote, isRetrying = false, }: DesktopConnectionRecoveryProps) { const { t } = useI18n(); const config = getDesktopRecoveryConfig(variant, hostLabel, hostUrl); const retryLabelKey = (config.retryLabelKey ?? 'onboarding.desktopRecovery.actions.retryConnection') as Parameters[0]; const descriptionParams = React.useMemo(() => { if (config.descriptionParams?.host) { return config.descriptionParams; } if (variant === 'remote-unreachable') { return { host: t('onboarding.desktopRecovery.placeholders.remoteServer') }; } if (variant === 'remote-wrong-service' || variant === 'remote-incompatible') { return { host: t('onboarding.desktopRecovery.placeholders.unknownServer') }; } return undefined; }, [config.descriptionParams, t, variant]); return (
{/* Icon and title */}
{getRecoveryIcon(config.iconKey)}

{t(config.titleKey as Parameters[0])}

{t( config.descriptionKey as Parameters[0], descriptionParams )}

{/* Host info if available */} {hostUrl && (variant === 'remote-unreachable' || variant === 'remote-wrong-service' || variant === 'remote-incompatible') && (
{t('onboarding.remoteConnection.field.serverAddress')}
{redactSensitiveUrl(hostUrl)}
)} {/* Action buttons */}
{config.showRetry && onRetry && ( )}
{config.showUseLocal && onUseLocal && ( )} {config.showUseRemote && onUseRemote && ( )}
); }