import { Text, View } from "react-native"; import { ArrowLeftToLine, RotateCw, Settings } from "lucide-react-native"; import { StyleSheet, useUnistyles } from "react-native-unistyles"; import { Button } from "@/components/ui/button"; import { LoadingSpinner } from "@/components/ui/loading-spinner"; import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"; import { formatConnectionStatus } from "@/utils/daemons"; import type { WorkspaceRouteState } from "@/screens/workspace/workspace-route-state"; interface WorkspaceRouteStateActions { onRetryHost: () => void; onManageHost: () => void; onDismissMissingWorkspace: () => void; } export function renderWorkspaceRouteGate(input: { state: WorkspaceRouteState; actions: WorkspaceRouteStateActions; }): React.ReactNode { switch (input.state.kind) { case "loading": return ; case "unreachable": return ( ); case "missing": return ( ); case "ready": case "reconnecting": return null; } } function getWorkspaceHostStateTitle( state: Extract, ): string { if (state.connectionStatus === "connecting" || state.connectionStatus === "idle") { return "Connecting"; } if (state.connectionStatus === "offline") { return `${state.hostName} is offline`; } return `Cannot reach ${state.hostName}`; } function WorkspaceConnecting({ hostName }: { hostName: string }) { const { theme } = useUnistyles(); return ( Loading workspace {hostName} ); } function WorkspaceUnreachable({ state, onRetry, onManageHost, }: { state: Extract; onRetry: () => void; onManageHost: () => void; }) { const { theme } = useUnistyles(); const canRetry = state.connectionStatus === "offline" || state.connectionStatus === "error"; return ( {state.connectionStatus === "connecting" || state.connectionStatus === "idle" ? ( ) : null} {getWorkspaceHostStateTitle(state)} {state.connectionStatus === "connecting" || state.connectionStatus === "idle" ? state.hostName : `Host status: ${formatConnectionStatus(state.connectionStatus)}`} {state.lastError ? ( {state.lastError} {state.lastError} ) : null} {canRetry ? ( ) : null} ); } function WorkspaceMissing({ hostName, onDismiss }: { hostName: string; onDismiss: () => void }) { return ( Workspace not found {hostName} ); } const styles = StyleSheet.create((theme) => ({ emptyState: { flex: 1, alignItems: "center", justifyContent: "center", gap: theme.spacing[3], paddingHorizontal: theme.spacing[6], }, textStack: { alignItems: "center", gap: theme.spacing[2], maxWidth: 520, }, title: { color: theme.colors.foreground, fontSize: theme.fontSize.base, fontWeight: theme.fontWeight.normal, textAlign: "center", }, description: { color: theme.colors.foregroundMuted, fontSize: theme.fontSize.sm, textAlign: "center", }, error: { color: theme.colors.destructive, fontSize: theme.fontSize.sm, lineHeight: Math.round(theme.fontSize.sm * 1.4), textAlign: "center", }, errorTooltip: { color: theme.colors.popoverForeground, fontSize: theme.fontSize.sm, maxWidth: 420, }, actions: { flexDirection: "row", alignItems: "center", justifyContent: "center", flexWrap: "wrap", gap: theme.spacing[2], }, }));