export const THEME_STORAGE_KEY = 'botmux.dashboard.theme';
export const SESSIONS_VIEW_STORAGE_KEY = 'botmux.dashboard.sessions.view';
export function normalizeThemeMode(value) {
    return value === 'system' || value === 'light' || value === 'dark' ? value : null;
}
export function normalizeSessionsViewMode(value) {
    return value === 'kanban' || value === 'board' || value === 'table' ? value : null;
}
export function resolveThemeMode(mode, systemPrefersDark) {
    if (mode === 'system')
        return systemPrefersDark ? 'dark' : 'light';
    return mode;
}
export function readStoredThemeMode(storage) {
    // 数字员工工作台视觉以 dark 为第一公民 — 未显式选择过主题时默认深色，
    // light / system 仍可在顶栏切换（保留原有功能入口）。
    return normalizeThemeMode(storage?.getItem(THEME_STORAGE_KEY)) ?? 'dark';
}
export function readStoredSessionsViewMode(storage) {
    return normalizeSessionsViewMode(storage?.getItem(SESSIONS_VIEW_STORAGE_KEY)) ?? 'board';
}
// ── 看板列顺序（用户可拖拽/按钮自定义，从左到右）─────────────────────────────
export const SESSIONS_BOARD_ORDER_STORAGE_KEY = 'botmux.dashboard.sessions.boardOrder';
export const DEFAULT_BOARD_ORDER = ['needs-you', 'starting', 'working', 'idle'];
/** 必须是默认四列的一个排列（防旧版本残留/手改 localStorage 的脏值）。 */
export function normalizeBoardOrder(value) {
    if (!Array.isArray(value) || value.length !== DEFAULT_BOARD_ORDER.length)
        return null;
    const seen = new Set(value);
    if (seen.size !== value.length)
        return null;
    for (const id of DEFAULT_BOARD_ORDER)
        if (!seen.has(id))
            return null;
    return value.slice();
}
export function readStoredBoardOrder(storage) {
    try {
        const raw = storage?.getItem(SESSIONS_BOARD_ORDER_STORAGE_KEY);
        if (!raw)
            return [...DEFAULT_BOARD_ORDER];
        return normalizeBoardOrder(JSON.parse(raw)) ?? [...DEFAULT_BOARD_ORDER];
    }
    catch {
        return [...DEFAULT_BOARD_ORDER];
    }
}
export function writeStoredBoardOrder(storage, order) {
    try {
        storage?.setItem(SESSIONS_BOARD_ORDER_STORAGE_KEY, JSON.stringify(order));
    }
    catch {
        // localStorage 不可用时顺序只在当前页生效
    }
}
export function writeStoredSessionsViewMode(storage, mode) {
    try {
        storage?.setItem(SESSIONS_VIEW_STORAGE_KEY, mode);
    }
    catch {
        // Some embedded browsers deny localStorage. The current page still updates.
    }
}
export const KANBAN_GROUPBY_STORAGE_KEY = 'botmux.dashboard.sessions.kanbanGroupBy';
export const KANBAN_TEAM_STORAGE_KEY = 'botmux.dashboard.sessions.kanbanTeam';
export function normalizeKanbanGroupBy(value) {
    return value === 'flow' || value === 'team' || value === 'bot' ? value : null;
}
export function readStoredKanbanGroupBy(storage) {
    return normalizeKanbanGroupBy(storage?.getItem(KANBAN_GROUPBY_STORAGE_KEY)) ?? 'flow';
}
export function writeStoredKanbanGroupBy(storage, mode) {
    try {
        storage?.setItem(KANBAN_GROUPBY_STORAGE_KEY, mode);
    }
    catch {
        // localStorage 不可用时只在当前页生效
    }
}
export const SIDEBAR_STORAGE_KEY = 'botmux.dashboard.sidebar';
export function normalizeSidebarMode(value) {
    return value === 'expanded' || value === 'collapsed' ? value : null;
}
export function readStoredSidebarMode(storage) {
    return normalizeSidebarMode(storage?.getItem(SIDEBAR_STORAGE_KEY)) ?? 'expanded';
}
export function writeStoredSidebarMode(storage, mode) {
    try {
        storage?.setItem(SIDEBAR_STORAGE_KEY, mode);
    }
    catch {
        // localStorage 不可用时只在当前页生效
    }
}
export const SKIN_IDS = [
    'default',
    'cyber',
    'genshin',
    'fallout',
    'prts',
    'bluearchive',
    'zzz',
    'dragonball',
    'ikun',
];
export const SKIN_STORAGE_KEY = 'botmux.dashboard.skin';
export function normalizeSkin(value) {
    return typeof value === 'string' && SKIN_IDS.includes(value)
        ? value
        : null;
}
export function readStoredSkin(storage) {
    return normalizeSkin(storage?.getItem(SKIN_STORAGE_KEY)) ?? 'default';
}
//# sourceMappingURL=preferences.js.map