"use strict";

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

Object.defineProperty(exports, "__esModule", {
  value: true
});
Object.defineProperty(exports, "css", {
  enumerable: true,
  get: function get() {
    return _react.css;
  }
});
Object.defineProperty(exports, "useTheme", {
  enumerable: true,
  get: function get() {
    return _react.useTheme;
  }
});
Object.defineProperty(exports, "styled", {
  enumerable: true,
  get: function get() {
    return _styled["default"];
  }
});
exports.ThemeProvider = void 0;

var _react = require("@emotion/react");

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

var _ColorModeProvider = require("../ColorModeProvider");

var _theme = require("../theme");

var _styled = _interopRequireDefault(require("@emotion/styled"));

var __jsx = _react2["default"].createElement;

// TODO: check into providerTheme type tslint error when ITHemeProvider is used
// @ts-ignore
var BaseThemeProvider = function BaseThemeProvider(_ref) {
  var providedTheme = _ref.theme,
      children = _ref.children;
  var colorMode = (0, _ColorModeProvider.useColorMode)(); // needs more work still to override existing styles, but still allow dependencies.
  // i.e, "button" color prop depends on primary, so passing a different primary color should change all props dependent on primary

  var emotionTheme = (0, _theme.baseTheme)({
    providedTheme: providedTheme,
    mode: colorMode === null || colorMode === void 0 ? void 0 : colorMode.mode
  });
  return __jsx(_react.ThemeProvider, {
    theme: emotionTheme
  }, children);
};

var ThemeProvider = function ThemeProvider(_ref2) {
  var _localStorage;

  var providedTheme = _ref2.theme,
      children = _ref2.children,
      defaultMode = _ref2.defaultMode;
  var mode = typeof window !== 'undefined' && ((_localStorage = localStorage) === null || _localStorage === void 0 ? void 0 : _localStorage.getItem('themeMode')) || defaultMode || 'light';
  return __jsx(_ColorModeProvider.ColorModeProvider, {
    defaultMode: mode
  }, __jsx(BaseThemeProvider, {
    theme: providedTheme
  }, children));
};

exports.ThemeProvider = ThemeProvider;
//# sourceMappingURL=ThemeProvider.js.map