"use strict";
/* Socket Lib - Built with esbuild */
"use strict";
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,
  applyColor: () => applyColor,
  checkbox: () => checkbox,
  confirm: () => confirm,
  createInquirerTheme: () => createInquirerTheme,
  createSeparator: () => createSeparator,
  input: () => input,
  isSocketTheme: () => isSocketTheme,
  password: () => password,
  resolveTheme: () => resolveTheme,
  search: () => search,
  select: () => select,
  wrapPrompt: () => wrapPrompt
});
module.exports = __toCommonJS(prompts_exports);
var import_abort = require("../process/abort");
var import_checkbox = __toESM(require("../external/@inquirer/checkbox"));
var import_confirm = __toESM(require("../external/@inquirer/confirm"));
var import_input = __toESM(require("../external/@inquirer/input"));
var import_password = __toESM(require("../external/@inquirer/password"));
var searchModule = __toESM(require("../external/@inquirer/search"));
var selectModuleImport = __toESM(require("../external/@inquirer/select"));
var import_yoctocolors_cjs = __toESM(require("../external/yoctocolors-cjs"));
var import_registry = require("../spinner/registry");
var import_context = require("../themes/context");
var import_themes = require("../themes/themes");
var import_resolve = require("../themes/resolve");
const abortSignal = (0, import_abort.getAbortSignal)();
const spinner = (0, import_registry.getDefaultSpinner)();
const searchRaw = searchModule.default;
const selectModule = selectModuleImport;
const selectRaw = selectModule.default;
const ActualSeparator = selectModule.Separator;
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 createInquirerTheme(theme) {
  if (typeof theme === "string" || isSocketTheme(theme)) {
    const socketTheme = resolveTheme(theme);
    const promptColor = (0, import_resolve.resolveColor)(
      socketTheme.colors.prompt,
      socketTheme.colors
    );
    const textDimColor = (0, import_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 (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: {
        // oxlint-disable-next-line socket/no-status-emoji -- Inquirer theme icon; consumed by the prompt library, not log output.
        checked: applyColor("\u2713", successColor),
        unchecked: " ",
        cursor: applyColor("\u276F", primaryColor)
      }
    };
  }
  if (theme === void 0 || theme === null) {
    return {};
  }
  return theme;
}
function createSeparator(text) {
  return new ActualSeparator(text);
}
function isSocketTheme(value) {
  return typeof value === "object" && value !== null && "name" in value && "colors" in value;
}
function resolveTheme(theme) {
  return typeof theme === "string" ? import_themes.THEMES[theme] ?? import_themes.THEMES.socket : 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 checkbox = /* @__PURE__ */ wrapPrompt(import_checkbox.default);
const confirm = /* @__PURE__ */ wrapPrompt(import_confirm.default);
const input = /* @__PURE__ */ wrapPrompt(import_input.default);
const password = /* @__PURE__ */ wrapPrompt(import_password.default);
const search = /* @__PURE__ */ wrapPrompt(searchRaw);
const select = /* @__PURE__ */ wrapPrompt(selectRaw);
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  Separator,
  applyColor,
  checkbox,
  confirm,
  createInquirerTheme,
  createSeparator,
  input,
  isSocketTheme,
  password,
  resolveTheme,
  search,
  select,
  wrapPrompt
});
