"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.loadTuiConfig = loadTuiConfig;
exports.saveTuiConfig = saveTuiConfig;
const tslib_1 = require("tslib");
const fs = tslib_1.__importStar(require("fs"));
const path = tslib_1.__importStar(require("path"));
const types_1 = require("./types");
function loadTuiConfig(configDir) {
    const configPath = path.join(configDir, "tui.json");
    if (!fs.existsSync(configPath)) {
        return { ...types_1.DEFAULT_TUI_CONFIG };
    }
    try {
        const raw = fs.readFileSync(configPath, "utf-8");
        const userConfig = JSON.parse(raw);
        return {
            ...types_1.DEFAULT_TUI_CONFIG,
            ...userConfig,
            theme: {
                ...types_1.DEFAULT_TUI_CONFIG.theme,
                ...(userConfig.theme || {}),
            },
        };
    }
    catch {
        return { ...types_1.DEFAULT_TUI_CONFIG };
    }
}
function saveTuiConfig(configDir, config) {
    const configPath = path.join(configDir, "tui.json");
    if (!fs.existsSync(configDir)) {
        fs.mkdirSync(configDir, { recursive: true });
    }
    fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
}
