"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var prompts_exports = {};
__export(prompts_exports, {
  arrowSelect: () => arrowSelect,
  ask: () => ask,
  askBool: () => askBool,
  askString: () => askString,
  askToggle: () => askToggle,
  dim: () => dim,
  printFeature: () => printFeature,
  printSection: () => printSection,
  printSeparator: () => printSeparator,
  reset: () => reset,
  violet: () => violet
});
module.exports = __toCommonJS(prompts_exports);
const violet = "\x1B[38;5;99m";
const reset = "\x1B[0m";
const dim = "\x1B[2m";
const bold = "\x1B[1m";
const green = "\x1B[32m";
const yellow = "\x1B[33m";
const cyan = "\x1B[36m";
function ask(rl, question) {
  return new Promise((resolve) => rl.question(question, resolve));
}
async function askBool(rl, question, description, defaultYes = true) {
  const hint = defaultYes ? "Y/n" : "y/N";
  console.log(`
  ${dim}${description}${reset}`);
  while (true) {
    const raw = await ask(rl, `  ${violet}${question}${reset} ${dim}(${hint})${reset} `);
    if (raw === "") return defaultYes;
    if (raw === "y" || raw === "Y") return true;
    if (raw === "n" || raw === "N") return false;
    console.log(`  Please enter y or n.`);
  }
}
async function askToggle(rl, label, description, defaultEnabled = true) {
  return arrowSelect(rl, label, [
    { value: true, label: "yes", description },
    { value: false, label: "no", description: "Skip" }
  ], defaultEnabled ? 0 : 1);
}
async function askString(rl, question, description, defaultValue) {
  console.log(`
  ${dim}${description}${reset}`);
  const raw = await ask(rl, `  ${violet}${question}${reset} ${dim}(${defaultValue})${reset} `);
  return raw === "" ? defaultValue : raw;
}
function printSection(icon, title) {
  console.log(`
  ${violet}${bold}${icon}  ${title}${reset}`);
  console.log(`  ${violet}${"\u2500".repeat(title.length + 4)}${reset}`);
}
function printSeparator() {
  console.log(`
  ${dim}${"\xB7".repeat(50)}${reset}`);
}
function printFeature(enabled, label) {
  const icon = enabled ? `${green}\u2713${reset}` : `${dim}\u2717${reset}`;
  const text = enabled ? label : `${dim}${label}${reset}`;
  console.log(`    ${icon} ${text}`);
}
async function arrowSelect(rl, label, options, defaultIndex = 0) {
  const CURSOR_UP = "\x1B[A";
  const CURSOR_DOWN = "\x1B[B";
  const CLEAR_LINE = "\x1B[2K\x1B[G";
  function descLineCount(desc) {
    const termWidth = process.stdout.columns || 80;
    return Math.max(1, Math.ceil((desc.length + 4) / termWidth));
  }
  let selected = defaultIndex;
  let prevDescLines = descLineCount(options[defaultIndex].description);
  function render(first) {
    if (!first) {
      process.stdout.write(`\x1B[${options.length + prevDescLines}A`);
    }
    for (let i = 0; i < options.length; i++) {
      const active = i === selected;
      const cursor = active ? `${green}${bold}\u276F${reset}` : " ";
      const text = active ? `${bold}${options[i].label}${reset}` : `${dim}${options[i].label}${reset}`;
      process.stdout.write(`${CLEAR_LINE}  ${cursor} ${text}
`);
    }
    const desc = options[selected].description;
    process.stdout.write(`${CLEAR_LINE}  ${dim}${desc}${reset}
`);
    prevDescLines = descLineCount(desc);
  }
  return new Promise((resolve) => {
    console.log(`
  ${violet}${label}${reset}`);
    render(true);
    rl.pause();
    const stdin = process.stdin;
    const wasTTY = stdin.isTTY;
    if (wasTTY) stdin.setRawMode(true);
    stdin.resume();
    stdin.setEncoding("utf8");
    function onData(key) {
      if (key === CURSOR_UP || key === "\x1B[A") {
        selected = (selected - 1 + options.length) % options.length;
        render(false);
      } else if (key === CURSOR_DOWN || key === "\x1B[B") {
        selected = (selected + 1) % options.length;
        render(false);
      } else if (key === "\r" || key === "\n" || key === " ") {
        stdin.removeListener("data", onData);
        if (wasTTY) stdin.setRawMode(false);
        stdin.pause();
        rl.resume();
        const totalLines = options.length + prevDescLines + 2;
        process.stdout.write(`\x1B[${options.length + prevDescLines}A`);
        process.stdout.write(`\x1B[1A`);
        process.stdout.write(`\x1B[1A`);
        for (let i = 0; i < totalLines; i++) {
          process.stdout.write(`${CLEAR_LINE}
`);
        }
        process.stdout.write(`\x1B[${totalLines}A`);
        process.stdout.write(`${CLEAR_LINE}  ${green}${bold}\u2713${reset} ${label} ${green}${bold}${options[selected].label}${reset}
`);
        resolve(options[selected].value);
      } else if (key === "") {
        stdin.removeListener("data", onData);
        if (wasTTY) stdin.setRawMode(false);
        process.exit(1);
      }
    }
    stdin.on("data", onData);
  });
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  arrowSelect,
  ask,
  askBool,
  askString,
  askToggle,
  dim,
  printFeature,
  printSection,
  printSeparator,
  reset,
  violet
});
//# sourceMappingURL=prompts.js.map
