"use strict";

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

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;

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

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

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

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

var _scene = require("../components/scene");

var _excluded = ["children"];

function toProps(props) {
  var defaultKeys = ['id', 'className', 'fog', 'inspector', 'background', 'vrModeUI', 'stats', 'screenshot', 'pool', 'keyboardShortcuts', 'embedded', 'deviceOrientationPermissionUI', 'debug', 'gltfModel', 'shadow', 'renderer', 'children'];
  var extraKeys = Object.keys(props).filter(function (key) {
    return !defaultKeys.includes(key);
  });
  var extraProps = extraKeys.reduce(function (acc, key) {
    var _extends2;

    return (0, _extends3.default)({}, acc, (_extends2 = {}, _extends2[key] = props[key], _extends2));
  }, {});
  var id = props.id,
      className = props.className,
      fog = props.fog,
      inspector = props.inspector,
      background = props.background,
      vrModeUI = props.vrModeUI,
      stats = props.stats,
      screenshot = props.screenshot,
      pool = props.pool,
      keyboardShortcuts = props.keyboardShortcuts,
      embedded = props.embedded,
      deviceOrientationPermissionUI = props.deviceOrientationPermissionUI,
      debug = props.debug,
      gltfModel = props.gltfModel,
      shadow = props.shadow,
      renderer = props.renderer;
  return (0, _extends3.default)({
    id: id,
    class: className,
    background: background && new _scene.Background(background).toString(),
    debug: debug !== undefined ? new _scene.Debug(debug).toString() : undefined,
    fog: fog && new _scene.Fog(fog).toString(),
    inspector: inspector && new _scene.Inspector(inspector).toString(),
    'vr-mode-ui': vrModeUI && new _scene.VrModeUI(vrModeUI).toString(),
    stats: stats !== undefined ? new _scene.Stats(stats).toString() : undefined,
    screenshot: screenshot && new _scene.Screenshot(screenshot).toString(),
    pool: pool && new _scene.Pool(pool).toString(),
    'keyboard-shortcuts': keyboardShortcuts && new _scene.KeyboardShortcuts(keyboardShortcuts).toString(),
    embedded: embedded !== undefined ? new _scene.Embedded(embedded).toString() : undefined,
    'device-orientation-permission-ui': deviceOrientationPermissionUI && new _scene.DeviceOrientationPermissionUI(deviceOrientationPermissionUI).toString(),
    'gltf-model': gltfModel && new _scene.GLTFModel(gltfModel).toString(),
    shadow: shadow && new _scene.Shadow(shadow).toString(),
    renderer: renderer && new _scene.Renderer(renderer).toString()
  }, extraProps);
}
/**
 * A scene is represented by the `<a-scene>` element. The scene is the global root object, and all [entities](https://aframe.io/docs/1.3.0/core/entity.html) are contained within the scene.
 *
 * The scene inherits from the [Entity](https://aframe.io/docs/1.3.0/core/entity.html) class so it inherits all of its properties, its methods, the ability to attach components, and the behavior to wait for all of its child nodes (e.g., `<a-assets>` and `<a-entity>`) to load before kicking off the render loop.
 *
 * @see https://aframe.io/docs/1.3.0/core/scene.html
 */


var Scene = function Scene(props) {
  var children = props.children,
      restProps = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);

  var _useState = (0, _react.useState)(false),
      domReady = _useState[0],
      setDomReady = _useState[1];

  (0, _react.useEffect)(function () {
    var domElm = document.getElementById('assets-management');

    if (domElm) {
      setDomReady(true);
    }

    var sceneEl = document.querySelector('a-scene');

    if (process.env.NODE_ENV === 'production') {
      sceneEl.addEventListener('loaded', function () {
        sceneEl.components.inspector.remove();
      });
    }
  }, []);
  return /*#__PURE__*/_react.default.createElement("a-scene", toProps(restProps), /*#__PURE__*/_react.default.createElement("a-assets", {
    id: "assets-management"
  }), domReady && children);
};

var _default = Scene;
exports.default = _default;