"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.loadSettings = loadSettings;
exports.saveSettings = saveSettings;
exports.getDefaultSettings = getDefaultSettings;
const node_path_1 = require("node:path");
const node_os_1 = require("node:os");
const node_fs_1 = require("node:fs");
const SETTINGS_PATH = (0, node_path_1.join)((0, node_os_1.homedir)(), '.aiusage', 'widget-settings.json');
const DEFAULT_SETTINGS = {
    theme: 'system',
    refreshIntervalSec: 60,
    rangeDays: 30,
    showCost: true,
    showHeatmap: true,
    showTokenBreakdown: true,
    locale: 'en',
    currency: 'USD',
};
function loadSettings() {
    try {
        if ((0, node_fs_1.existsSync)(SETTINGS_PATH)) {
            const raw = JSON.parse((0, node_fs_1.readFileSync)(SETTINGS_PATH, 'utf-8'));
            return { ...DEFAULT_SETTINGS, ...raw };
        }
    }
    catch {
        // Fall through to defaults
    }
    return { ...DEFAULT_SETTINGS };
}
function saveSettings(settings) {
    const dir = (0, node_path_1.join)((0, node_os_1.homedir)(), '.aiusage');
    if (!(0, node_fs_1.existsSync)(dir)) {
        (0, node_fs_1.mkdirSync)(dir, { recursive: true });
    }
    (0, node_fs_1.writeFileSync)(SETTINGS_PATH, JSON.stringify(settings, null, 2), 'utf-8');
}
function getDefaultSettings() {
    return { ...DEFAULT_SETTINGS };
}
