import _objectDestructuringEmpty from '@babel/runtime/helpers/objectDestructuringEmpty';
import { u as useViewHandler, S as SettingsHeader } from './index-bbdfb97a.js';
import { observer } from 'mobx-react-lite';
import { useState, useEffect } from 'react';
import { Swiper, SwiperSlide } from 'swiper/react';
import { s as swiperClass, a as swiperWrapper, b as swiperSlide } from './index.module-0226fe2f.js';
import SettingsScroller from './index-c6e30dc7.js';
import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
import _regeneratorRuntime from '@babel/runtime/regenerator';
import { DivaUtils } from '@crystaldesign/diva-core';
import NavForwardButton from './index-2ae3382c.js';
import classnames from 'classnames';
import { jsx, Fragment, jsxs } 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';
import './index-3bcdb4a8.js';
import './index-607ce1b1.js';
import './index-e8768440.js';
import './index-105eab2c.js';
import 'sift';
import './index-0d3bfd91.js';
import './index-2b5bdfe1.js';
import './index-caff71dc.js';
import './index-5cb692e9.js';
import './index.module-d6f043d2.js';
import './index-04a7a9b4.js';
import './index-755074ae.js';
import '@mui/icons-material/Block';
import '@mui/icons-material/Warning';
import './index-db439036.js';
import 'react-dropdown';
import './index-7f2e9c31.js';
import './index-4b3e6bbf.js';
import './index-69271b96.js';
import './index-9a965a68.js';
import '@crystaldesign/content-box';
import './index-e9a81262.js';
import './index-2f37b9f2.js';
import './index-bea5c228.js';
import './index-014a5003.js';
import 'swiper/modules';
import './UnlockCard-575022e0.js';
import './index-ce21cd4d.js';
import './index-6a697eea.js';
import './index-ea5e3e90.js';
import './index-69fd5e9e.js';
import './index-079ef135.js';
import './index-4b48794b.js';
import 'react-laag';
import './index.module-25687dd9.js';
import './index-3f40a92d.js';
import './index-66fd1759.js';
import './index-8a330776.js';
import './index-4fda4c71.js';
import './index-d896efe9.js';
import './index.module-fe49e10f.js';
import './index-6051ac01.js';
import './index-ec31a7cb.js';
import './index-79fbb400.js';
import './index-2e39dac3.js';
import './index-1641324b.js';
import './index-7635bafb.js';
import './index-0e0e6ac6.js';
import './index-a1cef81d.js';
import './index-4c03ac5c.js';
import './index-10d8be2f.js';
import './index-b7364bb1.js';
import './index-a253bbbf.js';
import './index-4ca1affe.js';
import 'rc-slider';
import './index-c44088dc.js';
import './index-e4d1ba18.js';
import './index-d5bb9bda.js';
import './index-dd2aabd2.js';
import './index-eb98a8c6.js';
import 'react-confetti-explosion';
import './index-d0331808.js';
import './index-7167c5bc.js';
import './index-5a146745.js';
import 'react-qr-code';
import './index-c648d661.js';
import './useCustomDimensions-8be02680.js';
import './index-c0a41b5b.js';
import './ussIsSticky-2f6bc37b.js';
import './index-290c519e.js';
import './index-be7a52a8.js';
import './index-9c4f9dc2.js';
import './index.module-613d19d3.js';
import './index-23081351.js';
import './index-b14a4a7c.js';
import './index-fdf81349.js';
import './index-688fe1aa.js';
import './index-49b01da7.js';
import './index-f4a37353.js';

