const HEADER_HEIGHT = 3;
const FOOTER_HEIGHT = 1;
export function computeExplorerLayout(opts) {
    const cols = normalizeSize(opts.cols);
    const rows = normalizeSize(opts.rows);
    const mode = resolveMode(cols);
    const footerHeight = rows > 0 ? Math.min(FOOTER_HEIGHT, rows) : 0;
    const headerHeight = Math.min(HEADER_HEIGHT, Math.max(0, rows - footerHeight));
    const contentY = headerHeight;
    const contentHeight = Math.max(0, rows - headerHeight - footerHeight);
    const footerY = headerHeight + contentHeight;
    const header = { x: 0, y: 0, width: cols, height: headerHeight };
    const footer = { x: 0, y: footerY, width: cols, height: footerHeight };
    if (mode === "too-narrow" || mode === "narrow-list-only") {
        return {
            mode,
            header,
            list: { x: 0, y: contentY, width: cols, height: contentHeight },
            detail: { x: 0, y: contentY + contentHeight, width: 0, height: 0 },
            footer
        };
    }
    if (opts.detailHidden === true) {
        return {
            mode,
            header,
            list: { x: 0, y: contentY, width: cols, height: contentHeight },
            detail: { x: cols, y: contentY, width: 0, height: contentHeight },
            footer
        };
    }
    if (mode === "narrow-vertical") {
        const listHeight = Math.ceil(contentHeight / 2);
        const detailHeight = contentHeight - listHeight;
        return {
            mode,
            header,
            list: { x: 0, y: contentY, width: cols, height: listHeight },
            detail: { x: 0, y: contentY + listHeight, width: cols, height: detailHeight },
            footer
        };
    }
    const listWidth = mode === "wide" ? Math.floor((cols * 5) / 12) : Math.floor((cols * 2) / 5);
    const detailWidth = cols - listWidth;
    return {
        mode,
        header,
        list: { x: 0, y: contentY, width: listWidth, height: contentHeight },
        detail: { x: listWidth, y: contentY, width: detailWidth, height: contentHeight },
        footer
    };
}
function resolveMode(cols) {
    if (cols < 40) {
        return "too-narrow";
    }
    if (cols < 80) {
        return "narrow-list-only";
    }
    if (cols < 100) {
        return "narrow-vertical";
    }
    if (cols < 120) {
        return "medium";
    }
    return "wide";
}
function normalizeSize(value) {
    if (!Number.isFinite(value)) {
        return 0;
    }
    return Math.max(0, Math.floor(value));
}
