"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleStatus = void 0;
const docker_1 = require("../../docker");
const ui_1 = require("../../utils/ui");
const options_1 = require("./options");
const KNOWN_FLAGS = ['--host'];
async function handleStatus(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 status = await new docker_1.DockerExecutor().status({ host: parsed.host });
        console.log((0, ui_1.ok)(`Docker status${parsed.host ? ` for ${parsed.host}` : ''}`));
        console.log('');
        console.log((0, ui_1.subheader)('Compose:'));
        console.log(status.compose.stdout.trim() || (0, ui_1.info)('No docker compose output.'));
        if (status.supervisor?.exitCode === 0 && status.supervisor.stdout.trim()) {
            console.log('');
            console.log((0, ui_1.subheader)('Supervisor:'));
            console.log(status.supervisor.stdout.trim());
        }
        else if (status.supervisor) {
            console.log('');
            console.log((0, ui_1.subheader)('Supervisor:'));
            const detail = (status.supervisor.stderr || status.supervisor.stdout).trim();
            console.log((0, ui_1.info)(`Supervisor status check failed for ${(0, ui_1.color)('ccs-cliproxy', 'command')}.\n${detail || 'No additional detail provided.'}`));
        }
        else {
            console.log('');
            console.log((0, ui_1.info)(`Supervisor status unavailable for ${(0, ui_1.color)('ccs-cliproxy', 'command')}.`));
        }
    }
    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.handleStatus = handleStatus;
//# sourceMappingURL=status-subcommand.js.map