"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.log = exports.logger = exports.Logger = exports.LogLevel = void 0;
const chalk_1 = __importDefault(require("chalk"));
var LogLevel;
(function (LogLevel) {
    LogLevel[LogLevel["ERROR"] = 0] = "ERROR";
    LogLevel[LogLevel["WARN"] = 1] = "WARN";
    LogLevel[LogLevel["INFO"] = 2] = "INFO";
    LogLevel[LogLevel["VERBOSE"] = 3] = "VERBOSE";
    LogLevel[LogLevel["DEBUG"] = 4] = "DEBUG";
})(LogLevel || (exports.LogLevel = LogLevel = {}));
class Logger {
    constructor() {
        this.logLevel = LogLevel.INFO;
        this.isQuiet = false;
        // Check for CLI flags in process.argv
        const args = process.argv;
        // Check for verbose flag
        if (args.includes("--verbose") || args.includes("-v")) {
            this.logLevel = LogLevel.VERBOSE;
        }
        // Check for quiet flag (quiet takes precedence)
        else if (args.includes("--quiet") || args.includes("-q")) {
            this.isQuiet = true;
            this.logLevel = LogLevel.ERROR;
        }
        // Check for npm_config environment variables (when called via npm scripts)
        else if (process.env.npm_config_verbose === "true") {
            this.logLevel = LogLevel.VERBOSE;
        }
        else if (process.env.npm_config_quiet === "true") {
            this.isQuiet = true;
            this.logLevel = LogLevel.ERROR;
        }
    }
    static getInstance() {
        if (!Logger.instance) {
            Logger.instance = new Logger();
        }
        return Logger.instance;
    }
    setLogLevel(level) {
        this.logLevel = level;
    }
    setQuiet(quiet) {
        this.isQuiet = quiet;
        if (quiet) {
            this.logLevel = LogLevel.ERROR;
        }
    }
    getLogLevel() {
        return this.logLevel;
    }
    shouldLog(level) {
        if (this.isQuiet && level > LogLevel.ERROR) {
            return false;
        }
        return level <= this.logLevel;
    }
    error(message, ...args) {
        if (this.shouldLog(LogLevel.ERROR)) {
            console.error(chalk_1.default.red(`❌ ${message}`), ...args);
        }
    }
    warn(message, ...args) {
        if (this.shouldLog(LogLevel.WARN)) {
            console.warn(chalk_1.default.yellow(`⚠️  ${message}`), ...args);
        }
    }
    info(message, ...args) {
        if (this.shouldLog(LogLevel.INFO)) {
            console.log(chalk_1.default.blue(`ℹ️  ${message}`), ...args);
        }
    }
    success(message, ...args) {
        if (this.shouldLog(LogLevel.INFO)) {
            console.log(chalk_1.default.green(`✅ ${message}`), ...args);
        }
    }
    verbose(message, ...args) {
        if (this.shouldLog(LogLevel.VERBOSE)) {
            console.log(chalk_1.default.gray(`🔍 ${message}`), ...args);
        }
    }
    debug(message, ...args) {
        if (this.shouldLog(LogLevel.DEBUG)) {
            console.log(chalk_1.default.gray(`🐛 ${message}`), ...args);
        }
    }
    // Clean progress indicators (always shown unless quiet)
    progress(message) {
        if (!this.isQuiet) {
            console.log(chalk_1.default.cyan(`⏳ ${message}`));
        }
    }
    step(message) {
        if (!this.isQuiet) {
            console.log(chalk_1.default.blue(`➡️  ${message}`));
        }
    }
    // Silent methods for internal use
    silent(message, ...args) {
        console.log(message, ...args);
    }
}
exports.Logger = Logger;
// Export singleton instance
exports.logger = Logger.getInstance();
// Convenience functions
exports.log = {
    error: (message, ...args) => exports.logger.error(message, ...args),
    warn: (message, ...args) => exports.logger.warn(message, ...args),
    info: (message, ...args) => exports.logger.info(message, ...args),
    success: (message, ...args) => exports.logger.success(message, ...args),
    verbose: (message, ...args) => exports.logger.verbose(message, ...args),
    debug: (message, ...args) => exports.logger.debug(message, ...args),
    progress: (message) => exports.logger.progress(message),
    step: (message) => exports.logger.step(message),
    silent: (message, ...args) => exports.logger.silent(message, ...args),
};
//# sourceMappingURL=logger.js.map