"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RendererModule = void 0;
const BaseChatModule_1 = require("./BaseChatModule");
const loadRenderer_1 = require("../renderer/loadRenderer");
const renderer_1 = require("../renderer");
const BUILTIN_RENDERERS = ["basic", "compact", "fancy"];
class RendererModule extends BaseChatModule_1.BaseChatModule {
    name = "renderer";
    description = "Renderer switching functionality";
    currentRendererName = "basic";
    agentModule;
    constructor(agentModule) {
        super();
        this.agentModule = agentModule;
    }
    async initialize(service) {
        await super.initialize(service);
        const context = service.getContext();
        if (!context.renderer) {
            service.setContext({ renderer: new renderer_1.ConsoleRenderer() });
        }
    }
    getCommands() {
        return [
            {
                name: "render",
                description: "Switch the active renderer or show current renderer info",
                handler: this.handleRenderCommand.bind(this),
            },
        ];
    }
    getModes() {
        return [];
    }
    async handleRenderCommand(args) {
        const specifier = args[0]?.trim();
        if (!specifier) {
            console.log(`\n🎨 Current renderer: ${this.currentRendererName}`);
            console.log("\nAvailable built-in renderers:");
            for (const name of BUILTIN_RENDERERS) {
                const marker = name === this.currentRendererName ? " ← active" : "";
                console.log(`  ${name}${marker}`);
            }
            console.log("\nUsage: /render <name>   (e.g. /render fancy, /render compact, /render basic)");
            console.log("       /render <path>   (e.g. /render ./my-renderer.js)");
            console.log("       /render <pkg>    (e.g. /render @my-org/knowhow-renderer)");
            return;
        }
        try {
            console.log(`🔄 Loading renderer: ${specifier}...`);
            const newRenderer = await (0, loadRenderer_1.loadRenderer)(specifier);
            const currentRenderer = this.chatService?.getContext()?.renderer;
            const activeTaskId = currentRenderer?.getActiveTaskId();
            if (activeTaskId) {
                newRenderer.setActiveTaskId(activeTaskId);
            }
            this.chatService?.setContext({ renderer: newRenderer });
            this.currentRendererName = specifier;
            if (this.agentModule && activeTaskId) {
                this.agentModule.rewireAgentRendering();
            }
            console.log(`✅ Renderer switched to: ${specifier}`);
        }
        catch (err) {
            console.error(`❌ Failed to load renderer "${specifier}": ${err.message}`);
        }
    }
    async handleInput(input, context) {
        return false;
    }
    async cleanup() {
    }
}
exports.RendererModule = RendererModule;
//# sourceMappingURL=RendererModule.js.map