"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useTerminalSize = useTerminalSize;
exports.getListColumns = getListColumns;
exports.getListWidth = getListWidth;
const react_1 = require("react");
const ink_1 = require("ink");
function useTerminalSize() {
    const { stdout } = (0, ink_1.useStdout)();
    const [size, setSize] = (0, react_1.useState)({
        columns: (stdout === null || stdout === void 0 ? void 0 : stdout.columns) || 80,
        rows: (stdout === null || stdout === void 0 ? void 0 : stdout.rows) || 24,
    });
    (0, react_1.useEffect)(() => {
        if (!stdout)
            return;
        const onResize = () => {
            setSize({
                columns: stdout.columns || 80,
                rows: stdout.rows || 24,
            });
        };
        stdout.on("resize", onResize);
        return () => {
            stdout.off("resize", onResize);
        };
    }, [stdout]);
    return size;
}
function getListColumns(width) {
    if (width >= 160)
        return 4;
    if (width >= 120)
        return 3;
    if (width >= 80)
        return 2;
    return 1;
}
function getListWidth(terminalWidth, numColumns) {
    // Account for borders and padding
    const availableWidth = terminalWidth - 4;
    return Math.floor(availableWidth / numColumns) - 2;
}
