import process__default from 'node:process';
import a from './index5.mjs';
import { ensureI18nInitialized, i18n } from './index2.mjs';
import { r as resolveCodeType } from './code-type-resolver.mjs';
import { checkAndUpdateTools, checkAndUpdateMyclaudeTools } from './auto-updater.mjs';
import { r as runCodexUpdate } from './codex.mjs';
import '../shared/ccjk.BAGoDD49.mjs';
import 'node:fs';
import 'node:url';
import '../shared/ccjk.bQ7Dh1g4.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 'node:child_process';
import './constants.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 './ccjk-config.mjs';
import '../shared/ccjk.BBtCGd_g.mjs';
import './index3.mjs';
import './index8.mjs';
import '../shared/ccjk.DeWpAShp.mjs';
import '../shared/ccjk.DZ2LLOa-.mjs';
import './version-checker.mjs';
import '../shared/ccjk.CxpGa6MC.mjs';
import './config.mjs';
import './claude-config.mjs';
import '../shared/ccjk.DDL-4C-k.mjs';
import '../shared/ccjk.BFQ7yr5S.mjs';
import './prompts.mjs';
import '../shared/ccjk.gDEDGD_t.mjs';

class ToolUpdateScheduler {
  /**
   * Update tools based on code type
   * @param codeType - The code tool type to update
   * @param skipPrompt - Whether to skip interactive prompts
   */
  async updateByCodeType(codeType, skipPrompt = false) {
    await ensureI18nInitialized();
    switch (codeType) {
      case "claude-code":
        await this.updateClaudeCodeTools(skipPrompt);
        break;
      case "clavue":
        await this.updateMyclaudeTools(skipPrompt);
        break;
      case "codex":
        await this.updateCodexTools(skipPrompt);
        break;
      default:
        throw new Error(`Unsupported code type: ${codeType}`);
    }
  }
  /**
   * Update Claude Code related tools
   * @param skipPrompt - Whether to skip interactive prompts
   */
  async updateClaudeCodeTools(skipPrompt) {
    await checkAndUpdateTools(skipPrompt);
  }
  /**
   * Update Clavue related tools
   * @param skipPrompt - Whether to skip interactive prompts
   */
  async updateMyclaudeTools(skipPrompt) {
    await checkAndUpdateMyclaudeTools(skipPrompt);
  }
  /**
   * Update Codex tools
   * @param skipPrompt - Whether to skip interactive prompts
   */
  async updateCodexTools(skipPrompt) {
    await runCodexUpdate(false, skipPrompt);
  }
}

async function checkUpdates(options = {}) {
  try {
    const skipPrompt = options.skipPrompt || false;
    let codeType;
    try {
      codeType = await resolveCodeType(options.codeType);
    } catch (err) {
      const errorMessage = err instanceof Error ? err.message : String(err);
      console.error(a.red(`${errorMessage}
Defaulting to "claude-code".`));
      codeType = "claude-code";
    }
    const scheduler = new ToolUpdateScheduler();
    await scheduler.updateByCodeType(codeType, skipPrompt);
  } catch (error) {
    const errorMessage = error instanceof Error ? error.message : String(error);
    console.error(a.red(`${i18n.t("updater:errorCheckingUpdates")} ${errorMessage}`));
    process__default.exit(1);
  }
}

export { checkUpdates };
