"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleConfig = void 0;
const docker_1 = require("../../docker");
const ui_1 = require("../../utils/ui");
const options_1 = require("./options");
const KNOWN_FLAGS = ['--host'];
async function handleConfig(args) {
    await (0, ui_1.initUI)();
    const parsed = (0, options_1.parseDockerTarget)(args, KNOWN_FLAGS);
    const errors = [
        ...parsed.errors,
        ...(0, options_1.collectUnexpectedDockerArgs)(parsed.remainingArgs, {
            knownFlags: [],
            maxPositionals: 0,
        }),
    ];
    if (errors.length > 0) {
        console.error((0, ui_1.box)((0, ui_1.fail)(errors.join('\n')), { title: 'Docker', padding: 1 }));
        process.exitCode = 1;
        return;
    }
    try {
        const config = new docker_1.DockerExecutor().getConfig({ host: parsed.host });
        const rows = [
            ['Mode', config.remote ? `remote (${config.host})` : 'local'],
            ['Local CCS Dir', config.ccsDir],
            ['Bundled Docker Dir', config.dockerDir],
            ['Compose File', config.composeFile],
            ['Dockerfile', config.dockerfile],
            ['Supervisor Config', config.supervisordConfig],
            ['Entrypoint', config.entrypoint],
            ['Remote Deploy Dir', config.remoteDeployDir],
            ['Compose Service', config.composeService],
            ['Container Name', config.containerName],
            ['Dashboard Port', String(config.dashboardPort)],
            ['CLIProxy Port', String(config.proxyPort)],
        ];
        console.log((0, ui_1.table)(rows.map(([key, value]) => [(0, ui_1.color)(key, 'primary'), value]), {
            head: ['Setting', 'Value'],
            style: 'ascii',
        }));
    }
    catch (error) {
        console.error((0, ui_1.box)((0, ui_1.fail)(error instanceof Error ? error.message : String(error)), {
            title: 'Docker',
            padding: 1,
        }));
        process.exitCode = 1;
    }
}
exports.handleConfig = handleConfig;
//# sourceMappingURL=config-subcommand.js.map