import a from './index5.mjs';
import { i as inquirer } from './index6.mjs';
import { d as detectSmartDefaults } from './code-type-resolver.mjs';
import { resolveSupportedLanguage, i18n } from './index2.mjs';
import { updateZcfConfig } from './ccjk-config.mjs';
import { g as getRuntimeVersion } from '../shared/ccjk.gDEDGD_t.mjs';
import { i as init } from './init.mjs';
import '../shared/ccjk.BAGoDD49.mjs';
import 'node:readline';
import 'stream';
import 'node:tty';
import 'node:process';
import 'node:async_hooks';
import '../shared/ccjk.Cjgrln_h.mjs';
import 'node:util';
import 'tty';
import 'fs';
import 'child_process';
import 'node:path';
import 'node:os';
import 'node:crypto';
import 'buffer';
import 'string_decoder';
import 'node:child_process';
import 'node:fs';
import './constants.mjs';
import '../shared/ccjk.bQ7Dh1g4.mjs';
import './json-config.mjs';
import '../shared/ccjk.RyizuzOI.mjs';
import './fs-operations.mjs';
import 'node:fs/promises';
import './platform.mjs';
import './main.mjs';
import 'module';
import 'node:stream';
import 'node:url';
import '../shared/ccjk.BBtCGd_g.mjs';
import './index3.mjs';
import './claude-config.mjs';
import '../shared/ccjk.DDL-4C-k.mjs';
import './banner.mjs';
import './config2.mjs';
import './config.mjs';
import '../shared/ccjk.DZ2LLOa-.mjs';
import '../shared/ccjk.DeWpAShp.mjs';
import '../shared/ccjk.DFRPtmK_.mjs';
import './auto-updater.mjs';
import './index8.mjs';
import './version-checker.mjs';
import '../shared/ccjk.CxpGa6MC.mjs';
import './clavue-config.mjs';
import './codex.mjs';
import '../shared/ccjk.BFQ7yr5S.mjs';
import './prompts.mjs';
import '../shared/ccjk.BXv8aYs1.mjs';
import '../shared/ccjk.L7yC58_i.mjs';
import '../shared/ccjk.C0WLUnFV.mjs';
import '../shared/ccjk.BtrioX1Z.mjs';
import './installer.mjs';
import '../shared/ccjk.DhJ1kyDR.mjs';
import '../shared/ccjk.BLsIiTqO.mjs';
import '../shared/ccjk.B2U7DsPy.mjs';
import '../shared/ccjk.Bq8TqZG_.mjs';

