import { Box, Text, TextAttributes, useUiHost } from "../../../ui";
import { colors } from "../../../theme/colors";
import type { ScannerHiloPayload } from "../../../api-client";
import { buildHiloBarRows, terminalBarCells, type HiloBarRow } from "./hilo-model";
const LABEL_WIDTH = 8;
const MIN_HALF_WIDTH = 4;
export interface HiloBarsProps {
windows: ScannerHiloPayload["windows"] | null | undefined;
width: number;
}
function halfWidthFor(width: number): number {
return Math.max(MIN_HALF_WIDTH, Math.floor((width - LABEL_WIDTH - 2) / 2));
}
function RowLabel({ row }: { row: HiloBarRow }) {
return (
{row.label}
);
}
/** Terminal bars are block runs at half-cell resolution, the densest option in cells. */
/** Counts sit beside the label, so an empty window reads as zero rather than a missing bar. */
function countWidthFor(rows: readonly HiloBarRow[]): number {
return Math.max(...rows.flatMap((row) => [String(row.lows).length, String(row.highs).length]), 1) + 1;
}
function TerminalHiloBars({ rows, halfWidth, width }: { rows: HiloBarRow[]; halfWidth: number; width: number }) {
const countWidth = countWidthFor(rows);
const barWidth = Math.max(0, halfWidth - countWidth);
return (
{rows.map((row) => {
const low = terminalBarCells(row.lowRatio, barWidth);
const high = terminalBarCells(row.highRatio, barWidth);
const lowBar = `${low.half ? "▐" : ""}${"█".repeat(low.full)}`;
const highBar = `${"█".repeat(high.full)}${high.half ? "▌" : ""}`;
return (
{lowBar}
{String(row.lows).padStart(countWidth)}
{String(row.highs).padEnd(countWidth)}
{highBar}
);
})}
);
}
/** Desktop bars are real flex-sized divs, so length is fractional instead of cell-quantized. */
function DesktopHiloBars({ rows, width }: { rows: HiloBarRow[]; width: number }) {
return (
{rows.map((row) => (
0 ? "2px" : "0",
}}
/>
{` ${row.lows}`}
{`${row.highs} `}
0 ? "2px" : "0",
}}
/>
))}
);
}
export function HiloBars({ windows, width }: HiloBarsProps) {
const isDesktopWeb = useUiHost().kind === "desktop-web";
const rows = buildHiloBarRows(windows);
return (
{isDesktopWeb
?
: }
);
}