1import type { EnvironmentThreadStatus } from "@t3tools/client-runtime/state/threads";
2
3export type ThreadSyncPhase = "loading" | "syncing";
4
5export function resolveThreadSyncPhase(input: {
6 readonly detailExists: boolean;
7 readonly shellExists: boolean;
8 readonly status: EnvironmentThreadStatus;
9}): ThreadSyncPhase | null {
10 if (!input.shellExists) {
11 return null;
12 }
13
14 switch (input.status) {
15 case "empty":
16 case "cached":
17 case "synchronizing":
18 return input.detailExists ? "syncing" : "loading";
19 case "deleted":
20 case "live":
21 return null;
22 }
23}
24
25export function threadSyncLabel(phase: ThreadSyncPhase): string {
26 return phase === "loading" ? "Loading messages..." : "Syncing messages...";
27}