"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const styled_components_1 = require("styled-components");
const globalStyle_1 = __importDefault(require("../../popover/globalStyle"));
const portal_1 = require("../../portal");
const theme_1 = __importDefault(require("../../theme"));
const toast_1 = require("../../toast");
const context_1 = require("./context");
const globalStyle_2 = __importDefault(require("./globalStyle"));
const notifyOffline_1 = __importDefault(require("./notifyOffline"));
const reducers_1 = require("./reducers");
const resetCSS_1 = __importDefault(require("./resetCSS"));
/** Provides theme to all wrapped components and by default includes CSS reset and global styles. */
const VuiProvider = ({ children, globalStyle = true, resetCSS = true, theme = theme_1.default, notifyOffline = false, }) => {
    const [toasts, toastsDispatch] = (0, react_1.useReducer)(reducers_1.toastsReducer, { list: [] });
    const [portalSlot, setPortalSlot] = (0, react_1.useReducer)(reducers_1.genericReducer, null);
    const addToast = (toast) => toastsDispatch({ type: 'add', toast });
    const removeToast = (id) => toastsDispatch({ type: 'remove', toast: { id } });
    const context = { toasts, addToast, removeToast, setPortalSlot };
    return ((0, jsx_runtime_1.jsx)(context_1.VuiContextProvider, { value: context, children: (0, jsx_runtime_1.jsx)(styled_components_1.ThemeProvider, { theme: theme, children: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [resetCSS && (0, jsx_runtime_1.jsx)(resetCSS_1.default, {}), (0, jsx_runtime_1.jsx)(globalStyle_2.default, { globalStyle: globalStyle }), (0, jsx_runtime_1.jsx)(globalStyle_1.default, {}), children, notifyOffline && (0, jsx_runtime_1.jsx)(notifyOffline_1.default, {}), (0, jsx_runtime_1.jsxs)(portal_1.Portal, { children: [portalSlot, (0, jsx_runtime_1.jsx)(toast_1.Toaster, {})] })] }) }) }));
};
exports.default = VuiProvider;
//# sourceMappingURL=vuiProvider.js.map