"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.createDocsCommand = createDocsCommand;
const p = __importStar(require("@clack/prompts"));
const browser_opener_1 = require("../services/browser-opener");
const env_loader_1 = require("../utils/env-loader");
const tool_docs_1 = require("../utils/tool-docs");
const logger_1 = require("../utils/logger");
const i18n_1 = require("../i18n");
const command_1 = require("../utils/command");
const README_URL = 'https://github.com/cymondez/runestone#readme';
function createDocsCommand() {
    const command = (0, command_1.createCommand)('docs')
        .description((0, i18n_1.t)('commands.docs.description'))
        .option('--ai-context', (0, i18n_1.t)('options.aiContext.description'))
        .action(async (options) => {
        if (!options.aiContext) {
            const locale = (0, i18n_1.resolveLocale)();
            const shouldOpen = await p.confirm({
                message: (0, i18n_1.formatMessage)(locale, 'docs.openReadme.prompt'),
                initialValue: true
            });
            if (p.isCancel(shouldOpen)) {
                p.cancel((0, i18n_1.formatMessage)(locale, 'docs.cancelled'));
                process.exit(0);
            }
            if (shouldOpen) {
                try {
                    (0, browser_opener_1.openUrl)(README_URL);
                    logger_1.logger.success((0, i18n_1.formatMessage)(locale, 'docs.openReadme.opened', { url: README_URL }));
                }
                catch (error) {
                    const message = error instanceof Error ? error.message : String(error);
                    logger_1.logger.error(message);
                    process.exitCode = 1;
                }
            }
            return;
        }
        const config = env_loader_1.envLoader.load();
        if (!env_loader_1.envLoader.hasRequiredVars(config)) {
            logger_1.logger.error((0, i18n_1.t)('docs.aiContext.notConfigured'));
            process.exitCode = 1;
            return;
        }
        process.stdout.write((0, tool_docs_1.renderAiPromptContext)(config));
    });
    return command;
}
//# sourceMappingURL=docs.js.map