import a from './index5.mjs';
import { i18n } from './index2.mjs';
import { f as configureApi, e as getExistingApiConfig } from './config.mjs';
import { g as getAllPresets } from '../shared/ccjk.DopKzo3z.mjs';
import '../shared/ccjk.BAGoDD49.mjs';
import 'node:fs';
import 'node:process';
import 'node:url';
import '../shared/ccjk.bQ7Dh1g4.mjs';
import '../shared/ccjk.RyizuzOI.mjs';
import './index6.mjs';
import 'node:readline';
import 'stream';
import 'node:tty';
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 './constants.mjs';
import './claude-config.mjs';
import 'node:child_process';
import '../shared/ccjk.DDL-4C-k.mjs';
import './ccjk-config.mjs';
import '../shared/ccjk.BBtCGd_g.mjs';
import './index3.mjs';
import './fs-operations.mjs';
import 'node:fs/promises';
import './json-config.mjs';
import './platform.mjs';
import './main.mjs';
import 'module';
import 'node:stream';

async function apiConfigure(options = {}) {
  const lang = options.lang || i18n.language || "en";
  const isZh = lang === "zh-CN";
  if (options.interactive !== false && !options.provider) {
    const { runConfigWizard } = await import('./index4.mjs');
    await runConfigWizard(lang);
    return;
  }
  if (!options.provider) {
    console.log(a.red(isZh ? "\u9519\u8BEF: \u5FC5\u987B\u6307\u5B9A --provider" : "Error: --provider is required"));
    console.log(a.dim(isZh ? "\u7528\u6CD5: ccjk api configure --provider <name> --key <key>" : "Usage: ccjk api configure --provider <name> --key <key>"));
    process.exit(1);
  }
  const presets = getAllPresets();
  const preset = presets.find(
    (p) => p.id === options.provider || p.name.toLowerCase() === options.provider?.toLowerCase()
  );
  if (!preset) {
    console.log(a.red(isZh ? `\u9519\u8BEF: \u672A\u77E5\u7684\u63D0\u4F9B\u5546 "${options.provider}"` : `Error: Unknown provider "${options.provider}"`));
    console.log(a.dim(isZh ? "\u63D0\u793A: \u4F7F\u7528 ccjk api list \u67E5\u770B\u53EF\u7528\u63D0\u4F9B\u5546" : "Tip: Use ccjk api list to see available providers"));
    process.exit(1);
  }
  if (preset.requiresApiKey && !options.key) {
    console.log(a.red(isZh ? "\u9519\u8BEF: \u5FC5\u987B\u6307\u5B9A --key" : "Error: --key is required"));
    process.exit(1);
  }
  if (!options.yes) {
    const inquirer = await import('./index6.mjs').then(function (n) { return n.c; });
    const { confirm } = await inquirer.default.prompt([{
      type: "confirm",
      name: "confirm",
      message: isZh ? `\u786E\u8BA4\u914D\u7F6E ${preset.name}?` : `Configure ${preset.name}?`,
      default: true
    }]);
    if (!confirm) {
      console.log(a.yellow(isZh ? "\u5DF2\u53D6\u6D88" : "Cancelled"));
      return;
    }
  }
  const config = {
    type: "api_key",
    apiKey: options.key,
    apiUrl: options.url || preset.baseUrl,
    model: options.model || preset.defaultModel
  };
  if (options.fastModel) {
    config.fastModel = options.fastModel;
  }
  const result = configureApi(config);
  if (result) {
    console.log(a.green(isZh ? `\u2713 \u5DF2\u914D\u7F6E ${preset.name}` : `\u2713 Configured ${preset.name}`));
    console.log(a.dim(isZh ? "\u63D0\u793A: \u91CD\u542F Claude Code \u4EE5\u5E94\u7528\u66F4\u6539" : "Tip: Restart Claude Code to apply changes"));
  } else {
    console.log(a.red(isZh ? "\u2717 \u914D\u7F6E\u5931\u8D25" : "\u2717 Configuration failed"));
    process.exit(1);
  }
}
async function apiList(options = {}) {
  const lang = options.lang || i18n.language || "en";
  const isZh = lang === "zh-CN";
  const config = getExistingApiConfig();
  if (options.json) {
    console.log(JSON.stringify({
      current: config,
      available: getAllPresets().map((p) => ({
        id: p.id,
        name: p.name,
        category: p.category,
        requiresApiKey: p.requiresApiKey
      }))
    }, null, 2));
    return;
  }
  console.log("");
  console.log(a.bold.cyan(isZh ? "\u{1F4CB} API \u914D\u7F6E" : "\u{1F4CB} API Configuration"));
  console.log(a.dim("\u2500".repeat(50)));
  console.log("");
  if (config) {
    console.log(a.green(isZh ? "\u5F53\u524D\u914D\u7F6E:" : "Current configuration:"));
    const apiUrl = config.apiUrl;
    const model = config.model;
    if (apiUrl) {
      console.log(`  ${a.dim("URL:")} ${apiUrl}`);
    }
    if (model) {
      console.log(`  ${a.dim("Model:")} ${model}`);
    }
  } else {
    console.log(a.yellow(isZh ? "\u672A\u914D\u7F6E API" : "No API configured"));
  }
  console.log("");
  console.log(a.dim(isZh ? "\u63D0\u793A: \u4F7F\u7528 ccjk api configure --provider <name> \u914D\u7F6E API" : "Tip: Use ccjk api configure --provider <name> to configure API"));
}

export { apiConfigure, apiList };
