"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _Loading = _interopRequireDefault(require("../Loading"));
var _ModelWrap = require("./ModelWrap");
var _constants = require("../..\\utils\\constants");
var _jsxRuntime = require("react/jsx-runtime");
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 (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; }
const Model = ({
  media,
  mediaVisible,
  isDetail,
  cssStyle: _cssStyle = ''
}) => {
  const contentElement = (0, _react.useRef)();
  const containerElement = (0, _react.useRef)(null);
  (0, _react.useLayoutEffect)(() => {
    var _mv$parentNode, _mv$parentNode$parent, _mv$parentNode$parent2;
    if (isDetail) {
      return;
    }
    const mv = contentElement.current;
    if (!mv) {
      return;
    }
    const {
      shadowRoot
    } = mv;
    if (!shadowRoot) {
      return;
    }
    const button = shadowRoot.querySelectorAll('#default-poster')[0];
    button.style.background = 'none';
    const el = (_mv$parentNode = mv.parentNode) === null || _mv$parentNode === void 0 ? void 0 : (_mv$parentNode$parent = _mv$parentNode.parentNode) === null || _mv$parentNode$parent === void 0 ? void 0 : (_mv$parentNode$parent2 = _mv$parentNode$parent.parentNode) === null || _mv$parentNode$parent2 === void 0 ? void 0 : _mv$parentNode$parent2.parentNode;
    mv.style.opacity = '0';
    mv.style.width = `${el === null || el === void 0 ? void 0 : el.offsetWidth}px`;
    mv.style.height = `${el === null || el === void 0 ? void 0 : el.offsetHeight}px`;
    setTimeout(() => {
      mv.style.opacity = '1';
    }, mediaVisible ? 800 : 1300);
  }, [isDetail, mediaVisible]);
  (0, _react.useEffect)(() => {
    var _contentElement$curre, _contentElement$curre2, _contentElement$curre3;
    if (!isDetail) {
      return;
    }
    const mv = contentElement.current;
    if (!mv) {
      return;
    }
    const {
      shadowRoot
    } = mv;
    if (!shadowRoot) {
      return;
    }
    const el2 = (_contentElement$curre = contentElement.current) === null || _contentElement$curre === void 0 ? void 0 : (_contentElement$curre2 = _contentElement$curre.parentNode) === null || _contentElement$curre2 === void 0 ? void 0 : (_contentElement$curre3 = _contentElement$curre2.parentNode) === null || _contentElement$curre3 === void 0 ? void 0 : _contentElement$curre3.parentNode;
    mv.style.width = `${el2 === null || el2 === void 0 ? void 0 : el2.offsetWidth}px`;
    mv.style.height = `${el2 === null || el2 === void 0 ? void 0 : el2.offsetWidth}px`;
  }, []);
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_ModelWrap.ModelWrap, {
    cssStyle: _cssStyle,
    children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
      className: "modelContainer",
      ref: containerElement,
      children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Loading.default, {
        cssStyle: `
          display: none;
        `
      }), /*#__PURE__*/(0, _jsxRuntime.jsx)("model-viewer", {
        ref: contentElement,
        src: (0, _constants.jsonProxy2)((0, _constants.revokeJsonProxy)(media)),
        ar: true,
        "ar-modes": "webxr scene-viewer quick-look",
        "environment-image": "neutral",
        "auto-rotate": true,
        "camera-controls": true,
        onClick: e => {
          e.stopPropagation();
        }
      })]
    })
  });
};
var _default = Model;
exports.default = _default;