"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.doSession = doSession;
exports.doContext = doContext;
exports.doDecisions = doDecisions;
const utils_1 = require("../utils");
const project = (0, utils_1.getProjectName)();
function doSession(args) {
    (0, utils_1.printHeader)('Cell Session');
    const sub = args[1] || '';
    if (sub === 'start') {
        const tool = args[2] || 'cli';
        (0, utils_1.httpPost)('/session/start', { toolName: tool, project }).then((result) => {
            (0, utils_1.printSuccess)(`Session ${result.sessionId} started for ${project} on ${tool}`);
        }).catch(() => (0, utils_1.printWarning)('Failed to start session'));
        return;
    }
    if (sub === 'end') {
        const sessionId = parseInt(args[2] || '0');
        if (!sessionId) {
            (0, utils_1.printWarning)('Usage: cell session end <sessionId>');
            return;
        }
        (0, utils_1.httpPost)('/session/end', { sessionId }).then(() => {
            (0, utils_1.printSuccess)(`Session ${sessionId} ended`);
        }).catch(() => (0, utils_1.printWarning)('Failed to end session'));
        return;
    }
    // Default: show recent sessions
    (0, utils_1.httpGet)(`/session/history?project=${project}&limit=5`).then((result) => {
        if (result.sessions && result.sessions.length > 0) {
            for (const s of result.sessions) {
                console.log(`  Session ${s.sessionId}: ${s.tool} (${s.startTime})`);
                (0, utils_1.printDim)(`    Files: ${s.filesCount} | Decisions: ${s.decisionsCount}`);
            }
        }
        else {
            (0, utils_1.printDim)('No sessions found');
        }
    }).catch(() => (0, utils_1.printWarning)('Failed to get sessions'));
}
function doContext(args) {
    (0, utils_1.printHeader)('Cell Context');
    const tool = args[1] || 'cli';
    const compact = args.includes('--short');
    const projectPath = process.env.CELL_PROJECT_PATH || process.cwd();
    (0, utils_1.httpGet)(`/context/inject?projectPath=${encodeURIComponent(projectPath)}&tool=${tool}&compact=${compact}`).then((result) => {
        if (result.content && result.content.length > 0) {
            for (const c of result.content) {
                console.log(c.text);
            }
        }
        else {
            (0, utils_1.printDim)('No context available. Run: cell scan');
        }
    }).catch(() => (0, utils_1.printWarning)('Failed to get context'));
}
function doDecisions(args) {
    (0, utils_1.printHeader)('Cell Decisions');
    (0, utils_1.httpGet)(`/session/decisions?project=${project}`).then((result) => {
        if (result.decisions && result.decisions.length > 0) {
            for (const d of result.decisions.slice(0, 20)) {
                const icon = d.worked ? '✅' : '❌';
                console.log(`  ${icon} ${d.decision}`);
                (0, utils_1.printDim)(`    ${d.approach || ''} | ${d.created_at}`);
            }
        }
        else {
            (0, utils_1.printDim)('No decisions logged yet');
        }
        if (result.summary) {
            console.log();
            console.log(utils_1.C.bold('  Summary:'));
            console.log(`    Total: ${result.summary.total || 0}`);
            console.log(`    Worked: ${result.summary.worked || 0}`);
            console.log(`    Failed: ${result.summary.failed || 0}`);
        }
    }).catch(() => (0, utils_1.printWarning)('Failed to get decisions'));
}
//# sourceMappingURL=session.js.map