import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
import { useReducer } from 'react';
import { ThemeProvider } from 'styled-components';
import PopoverStyle from '../../popover/globalStyle';
import { Portal } from '../../portal';
import defaultTheme from '../../theme';
import { Toaster } from '../../toast';
import { VuiContextProvider } from './context';
import GlobalStyle from './globalStyle';
import NotifyOffline from './notifyOffline';
import { genericReducer, toastsReducer } from './reducers';
import ResetCSS from './resetCSS';
/** Provides theme to all wrapped components and by default includes CSS reset and global styles. */
const VuiProvider = ({ children, globalStyle = true, resetCSS = true, theme = defaultTheme, notifyOffline = false, }) => {
    const [toasts, toastsDispatch] = useReducer(toastsReducer, { list: [] });
    const [portalSlot, setPortalSlot] = useReducer(genericReducer, null);
    const addToast = (toast) => toastsDispatch({ type: 'add', toast });
    const removeToast = (id) => toastsDispatch({ type: 'remove', toast: { id } });
    const context = { toasts, addToast, removeToast, setPortalSlot };
    return (_jsx(VuiContextProvider, { value: context, children: _jsx(ThemeProvider, { theme: theme, children: _jsxs(_Fragment, { children: [resetCSS && _jsx(ResetCSS, {}), _jsx(GlobalStyle, { globalStyle: globalStyle }), _jsx(PopoverStyle, {}), children, notifyOffline && _jsx(NotifyOffline, {}), _jsxs(Portal, { children: [portalSlot, _jsx(Toaster, {})] })] }) }) }));
};
export default VuiProvider;
//# sourceMappingURL=vuiProvider.js.map