import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
var _excluded = ["src", "children"];
import React, { Fragment, useId } from 'react';
import { toProps, CreateAsset, AssetItem } from '../core';
import EventListener from '../event/EventListener';
var PREFIX_ASSET = 'model';

/**
 * The glTF model primitive displays a 3D glTF model
 * created from a 3D modeling program or downloaded from the web.
 *
 * @see https://aframe.io/docs/master/primitives/a-gltf-model.html
 *
 * @example
 * ```tsx
 * <Scene>
 *   <Assets>
 *     <AssetItem id="tree" src="tree.gltf" />
 *   </Assets>
 *
 *   // Using the asset management system.
 *   <GLTFModel src="#tree" />
 *
 *   // Defining the URL inline.
 *   // Not recommended but more comfortable for web developers.
 *   <GLTFModel src="tree.gltf" />
 * </Scene>
 * ```
 */
export var GLTFModel = function GLTFModel(props) {
  var src = props.src,
      children = props.children,
      restProps = _objectWithoutPropertiesLoose(props, _excluded);

  var uid = useId();
  var gltfId = "" + PREFIX_ASSET + uid + "gltf";
  return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(CreateAsset, null, /*#__PURE__*/React.createElement(AssetItem, {
    id: gltfId,
    src: src
  })), /*#__PURE__*/React.createElement(EventListener, _extends({
    primitive: "a-gltf-model"
  }, toProps(restProps), {
    src: gltfId
  }), children));
};