"use strict";
/**
 * Config Auth Show Command
 *
 * Display current dashboard authentication status.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleShow = void 0;
const ui_1 = require("../../utils/ui");
const config_loader_facade_1 = require("../../config/config-loader-facade");
/**
 * Get auth status info with ENV override detection
 */
function getAuthStatus() {
    const config = (0, config_loader_facade_1.getDashboardAuthConfig)();
    return {
        enabled: config.enabled,
        configured: !!(config.username && config.password_hash),
        username: config.username,
        sessionTimeoutHours: config.session_timeout_hours ?? 24,
        envOverride: {
            enabled: process.env.CCS_DASHBOARD_AUTH_ENABLED !== undefined,
            username: process.env.CCS_DASHBOARD_USERNAME !== undefined,
            passwordHash: process.env.CCS_DASHBOARD_PASSWORD_HASH !== undefined,
        },
    };
}
/**
 * Handle show command - display current auth status
 */
async function handleShow() {
    await (0, ui_1.initUI)();
    console.log('');
    console.log((0, ui_1.header)('Dashboard Auth Status'));
    console.log('');
    const status = getAuthStatus();
    // Status section
    console.log((0, ui_1.subheader)('Configuration'));
    if (status.enabled) {
        console.log((0, ui_1.ok)('Authentication: Enabled'));
    }
    else {
        console.log((0, ui_1.info)('Authentication: Disabled'));
    }
    if (status.configured) {
        console.log((0, ui_1.ok)(`Username: ${status.username}`));
        console.log((0, ui_1.info)(`Session timeout: ${status.sessionTimeoutHours} hours`));
    }
    else {
        console.log((0, ui_1.warn)('Not configured - run `ccs config auth setup`'));
    }
    console.log('');
    // ENV override section
    const hasEnvOverride = status.envOverride.enabled || status.envOverride.username || status.envOverride.passwordHash;
    if (hasEnvOverride) {
        console.log((0, ui_1.subheader)('Environment Overrides'));
        console.log((0, ui_1.warn)('The following ENV vars override config.yaml:'));
        if (status.envOverride.enabled) {
            const value = process.env.CCS_DASHBOARD_AUTH_ENABLED;
            console.log(`  ${(0, ui_1.color)('CCS_DASHBOARD_AUTH_ENABLED', 'command')}=${value}`);
        }
        if (status.envOverride.username) {
            const value = process.env.CCS_DASHBOARD_USERNAME;
            console.log(`  ${(0, ui_1.color)('CCS_DASHBOARD_USERNAME', 'command')}=${value}`);
        }
        if (status.envOverride.passwordHash) {
            console.log(`  ${(0, ui_1.color)('CCS_DASHBOARD_PASSWORD_HASH', 'command')}=***`);
        }
        console.log('');
    }
    // Help section
    console.log((0, ui_1.subheader)('Commands'));
    console.log((0, ui_1.dim)('  ccs config auth setup     Configure authentication'));
    console.log((0, ui_1.dim)('  ccs config auth disable   Disable authentication'));
    console.log((0, ui_1.dim)('  ccs config                Open dashboard'));
    console.log('');
}
exports.handleShow = handleShow;
//# sourceMappingURL=show-command.js.map