#!/usr/bin/env node

// src/config.ts
import fs from "fs";
import path from "path";
import os from "os";
var MODES = [
  "elevator",
  "typewriter",
  "ambient",
  "retro",
  "minimal",
  "spotify"
];
var DEFAULT_CONFIG = {
  mode: "elevator",
  volume: 70,
  enabled: true
};
function getConfigDir() {
  if (process.env.CODEVATOR_HOME) return process.env.CODEVATOR_HOME;
  return path.join(os.homedir(), ".codevator");
}
function getConfigPath() {
  return path.join(getConfigDir(), "config.json");
}
function getConfig() {
  try {
    const raw = fs.readFileSync(getConfigPath(), "utf-8");
    return JSON.parse(raw);
  } catch {
    return { ...DEFAULT_CONFIG };
  }
}
function setConfig(partial) {
  const current = getConfig();
  const merged = { ...current, ...partial };
  const dir = getConfigDir();
  fs.mkdirSync(dir, { recursive: true });
  fs.writeFileSync(getConfigPath(), JSON.stringify(merged, null, 2));
}
var SOUND_EXTENSIONS = [".mp3", ".wav", ".ogg", ".m4a"];
function isValidMode(mode) {
  if (MODES.includes(mode)) return true;
  const soundsDir = path.join(getConfigDir(), "sounds");
  return SOUND_EXTENSIONS.some((ext) => fs.existsSync(path.join(soundsDir, `${mode}${ext}`)));
}

export {
  MODES,
  getConfigDir,
  getConfig,
  setConfig,
  isValidMode
};
