import type { ReactNode } from 'react' import { useNavigate } from '@tanstack/react-router' import { AlertCircle, CheckCircle2, Circle, Loader2, Server, Settings, WifiOff, } from 'lucide-react' import { useTranslation } from 'react-i18next' import { cn } from '@/lib/utils' import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert' import { Button } from '@/components/ui/button' type LoadingPhase = 'idle' | 'settings' | 'connection' | 'done' type StepStatus = 'pending' | 'loading' | 'done' function getSettingsStatus(phase: LoadingPhase): StepStatus { if (phase === 'settings') return 'loading' if (phase === 'connection' || phase === 'done') return 'done' return 'pending' } function getConnectionStatus( phase: LoadingPhase, connectionOk: boolean | null ): StepStatus { if (phase === 'connection') return 'loading' if (phase === 'done' && connectionOk) return 'done' return 'pending' } interface DeploymentAccessGuardProps { children: ReactNode loading: boolean loadingPhase?: LoadingPhase isEnabled: boolean connectionLoading: boolean connectionOk: boolean | null connectionError: string | null onRetry: () => void } function LoadingStep({ label, status, }: { label: string status: 'pending' | 'loading' | 'done' }) { return (
{status === 'loading' && ( )} {status === 'done' && } {status === 'pending' && ( )} {label}
) } export function DeploymentAccessGuard({ children, loading, loadingPhase = 'settings', isEnabled, connectionLoading, connectionOk, connectionError, onRetry, }: DeploymentAccessGuardProps) { const { t } = useTranslation() const navigate = useNavigate() const handleGoToSettings = () => { navigate({ to: '/system-settings/models/$section', params: { section: 'model-deployment' }, }) } // Combined loading state with step indicator if (loading || connectionLoading) { const settingsStatus = getSettingsStatus(loadingPhase) const connectionStatus = getConnectionStatus(loadingPhase, connectionOk) return (
) } // Disabled state if (!isEnabled) { return (

{t('Model deployment service is disabled')}

{t('Configuration required')} {t( 'Please enable io.net model deployment service and configure an API key in System Settings.' )}
) } // Connection error state if (connectionOk === false && connectionError) { return (

{t('Connection failed')}

{t('Connection error')} {t(connectionError)}
) } return <>{children} }