import React, { useLayoutEffect } from 'react';
import * as PropTypes from 'prop-types';
import * as S from './styles';
var SceneryThemeColorMap;
/**
 * @public
 */

(function (SceneryThemeColorMap) {
  SceneryThemeColorMap["white"] = "#FFFFFF";
  SceneryThemeColorMap["grey"] = "#FAFAFA";
})(SceneryThemeColorMap || (SceneryThemeColorMap = {}));

var usePageLayout = function usePageLayout(_ref) {
  var sceneryRef = _ref.sceneryRef,
      sceneryTheme = _ref.sceneryTheme;
  useLayoutEffect(function () {
    var elem = null;

    if (typeof sceneryRef === 'function') {
      elem = sceneryRef();
    } else if (typeof sceneryRef === 'string') {
      elem = document.querySelector(sceneryRef) || document.getElementById(sceneryRef);
    }

    if (!elem) {
      return;
    }

    var elemNotNull = elem;
    var prevElemBackgroundColor = elemNotNull.style.backgroundColor;
    elemNotNull.style.backgroundColor = SceneryThemeColorMap[sceneryTheme];
    return function () {
      elemNotNull.style.backgroundColor = prevElemBackgroundColor;
    };
  }, [sceneryTheme, sceneryRef]);
};
/**
 * 整个页面的容器。
 * @public
 */


var Page = function Page(_ref2) {
  var _ref2$sceneryTheme = _ref2.sceneryTheme,
      sceneryTheme = _ref2$sceneryTheme === void 0 ? 'white' : _ref2$sceneryTheme,
      _ref2$sceneryRef = _ref2.sceneryRef,
      sceneryRef = _ref2$sceneryRef === void 0 ? function () {
    return document.body;
  } : _ref2$sceneryRef,
      className = _ref2.className,
      style = _ref2.style,
      children = _ref2.children;
  usePageLayout({
    sceneryTheme: sceneryTheme,
    sceneryRef: sceneryRef
  });
  return React.createElement(S.Page, {
    className: className,
    style: style
  }, children);
};

Page.propTypes = {
  className: PropTypes.string,
  children: PropTypes.node,
  style: PropTypes.objectOf(PropTypes.any),
  // eslint-disable-next-line react/no-unused-prop-types
  sceneryTheme: PropTypes.oneOf(['white', 'grey']),
  // eslint-disable-next-line react/no-unused-prop-types
  sceneryRef: PropTypes.oneOfType([PropTypes.string, PropTypes.bool, PropTypes.func])
};
export default Page;