"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.promptForConfig = promptForConfig;
const readline = __importStar(require("readline/promises"));
const process_1 = require("process");
const constants_1 = require("./constants");
const logger = __importStar(require("./logger"));
async function ask(rl, question, defaultValue) {
    const answer = await rl.question(`  ${question} [${defaultValue}]: `);
    return answer.trim() || defaultValue;
}
async function confirm(rl, question, defaultYes) {
    const hint = defaultYes ? 'Y/n' : 'y/N';
    const answer = await rl.question(`  ${question} [${hint}]: `);
    if (!answer.trim())
        return defaultYes;
    return answer.trim().toLowerCase().startsWith('y');
}
async function promptForConfig(detected, options) {
    // Non-interactive: accept all defaults
    if (options.yes || options.detect) {
        return {
            config: {
                ...detected,
                projectName: options.name || detected.projectName,
                coverageThreshold: constants_1.DEFAULT_COVERAGE,
                claudeCode: true,
            },
            mode: options.detect ? 'dx-only' : 'full',
        };
    }
    const rl = readline.createInterface({ input: process_1.stdin, output: process_1.stdout });
    try {
        // Show detected stack
        logger.header('Detected Stack');
        const langs = Object.entries(detected.languages)
            .filter(([, v]) => v)
            .map(([k]) => k);
        const infra = Object.entries(detected.infrastructure)
            .filter(([, v]) => v)
            .map(([k]) => k);
        if (langs.length)
            logger.info(`Languages: ${langs.join(', ')}`);
        if (infra.length)
            logger.info(`Infrastructure: ${infra.join(', ')}`);
        console.log('');
        const includeAll = await confirm(rl, 'Include all detected?', true);
        if (!includeAll) {
            // Allow deselecting — for simplicity, just ask per language
            for (const lang of Object.keys(detected.languages)) {
                if (detected.languages[lang]) {
                    detected.languages[lang] = await confirm(rl, `Include ${lang}?`, true);
                }
            }
        }
        const projectName = options.name || (await ask(rl, 'Project name?', detected.projectName));
        const includeFull = await confirm(rl, 'Include quality infrastructure (CI, hooks, linters)?', true);
        const mode = includeFull ? 'full' : 'dx-only';
        let coverageThreshold = constants_1.DEFAULT_COVERAGE;
        if (includeFull) {
            coverageThreshold = await ask(rl, 'Coverage threshold?', constants_1.DEFAULT_COVERAGE);
        }
        return {
            config: {
                ...detected,
                projectName,
                coverageThreshold,
                claudeCode: true,
            },
            mode,
        };
    }
    finally {
        rl.close();
    }
}
//# sourceMappingURL=prompts.js.map