/*
 * Copyright (c) 2023-2025 Datalayer, Inc.
 * Distributed under the terms of the Modified BSD License.
 */
import { createStore } from 'zustand/vanilla';
import { useStore } from 'zustand';
export const layoutStore = createStore((set, get) => ({
    backdrop: undefined,
    banner: undefined,
    bootstrapped: false,
    item: undefined,
    itemsRefreshCount: 0,
    leftPortal: undefined,
    leftSidebarVariant: 'empty',
    organization: undefined,
    rightPortal: undefined,
    screenCapture: undefined,
    space: undefined,
    team: undefined,
    hideBackdrop: () => set((state) => ({
        backdrop: { open: false, message: undefined },
    })),
    hideScreencapture: () => set((state) => ({
        screenshot: { open: false, message: undefined },
    })),
    setBootstrapped: (bootstrapped) => set((state) => ({ bootstrapped })),
    showBackdrop: (message) => set((state) => ({ backdrop: { open: true, message } })),
    showScreencapture: (message) => set((state) => ({ screenshot: { open: true, message } })),
    setBanner: (bannerDisplay) => set((state) => ({
        banner: {
            timestamp: new Date(),
            message: bannerDisplay.message,
            variant: bannerDisplay.variant,
        },
    })),
    setLeftPortal: (leftPortal) => set((state) => ({ leftPortal })),
    setRightPortal: (rightPortal) => set((state) => ({ rightPortal })),
    resetLeftPortal: () => set((state) => ({
        leftPortal: state.leftPortal?.pinned ? state.leftPortal : undefined,
    })),
    resetRightPortal: () => set((state) => ({
        rightPortal: state.rightPortal?.pinned ? state.rightPortal : undefined,
    })),
    resetForcedLeftPortal: () => set((state) => ({ leftPortal: undefined })),
    resetForcedRightPortal: () => set((state) => ({ rightPortal: undefined })),
    setLeftSidebarVariant: (leftSidebarVariant) => set((state) => ({ leftSidebarVariant })),
    updateLayoutOrganization: (organization) => set((state) => {
        return {
            organization: organization
                ? {
                    ...state.organization,
                    ...organization,
                }
                : undefined,
        };
    }),
    updateLayoutTeam: (team) => set((state) => {
        return {
            team: team
                ? {
                    ...state.team,
                    ...team,
                }
                : undefined,
        };
    }),
    updateLayoutSpace: (space) => set((state) => {
        return {
            space: space
                ? {
                    ...state.space,
                    ...space,
                }
                : undefined,
        };
    }),
    setItem: (item) => set((state) => ({ item })),
    triggerItemsRefresh: () => set((state) => ({
        itemsRefreshCount: state.itemsRefreshCount + 1,
    })),
    setScreencapture: (screenCapture) => set((state) => ({ screenCapture })),
    reset: () => set((state) => ({ bootstrapped: false })),
}));
export function useLayoutStore(selector) {
    return useStore(layoutStore, selector);
}
export default useLayoutStore;
