"use strict";
/* Socket Lib - Built with rolldown */
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_runtime = require('../_virtual/_rolldown/runtime.js');
const require_themes_themes = require('../themes/themes.js');
const require_themes_context = require('../themes/context.js');
const require_process_abort = require('../process/abort.js');
const require_themes_resolve = require('../themes/resolve.js');
const require_spinner_default = require('../spinner/default.js');
let src_external_yoctocolors_cjs = require("../external/yoctocolors-cjs");
src_external_yoctocolors_cjs = require_runtime.__toESM(src_external_yoctocolors_cjs);
let src_external__inquirer_checkbox = require("../external/@inquirer/checkbox");
src_external__inquirer_checkbox = require_runtime.__toESM(src_external__inquirer_checkbox);
let src_external__inquirer_confirm = require("../external/@inquirer/confirm");
src_external__inquirer_confirm = require_runtime.__toESM(src_external__inquirer_confirm);
let src_external__inquirer_input = require("../external/@inquirer/input");
src_external__inquirer_input = require_runtime.__toESM(src_external__inquirer_input);
let src_external__inquirer_password = require("../external/@inquirer/password");
src_external__inquirer_password = require_runtime.__toESM(src_external__inquirer_password);
let src_external__inquirer_search = require("../external/@inquirer/search");
src_external__inquirer_search = require_runtime.__toESM(src_external__inquirer_search);
let src_external__inquirer_select = require("../external/@inquirer/select");
src_external__inquirer_select = require_runtime.__toESM(src_external__inquirer_select);

