"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getDefaults = getDefaults;
exports.setDefaults = setDefaults;
const node_fs_1 = require("node:fs");
const node_path_1 = require("node:path");
const paths_1 = require("../server/paths");
function prefsDir() {
    return (0, paths_1.getCockpitDir)();
}
function defaultsFile() {
    return (0, node_path_1.join)(prefsDir(), "defaults.json");
}
const fallback = {
    thinkingLevel: "high",
    bypassAllPermissions: false,
    diffStyle: "split",
    dismissKeyboardOnSend: true,
    thinkingExpanded: false,
    readExpanded: false,
    editExpanded: false,
    toolCallsExpanded: false,
    modelSlots: { main: "sonnet" },
    messageStitching: true,
    reviewsEnabled: true,
};
function getDefaults() {
    try {
        const raw = JSON.parse((0, node_fs_1.readFileSync)(defaultsFile(), "utf-8"));
        if (raw.model && !raw.modelSlots) {
            raw.modelSlots = { main: raw.model };
            delete raw.model;
        }
        return { ...fallback, ...raw };
    }
    catch {
        return { ...fallback };
    }
}
function setDefaults(partial) {
    const current = getDefaults();
    const updated = { ...current, ...partial };
    try {
        (0, node_fs_1.mkdirSync)(prefsDir(), { recursive: true });
        (0, node_fs_1.writeFileSync)(defaultsFile(), JSON.stringify(updated, null, 2) + "\n");
    }
    catch {
        // best effort
    }
    return updated;
}
