"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CommandView = void 0;
const chalk_1 = __importDefault(require("chalk"));
const art_1 = require("../utils/art");
class CommandView {
    constructor() {
        this.genericStyle = chalk_1.default.blue;
        this.highlightStyle = chalk_1.default.redBright.bold;
        this.av = new art_1.Art(this.genericStyle, this.highlightStyle);
    }
    render(input) {
        process.stdout.write(input);
        process.stdout.write("\n");
    }
    headerRender(input) {
        const str = this.av.createMessage(input);
        this.render(str);
    }
    headerPattern(pattern) {
        return pattern.replace(/\*\*/g, "\\*\\*");
    }
    renderFileAdd({ pattern, filePaths, }) {
        const headerEmoji = filePaths.length > 0 ? "✅" : "❌";
        const emoji = filePaths.length > 0 ? "📜" : "❌";
        this.headerRender(`Glob (**${this.headerPattern(pattern)}**) added **${filePaths.length}** files ${headerEmoji}`);
        this.renderPatternAndFileNames({ emoji, pattern, filePaths });
    }
    renderRemoveFile({ pattern, filePaths, }) {
        const headerEmoji = filePaths.length > 0 ? "✅" : "😔";
        const emoji = filePaths.length > 0 ? "🗑️" : "❌";
        this.headerRender(`Glob (**${this.headerPattern(pattern)}**) removed **${filePaths.length}** files ${headerEmoji}:`);
        this.renderPatternAndFileNames({ emoji, pattern, filePaths });
    }
    renderListFilePaths(filePaths) {
        this.headerRender(`We are tracking **${filePaths.length || "no"}** files 🕵️`);
        if (filePaths.length > 0) {
            filePaths.forEach((filePath) => {
                this.renderIgnoringCwd(`| 🔎 ${filePath}`);
            });
        }
    }
    renderFindByPaths({ pattern, filePaths, }) {
        const headerEmoji = filePaths.length > 0 ? "✅" : "😔";
        const emoji = filePaths.length > 0 ? "🔎" : "❌";
        this.headerRender(`Glob (**${this.headerPattern(pattern)}**) found **${filePaths.length}** files ${headerEmoji}`);
        this.renderPatternAndFileNames({ emoji, pattern, filePaths });
    }
    renderInvalidCommand(examples) {
        this.headerRender(`Invalid use. Usage: **/<cmd> ${examples.join(" ")}**`);
    }
    renderPatternAndFileNames({ emoji, pattern, filePaths, }) {
        if (filePaths.length === 0) {
            this.render(this.genericStyle(`${emoji} None found...`));
            return;
        }
        // Sort array by number of found paths in ascending order
        const sortedFilepaths = filePaths.sort((a, b) => a.length - b.length);
        sortedFilepaths.forEach((filePath) => this.renderIgnoringCwd(`| ${emoji} ${filePath}`));
    }
    renderIgnoringCwd(input) {
        const cwd = process.cwd();
        const cwdRegex = new RegExp(cwd, "g");
        if (cwdRegex.test(input)) {
            const simplifiedInput = input.replace(cwdRegex, ".");
            this.render(chalk_1.default.hex("#abb2bf").bold(simplifiedInput));
        }
        else {
            this.render(this.genericStyle(input));
        }
    }
}
exports.CommandView = CommandView;
