import { SETTINGS_FILE } from './constants.mjs';
import { n as normalizeClaudeFamilySettings } from '../shared/ccjk.DDL-4C-k.mjs';
import { exists, ensureDir } from './fs-operations.mjs';
import { readJsonConfig, writeJsonConfig } from './json-config.mjs';
import { e as deepMerge } from './claude-config.mjs';
import { d as dirname } from '../shared/ccjk.bQ7Dh1g4.mjs';
import 'node:os';
import './index2.mjs';
import 'node:fs';
import 'node:process';
import 'node:url';
import './ccjk-config.mjs';
import '../shared/ccjk.BBtCGd_g.mjs';
import './index3.mjs';
import 'node:crypto';
import 'node:fs/promises';
import '../shared/ccjk.RyizuzOI.mjs';
import '../shared/ccjk.BAGoDD49.mjs';
import 'node:child_process';
import './platform.mjs';
import './main.mjs';
import 'module';
import 'node:path';
import 'node:stream';
import 'node:readline';

function readClaudeConfig(configPath = SETTINGS_FILE) {
  try {
    if (!exists(configPath)) {
      return null;
    }
    return readJsonConfig(configPath) || null;
  } catch (error) {
    console.error(`Failed to read Claude config from ${configPath}:`, error);
    return null;
  }
}
function writeClaudeConfig(config, options = {}, configPath = SETTINGS_FILE) {
  try {
    ensureDir(dirname(configPath));
    normalizeClaudeFamilySettings(config);
    writeJsonConfig(configPath, config, {
      atomic: options.atomic !== false,
      pretty: true,
      backup: options.backup
    });
  } catch (error) {
    console.error(`Failed to write Claude config to ${configPath}:`, error);
    throw new Error(`Failed to write Claude config: ${error instanceof Error ? error.message : String(error)}`);
  }
}
function updateClaudeConfig(updates, options = {}, configPath = SETTINGS_FILE) {
  const existingConfig = readClaudeConfig(configPath) || {};
  const mergedConfig = deepMerge(existingConfig, updates, {
    mergeArrays: options.merge === "preserve",
    arrayMergeStrategy: "unique"
  });
  writeClaudeConfig(mergedConfig, options, configPath);
  return mergedConfig;
}

export { readClaudeConfig, updateClaudeConfig, writeClaudeConfig };
