import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
import _regeneratorRuntime from '@babel/runtime/regenerator';
import { s as styleInject, u as useViewHandler } from './index-bbdfb97a.js';
import { useState, useEffect } from 'react';
import OrbitControlElement from 'react-3d-cube-interaction';
import { observer } from 'mobx-react-lite';
import { useTranslation, useDivaCore } from '@crystaldesign/diva-core';
import classnames from 'classnames';
import { jsx, Fragment } from 'react/jsx-runtime';
import '@babel/runtime/helpers/defineProperty';
import 'react-dynamic-multi-render';
import '@babel/runtime/helpers/objectWithoutProperties';
import '@babel/runtime/helpers/classCallCheck';
import '@babel/runtime/helpers/createClass';
import '@babel/runtime/helpers/toConsumableArray';
import '@crystaldesign/diva-utils';
import 'mobx';
import '@crystaldesign/web-planner-logic';
import 'qrcode.react';
import '@babel/runtime/helpers/typeof';
import 'flat';
import 'react-switch';
import 'react-countup';

var orbitInteractionContainer = "orbit-interaction-container-BHDEA";
var cubeText = "cubeText-rsimr";
var mobile = "mobile-YALCk";
var roomVisible = "room-visible-QNMOE";
var css_248z = ".orbit-interaction-container-BHDEA {\n  position: absolute;\n  bottom: 16px;\n  right: 20px;\n  z-index: 350;\n}\n\n.cubeText-rsimr {\n  font-size: max(12px, min(2vw, 20px));\n}\n\n.mobile-YALCk.orbit-interaction-container-BHDEA {\n  position: absolute;\n  bottom: 52px;\n  left: 10px;\n  right: auto;\n  right: initial;\n  z-index: 350;\n}\n\n.room-visible-QNMOE {\n  display: none;\n}\n";
styleInject(css_248z);

var camRotHorizontal_LastFrame = undefined;
var camRotVertical_LastFrame = undefined;
var AUTO_HIDE_IN_MS = 2000;
var timeOut = undefined;
var OrbitInteractionStandard = function OrbitInteractionStandard(_ref) {
  var _viewHandler$productS;
  var _ref$orbitInteraction = _ref.orbitInteractionContainerClass,
    orbitInteractionContainerClass = _ref$orbitInteraction === void 0 ? orbitInteractionContainer : _ref$orbitInteraction;
  var viewHandler = useViewHandler();
  var _useState = useState(true),
    _useState2 = _slicedToArray(_useState, 2),
    isHidden = _useState2[0],
    setHidden = _useState2[1];
  var _useTranslation = useTranslation(),
    t = _useTranslation.t;
  var _useDivaCore = useDivaCore(),
    isModalOpen = _useDivaCore.state.isModalOpen;

  // When modal is open, don't use the SVG as interaction element to fix Safari iPad touch event issue
  // The SVG's event listeners from react-3d-cube-interaction interfere with Safari's touch handling
  var interactionElement = isModalOpen ? null : (_viewHandler$productS = viewHandler.productState.planner3DImageSvgArea) !== null && _viewHandler$productS !== void 0 ? _viewHandler$productS : document.getElementById('diva3dImg');
  useEffect(function () {
    if (timeOut) clearTimeout(timeOut);
    if (isHidden) {
      timeOut = setTimeout(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
        return _regeneratorRuntime.wrap(function _callee$(_context) {
          while (1) switch (_context.prev = _context.next) {
            case 0:
              viewHandler.productState.setOrbitIsHidden(true);
            case 1:
            case "end":
              return _context.stop();
          }
        }, _callee);
      })), AUTO_HIDE_IN_MS);
    } else {
      viewHandler.productState.setOrbitIsHidden(false);
    }
  }, [isHidden]);
  if (!viewHandler.productState.doShowRenderImage || viewHandler.productState.doShowAIRoom || viewHandler.productState.plannerRenderingIsStaticBG) {
    return /*#__PURE__*/jsx(Fragment, {});
  }
  var initParams = viewHandler.viewPlannerHandler.getOrbitCubeInitParams();
  var onRotationChange = function onRotationChange(p) {
    if (viewHandler.productState.ignoreUpdateRenderingOnOrbitChanged) {
      viewHandler.productState.setIgnoreUpdateRenderingOnOrbitChanged(false);
      return;
    }
    if (camRotHorizontal_LastFrame != undefined && camRotVertical_LastFrame != undefined && p.horizontal == camRotHorizontal_LastFrame && p.vertical == camRotVertical_LastFrame) return;
    var rotHori = p.horizontal;
    var rotVert = p.vertical;
    camRotHorizontal_LastFrame = p.horizontal;
    camRotVertical_LastFrame = p.vertical;
    viewHandler.viewPlannerHandler.updateOrbitCubeInitParams(p.horizontal, p.vertical);
    viewHandler.divaWebPlanner.handle3DVisualizationChanged('Nav3DSetVPByVal', {
      nav3DSetVPByVal: {
        rotX: rotHori,
        rotY: rotVert
      }
    });
  };

  /**
   *
   * @param p form 10 (max zoom) to -10 (min zoom)
   */
  var onZoomChange = function onZoomChange(zoom) {
    var p = Math.round(zoom.absoluteZoom);
    viewHandler.divaWebPlanner.handle3DVisualizationChanged('Nav3DZoom', {
      nav3DZoom: {
        zoomVal: p
      }
    });
  };
  if (viewHandler.uiState.isLoading) {
    camRotHorizontal_LastFrame = undefined;
    camRotVertical_LastFrame = undefined;
  }
  return /*#__PURE__*/jsx("div", {
    className: classnames(orbitInteractionContainerClass, viewHandler.uiState.isInMobileView ? mobile : undefined, viewHandler.productState.roomListExpanded ? roomVisible : undefined),
    children: /*#__PURE__*/jsx(OrbitControlElement, {
      hiddenState: [isHidden, setHidden],
      ref: function ref(_ref3) {
        return viewHandler.productState.setOrbitCubeElement(_ref3);
      },
      size: viewHandler.uiState.isInMobileView ? '40px' : '80px',
      interactionElement: interactionElement,
      onRotationChange: onRotationChange,
      onZoomChange: onZoomChange,
      autoHide: AUTO_HIDE_IN_MS,
      initialRotation: initParams != undefined ? {
        horizontal: initParams.rotHorizontal,
        vertical: initParams.rotVertical
      } : undefined,
      zoomFactorResetDelay: 500,
      minCssScale: 0.5,
      maxCssScale: 1.5,
      disableDefaultScrollBehaviour: true,
      cubeFaceChildren: {
        back: /*#__PURE__*/jsx("div", {
          className: cubeText,
          children: t('cube.back')
        }),
        bottom: /*#__PURE__*/jsx("div", {
          className: cubeText,
          children: t('cube.bottom')
        }),
        front: /*#__PURE__*/jsx("div", {
          className: cubeText,
          children: t('cube.front')
        }),
        left: /*#__PURE__*/jsx("div", {
          className: cubeText,
          children: t('cube.left')
        }),
        right: /*#__PURE__*/jsx("div", {
          className: cubeText,
          children: t('cube.right')
        }),
        top: /*#__PURE__*/jsx("div", {
          className: cubeText,
          children: t('cube.top')
        })
      }
    })
  });
};
var OrbitInteractionStandard$1 = observer(OrbitInteractionStandard);

export { OrbitInteractionStandard$1 as default };
