/*
This file is part of the Notesnook project (https://notesnook.com/)

Copyright (C) 2023 Streetwriters (Private) Limited

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
import { create } from "zustand";
export const useToolbarStore = create((set, get) => ({
    downloadOptions: undefined,
    isMobile: false,
    openedPopups: {},
    setDownloadOptions: (options) => set({ downloadOptions: options }),
    setIsMobile: (isMobile) => set({ isMobile }),
    toolbarLocation: "top",
    setToolbarLocation: (location) => set({ toolbarLocation: location }),
    closePopup: (id) => set({
        openedPopups: Object.assign(Object.assign({}, get().openedPopups), { [id]: undefined })
    }),
    isPopupOpen: (id) => !!get().openedPopups[id],
    openPopup: (ref) => set({
        openedPopups: Object.assign(Object.assign({}, get().openedPopups), { [ref.id]: ref })
    }),
    closePopupGroup: (group, excluded) => set((state) => {
        for (const key in state.openedPopups) {
            const ref = state.openedPopups[key];
            if (ref && ref.group === group && !excluded.includes(ref.id)) {
                state.openedPopups[key] = undefined;
            }
        }
        return state;
    }),
    closeAllPopups: () => set({ openedPopups: {} }),
    fontFamily: "sans-serif",
    setFontFamily: (fontFamily) => set({ fontFamily }),
    fontSize: 16,
    setFontSize: (fontSize) => set({ fontSize })
}));
export function useToolbarLocation() {
    return useToolbarStore((store) => store.toolbarLocation);
}
export function useIsMobile() {
    return useToolbarStore((store) => store.isMobile);
}
