"use strict";

require("core-js/modules/web.dom-collections.iterator.js");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

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

var THREE = _interopRequireWildcard(require("three"));

var _fiber = require("@react-three/fiber");

var _drei = require("@react-three/drei");

var _config = _interopRequireDefault(require("next/config"));

const _excluded = ["position", "quaternion", "pet"];

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

const {
  publicRuntimeConfig
} = (0, _config.default)();
const positionTmp = new THREE.Vector3(0, 6, 0);
const quaternionTmp = new THREE.Quaternion();

const Balloon = _ref => {
  let {
    position,
    quaternion,
    pet
  } = _ref,
      props = _objectWithoutProperties(_ref, _excluded);

  const group = (0, _react.useRef)();
  const {
    scene,
    animations
  } = (0, _drei.useGLTF)("".concat(publicRuntimeConfig.CONFIG.s3.endpoint, "/bv/pet/").concat(pet.name, ".glb"));
  const {
    actions,
    names
  } = (0, _drei.useAnimations)(animations, group);
  scene.traverse(c => {
    if (c.material) {
      c.material.alphaTest = 0.4;
      c.material.depthWrite = true;
      c.material.side = THREE.DoubleSide;
    }
  });
  (0, _react.useEffect)(() => {
    var _actions$names$;

    (_actions$names$ = actions[names[0]]) === null || _actions$names$ === void 0 ? void 0 : _actions$names$.reset().play();
    return () => {
      var _actions$names$2;

      return (_actions$names$2 = actions[names[0]]) === null || _actions$names$2 === void 0 ? void 0 : _actions$names$2.fadeOut(0.5);
    };
  }, [scene, actions, names]);
  (0, _fiber.useFrame)((state, delta) => {
    positionTmp.set(position.x + 0.5, position.y + 1, position.z - 0.3);
    quaternionTmp.set(quaternion.x, quaternion.y, quaternion.z, quaternion.w);

    if (positionTmp && quaternionTmp) {
      group.current.quaternion.copy(quaternionTmp);
      group.current.position.lerp(positionTmp, 0.05);
    }
  });
  return /*#__PURE__*/_react.default.createElement("group", {
    ref: group,
    dispose: null,
    scale: 0.2
  }, /*#__PURE__*/_react.default.createElement("primitive", {
    object: scene
  }));
};

var _default = Balloon;
exports.default = _default;

_drei.useGLTF.preload("".concat(publicRuntimeConfig.CONFIG.s3.endpoint, "/bv/OzoneHall/takodachi.glb"));