"use strict";
/**
 * Config Auth Disable Command
 *
 * Disable dashboard authentication with confirmation.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleDisable = void 0;
const prompt_1 = require("../../utils/prompt");
const ui_1 = require("../../utils/ui");
const config_loader_facade_1 = require("../../config/config-loader-facade");
/**
 * Handle disable command - disable auth with confirmation
 */
async function handleDisable() {
    await (0, ui_1.initUI)();
    console.log('');
    console.log((0, ui_1.header)('Disable Dashboard Auth'));
    console.log('');
    const config = (0, config_loader_facade_1.getDashboardAuthConfig)();
    // Check if already disabled
    if (!config.enabled) {
        console.log((0, ui_1.info)('Dashboard authentication is already disabled.'));
        console.log('');
        console.log((0, ui_1.dim)('    To enable: ccs config auth setup'));
        console.log('');
        return;
    }
    // Check for ENV override
    if (process.env.CCS_DASHBOARD_AUTH_ENABLED) {
        console.log((0, ui_1.warn)('CCS_DASHBOARD_AUTH_ENABLED environment variable is set.'));
        console.log((0, ui_1.info)('Disabling in config.yaml, but ENV var will still override.'));
        console.log('');
    }
    // Confirm before disabling
    console.log((0, ui_1.warn)('This will disable login protection for the dashboard.'));
    console.log((0, ui_1.info)('Anyone with network access will be able to view the dashboard.'));
    console.log('');
    const confirmed = await prompt_1.InteractivePrompt.confirm('Disable authentication?', {
        default: false, // Safe default
    });
    if (!confirmed) {
        console.log('');
        console.log((0, ui_1.info)('Cancelled. Authentication remains enabled.'));
        console.log('');
        return;
    }
    // Disable auth
    (0, config_loader_facade_1.mutateConfig)((fullConfig) => {
        fullConfig.dashboard_auth = {
            enabled: false,
            username: fullConfig.dashboard_auth?.username ?? '',
            password_hash: fullConfig.dashboard_auth?.password_hash ?? '',
            session_timeout_hours: fullConfig.dashboard_auth?.session_timeout_hours ?? 24,
        };
    });
    console.log('');
    console.log((0, ui_1.ok)('Dashboard authentication disabled'));
    console.log('');
    console.log((0, ui_1.info)('Credentials preserved - re-enable with: ccs config auth setup'));
    console.log('');
}
exports.handleDisable = handleDisable;
//# sourceMappingURL=disable-command.js.map