import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
import _extends from "@babel/runtime/helpers/esm/extends";
var _excluded = ["children", "onClick", "onMouseEnter", "onMouseLeave"];
import React from 'react';
import { Animation, Camera, Cursor, DaydreamControls, GearvrControls, GenericTrackedControllerControls, Geometry, GLTFModel, HandControls, HandTrackingControls, HpMixedRealityControls, LaserControls, Layer, Light, Line, Link, LookControls, MagicleapControls, Material, ObjModel, OculusGoControls, OculusTouchControls, Position, Raycaster, Rotation, Scale, Shadow, Sound, Text, TrackedControlsWebVR, TrackedControlsWebXR, TrackedControls, ValveIndexControls, Visible, ViveControls, ViveFocusControls, WASDControls, WindowsMotionControls } from '../components';
import EventListener from '../event/EventListener';
import parse from '../utils/propParser';
export function toProps(props, removalKeys) {
  var defaultKeys = ['id', 'className', 'children', 'animation', 'camera', 'cursor', 'daydreamControls', 'gearvrControls', 'genericTrackedControllerControls', 'geometry', 'gltfModel', 'handControls', 'handTrackingControls', 'hpMixedRealityControls', 'laserControls', 'layer', 'light', 'line', 'link', 'lookControls', 'magicleapControls', 'material', 'objModel', 'oculusGoControls', 'oculusTouchControls', 'position', 'raycaster', 'rotation', 'scale', 'shadow', 'sound', 'text', 'trackedControlsWebVR', 'trackedControlsWebXR', 'trackedControls', 'valveIndexControls', 'visible', 'viveControls', 'viveFocusControls', 'wasdControls', 'windowsMotionControls'];
  var animationKeys = Object.keys(props).filter(function (key) {
    return key.includes('animation__');
  });
  var animationProps = animationKeys.reduce(function (acc, key) {
    var _ref;

    return _extends({}, acc, props[key] && (_ref = {}, _ref[key] = new Animation(props[key]).toString(), _ref));
  }, {});
  var extraKeys = Object.keys(props).filter(function (key) {
    return !defaultKeys.includes(key) && !key.includes('animation__');
  });
  var extraProps = (removalKeys ? extraKeys.filter(function (key) {
    return !removalKeys.includes(key);
  }) : extraKeys).reduce(function (acc, key) {
    var _ref2;

    return _extends({}, acc, props[key] && (_ref2 = {}, _ref2[key] = parse(props[key]), _ref2));
  }, {});
  var id = props.id,
      className = props.className,
      animation = props.animation,
      camera = props.camera,
      cursor = props.cursor,
      daydreamControls = props.daydreamControls,
      gearvrControls = props.gearvrControls,
      genericTrackedControllerControls = props.genericTrackedControllerControls,
      geometry = props.geometry,
      gltfModel = props.gltfModel,
      handControls = props.handControls,
      handTrackingControls = props.handTrackingControls,
      hpMixedRealityControls = props.hpMixedRealityControls,
      laserControls = props.laserControls,
      layer = props.layer,
      light = props.light,
      line = props.line,
      link = props.link,
      lookControls = props.lookControls,
      magicleapControls = props.magicleapControls,
      material = props.material,
      objModel = props.objModel,
      oculusGoControls = props.oculusGoControls,
      oculusTouchControls = props.oculusTouchControls,
      position = props.position,
      raycaster = props.raycaster,
      rotation = props.rotation,
      scale = props.scale,
      shadow = props.shadow,
      sound = props.sound,
      text = props.text,
      trackedControlsWebVR = props.trackedControlsWebVR,
      trackedControlsWebXR = props.trackedControlsWebXR,
      trackedControls = props.trackedControls,
      valveIndexControls = props.valveIndexControls,
      visible = props.visible,
      viveControls = props.viveControls,
      viveFocusControls = props.viveFocusControls,
      wasdControls = props.wasdControls,
      windowsMotionControls = props.windowsMotionControls;
  return _extends({}, id && {
    id: id
  }, className && {
    class: className
  }, animation && {
    animation: new Animation(animation).toString()
  }, camera && {
    camera: new Camera(camera).toString()
  }, cursor && {
    cursor: new Cursor(cursor).toString()
  }, daydreamControls && {
    'daydream-controls': new DaydreamControls(daydreamControls).toString()
  }, gearvrControls && {
    'gearvr-controls': new GearvrControls(gearvrControls).toString()
  }, genericTrackedControllerControls && {
    'generic-tracked-controller-controls': new GenericTrackedControllerControls(genericTrackedControllerControls).toString()
  }, geometry && {
    geometry: new Geometry(geometry).toString()
  }, gltfModel && {
    'gltf-model': new GLTFModel(gltfModel).toString()
  }, handControls && {
    'hand-controls': new HandControls(handControls).toString()
  }, handTrackingControls && {
    'hand-tracking-controls': new HandTrackingControls(handTrackingControls).toString()
  }, hpMixedRealityControls && {
    'hp-mixed-reality-controls': new HpMixedRealityControls(hpMixedRealityControls).toString()
  }, laserControls && {
    'laser-controls': new LaserControls(laserControls).toString()
  }, layer && {
    layer: new Layer(layer).toString()
  }, light && {
    light: new Light(light).toString()
  }, line && {
    line: new Line(line).toString()
  }, link && {
    link: new Link(link).toString()
  }, lookControls && {
    'look-controls': new LookControls(lookControls).toString()
  }, magicleapControls && {
    'magicleap-controls': new MagicleapControls(magicleapControls).toString()
  }, material && {
    material: new Material(material).toString()
  }, objModel && {
    'obj-model': new ObjModel(objModel).toString()
  }, oculusGoControls && {
    'oculus-go-controls': new OculusGoControls(oculusGoControls).toString()
  }, oculusTouchControls && {
    'oculus-touch-controls': new OculusTouchControls(oculusTouchControls).toString()
  }, position && {
    position: new Position(position).toString()
  }, raycaster && {
    raycaster: new Raycaster(raycaster).toString()
  }, rotation && {
    rotation: new Rotation(rotation).toString()
  }, scale && {
    scale: new Scale(scale).toString()
  }, shadow && {
    shadow: new Shadow(shadow).toString()
  }, sound && {
    sound: new Sound(sound).toString()
  }, text && {
    text: new Text(text).toString()
  }, trackedControlsWebVR && {
    'tracked-controls-webvr': new TrackedControlsWebVR(trackedControlsWebVR).toString()
  }, trackedControlsWebXR && {
    'tracked-controls-webxr': new TrackedControlsWebXR(trackedControlsWebXR).toString()
  }, trackedControls && {
    'tracked-controls': new TrackedControls(trackedControls).toString()
  }, valveIndexControls && {
    'valve-index-controls': new ValveIndexControls(valveIndexControls).toString()
  }, {
    visible: visible !== undefined ? new Visible(visible).toString() : undefined
  }, viveControls && {
    'vive-controls': new ViveControls(viveControls).toString()
  }, viveFocusControls && {
    'vive-focus-controls': new ViveFocusControls(viveFocusControls).toString()
  }, wasdControls && {
    'wasd-controls': new WASDControls(wasdControls).toString()
  }, windowsMotionControls && {
    'windows-motion-controls': new WindowsMotionControls(windowsMotionControls).toString()
  }, animationProps, extraProps);
}
/**
 * A-Frame represents an entity via the `<a-entity>` element. As defined in the [entity-component-system pattern](https://aframe.io/docs/1.3.0/introduction/entity-component-system.html),
 * entities are placeholder objects to which we plug in components to provide them
 * appearance, behavior, and functionality.
 *
 * In A-Frame, entities are inherently attached with the
 * [position](https://aframe.io/docs/1.3.0/components/position.html),
 * [rotation](https://aframe.io/docs/1.3.0/components/rotation.html), and
 * [scale](https://aframe.io/docs/1.3.0/components/scale.html) components.
 *
 * @see https://aframe.io/docs/1.3.0/core/entity.html
 */

var Entity = function Entity(props) {
  var children = props.children,
      onClick = props.onClick,
      onMouseEnter = props.onMouseEnter,
      onMouseLeave = props.onMouseLeave,
      restProps = _objectWithoutPropertiesLoose(props, _excluded);

  return /*#__PURE__*/React.createElement(EventListener, _extends({
    primitive: "a-entity",
    events: {
      click: function click() {
        if (onClick) {
          onClick();
        }
      },
      mouseenter: function mouseenter() {
        if (onClick) {
          var canvas = window.document.querySelector('canvas.a-canvas');
          canvas.style.cursor = 'pointer';
        }

        if (onMouseEnter) {
          onMouseEnter();
        }
      },
      mouseleave: function mouseleave() {
        if (onClick) {
          var canvas = window.document.querySelector('canvas.a-canvas');
          canvas.style.cursor = 'grab';
        }

        if (onMouseLeave) {
          onMouseLeave();
        }
      }
    }
  }, toProps(restProps)), children);
};

export default Entity;