"use strict";
/**
 * Spinner / Progress
 *
 * Ora-based spinner with TTY fallback
 * @module utils/ui/spinner
 */
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.spinner = void 0;
const types_1 = require("./types");
const init_1 = require("./init");
const colors_1 = require("./colors");
const indicators_1 = require("./indicators");
/**
 * Create and start a spinner
 * Falls back to plain text output in non-TTY environments
 */
async function spinner(options) {
    const opts = typeof options === 'string' ? { text: options } : options;
    const isEnabled = (0, init_1.isInteractive)();
    // Lazy load ora if not already loaded
    if (!types_1.moduleCache.ora && isEnabled) {
        try {
            types_1.moduleCache.ora = (await Promise.resolve().then(() => __importStar(require('ora')))).default;
        }
        catch (_e) {
            // Fallback to plain text
        }
    }
    if (types_1.moduleCache.ora && isEnabled) {
        const s = types_1.moduleCache
            .ora({
            text: opts.text,
            color: 'cyan',
            prefixText: opts.prefixText,
            isEnabled,
        })
            .start();
        return {
            succeed: (msg) => s.succeed(msg || `${(0, colors_1.color)('[OK]', 'success')} ${opts.text}`),
            fail: (msg) => s.fail(msg || `${(0, colors_1.color)('[X]', 'error')} ${opts.text}`),
            warn: (msg) => s.warn(msg || `${(0, colors_1.color)('[!]', 'warning')} ${opts.text}`),
            info: (msg) => s.info(msg || `${(0, colors_1.color)('[i]', 'info')} ${opts.text}`),
            update: (text) => {
                s.text = text;
            },
            stop: () => s.stop(),
        };
    }
    // Fallback: plain text (non-TTY)
    console.log(`[i] ${opts.text}...`);
    return {
        succeed: (msg) => console.log((0, indicators_1.ok)(msg || opts.text)),
        fail: (msg) => console.log((0, indicators_1.fail)(msg || opts.text)),
        warn: (msg) => console.log((0, indicators_1.warn)(msg || opts.text)),
        info: (msg) => console.log((0, indicators_1.info)(msg || opts.text)),
        update: (_text) => {
            /* no-op in non-TTY */
        },
        stop: () => {
            /* no-op */
        },
    };
}
exports.spinner = spinner;
//# sourceMappingURL=spinner.js.map