1import type { EnvironmentConnectionPhase } from "@t3tools/client-runtime/connection";
2import type { EnvironmentShellStatus } from "@t3tools/client-runtime/state/shell";
3import type { EnvironmentThreadStatus } from "@t3tools/client-runtime/state/threads";
4
5/**
6 * Reports whether the route-local projections can still yield the requested
7 * thread. Explicit terminal outcomes win over unrelated synchronization.
8 */
9export function threadRouteIsHydrating(input: {
10 readonly isLoadingConnections: boolean;
11 readonly connectionState: EnvironmentConnectionPhase;
12 readonly shellStatus: EnvironmentShellStatus;
13 readonly shellHasError: boolean;
14 readonly detailStatus: EnvironmentThreadStatus;
15 readonly detailHasError: boolean;
16}): boolean {
17 if (input.detailStatus === "deleted" || input.shellHasError || input.detailHasError) {
18 return false;
19 }
20 if (input.isLoadingConnections) {
21 return true;
22 }
23 if (
24 input.connectionState === "available" ||
25 input.connectionState === "offline" ||
26 input.connectionState === "error"
27 ) {
28 return false;
29 }
30 return (
31 input.connectionState === "connecting" ||
32 input.connectionState === "reconnecting" ||
33 input.shellStatus === "synchronizing" ||
34 (input.connectionState === "connected" && input.shellStatus === "empty") ||
35 input.detailStatus === "synchronizing" ||
36 (input.connectionState === "connected" && input.detailStatus === "empty")
37 );
38}