"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 prompt_utils_exports = {};
__export(prompt_utils_exports, {
  CLIPrompt: () => CLIPrompt
});
module.exports = __toCommonJS(prompt_utils_exports);
var import_prompts = __toESM(require("prompts"));
class CLIPrompt {
  constructor(_props, _logger) {
    this._props = _props;
    this._logger = _logger;
  }
  async confirm(message) {
    if (this._props.confirm) {
      this._logger.debug(`Confirming automatically (non-interactive mode): ${message}`);
      return true;
    }
    const { confirm } = await this._prompts({
      type: "confirm",
      name: "confirm",
      message,
      initial: false
    });
    if (!confirm) {
      return false;
    }
    return true;
  }
  async password(message, opts = {}) {
    if (this._props.confirm) {
      this._logger.debug(`Return default (non-interactive mode): ${message}`);
      return opts?.default;
    }
    const { prompted } = await this._prompts({
      type: "password",
      name: "prompted",
      message,
      initial: opts?.initial
    });
    return prompted ? prompted : void 0;
  }
  async select(message, opts = {}) {
    if (this._props.confirm) {
      this._logger.debug(`Return default (non-interactive mode): ${message}`);
      return opts?.default;
    }
    const isNumber = typeof opts?.choices?.[0]?.value === "number";
    const transformedChoices = isNumber ? opts?.choices?.map((c) => ({ ...c, value: c.value === 0 ? Symbol.for("0") : c.value })) : opts?.choices;
    const { prompted } = await this._prompts({
      type: "autocomplete",
      name: "prompted",
      message,
      initial: opts?.initial?.value,
      choices: transformedChoices
    });
    return prompted !== void 0 ? isNumber && prompted === Symbol.for("0") ? 0 : prompted : void 0;
  }
  async text(message, opts = {}) {
    if (this._props.confirm) {
      this._logger.debug(`Return default (non-interactive mode): ${message}`);
      return opts?.default;
    }
    const { prompted } = await this._prompts({
      type: "text",
      name: "prompted",
      message,
      initial: opts?.initial
    });
    return prompted ? prompted : void 0;
  }
  _prompts = (...args) => {
    this._logger.cleanup();
    return (0, import_prompts.default)(...args);
  };
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  CLIPrompt
});
//# sourceMappingURL=prompt-utils.js.map
