1// @effect-diagnostics globalDate:off - Vendored @clo/lib has no Effect dependency.
2import type { ReadOnlyNode } from "./progress.ts";
3
4export function isVisible(node: ReadOnlyNode): boolean {
5 return !node.hidden && (!node.passive || node.children.some(isVisible));
6}
7
8export function remainingSeconds(node: ReadOnlyNode): number | null {
9 const { estimatedTime } = node;
10 if (!estimatedTime) return null;
11 const ms = estimatedTime - Date.now();
12 return ms > 1000 && !findLongerEstimate(node, estimatedTime) ? Math.round(ms / 1000) : null;
13}
14
15function findLongerEstimate(state: ReadOnlyNode, estimatedTime: number): boolean {
16 return state.children.some(
17 (child) =>
18 isVisible(child) &&
19 ((child.estimatedTime ?? 0) > estimatedTime || findLongerEstimate(child, estimatedTime)),
20 );
21}
22
23export const maxLogLines = 3;