"use strict";

require("core-js/modules/es.array.iterator.js");
require("core-js/modules/es.object.define-property.js");
require("core-js/modules/es.object.get-own-property-descriptor.js");
require("core-js/modules/es.object.to-string.js");
require("core-js/modules/es.string.iterator.js");
require("core-js/modules/es.weak-map.js");
require("core-js/modules/esnext.weak-map.delete-all.js");
require("core-js/modules/esnext.weak-map.emplace.js");
require("core-js/modules/web.dom-collections.iterator.js");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.useWindowFocus = exports.useUnmount = exports.useTheme = exports.useDelayedValue = exports.useDelayedMeasure = exports.LanguageName = void 0;
require("core-js/modules/web.timers.js");
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _react = require("react");
var _reactUseMeasure = _interopRequireDefault(require("react-use-measure"));
var theme_ = _interopRequireWildcard(require("../theme/generate"));
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
// FIXME: Files in 'lib' are commonjs modules.
//        There's no variable binding unless you reference the whole module.

var useUnmount = exports.useUnmount = function useUnmount(callback) {
  (0, _react.useEffect)(function () {
    return callback;
  }, []);
};
var LanguageName = exports.LanguageName = {
  zh: '简体中文',
  en: 'English'
};
var useTheme = exports.useTheme = function useTheme() {
  var _useState = (0, _react.useState)(theme_.themeMode),
    _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
    theme = _useState2[0],
    setTheme = _useState2[1];
  var toggleTheme = (0, _react.useCallback)(function () {
    var nextTheme = theme_.themeMode === 'light' ? 'dark' : 'light';
    theme_.setThemeMode(nextTheme);
    setTheme(theme_.themeMode);
    theme_.generateTheme();
    document.documentElement.style.colorScheme = nextTheme;
  }, []);
  return [theme, toggleTheme];
};
var useWindowFocus = exports.useWindowFocus = function useWindowFocus() {
  var _useState3 = (0, _react.useState)(true),
    _useState4 = (0, _slicedToArray2["default"])(_useState3, 2),
    focus = _useState4[0],
    setFocus = _useState4[1];
  (0, _react.useEffect)(function () {
    var onFocus = function onFocus() {
      return setFocus(true);
    };
    var onBlur = function onBlur() {
      return setFocus(false);
    };
    window.addEventListener('focus', onFocus);
    window.addEventListener('blur', onBlur);
    return function () {
      window.removeEventListener('focus', onFocus);
      window.removeEventListener('blur', onBlur);
    };
  }, []);
  return focus;
};
var useDelayedValue = exports.useDelayedValue = function useDelayedValue(realValue, delay) {
  var _useState5 = (0, _react.useState)(null),
    _useState6 = (0, _slicedToArray2["default"])(_useState5, 2),
    value = _useState6[0],
    setValue = _useState6[1];
  (0, _react.useEffect)(function () {
    var timer = setTimeout(function () {
      return setValue(realValue);
    }, delay);
    return function () {
      return clearTimeout(timer);
    };
  }, [realValue, delay]);
  return value;
};
// Delay `useMeasure()`'s refreshing, improve re-layout performance.
// Also a workaround for 'loop completed with undelivered notifications' error.
// Since we only need width and height, other properties are hidden from type.
var useDelayedMeasure = exports.useDelayedMeasure = function useDelayedMeasure() {
  var delay = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  var _useMeasure = (0, _reactUseMeasure["default"])(),
    _useMeasure2 = (0, _slicedToArray2["default"])(_useMeasure, 2),
    ref = _useMeasure2[0],
    bounds_ = _useMeasure2[1];
  var bounds = useDelayedValue(bounds_, delay) || {
    width: 0,
    height: 0
  };
  return [ref, bounds];
};