/**
 * @license
 * Copyright 2025 Vybestack LLC
 * SPDX-License-Identifier: Apache-2.0
 */
export const initialAppState = {
    openDialogs: {
        theme: false,
        auth: false,
        editor: false,
        providerModel: false,
        provider: false,
        privacy: false,
        loadProfile: false,
        tools: false,
        oauthCode: false,
    },
    warnings: new Map(),
    errors: {
        theme: null,
        auth: null,
        editor: null,
    },
    lastAddItemAction: null,
};
export function appReducer(state, action) {
    switch (action.type) {
        case 'ADD_ITEM':
            // This action triggers a side effect in SessionController
            return {
                ...state,
                lastAddItemAction: action.payload,
            };
        case 'OPEN_DIALOG':
            return {
                ...state,
                openDialogs: {
                    ...state.openDialogs,
                    [action.payload]: true,
                },
            };
        case 'CLOSE_DIALOG':
            return {
                ...state,
                openDialogs: {
                    ...state.openDialogs,
                    [action.payload]: false,
                },
            };
        case 'SET_WARNING': {
            const newWarnings = new Map(state.warnings);
            newWarnings.set(action.payload.key, action.payload.message);
            return {
                ...state,
                warnings: newWarnings,
            };
        }
        case 'CLEAR_WARNING': {
            const newWarnings = new Map(state.warnings);
            newWarnings.delete(action.payload);
            return {
                ...state,
                warnings: newWarnings,
            };
        }
        case 'SET_THEME_ERROR':
            return {
                ...state,
                errors: {
                    ...state.errors,
                    theme: action.payload,
                },
            };
        case 'SET_AUTH_ERROR':
            return {
                ...state,
                errors: {
                    ...state.errors,
                    auth: action.payload,
                },
            };
        case 'SET_EDITOR_ERROR':
            return {
                ...state,
                errors: {
                    ...state.errors,
                    editor: action.payload,
                },
            };
        default:
            return state;
    }
}
//# sourceMappingURL=appReducer.js.map