"use strict";
/**
 * Box Rendering
 *
 * Styled box containers with fallback ASCII rendering
 * @module utils/ui/boxes
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.warnBox = exports.infoBox = exports.errorBox = exports.box = void 0;
const types_1 = require("./types");
const init_1 = require("./init");
/**
 * Fallback ASCII box renderer (when boxen not available)
 */
function renderAsciiBox(content, options) {
    const lines = content.split('\n');
    const maxLen = Math.max(...lines.map((l) => l.length), (options.title?.length || 0) + 4);
    const width = maxLen + 4;
    let result = '';
    const padding = options.padding ?? 1;
    // Top border with optional title
    if (options.title) {
        const titlePad = Math.floor((width - options.title.length - 4) / 2);
        result +=
            '+' +
                '-'.repeat(titlePad) +
                ' ' +
                options.title +
                ' ' +
                '-'.repeat(width - titlePad - options.title.length - 4) +
                '+\n';
    }
    else {
        result += '+' + '-'.repeat(width - 2) + '+\n';
    }
    // Padding top
    for (let i = 0; i < padding; i++) {
        result += '|' + ' '.repeat(width - 2) + '|\n';
    }
    // Content
    for (const line of lines) {
        const pad = width - line.length - 4;
        result += '| ' + line + ' '.repeat(Math.max(0, pad)) + ' |\n';
    }
    // Padding bottom
    for (let i = 0; i < padding; i++) {
        result += '|' + ' '.repeat(width - 2) + '|\n';
    }
    // Bottom border
    result += '+' + '-'.repeat(width - 2) + '+';
    return result;
}
/**
 * Render content in a styled box
 */
function box(content, options = {}) {
    if (!types_1.moduleCache.boxen) {
        return renderAsciiBox(content, options);
    }
    const borderColor = (0, init_1.useColors)() ? options.borderColor || types_1.COLORS.primary : undefined;
    return types_1.moduleCache.boxen(content, {
        padding: options.padding ?? 1,
        margin: options.margin ?? 0,
        borderStyle: options.borderStyle || 'round',
        borderColor,
        title: options.title,
        titleAlignment: options.titleAlignment || 'center',
    });
}
exports.box = box;
/**
 * Render error box (red border)
 */
function errorBox(content, title = 'ERROR') {
    return box(content, {
        title,
        borderColor: 'red',
        borderStyle: 'round',
        padding: 1,
        margin: 1,
    });
}
exports.errorBox = errorBox;
/**
 * Render info box (primary color border)
 */
function infoBox(content, title) {
    return box(content, {
        title,
        borderColor: types_1.COLORS.primary,
        borderStyle: 'round',
        padding: 1,
    });
}
exports.infoBox = infoBox;
/**
 * Render warning box (yellow border)
 */
function warnBox(content, title = 'WARNING') {
    return box(content, {
        title,
        borderColor: 'yellow',
        borderStyle: 'round',
        padding: 1,
    });
}
exports.warnBox = warnBox;
//# sourceMappingURL=boxes.js.map