/**
 * 4Runr OS UI Primitives
 * Building blocks for all views - compose these, don't print raw strings
 */
import { C_BRAND, C_ACCENT, C_TEXT, C_MUTED, C_SUCCESS, C_WARN, C_ERROR, C_DIM, C_BRAND_BRIGHT, RESET, BOLD, } from './theme.js';
/**
 * Header: consistent brand bar at top
 * Phase 4: Authority, not decoration
 * Format: 4Runr | AI AGENT OPERATING SYSTEM | vX.Y.Z | [MODE]
 * Strong separator, not decorative box
 */
export function Header(version, mode) {
    const modeText = mode ? ` | ${mode}` : '';
    const terminalWidth = process.stdout.columns || 80;
    const separatorWidth = Math.max(terminalWidth - 2, 78);
    const separator = `${C_BRAND}${'═'.repeat(separatorWidth)}${RESET}`;
    // Header line: Brand (purple), system name (white), version (muted), mode
    const headerLine = `  ${C_BRAND_BRIGHT}4Runr${RESET}  ${C_TEXT}AI AGENT OPERATING SYSTEM${RESET}  ${C_MUTED}v${version}${RESET}${modeText}`;
    return `${separator}\n${headerLine}\n${separator}`;
}
/**
 * StatusBar: 1-2 line HUD after each command
 * Shows: MODE, CONNECTION, WORKSPACE, LAST ACTION
 */
export function StatusBar(params) {
    const { mode, connected, target, workspace, lastAction } = params;
    const modeText = `MODE: ${mode}`;
    const connText = connected
        ? `CONNECTION: ${C_SUCCESS}Connected${RESET}${target ? ` ${C_MUTED}(${target})${RESET}` : ''}`
        : `CONNECTION: ${C_WARN}Not Connected${RESET}`;
    const workspaceText = workspace ? `WORKSPACE: ${C_TEXT}${workspace}${RESET}` : '';
    const lastText = lastAction ? `LAST: ${lastAction}` : '';
    const parts = [modeText, connText, workspaceText, lastText].filter(Boolean);
    return `${C_DIM}${parts.join('  ')}${RESET}`;
}
/**
 * Section: clean blocks with strong separators
 * Phase 4: Structural separators, not decorative
 * Structure: Title (ALL CAPS) | Full-width separator | Lines (indented)
 */
export function Section(title, lines) {
    // Headers: ALL CAPS, visually dominant (brand color for authority)
    const titleLine = `${C_BRAND}${BOLD}${title.toUpperCase()}${RESET}`;
    // Strong separator: full-width, structural boundary (not decorative)
    // Use full terminal width (80 chars standard, but adapt to actual width)
    const terminalWidth = process.stdout.columns || 80;
    const separator = `${C_DIM}${'─'.repeat(Math.max(terminalWidth - 2, 78))}${RESET}`;
    // Content: indented, calm alignment
    const content = lines.length > 0
        ? lines.map(line => `  ${line}`).join('\n')
        : `  ${C_MUTED}(empty)${RESET}`;
    return `${titleLine}\n${separator}\n${content}`;
}
/**
 * Table: aligned columns for lists
 * Handles truncation: IDs (8 chars), names (with ...), max 10 rows default
 */
export function Table(headers, rows, maxRows = 10) {
    if (rows.length === 0) {
        return `${C_MUTED}  (empty)${RESET}`;
    }
    const displayRows = rows.slice(0, maxRows);
    // Calculate column widths
    const widths = headers.map((header, i) => {
        const headerWidth = header.length;
        const maxContentWidth = Math.max(...displayRows.map(row => (row[i] || '').length));
        return Math.max(headerWidth, maxContentWidth, 8);
    });
    // Build header
    const headerLine = headers
        .map((header, i) => header.padEnd(widths[i]))
        .join('  ');
    // Build rows
    const rowLines = displayRows.map(row => {
        return row
            .map((cell, i) => {
            const width = widths[i];
            // Truncate if needed
            if (cell.length > width) {
                return cell.substring(0, width - 3) + '...';
            }
            return cell.padEnd(width);
        })
            .join('  ');
    });
    const headerText = `${C_MUTED}${headerLine}${RESET}`;
    const rowText = rowLines.map(line => `  ${line}`).join('\n');
    return `${headerText}\n${rowText}${rows.length > maxRows ? `\n${C_MUTED}  ... ${rows.length - maxRows} more${RESET}` : ''}`;
}
/**
 * Alert: consistent success/warn/error output
 * Format: [OK|WARN|ERROR|INFO] Title | Detail | NEXT: command
 */
export function Alert(type, title, message, hintCommand) {
    const typeMap = {
        success: { label: 'OK', color: C_SUCCESS },
        warn: { label: 'WARN', color: C_WARN },
        error: { label: 'ERROR', color: C_ERROR },
        info: { label: 'INFO', color: C_ACCENT },
    };
    const { label, color } = typeMap[type];
    const titleLine = `${color}${label}${RESET}  ${title}`;
    const messageLine = message ? `\n  ${C_MUTED}${message}${RESET}` : '';
    const hintLine = hintCommand ? `\n  ${C_ACCENT}NEXT: ${hintCommand}${RESET}` : '';
    return `${titleLine}${messageLine}${hintLine}`;
}
/**
 * Progress: show work is happening
 * Modes: spinner (if supported) or fallback line
 */
let progressActive = false;
let progressInterval = null;
export function Progress(label, mode = 'line') {
    const frames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
    let frameIndex = 0;
    return {
        start: () => {
            if (progressActive)
                return;
            progressActive = true;
            if (mode === 'spinner' && process.stdout.isTTY) {
                process.stdout.write(`${C_ACCENT}${label}${RESET} `);
                progressInterval = setInterval(() => {
                    process.stdout.write(`\r${C_ACCENT}${label}${RESET} ${frames[frameIndex % frames.length]}`);
                    frameIndex++;
                }, 100);
            }
            else {
                process.stdout.write(`${C_ACCENT}${label}${RESET} ${C_MUTED}WORKING...${RESET}`);
            }
        },
        stop: (success, message) => {
            if (progressInterval) {
                clearInterval(progressInterval);
                progressInterval = null;
            }
            progressActive = false;
            if (mode === 'spinner' && process.stdout.isTTY) {
                process.stdout.write(`\r${' '.repeat(50)}\r`); // Clear line
            }
            const status = success ? `${C_SUCCESS}OK${RESET}` : `${C_ERROR}ERROR${RESET}`;
            const msg = message ? ` ${message}` : '';
            console.log(`${C_ACCENT}${label}${RESET} ${status}${msg}`);
        },
    };
}
/**
 * Prompt: consistent input line
 * Format: 4runr> or 4runr:view>
 */
export function Prompt(view) {
    const viewSuffix = view ? `:${view}` : '';
    return `${C_ACCENT}4runr${viewSuffix}>${RESET} `;
}
/**
 * Helper: truncate ID to 8 chars
 */
export function truncateId(id, length = 8) {
    return id.length > length ? id.substring(0, length) : id;
}
/**
 * Helper: truncate text with ellipsis
 */
export function truncateText(text, maxLength) {
    if (text.length <= maxLength)
        return text;
    return text.substring(0, maxLength - 3) + '...';
}
//# sourceMappingURL=ui-primitives.js.map