/*! © 2026 Yahoo, Inc. UDS Tailwind and Purger v0.0.0-development */

//#region ../cli/dist/lib/spinner.mjs
/*! © 2026 Yahoo, Inc. UDS CLI v0.0.0-development */
/**
* Simple terminal spinner for showing progress during long operations.
* Uses Braille spinner characters for a smooth animation.
*/
let spinnerInterval = null;
let currentMessage = "";
const frames = [
	"⠋",
	"⠙",
	"⠹",
	"⠸",
	"⠼",
	"⠴",
	"⠦",
	"⠧",
	"⠇",
	"⠏"
];
let frameIndex = 0;
/**
* Start a spinner with a message.
* Only one spinner can be active at a time.
*/
function spinStart(message) {
	if (spinnerInterval) spinStop();
	currentMessage = message;
	frameIndex = 0;
	process.stdout.write("\x1B[?25l");
	spinnerInterval = setInterval(() => {
		const frame = frames[frameIndex];
		process.stdout.write(`\r${frame} ${currentMessage}`);
		frameIndex = (frameIndex + 1) % frames.length;
	}, 80);
}
/**
* Stop the spinner and optionally show a final message.
* @param iconOrMessage - Optional icon to show OR the message if second param not provided
* @param message - Optional final message to display
*/
function spinStop(iconOrMessage, message) {
	if (spinnerInterval) {
		clearInterval(spinnerInterval);
		spinnerInterval = null;
	}
	process.stdout.write("\r\x1B[K");
	process.stdout.write("\x1B[?25h");
	if (iconOrMessage || message) {
		const finalMessage = message ? `${iconOrMessage} ${message}` : iconOrMessage;
		console.log(finalMessage);
	}
}

//#endregion
exports.spinStart = spinStart;
exports.spinStop = spinStop;