import { jsx as _jsx } from "react/jsx-runtime";
import { useEffect } from 'react';
import { useAtom, useAtomValue } from 'jotai';
import { layoutAtom, collapsedSidebarAtom } from '../jotai/app.js';
import { globalStoreAtom } from '../jotai/store.js';
export function withStore(WrappedComponent) {
    const WithStore = ({ portalOptions, ...props }) => {
        const [layout, setLayout] = useAtom(layoutAtom);
        const [collapsedSidebar, setCollapseSidebar] = useAtom(collapsedSidebarAtom);
        const { options, parser } = useAtomValue(globalStoreAtom);
        useEffect(() => {
            if (portalOptions?.layout) {
                setLayout(portalOptions.layout);
            }
        }, [portalOptions?.layout, setLayout]);
        useEffect(() => {
            if (typeof portalOptions?.collapsedSidebar === 'boolean') {
                setCollapseSidebar(portalOptions.collapsedSidebar);
            }
        }, [portalOptions?.collapsedSidebar, setCollapseSidebar]);
        if (!parser) {
            return null;
        }
        return (_jsx(WrappedComponent, { ...props, options: options, layout: layout, collapsedSidebar: collapsedSidebar, parser: parser }));
    };
    return WithStore;
}
//# sourceMappingURL=withStore.js.map