"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.useColorMode = useColorMode;
exports.ColorModeProvider = exports.ColorModeContext = void 0;

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

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

var __jsx = _react["default"].createElement;
var ColorModeContext = /*#__PURE__*/(0, _react.createContext)(null);
exports.ColorModeContext = ColorModeContext;

var ColorModeProvider = function ColorModeProvider(_ref) {
  var children = _ref.children,
      defaultMode = _ref.defaultMode;

  var _useState = (0, _react.useState)(defaultMode),
      mode = _useState[0],
      updateMode = _useState[1];

  var setMode = function setMode(newMode) {
    updateMode(newMode);

    if (typeof window !== 'undefined' && localStorage) {
      localStorage.setItem('themeMode', newMode); // save theme selection
    }
  };

  var context = {
    mode: mode,
    setMode: setMode
  };
  return __jsx(ColorModeContext.Provider, {
    value: context
  }, children);
};

exports.ColorModeProvider = ColorModeProvider;

function useColorMode() {
  var _colorMode = (0, _react.useContext)(ColorModeContext);

  if (_colorMode === undefined) {
    // will use light theme by default
    console.log('useColorMode must be used within a ColorModeProvider');
    return null;
  } // @ts-ignore


  return _colorMode;
}
//# sourceMappingURL=ColorModeProvider.js.map