var useSwiperHook = function useSwiperHook(viewHandler) {
  var _useState = useState(null),
    _useState2 = _slicedToArray(_useState, 2),
    swiperRef = _useState2[0],
    setSwiperRef = _useState2[1];
  var _useState3 = useState([]),
    _useState4 = _slicedToArray(_useState3, 2),
    allSwipes = _useState4[0],
    setAllSwipes = _useState4[1];
  useEffect(function () {
    var allSwipes = Object.keys(viewHandler.tabGroupState.allTabGroups);
    setAllSwipes(allSwipes);
    if (viewHandler.tabGroupState.curTabGroup) {
      if (allSwipes.indexOf(viewHandler.tabGroupState.curTabGroup.key) != (swiperRef === null || swiperRef === void 0 ? void 0 : swiperRef.activeIndex)) {
        swiperRef === null || swiperRef === void 0 || swiperRef.slideTo(allSwipes.indexOf(viewHandler.tabGroupState.curTabGroup.key), 400);
      }
    }
  }, [viewHandler.tabGroupState.allTabGroups, viewHandler.tabGroupState.curTabGroup, swiperRef]);
  var teaseSwipe = /*#__PURE__*/function () {
    var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
      var offset,
        duration,
        durationQuarter,
        currentTranslate,
        teaseTranslate,
        _args = arguments;
      return _regeneratorRuntime.wrap(function _callee$(_context) {
        while (1) switch (_context.prev = _context.next) {
          case 0:
            offset = _args.length > 0 && _args[0] !== undefined ? _args[0] : 50;
            duration = _args.length > 1 && _args[1] !== undefined ? _args[1] : 500;
            if (swiperRef) {
              _context.next = 4;
              break;
            }
            return _context.abrupt("return");
          case 4:
            durationQuarter = duration * 0.25;
            currentTranslate = swiperRef.getTranslate();
            teaseTranslate = currentTranslate - offset;
            swiperRef.allowTouchMove = false;

            // Smooth initial movement outward - slower
            swiperRef.setTransition(durationQuarter * 2); // Increased from 1.5 to 2
            swiperRef.setTranslate(teaseTranslate);
            _context.next = 12;
            return DivaUtils.Sleep(durationQuarter * 2);
          case 12:
            // Increased sleep to match transition

            // Gentle bounce back
            swiperRef.setTransition(durationQuarter);
            swiperRef.setTranslate(currentTranslate - offset * 0.5);
            _context.next = 16;
            return DivaUtils.Sleep(durationQuarter);
          case 16:
            // Small outward movement - faster
            swiperRef.setTransition(durationQuarter * 0.5);
            swiperRef.setTranslate(teaseTranslate * 0.8);
            _context.next = 20;
            return DivaUtils.Sleep(durationQuarter * 0.5);
          case 20:
            // Final smooth return
            swiperRef.setTransition(durationQuarter * 1.75);
            swiperRef.setTranslate(currentTranslate);
            swiperRef.allowTouchMove = true;
          case 23:
          case "end":
            return _context.stop();
        }
      }, _callee);
    }));
    return function teaseSwipe() {
      return _ref.apply(this, arguments);
    };
  }();

  //  useEffect(() => {
  //    const timeout = setTimeout(() => {
  //      teaseSwipe(100, 1000);
  //    }, 3000);
  //    return () => clearTimeout(timeout);
  //  }, [swiperRef]);

  var handleSlideChange = function handleSlideChange(e) {
    if (viewHandler.tabGroupState.curTabGroup === undefined) return;
    window.lastNavigationType = 'SETTINGS_SWIPER_SWIPE';
    var diff = e.activeIndex - allSwipes.indexOf(viewHandler.tabGroupState.curTabGroup.key);
    if (diff == 1) {
      viewHandler.actionButtonState.onClickConfiguratorSettingsForth(true, true);
    } else if (diff == -1) {
      viewHandler.actionButtonState.onClickConfiguratorSettingsBack();
    } else if (diff !== 0) {
      if (viewHandler.tabGroupState.allTabGroups[allSwipes[e.activeIndex]]) {
        viewHandler.tabGroupState.navigateToTabgroupByPosNr(viewHandler.tabGroupState.allTabGroups[allSwipes[e.activeIndex]].posNr);
      }
    }
  };
  var handleSetTransition = function handleSetTransition() {
    viewHandler.uiState.swiperNavigationActive = true;
  };
  var handleTransitionEnd = function handleTransitionEnd() {
    viewHandler.uiState.swiperNavigationActive = false;
  };
  var initialSlide = viewHandler.tabGroupState.curTabGroup ? allSwipes.indexOf(viewHandler.tabGroupState.curTabGroup.key) : 0;
  return {
    swiperRef: swiperRef,
    setSwiperRef: setSwiperRef,
    allSwipes: allSwipes,
    handleSlideChange: handleSlideChange,
    handleSetTransition: handleSetTransition,
    handleTransitionEnd: handleTransitionEnd,
    initialSlide: initialSlide,
    teaseSwipe: teaseSwipe
  };
};

var SettingsSwiper = function SettingsSwiper(_ref) {
  _objectDestructuringEmpty(_ref);
  var viewHandler = useViewHandler();
  var _useSwiperHook = useSwiperHook(viewHandler),
    setSwiperRef = _useSwiperHook.setSwiperRef,
    allSwipes = _useSwiperHook.allSwipes,
    handleSlideChange = _useSwiperHook.handleSlideChange,
    handleSetTransition = _useSwiperHook.handleSetTransition,
    handleTransitionEnd = _useSwiperHook.handleTransitionEnd,
    initialSlide = _useSwiperHook.initialSlide;
  var noSwiping = '.no-swiping';
  if (!viewHandler.tabGroupState.curTabGroup || !(allSwipes !== null && allSwipes !== void 0 && allSwipes.length)) return /*#__PURE__*/jsx(Fragment, {});
  return /*#__PURE__*/jsx(Swiper, {
    onSlideChange: handleSlideChange,
    onSetTransition: handleSetTransition,
    onTransitionEnd: handleTransitionEnd,
    initialSlide: initialSlide,
    onSwiper: setSwiperRef,
    className: swiperClass,
    noSwipingSelector: noSwiping,
    resizeObserver: true,
    slidesPerView: 1,
    threshold: 30,
    wrapperClass: classnames('swiper-wrapper', swiperWrapper),
    children: allSwipes.map(function (swipe) {
      var _Array$from$;
      var tabGroup = viewHandler.tabGroupState.allTabGroups[swipe];
      var title = tabGroup ? (_Array$from$ = Array.from(tabGroup.options.values())[0]) === null || _Array$from$ === void 0 ? void 0 : _Array$from$.title : undefined;
      return /*#__PURE__*/jsx(SwiperSlide, {
        className: swiperSlide,
        children: swipe == viewHandler.tabGroupState.curTabGroup.key ? /*#__PURE__*/jsxs(Fragment, {
          children: [/*#__PURE__*/jsx(SettingsScroller, {}, swipe), /*#__PURE__*/jsx(NavForwardButton, {})]
        }) : /*#__PURE__*/jsx("div", {
          style: {
            height: '100%',
            overflow: 'auto',
            width: 'calc(100% - 20px)',
            marginLeft: 'var(--settingsScrollerPaddingLeft)'
          },
          children: title && /*#__PURE__*/jsx(SettingsHeader, {
            text: title,
            isSettingsHeader: false,
            isInScroller: true
          })
        })
      }, swipe);
    })
  });
};
var SettingsSwiper$1 = observer(SettingsSwiper);

export { SettingsSwiper$1 as default };
