"use strict";
/* Socket Lib - Built with esbuild */
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var prompts_exports = {};
__export(prompts_exports, {
  Separator: () => ActualSeparator,
  checkbox: () => checkbox,
  confirm: () => confirm,
  createInquirerTheme: () => createInquirerTheme,
  createSeparator: () => createSeparator,
  input: () => input,
  password: () => password,
  search: () => search,
  select: () => select,
  wrapPrompt: () => wrapPrompt
});
module.exports = __toCommonJS(prompts_exports);
var import_process = require("#constants/process");
var import_context = require("../themes/context");
var import_themes = require("../themes/themes");
var import_utils = require("../themes/utils");
var import_yoctocolors_cjs = __toESM(require("../external/yoctocolors-cjs"));
const abortSignal = (0, import_process.getAbortSignal)();
const spinner = (0, import_process.getSpinner)();
function applyColor(text, color) {
  if (typeof color === "string") {
    return import_yoctocolors_cjs.default[color](text);
  }
  const { 0: r, 1: g, 2: b } = color;
  return `\x1B[38;2;${r};${g};${b}m${text}\x1B[39m`;
}
function resolveTheme(theme) {
  return typeof theme === "string" ? import_themes.THEMES[theme] : theme;
}
function isSocketTheme(value) {
  return typeof value === "object" && value !== null && "name" in value && "colors" in value;
}
function createInquirerTheme(theme) {
  if (typeof theme === "string" || isSocketTheme(theme)) {
    const socketTheme = resolveTheme(theme);
    const promptColor = (0, import_utils.resolveColor)(
      socketTheme.colors.prompt,
      socketTheme.colors
    );
    const textDimColor = (0, import_utils.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 (uses colors.prompt)
        message: (text) => applyColor(text, promptColor),
        // Answer text (uses primary color)
        answer: (text) => applyColor(text, primaryColor),
        // Help text / descriptions (uses textDim)
        help: (text) => applyColor(text, textDimColor),
        description: (text) => applyColor(text, textDimColor),
        // Disabled items (uses textDim)
        disabled: (text) => applyColor(text, textDimColor),
        // Error messages (uses error color)
        error: (text) => applyColor(text, errorColor),
        // Highlight/active (uses primary color)
        highlight: (text) => applyColor(text, primaryColor)
      },
      icon: {
        // Use success color for confirmed items
        checked: applyColor("\u2713", successColor),
        unchecked: " ",
        // Cursor uses primary color
        cursor: applyColor("\u276F", primaryColor)
      }
    };
  }
  return theme;
}
// @__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((0, import_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;
  };
}
const checkboxRaw = require("../external/@inquirer/checkbox");
const confirmRaw = require("../external/@inquirer/confirm");
const inputRaw = require("../external/@inquirer/input");
const passwordRaw = require("../external/@inquirer/password");
const searchRaw = require("../external/@inquirer/search");
const selectRaw = require("../external/@inquirer/select");
const ActualSeparator = selectRaw.Separator;
const checkbox = /* @__PURE__ */ wrapPrompt(checkboxRaw);
const confirm = /* @__PURE__ */ wrapPrompt(confirmRaw);
const input = /* @__PURE__ */ wrapPrompt(inputRaw);
const password = /* @__PURE__ */ wrapPrompt(passwordRaw);
const search = /* @__PURE__ */ wrapPrompt(searchRaw);
const select = /* @__PURE__ */ wrapPrompt(selectRaw);
function createSeparator(text) {
  return new ActualSeparator(text);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  Separator,
  checkbox,
  confirm,
  createInquirerTheme,
  createSeparator,
  input,
  password,
  search,
  select,
  wrapPrompt
});
