"use strict";

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

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

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

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

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

var _components = require("../components");

var _core = require("../core");

var _EventListener = _interopRequireDefault(require("../event/EventListener"));

var _excluded = ["children", "onClick", "onMouseEnter", "onMouseLeave"];

function toPlaneProps(_ref) {
  var ambientOcclusionMap = _ref.ambientOcclusionMap,
      ambientOcclusionMapIntensity = _ref.ambientOcclusionMapIntensity,
      ambientOcclusionTextureOffset = _ref.ambientOcclusionTextureOffset,
      ambientOcclusionTextureRepeat = _ref.ambientOcclusionTextureRepeat,
      color = _ref.color,
      displacementBias = _ref.displacementBias,
      displacementMap = _ref.displacementMap,
      displacementScale = _ref.displacementScale,
      displacementTextureOffset = _ref.displacementTextureOffset,
      displacementTextureRepeat = _ref.displacementTextureRepeat,
      envMap = _ref.envMap,
      fog = _ref.fog,
      _ref$height = _ref.height,
      height = _ref$height === void 0 ? 1 : _ref$height,
      metalness = _ref.metalness,
      normalMap = _ref.normalMap,
      normalScale = _ref.normalScale,
      normalTextureOffset = _ref.normalTextureOffset,
      normalTextureRepeat = _ref.normalTextureRepeat,
      repeat = _ref.repeat,
      roughness = _ref.roughness,
      segmentsHeight = _ref.segmentsHeight,
      segmentsWidth = _ref.segmentsWidth,
      sphericalEnvMap = _ref.sphericalEnvMap,
      src = _ref.src,
      _ref$width = _ref.width,
      width = _ref$width === void 0 ? 1 : _ref$width,
      wireframe = _ref.wireframe,
      wireframeLinewidth = _ref.wireframeLinewidth;
  return (0, _extends2.default)({}, ambientOcclusionMap && {
    'ambient-occlusion-map': ambientOcclusionMap
  }, ambientOcclusionMapIntensity && {
    'ambient-occlusion-map-intensity': ambientOcclusionMapIntensity
  }, ambientOcclusionTextureOffset && {
    'ambient-occlusion-texture-offset': new _components.Vec2(ambientOcclusionTextureOffset).toString()
  }, ambientOcclusionTextureRepeat && {
    'ambient-occlusion-texture-repeat': new _components.Vec2(ambientOcclusionTextureRepeat).toString()
  }, color && {
    color: color
  }, displacementBias && {
    'displacement-bias': displacementBias
  }, displacementMap && {
    'displacement-map': displacementMap
  }, displacementScale && {
    'displacement-scale': displacementScale
  }, displacementTextureOffset && {
    'displacement-texture-offset': new _components.Vec2(displacementTextureOffset).toString()
  }, displacementTextureRepeat && {
    'displacement-texture-repeat': new _components.Vec2(displacementTextureRepeat).toString()
  }, envMap && {
    'env-map': envMap
  }, fog && {
    fog: fog
  }, height && {
    height: height
  }, metalness && {
    metalness: metalness
  }, normalMap && {
    'normal-map': normalMap
  }, normalScale && {
    'normal-scale': new _components.Vec2(normalScale).toString()
  }, normalTextureOffset && {
    'normal-texture-offset': new _components.Vec2(normalTextureOffset).toString()
  }, normalTextureRepeat && {
    'normal-texture-repeat': new _components.Vec2(normalTextureRepeat).toString()
  }, repeat && {
    repeat: new _components.Vec2(repeat).toString()
  }, roughness && {
    roughness: roughness
  }, segmentsHeight && {
    'segments-height': segmentsHeight
  }, segmentsWidth && {
    'segments-width': segmentsWidth
  }, sphericalEnvMap && {
    'spherical-env-map': sphericalEnvMap
  }, src && {
    src: src
  }, width && {
    width: width
  }, wireframe && {
    wireframe: wireframe
  }, wireframeLinewidth && {
    'wireframe-linewidth': wireframeLinewidth
  });
}
/**
 * The plane primitive creates flat surfaces using the [geometry](https://aframe.io/docs/1.3.0/components/geometry.html) component with the type set to `plane`.
 *
 * @see https://aframe.io/docs/1.3.0/primitives/a-plane.html
 *
 * @example
 * ```tsx
 * <Scene>
 *   <Assets>
 *     <img id="ground" src="ground.jpg" />
 *   </Assets>
 *
 *   // Basic plane.
 *   <Plane
 *     color="#CCC"
 *     height={20}
 *     width={20}
 *   />
 *
 *   // Textured plane parallel to ground.
 *   <Plane
 *     src="#ground"
 *     height={100}
 *     width={100}
 *     rotation={{ x: -90, y: 0, z: 0 }}
 *   />
 * </Scene>
 * ```
 */


var Plane = function Plane(props) {
  var planeKeys = ['ambientOcclusionMap', 'ambientOcclusionMapIntensity', 'ambientOcclusionTextureOffset', 'ambientOcclusionTextureRepeat', 'color', 'displacementBias', 'displacementMap', 'displacementScale', 'displacementTextureOffset', 'displacementTextureRepeat', 'envMap', 'fog', 'height', 'metalness', 'normalMap', 'normalScale', 'normalTextureOffset', 'normalTextureRepeat', 'repeat', 'roughness', 'segmentsHeight', 'segmentsWidth', 'sphericalEnvMap', 'src', 'width', 'wireframe', 'wireframeLinewidth'];
  var children = props.children,
      onClick = props.onClick,
      onMouseEnter = props.onMouseEnter,
      onMouseLeave = props.onMouseLeave,
      restProps = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
  return /*#__PURE__*/_react.default.createElement(_EventListener.default, (0, _extends2.default)({
    primitive: "a-plane",
    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();
        }
      }
    }
  }, (0, _core.toProps)(restProps, planeKeys), toPlaneProps(restProps)));
};

exports.Plane = Plane;