const ccjkVersion = getRuntimeVersion();
function displayHeader() {
  console.log("");
  console.log(a.bold.green("\u26A1 CCJK Quick Setup"));
  console.log(a.gray(`   v${ccjkVersion} \u2022 One-click configuration`));
  console.log(a.gray(`   ${"\u2500".repeat(50)}`));
  console.log("");
}
function displayStep(step, total, message) {
  const prefix = a.green(`[${step}/${total}]`);
  console.log(`${prefix} ${message}`);
}
function displaySuccess(result, defaults) {
  const isZh = i18n.language === "zh-CN";
  console.log("");
  console.log(a.bold.green("\u2705 Setup Complete!"));
  console.log(a.gray(`   ${"\u2500".repeat(50)}`));
  console.log("");
  console.log(a.bold("\u{1F4E6} Configured:"));
  console.log(`  \u2022 MCP Services: ${a.green(defaults.mcpServices.join(", "))}`);
  console.log(`  \u2022 Skills: ${a.green(defaults.skills.length)} enabled`);
  console.log(`  \u2022 Agents: ${a.green(defaults.agents.length)} ready`);
  console.log(`  \u2022 Provider: ${a.green(defaults.apiProvider || "anthropic")}`);
  if (defaults.recommendedHooks.length > 0) {
    console.log(`  \u2022 Hooks: ${a.green(defaults.recommendedHooks.join(", "))}`);
  }
  console.log("");
  console.log(a.bold.green("\u23F1\uFE0F  ") + a.white(`Completed in ${result.duration}s`));
  console.log("");
  console.log(a.bold("\u{1F3AF} Quick Start:"));
  console.log(`  1. ${a.gray("Open your project directory")}`);
  console.log(`  2. ${a.green("claude")}`);
  console.log(`  3. ${a.gray("Start coding with AI assistance!")}`);
  console.log("");
  console.log(a.gray(isZh ? '\u{1F4A1} \u8FD0\u884C "ccjk menu" \u83B7\u53D6\u66F4\u591A\u9009\u9879' : '\u{1F4A1} Run "ccjk menu" for more options'));
  console.log("");
}
function displayError(result) {
  console.log("");
  console.log(a.bold.red("\u274C Setup Failed"));
  console.log(a.gray(`   ${"\u2500".repeat(50)}`));
  console.log("");
  if (result.errors) {
    for (const error of result.errors) {
      console.log(a.red(`  \u2022 ${error}`));
    }
  }
  console.log("");
  console.log(a.gray("\u{1F4A1} Run with verbose mode for details: npx ccjk quick-setup --verbose"));
  console.log("");
}
async function promptProvider() {
  const isZh = i18n.language === "zh-CN";
  const { provider } = await inquirer.prompt({
    type: "list",
    name: "provider",
    message: isZh ? "\u9009\u62E9 API \u63D0\u4F9B\u5546:" : "Select API provider:",
    choices: [
      { name: "Anthropic (\u5B98\u65B9)", value: "anthropic" },
      { name: "OpenRouter", value: "openrouter" },
      { name: "Amazon Bedrock", value: "bedrock" },
      { name: "Google Vertex AI", value: "vertex" },
      { name: isZh ? "\u5176\u4ED6" : "Other", value: "other" }
    ],
    default: "anthropic"
  });
  return provider;
}
async function promptApiKey(provider) {
  const isZh = i18n.language === "zh-CN";
  const providerNames = {
    anthropic: "Anthropic",
    openrouter: "OpenRouter",
    bedrock: "Amazon Bedrock",
    vertex: "Google Vertex AI",
    other: isZh ? "\u81EA\u5B9A\u4E49" : "Custom"
  };
  const { apiKey } = await inquirer.prompt({
    type: "password",
    name: "apiKey",
    message: isZh ? `\u8F93\u5165 ${providerNames[provider] || provider} API \u5BC6\u94A5:` : `Enter ${providerNames[provider] || provider} API key:`,
    mask: "*",
    validate: (input) => {
      if (!input || input.trim().length === 0) {
        return isZh ? "API \u5BC6\u94A5\u4E0D\u80FD\u4E3A\u7A7A" : "API key cannot be empty";
      }
      return true;
    }
  });
  return apiKey.trim();
}
async function promptCustomConfig() {
  const isZh = i18n.language === "zh-CN";
  const result = await inquirer.prompt([
    {
      type: "confirm",
      name: "customizeMcp",
      message: isZh ? "\u662F\u5426\u81EA\u5B9A\u4E49 MCP \u670D\u52A1? (\u9ED8\u8BA4: context7, mcp-deepwiki, open-websearch)" : "Customize MCP services? (default: context7, mcp-deepwiki, open-websearch)",
      default: false
    },
    {
      type: "confirm",
      name: "customizeSkills",
      message: isZh ? "\u662F\u5426\u81EA\u5B9A\u4E49 Skills? (\u9ED8\u8BA4: \u5E38\u7528 5 \u4E2A)" : "Customize Skills? (default: 5 common skills)",
      default: false
    },
    {
      type: "confirm",
      name: "customizeAgents",
      message: isZh ? "\u662F\u5426\u81EA\u5B9A\u4E49 Agents? (\u9ED8\u8BA4: \u901A\u7528 2 \u4E2A)" : "Customize Agents? (default: 2 general agents)",
      default: false
    }
  ]);
  return result;
}
async function promptMcpServices() {
  const isZh = i18n.language === "zh-CN";
  const { services } = await inquirer.prompt({
    type: "checkbox",
    name: "services",
    message: isZh ? "\u9009\u62E9 MCP \u670D\u52A1:" : "Select MCP services:",
    choices: [
      { name: "context7 (\u6587\u6863\u67E5\u8BE2)", value: "context7", checked: true },
      { name: "mcp-deepwiki (DeepWiki)", value: "mcp-deepwiki", checked: true },
      { name: "open-websearch (\u7F51\u7EDC\u641C\u7D22)", value: "open-websearch", checked: true },
      { name: "spec-workflow (\u89C4\u8303\u5DE5\u4F5C\u6D41)", value: "spec-workflow" },
      { name: "serena (Serena \u52A9\u624B)", value: "serena" },
      { name: "Playwright (\u6D4F\u89C8\u5668\u81EA\u52A8\u5316)", value: "Playwright" },
      { name: "sqlite (\u6570\u636E\u5E93)", value: "sqlite" },
      { name: isZh ? "\u5168\u90E8" : "All", value: "__all__" }
    ]
  });
  if (services.includes("__all__")) {
    return ["context7", "mcp-deepwiki", "open-websearch", "spec-workflow", "serena", "Playwright", "sqlite"];
  }
  return services;
}
async function promptSkills() {
  const isZh = i18n.language === "zh-CN";
  const { skills } = await inquirer.prompt({
    type: "checkbox",
    name: "skills",
    message: isZh ? "\u9009\u62E9 Skills:" : "Select Skills:",
    choices: [
      { name: "git-commit (\u667A\u80FD\u63D0\u4EA4)", value: "git-commit", checked: true },
      { name: "feat (\u529F\u80FD\u5F00\u53D1)", value: "feat", checked: true },
      { name: "workflow (\u5DE5\u4F5C\u6D41)", value: "workflow", checked: true },
      { name: "init-project (\u9879\u76EE\u521D\u59CB\u5316)", value: "init-project", checked: true },
      { name: "git-worktree (Git \u6811)", value: "git-worktree" },
      { name: "git-rollback (Git \u56DE\u6EDA)", value: "git-rollback" },
      { name: "git-cleanBranches (\u6E05\u7406\u5206\u652F)", value: "git-cleanBranches" },
      { name: "interview (AI \u9762\u8BD5)", value: "interview" },
      { name: isZh ? "\u5168\u90E8" : "All", value: "__all__" }
    ]
  });
  if (skills.includes("__all__")) {
    return ["git-commit", "feat", "workflow", "init-project", "git-worktree", "git-rollback", "git-cleanBranches", "interview"];
  }
  return skills;
}
async function promptAgents() {
  const isZh = i18n.language === "zh-CN";
  const { agents } = await inquirer.prompt({
    type: "checkbox",
    name: "agents",
    message: isZh ? "\u9009\u62E9 Agents:" : "Select Agents:",
    choices: [
      { name: "typescript-cli-architect (CLI \u67B6\u6784)", value: "typescript-cli-architect", checked: true },
      { name: "ccjk-testing-specialist (\u6D4B\u8BD5\u4E13\u5BB6)", value: "ccjk-testing-specialist", checked: true },
      { name: "ccjk-tools-integration-specialist (\u5DE5\u5177\u96C6\u6210)", value: "ccjk-tools-integration-specialist" },
      { name: "ccjk-config-architect (\u914D\u7F6E\u67B6\u6784)", value: "ccjk-config-architect" },
      { name: "ccjk-devops-engineer (DevOps)", value: "ccjk-devops-engineer" },
      { name: isZh ? "\u5168\u90E8" : "All", value: "__all__" }
    ]
  });
  if (agents.includes("__all__")) {
    return ["typescript-cli-architect", "ccjk-testing-specialist", "ccjk-tools-integration-specialist", "ccjk-config-architect", "ccjk-devops-engineer"];
  }
  return agents;
}
function applyDefaultsToInitOptions(defaults, apiKey, provider, lang, skipApiConfig = false) {
  return {
    skipPrompt: true,
    skipBanner: true,
    configLang: lang,
    allLang: lang,
    apiType: skipApiConfig ? "skip" : "api_key",
    apiKey: skipApiConfig ? void 0 : apiKey,
    provider: skipApiConfig ? void 0 : provider,
    // Recommended MCP services based on platform
    mcpServices: defaults.mcpServices,
    // Skills to install (separate from workflows)
    skills: defaults.skills.map((s) => s.replace("ccjk:", "")),
    codeType: defaults.codeToolType || "claude-code",
    configAction: "backup",
    // Minimal options for speed
    outputStyles: ["engineer-professional"],
    defaultOutputStyle: "engineer-professional",
    installCometixLine: false,
    installSuperpowers: false
  };
}
async function quickSetup(options = {}) {
  const startTime = Date.now();
  const result = {
    success: false,
    duration: 0,
    steps: {
      detection: false,
      apiKey: false,
      installation: false,
      validation: false
    },
    errors: []
  };
  try {
    const lang = resolveSupportedLanguage(options.lang);
    if (lang !== i18n.language) {
      await i18n.changeLanguage(lang);
    }
    displayHeader();
    displayStep(1, 4, "Detecting environment...");
    const defaults = await detectSmartDefaults();
    result.steps.detection = true;
    console.log(`  ${a.gray("Platform:")} ${a.green(defaults.platform)}`);
    console.log(`  ${a.gray("Code Tool:")} ${a.green(defaults.codeToolType || "claude-code")}`);
    if (defaults.projectContext) {
      const ctx = defaults.projectContext;
      const parts = [ctx.language, ctx.framework !== "none" ? ctx.framework : null, ctx.testRunner !== "none" ? ctx.testRunner : null, ctx.packageManager !== "none" ? ctx.packageManager : null].filter(Boolean);
      console.log(`  ${a.gray("Project:")} ${a.green(parts.join(" + "))}`);
      if (ctx.runtime.isHeadless)
        console.log(`  ${a.gray("Runtime:")} ${a.yellow("headless server")}`);
      if (ctx.runtime.isContainer)
        console.log(`  ${a.gray("Runtime:")} ${a.yellow("container")}`);
      if (ctx.runtime.isCI)
        console.log(`  ${a.gray("Runtime:")} ${a.yellow("CI/CD")}`);
    }
    console.log("");
    displayStep(2, 4, "Configuring API key...");
    let apiKey;
    let provider;
    if (options.apiKey) {
      apiKey = options.apiKey;
      provider = options.provider || defaults.apiProvider || "anthropic";
      console.log(`  ${a.gray("Using provided API key")}`);
    } else if (defaults.apiKey && !options.skipPrompt) {
      const isZh = i18n.language === "zh-CN";
      const { useDetected } = await inquirer.prompt({
        type: "confirm",
        name: "useDetected",
        message: isZh ? `\u4F7F\u7528\u68C0\u6D4B\u5230\u7684 API \u5BC6\u94A5 (${defaults.apiKey?.substring(0, 12)}...)?` : `Use detected API key (${defaults.apiKey?.substring(0, 12)}...)?`,
        default: true
      });
      if (useDetected) {
        apiKey = defaults.apiKey;
        provider = defaults.apiProvider || "anthropic";
        console.log(`  ${a.gray("Using detected API key")}`);
      } else {
        provider = await promptProvider();
        apiKey = await promptApiKey(provider);
      }
    } else if (defaults.apiKey && options.skipPrompt) {
      apiKey = defaults.apiKey;
      provider = defaults.apiProvider || "anthropic";
      console.log(`  ${a.gray("Using detected API key")}`);
    } else {
      provider = options.provider || await promptProvider();
      apiKey = await promptApiKey(provider);
    }
    result.steps.apiKey = true;
    console.log(`  ${a.gray("Provider:")} ${a.green(provider)}`);
    console.log("");
    let customMcpServices;
    let customSkills;
    let customAgents;
    if (!options.skipPrompt) {
      const isZh = i18n.language === "zh-CN";
      const { wantsCustom } = await inquirer.prompt({
        type: "confirm",
        name: "wantsCustom",
        message: isZh ? "\u662F\u5426\u81EA\u5B9A\u4E49\u914D\u7F6E? (\u5426\u5219\u4F7F\u7528\u667A\u80FD\u9ED8\u8BA4\u503C)" : "Customize configuration? (otherwise use smart defaults)",
        default: false
      });
      if (wantsCustom) {
        const customConfig = await promptCustomConfig();
        if (customConfig.customizeMcp) {
          customMcpServices = await promptMcpServices();
        }
        if (customConfig.customizeSkills) {
          customSkills = await promptSkills();
        }
        if (customConfig.customizeAgents) {
          customAgents = await promptAgents();
        }
      }
    }
    displayStep(3, 4, "Applying configuration...");
    const finalMcpServices = customMcpServices || defaults.mcpServices;
    const finalSkills = customSkills || defaults.skills;
    const finalAgents = customAgents || defaults.agents;
    const hasApiKey = !!apiKey && apiKey.length > 0;
    const initOptions = applyDefaultsToInitOptions(
      { ...defaults, mcpServices: finalMcpServices, skills: finalSkills, agents: finalAgents },
      hasApiKey ? apiKey : "",
      hasApiKey ? provider : "anthropic",
      lang,
      !hasApiKey
    );
    updateZcfConfig({
      version: ccjkVersion,
      preferredLang: lang,
      templateLang: lang,
      aiOutputLang: lang,
      codeToolType: defaults.codeToolType || "claude-code"
    });
    console.log(`  ${a.gray("MCP Services:")} ${a.green(finalMcpServices.join(", "))}${customMcpServices ? a.yellow(" (custom)") : ""}`);
    console.log(`  ${a.gray("Skills:")} ${a.green(finalSkills.join(", "))}${customSkills ? a.yellow(" (custom)") : ""}`);
    console.log(`  ${a.gray("Agents:")} ${a.green(finalAgents.join(", "))}${customAgents ? a.yellow(" (custom)") : ""}`);
    console.log("");
    displayStep(4, 4, "Executing installation...");
    await init(initOptions);
    if (Array.isArray(initOptions.skills) && initOptions.skills.length > 0) {
      try {
        const { ccjkSkills } = await import('./ccjk-skills.mjs');
        await ccjkSkills({
          interactive: false,
          force: false
        });
      } catch (error) {
        const msg = error instanceof Error ? error.message : String(error);
        console.log(a.yellow(`  \u26A0 Skills installation skipped: ${msg}`));
      }
    }
    result.steps.installation = true;
    result.steps.validation = true;
    try {
      const { installRecommendedHooks } = await import('./hook-installer.mjs');
      const hooksAdded = await installRecommendedHooks(defaults.recommendedHooks);
      if (hooksAdded > 0) {
        console.log(`  ${a.green("\u2713")} Installed ${a.cyan(String(hooksAdded))} recommended hooks`);
      }
    } catch {
    }
    result.duration = Math.round((Date.now() - startTime) / 1e3);
    result.success = true;
    displaySuccess(result, defaults);
    return result;
  } catch (error) {
    result.duration = Math.round((Date.now() - startTime) / 1e3);
    const errorMessage = error instanceof Error ? error.message : String(error);
    result.errors?.push(errorMessage);
    displayError(result);
    return result;
  }
}

export { quickSetup };
