"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.EnhancedSpinner = void 0;
const chalk_1 = __importDefault(require("chalk"));
class EnhancedSpinner {
    // Keep output single-line and minimal
    constructor(text) {
        this.text = text;
        this.isSpinning = false;
        this.spinnerChars = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
        this.currentFrame = 0;
        this.interval = null;
        this.startTime = null;
        this.lastLineLength = 0;
    }
    clearLine() {
        // Clear the current line completely
        process.stdout.write("\r" + " ".repeat(this.lastLineLength) + "\r");
    }
    // Removed encouragement messages to avoid noisy logs
    updateSpinner() {
        const elapsed = this.startTime ? Date.now() - this.startTime : 0;
        const elapsedSeconds = Math.floor(elapsed / 1000);
        const timeDisplay = elapsedSeconds > 0 ? chalk_1.default.gray(` (${elapsedSeconds}s)`) : "";
        // Clear the current line completely
        this.clearLine();
        // Show main spinner line with encouragement inline
        const mainLine = `${chalk_1.default.blue(this.spinnerChars[this.currentFrame])} ${this.text}${timeDisplay}`;
        process.stdout.write(mainLine);
        this.lastLineLength = mainLine.replace(/\x1b\[[0-9;]*m/g, "").length;
        this.currentFrame = (this.currentFrame + 1) % this.spinnerChars.length;
    }
    start() {
        this.isSpinning = true;
        this.startTime = Date.now();
        this.interval = setInterval(() => {
            this.updateSpinner();
        }, 100);
        return this;
    }
    success(options = {}) {
        if (this.isSpinning) {
            if (this.interval)
                clearInterval(this.interval);
            this.clearLine();
            process.stdout.write(`${chalk_1.default.green("✅")} ${options.text || this.text}\n`);
            this.isSpinning = false;
        }
        return this;
    }
    error(options = {}) {
        if (this.isSpinning) {
            if (this.interval)
                clearInterval(this.interval);
            this.clearLine();
            process.stdout.write(`${chalk_1.default.red("❌")} ${options.text || this.text}\n`);
            this.isSpinning = false;
        }
        return this;
    }
    warn(options = {}) {
        if (this.isSpinning) {
            if (this.interval)
                clearInterval(this.interval);
            this.clearLine();
            process.stdout.write(`${chalk_1.default.yellow("⚠️")} ${options.text || this.text}\n`);
            this.isSpinning = false;
        }
        return this;
    }
    updateText(newText) {
        this.text = newText;
        return this;
    }
    reset() {
        this.startTime = Date.now();
        return this;
    }
    // Add missing methods for compatibility
    succeed(text) {
        return this.success({ text });
    }
    fail(text) {
        return this.error({ text });
    }
    stop() {
        if (this.isSpinning && this.interval) {
            clearInterval(this.interval);
            this.clearLine();
            this.isSpinning = false;
        }
        return this;
    }
}
exports.EnhancedSpinner = EnhancedSpinner;
//# sourceMappingURL=spinner.js.map