"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

exports.__esModule = true;
exports.default = void 0;

var _react = _interopRequireDefault(require("react"));

var _useTheme = _interopRequireDefault(require("../hooks/useTheme"));

var _themeContext = _interopRequireDefault(require("../contexts/themeContext"));

var _light = _interopRequireDefault(require("./variants/light"));

var _dark = _interopRequireDefault(require("./variants/dark"));

var _cosmic = _interopRequireDefault(require("./variants/cosmic"));

var _utils = require("./utils");

var _CssBaseline = require("../components/CssBaseline");

var _jsxRuntime = require("react/jsx-runtime");

const ThemeProvider = ({
  children,
  theme,
  baseline = true
}) => {
  //  Case of theme being different from defaults
  let userTheme = _light.default; // default theme

  if (typeof theme !== "string") {
    const customTheme = theme;
    const currentTheme = (0, _useTheme.default)();
    const baseTheme = customTheme.type ? (0, _utils.getThemeByType)(customTheme.type) : currentTheme;
    const merged = (0, _utils.mergeTheme)(baseTheme, customTheme); // Case of theme being different from defaults

    userTheme = currentTheme.type !== merged.type ? (0, _utils.switchTheme)(merged) : merged;
  }

  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_themeContext.default.Provider, {
    value: typeof theme === "string" ? theme === "light" ? _light.default : theme === "dark" ? _dark.default : theme === "cosmic" ? _cosmic.default : userTheme // default
    : userTheme,
    children: [baseline && /*#__PURE__*/(0, _jsxRuntime.jsx)(_CssBaseline.CssBaseline, {}), children]
  });
};

var _default = ThemeProvider;
exports.default = _default;
module.exports = exports.default;