//#region src/stdio/prompts.ts
/**
* @file User prompt utilities for interactive scripts. Provides inquirer.js
*   integration with spinner support, context handling, and theming.
*/
const abortSignal = require_process_abort.getAbortSignal();
const spinner = require_spinner_default.getDefaultSpinner();
const searchRaw = src_external__inquirer_search.default;
const selectModule = src_external__inquirer_select;
const selectRaw = selectModule.default;
const ActualSeparator = selectModule.Separator;
/**
* Apply a color to text using yoctocolors. Handles both named colors and RGB
* tuples.
*
* @private
*/
function applyColor(text, color) {
	if (typeof color === "string") return src_external_yoctocolors_cjs.default[color](text);
	const { 0: r, 1: g, 2: b } = color;
	return `\u001B[38;2;${r};${g};${b}m${text}\u001B[39m`;
}
/**
* Convert Socket theme to @inquirer theme format. Maps our theme colors to
* inquirer's style functions. Handles theme names, Theme objects, and passes
* through @inquirer themes.
*
* @example
*   ;```ts
*   // Socket theme name
*   createInquirerTheme('sunset')
*
*   // Socket Theme object
*   createInquirerTheme(SUNSET_THEME)
*
*   // @inquirer theme (passes through)
*   createInquirerTheme({ style: {...}, icon: {...} })
*   ```
*
* @param theme - Socket theme name, Theme object, or @inquirer theme.
*
* @returns @inquirer theme object
*/
function createInquirerTheme(theme) {
	if (typeof theme === "string" || isSocketTheme(theme)) {
		const socketTheme = resolveTheme(theme);
		const promptColor = require_themes_resolve.resolveColor(socketTheme.colors.prompt, socketTheme.colors);
		const textDimColor = require_themes_resolve.resolveColor(socketTheme.colors.textDim, socketTheme.colors);
		const errorColor = socketTheme.colors.error;
		const successColor = socketTheme.colors.success;
		const primaryColor = socketTheme.colors.primary;
		return {
			style: {
				message: (text) => applyColor(text, promptColor),
				answer: (text) => applyColor(text, primaryColor),
				help: (text) => applyColor(text, textDimColor),
				description: (text) => applyColor(text, textDimColor),
				disabled: (text) => applyColor(text, textDimColor),
				error: (text) => applyColor(text, errorColor),
				highlight: (text) => applyColor(text, primaryColor)
			},
			icon: {
				checked: applyColor("✓", successColor),
				unchecked: " ",
				cursor: applyColor("❯", primaryColor)
			}
		};
	}
	if (theme === void 0 || theme === null) return {};
	return theme;
}
/**
* Create a separator for select prompts. Creates a visual separator line in
* choice lists.
*
* @example
*   import { select, createSeparator } from '@socketsecurity/lib/stdio/prompts'
*
*   const choice = await select({
*     message: 'Choose an option:',
*     choices: [
*       { name: 'Option 1', value: 1 },
*       createSeparator(),
*       { name: 'Option 2', value: 2 },
*     ],
*   })
*
* @param text - Optional separator text (defaults to '───────')
*
* @returns Separator instance
*/
function createSeparator(text) {
	return new ActualSeparator(text);
}
/**
* Check if value is a Socket Theme object.
*
* @param value - Value to check.
*
* @returns True if value is a Socket Theme
*/
function isSocketTheme(value) {
	return typeof value === "object" && value !== null && "name" in value && "colors" in value;
}
/**
* Resolve theme name or object to Theme.
*
* @param theme - Theme name or object.
*
* @returns Resolved Theme
*/
function resolveTheme(theme) {
	return typeof theme === "string" ? require_themes_themes.THEMES[theme] ?? require_themes_themes.THEMES.socket : theme;
}
/**
* Wrap an inquirer prompt with spinner handling, theme injection, and signal
* injection. Automatically stops/starts spinners during prompt display, injects
* the current theme, and injects abort signals. Trims string results and
* handles cancellation gracefully.
*
* @example
*   const myPrompt = wrapPrompt(rawInquirerPrompt)
*   const result = await myPrompt({ message: 'Enter name:' })
*
* @template T - Type of the prompt result.
*
* @param inquirerPrompt - The inquirer prompt function to wrap.
*
* @returns Wrapped prompt function with spinner, theme, and signal handling
*/
/*@__NO_SIDE_EFFECTS__*/
function wrapPrompt(inquirerPrompt) {
	return async (...args) => {
		const origContext = args.length > 1 ? args[1] : void 0;
		const { spinner: contextSpinner, ...contextWithoutSpinner } = origContext ?? {};
		const spinnerInstance = contextSpinner !== void 0 ? contextSpinner : spinner;
		const signal = abortSignal;
		const config = args[0];
		if (config && typeof config === "object") if (!config["theme"]) config["theme"] = createInquirerTheme(require_themes_context.getTheme());
		else config["theme"] = createInquirerTheme(config["theme"]);
		if (origContext) args[1] = {
			signal,
			...contextWithoutSpinner
		};
		else args[1] = { signal };
		const wasSpinning = !!spinnerInstance?.isSpinning;
		spinnerInstance?.stop();
		let result;
		try {
			result = await inquirerPrompt(...args);
		} catch (e) {
			if (e instanceof TypeError) throw e;
		}
		if (wasSpinning) spinnerInstance.start();
		return typeof result === "string" ? result.trim() : result;
	};
}
/**
* Prompt to select multiple items from a list of choices. Wrapped with spinner
* handling and abort signal support.
*
* @example
*   const choices = await checkbox({
*     message: 'Select options:',
*     choices: [
*       { name: 'Option 1', value: 'opt1' },
*       { name: 'Option 2', value: 'opt2' },
*       { name: 'Option 3', value: 'opt3' },
*     ],
*   })
*/
const checkbox = /* @__PURE__ */ wrapPrompt(src_external__inquirer_checkbox.default);
/**
* Prompt for a yes/no confirmation. Wrapped with spinner handling and abort
* signal support.
*
* @example
*   const answer = await confirm({ message: 'Continue?' })
*   if (answer) { // user confirmed }
*/
const confirm = /* @__PURE__ */ wrapPrompt(src_external__inquirer_confirm.default);
/**
* Prompt for text input. Wrapped with spinner handling and abort signal
* support. Result is automatically trimmed.
*
* @example
*   const name = await input({ message: 'Enter your name:' })
*/
const input = /* @__PURE__ */ wrapPrompt(src_external__inquirer_input.default);
/**
* Prompt for password input (hidden characters). Wrapped with spinner handling
* and abort signal support.
*
* @example
*   const token = await password({ message: 'Enter API token:' })
*/
const password = /* @__PURE__ */ wrapPrompt(src_external__inquirer_password.default);
/**
* Prompt with searchable/filterable choices. Wrapped with spinner handling and
* abort signal support.
*
* @example
*   const result = await search({
*     message: 'Select a package:',
*     source: async input => fetchPackages(input),
*   })
*/
const search = /* @__PURE__ */ wrapPrompt(searchRaw);
/**
* Prompt to select from a list of choices. Wrapped with spinner handling and
* abort signal support.
*
* @example
*   const choice = await select({
*     message: 'Choose an option:',
*     choices: [
*       { name: 'Option 1', value: 'opt1' },
*       { name: 'Option 2', value: 'opt2' },
*     ],
*   })
*/
const select = /* @__PURE__ */ wrapPrompt(selectRaw);

//#endregion
exports.Separator = ActualSeparator;
exports.applyColor = applyColor;
exports.checkbox = checkbox;
exports.confirm = confirm;
exports.createInquirerTheme = createInquirerTheme;
exports.createSeparator = createSeparator;
exports.input = input;
exports.isSocketTheme = isSocketTheme;
exports.password = password;
exports.resolveTheme = resolveTheme;
exports.search = search;
exports.select = select;
exports.wrapPrompt = wrapPrompt;