import _defineProperty from '@babel/runtime/helpers/defineProperty';
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
import { u as useViewHandler } from './index-bbdfb97a.js';
import { useState, useEffect } from 'react';
import { observer } from 'mobx-react-lite';
import { useDivaCore, DivaUtils } from '@crystaldesign/diva-core';
import ConfettiExplosion from 'react-confetti-explosion';
import { jsx, Fragment } from 'react/jsx-runtime';
import 'react-dynamic-multi-render';
import '@babel/runtime/helpers/asyncToGenerator';
import '@babel/runtime/helpers/objectWithoutProperties';
import '@babel/runtime/regenerator';
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 'classnames';
import 'qrcode.react';
import '@babel/runtime/helpers/typeof';
import 'flat';
import 'react-switch';
import 'react-countup';

function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var bigExplodeProps = {
  force: 0.6,
  duration: 5000,
  particleCount: 200,
  floorHeight: 1600,
  floorWidth: 1600
};
var ConfettiInSummary = function ConfettiInSummary(props) {
  var _theme$palette$primar, _theme$palette, _theme$palette$primar2, _theme$palette2, _theme$palette$primar3, _theme$palette3;
  var viewHandler = useViewHandler();
  var _useDivaCore = useDivaCore(),
    theme = _useDivaCore.state.theme;
  var delay = viewHandler.getViewConfig().navigateMobileSwiper && viewHandler.getIsInMobileView();
  var _useState = useState(!delay),
    _useState2 = _slicedToArray(_useState, 2),
    visible = _useState2[0],
    setVisible = _useState2[1];
  useEffect(function () {
    if (!delay) return;
    setTimeout(function () {
      setVisible(true);
    }, 300);
  }, []);
  var _useState3 = useState(false),
    _useState4 = _slicedToArray(_useState3, 2),
    shouldShowConfetti = _useState4[0],
    setShouldShowConfetti = _useState4[1];
  useEffect(function () {
    var _viewHandler$uiState$, _viewHandler$uiState$2;
    var confettiCooldownInHours = (_viewHandler$uiState$ = (_viewHandler$uiState$2 = viewHandler.uiState.ViewConfig.showConfettiInSummary) === null || _viewHandler$uiState$2 === void 0 ? void 0 : _viewHandler$uiState$2.confettiCooldownInHours) !== null && _viewHandler$uiState$ !== void 0 ? _viewHandler$uiState$ : 0;

    //handeling strict mode
    if (localStorage.getItem('lastConfettiSessionId') === DivaUtils.SessionId && localStorage.getItem('lastConfettiChange') == viewHandler.settingsState.configChanged.toString()) return;
    if (confettiCooldownInHours > 0) {
      var lastConfettiTime = localStorage.getItem('lastConfettiTime');
      if (lastConfettiTime) {
        var diff = Date.now() - Number(lastConfettiTime);
        if (diff < confettiCooldownInHours * 60 * 60 * 1000) {
          setShouldShowConfetti(false);
          return;
        }
      }
      // Set the timestamp only when we're actually going to show confetti
      localStorage.setItem('lastConfettiTime', Date.now().toString());
      localStorage.setItem('lastConfettiChange', viewHandler.settingsState.configChanged.toString());
      setShouldShowConfetti(true);
      return;
    }

    // Session-based logic (confettiCooldownInHours == 0)

    if (localStorage.getItem('lastConfettiSessionId') === DivaUtils.SessionId) {
      setShouldShowConfetti(false);
      return;
    }
    // Set the session ID only when we're actually going to show confetti
    localStorage.setItem('lastConfettiSessionId', DivaUtils.SessionId);
    localStorage.setItem('lastConfettiChange', viewHandler.settingsState.configChanged.toString());
    setShouldShowConfetti(true);
  }, []);
  if (!viewHandler.uiState.ViewConfig.showConfettiInSummary) return /*#__PURE__*/jsx(Fragment, {});
  if (!shouldShowConfetti) return /*#__PURE__*/jsx(Fragment, {});
  if (!viewHandler.isParentViewVisible) return /*#__PURE__*/jsx(Fragment, {});
  var confettiProps = viewHandler.uiState.ViewConfig.showConfettiInSummary.confettiProps;
  return /*#__PURE__*/jsx("div", {
    style: {
      display: 'flex',
      justifyContent: 'center',
      alignItems: 'center',
      width: '100%'
    },
    children: visible && /*#__PURE__*/jsx(ConfettiExplosion, _objectSpread(_objectSpread(_objectSpread({
      zIndex: 1000001
    }, bigExplodeProps), confettiProps !== null && confettiProps !== void 0 ? confettiProps : {}), {}, {
      colors: [(_theme$palette$primar = (_theme$palette = theme.palette) === null || _theme$palette === void 0 || (_theme$palette = _theme$palette.primary) === null || _theme$palette === void 0 ? void 0 : _theme$palette.main) !== null && _theme$palette$primar !== void 0 ? _theme$palette$primar : '', (_theme$palette$primar2 = (_theme$palette2 = theme.palette) === null || _theme$palette2 === void 0 || (_theme$palette2 = _theme$palette2.primary) === null || _theme$palette2 === void 0 ? void 0 : _theme$palette2.dark) !== null && _theme$palette$primar2 !== void 0 ? _theme$palette$primar2 : '', (_theme$palette$primar3 = (_theme$palette3 = theme.palette) === null || _theme$palette3 === void 0 || (_theme$palette3 = _theme$palette3.primary) === null || _theme$palette3 === void 0 ? void 0 : _theme$palette3.light) !== null && _theme$palette$primar3 !== void 0 ? _theme$palette$primar3 : '']
    }))
  });
};
var ConfettiInSummary$1 = observer(ConfettiInSummary);

export { ConfettiInSummary$1 as default };
