"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TokenView = void 0;
const chalk_1 = __importDefault(require("chalk"));
const art_1 = require("../utils/art");
const chalk_util_1 = require("../utils/chalk-util");
class TokenView {
    constructor() {
        this.genericStyle = chalk_1.default.blue;
        this.highlightStyle = chalk_1.default.redBright.bold;
        this.av = new art_1.Art(this.genericStyle, this.highlightStyle);
    }
    headerRender(input) {
        const str = this.av.createMessage(input);
        this.render(str);
    }
    render(input, renderColor = "lightBlue") {
        (0, chalk_util_1.chalkRender)(input, renderColor);
        process.stdout.write("\n");
    }
    renderTokenReport(tokenReport) {
        // this function will interact with the SPC to get the token report
        // this token report will display the following
        // - Total Tokens Remaining:
        // - Tokens Budgetted: (just max tokens)
        // - Tokens Used: (SP + CB + ER)
        // - Total for Files: `<>`
        //   - File1: `<>`
        //   - File2: `<>`
        //   - File3: `<>`
        // - System Prompt Total Tokens: `<>`
        //   - Prefix Instruction: `<>`
        //   - Injection Files: `<>`
        //   - Sufffix Instruction: `<>`
        // - Conversation Buffer: `<>`
        // - Error Correction: `<>`
        // - (Unaccounted) Conversation History: `<>`
        // start rendering here via this.render(...)
        const tokensRemainingEmoji = tokenReport.totalTokensRemaining > 0 ? "✅" : "❌";
        let output = "";
        output += "Token Report";
        output += "\n-------------";
        output += `\nTotal Tokens Remaining: ${tokenReport.totalTokensRemaining} ${tokensRemainingEmoji}`;
        output += `\nTokens Budgetted: ${tokenReport.tokensBudgeted}`;
        output += `\nTokens Used: ${tokenReport.tokensUsed}`;
        output += `\nTotal for Files: ${tokenReport.totalForFiles}`;
        output += `\nFile Breakdown:`;
        let maxFileNameLength = Math.max(...tokenReport.fileBreakdown.map((file) => file.fileName.length));
        output += `\n| 📚 ${"Filename".padEnd(maxFileNameLength)}: Tokens`;
        tokenReport.fileBreakdown
            .sort((a, b) => b.tokenLength - a.tokenLength)
            .forEach((file) => {
            let paddedFileName = file.fileName.padEnd(maxFileNameLength);
            output += `\n| 📜 ${(0, chalk_util_1.chalkString)(`${paddedFileName}: ${file.tokenLength}`, "steelBlue")}`;
        });
        output += `\nSystem Prompt Total Tokens: ${tokenReport.systemPromptTotalTokens}`;
        output += `\nSystem Prompt Breakdown:`;
        output += `\n  Prefix Instruction: ${tokenReport.systemPromptBreakdown.prefixInstruction}`;
        output += `\n  Injection Instruction: ${tokenReport.systemPromptBreakdown.injectionInstruction}`;
        output += `\n  Suffix Instruction: ${tokenReport.systemPromptBreakdown.suffixInstruction}`;
        output += `\nConversation Buffer: ${tokenReport.conversationBuffer}`;
        output += `\nError Correction: ${tokenReport.errorCorrection}`;
        output += `\n(Unaccounted) Conversation History: ${tokenReport.unaccountedConversationHistory}`;
        this.render(output);
    }
    renderFilesTooLargeError(tokenReport) {
        this.headerRender(`Files **exceed usage by ${tokenReport.totalTokensRemaining * -1}** tokens. Use:`);
        this.headerRender("- **/tr** to see tokens per file.");
        this.headerRender("- **/rf <glob-pattern>** to remove reduce files tracked.");
    }
    renderNLInputTooLargeError({ inputTL, tokensRemaining, }) {
        this.headerRender("Natural Langauge input is **too long**.");
        this.headerRender(`- Input Token Length is: **${inputTL}**`);
        this.headerRender(`- Remaining tokens is is: **${tokensRemaining}**`);
    }
}
exports.TokenView = TokenView;
