import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
import { s as styleInject, u as useViewHandler } from './index-bbdfb97a.js';
import { observer } from 'mobx-react-lite';
import { useRef, useState, useEffect } from 'react';
import { Swiper, SwiperSlide } from 'swiper/react';
import { Navigation } from 'swiper/modules';
import { useTranslation } from '@crystaldesign/diva-core';
import { jsxs, jsx } from 'react/jsx-runtime';
import '@babel/runtime/helpers/defineProperty';
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';

var wcConfiguratorAiRoom = "wc-configurator-ai-room-BITO0";
var galleryContainer = "gallery-container-Ly7-0";
var gallerySlide = "gallery-slide-GiS-r";
var aiRoomImage = "ai-room-image-seKys";
var slideCounter = "slide-counter-Uh6Iz";
var loadingOverlay = "loading-overlay-t1CPa";
var spinner = "spinner-bUgHj";
var loadingText = "loading-text-v1LhC";
var aiWarningBadge = "ai-warning-badge-VRwxc";
var css_248z = ".wc-configurator-ai-room-BITO0 {\n  width: 100%;\n  height: 100%;\n  position: absolute;\n  top: 0;\n  left: 0;\n  z-index: 990;\n  display: flex;\n  background-color: #fff;\n  align-items: center;\n  justify-content: center;\n  overflow: hidden;\n}\n\n/* ── Gallery ────────────────────────────────────────────── */\n\n.gallery-container-Ly7-0 {\n  position: absolute;\n  top: 0;\n  right: 0;\n  bottom: 0;\n  left: 0;\n}\n\n.gallery-container-Ly7-0 .swiper {\n  position: relative;\n  width: 100%;\n  height: 100%;\n  overflow: hidden;\n  z-index: 1;\n}\n\n.gallery-container-Ly7-0 .swiper-wrapper {\n  position: relative;\n  height: 100%;\n  z-index: 1;\n  display: flex;\n  transition-property: transform;\n}\n\n.gallery-container-Ly7-0 .swiper-slide {\n  flex-shrink: 0;\n  height: 100%;\n}\n\n.gallery-slide-GiS-r {\n  width: 100%;\n  height: 100%;\n  display: flex;\n  align-items: center;\n  justify-content: center;\n  transition:\n    filter 0.8s cubic-bezier(0.4, 0, 0.2, 1),\n    transform 0.8s cubic-bezier(0.4, 0, 0.2, 1);\n  will-change: filter, transform;\n}\n\n.ai-room-image-seKys {\n  max-width: 100%;\n  max-height: 100%;\n  width: auto;\n  height: auto;\n  -o-object-fit: contain;\n     object-fit: contain;\n  -webkit-user-select: none;\n     -moz-user-select: none;\n          user-select: none;\n}\n\n/* ── Navigation arrows ──────────────────────────────────── */\n\n.gallery-container-Ly7-0 .swiper-button-prev,\n.gallery-container-Ly7-0 .swiper-button-next {\n  position: absolute;\n  top: 50%;\n  width: 44px;\n  height: 44px;\n  margin-top: -22px;\n  z-index: 10;\n  cursor: pointer;\n  display: flex;\n  align-items: center;\n  justify-content: center;\n  background: rgba(0, 0, 0, 0.35);\n  border-radius: 50%;\n  color: #fff;\n  backdrop-filter: blur(6px);\n  -webkit-backdrop-filter: blur(6px);\n  transition:\n    background 0.2s,\n    transform 0.15s;\n  -webkit-tap-highlight-color: transparent;\n  outline: none;\n}\n\n.gallery-container-Ly7-0 .swiper-button-prev:hover,\n.gallery-container-Ly7-0 .swiper-button-next:hover {\n  background: rgba(0, 0, 0, 0.55);\n  transform: scale(1.06);\n}\n\n.gallery-container-Ly7-0 .swiper-button-prev:active,\n.gallery-container-Ly7-0 .swiper-button-next:active {\n  transform: scale(0.96);\n}\n\n.gallery-container-Ly7-0 .swiper-button-prev:focus,\n.gallery-container-Ly7-0 .swiper-button-prev:active,\n.gallery-container-Ly7-0 .swiper-button-next:focus,\n.gallery-container-Ly7-0 .swiper-button-next:active {\n  outline: none;\n  -webkit-tap-highlight-color: transparent;\n}\n\n.gallery-container-Ly7-0 .swiper-button-prev::before,\n.gallery-container-Ly7-0 .swiper-button-next::before {\n  display: none !important;\n}\n\n.gallery-container-Ly7-0 .swiper-button-prev:after,\n.gallery-container-Ly7-0 .swiper-button-next:after {\n  text-transform: none !important;\n}\n\n.gallery-container-Ly7-0 .swiper-button-prev:after,\n.gallery-container-Ly7-0 .swiper-button-next:after {\n  font-family: swiper-icons;\n  font-size: 18px;\n  letter-spacing: 0;\n  font-feature-settings: ;\n  font-variant: normal;\n  font-variant: initial;\n  line-height: 1;\n}\n\n.gallery-container-Ly7-0 .swiper-button-prev {\n  left: 16px;\n}\n\n.gallery-container-Ly7-0 .swiper-button-next {\n  right: 16px;\n}\n\n.gallery-container-Ly7-0 .swiper-button-prev:after {\n  content: 'prev';\n}\n\n.gallery-container-Ly7-0 .swiper-button-next:after {\n  content: 'next';\n}\n\n.gallery-container-Ly7-0 .swiper-button-disabled {\n  opacity: 0;\n  pointer-events: none;\n}\n\n.gallery-container-Ly7-0 .swiper-button-prev svg,\n.gallery-container-Ly7-0 .swiper-button-next svg {\n  display: none;\n}\n\n/* ── Slide counter ──────────────────────────────────────── */\n\n.slide-counter-Uh6Iz {\n  position: absolute;\n  bottom: 84px;\n  left: 50%;\n  transform: translateX(-50%);\n  z-index: 5;\n  padding: 5px 14px;\n  font-size: 13px;\n  font-weight: 500;\n  letter-spacing: 0.04em;\n  color: rgba(255, 255, 255, 0.92);\n  background: rgba(0, 0, 0, 0.38);\n  border-radius: 20px;\n  backdrop-filter: blur(6px);\n  -webkit-backdrop-filter: blur(6px);\n  pointer-events: none;\n  -webkit-user-select: none;\n     -moz-user-select: none;\n          user-select: none;\n}\n\n.mobile .slide-counter-Uh6Iz {\n  bottom: 20px;\n}\n\n/* ── Loading slide (rendered inside the gallery swiper) ── */\n\n.loading-overlay-t1CPa {\n  display: flex;\n  flex-direction: column;\n  align-items: center;\n  justify-content: center;\n  background: rgba(0, 0, 0, 0.25);\n  animation: overlayFadeIn-aFU2G 0.6s ease both;\n}\n\n@keyframes overlayFadeIn-aFU2G {\n  from {\n    opacity: 0;\n  }\n  to {\n    opacity: 1;\n  }\n}\n\n.spinner-bUgHj {\n  width: 52px;\n  height: 52px;\n  border: 3px solid rgba(255, 255, 255, 0.25);\n  border-top-color: #fff;\n  border-radius: 50%;\n  animation: spin-CwPAa 0.9s linear infinite;\n}\n\n@keyframes spin-CwPAa {\n  to {\n    transform: rotate(360deg);\n  }\n}\n\n.loading-text-v1LhC {\n  margin-top: 20px;\n  font-size: 15px;\n  font-weight: 400;\n  letter-spacing: 0.02em;\n  color: #fff;\n  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.45);\n  animation: textSlideIn-u-Flk 0.5s ease both;\n  -webkit-user-select: none;\n     -moz-user-select: none;\n          user-select: none;\n}\n\n@keyframes textSlideIn-u-Flk {\n  from {\n    opacity: 0;\n    transform: translateY(8px);\n  }\n  to {\n    opacity: 1;\n    transform: translateY(0);\n  }\n}\n\n/* ── Warning badge ──────────────────────────────────────── */\n\n.ai-warning-badge-VRwxc {\n  position: absolute;\n  bottom: 16px;\n  right: 16px;\n  padding: 6px 12px;\n  background-color: rgba(0, 0, 0, 0.4);\n  color: rgba(255, 255, 255, 0.9);\n  font-size: 12px;\n  border-radius: 4px;\n  pointer-events: none;\n  backdrop-filter: blur(4px);\n  -webkit-backdrop-filter: blur(4px);\n  font-weight: 500;\n  z-index: 5;\n}\n\n.mobile .ai-warning-badge-VRwxc {\n  font-size: 11px;\n}\n";
styleInject(css_248z);

var LOADING_MESSAGES = {
  de: ["Lichter werden eingerichtet\u2026", "Kamera wird positioniert\u2026", "M\xF6bel werden platziert\u2026", "Stoffe werden ausgew\xE4hlt\u2026", "Schatten werden angepasst\u2026", "Accessoires werden gestylt\u2026", "W\xE4nde werden gestrichen\u2026", "Letzte Details werden hinzugef\xFCgt\u2026", "Raum wird arrangiert\u2026", "Szene wird perfektioniert\u2026", "Oberfl\xE4chen werden poliert\u2026", "Ambiente wird abgestimmt\u2026"],
  en: ["Setting up lights\u2026", "Positioning camera\u2026", "Placing furniture\u2026", "Choosing fabrics\u2026", "Adjusting shadows\u2026", "Styling accessories\u2026", "Painting the walls\u2026", "Adding final touches\u2026", "Arranging the room\u2026", "Perfecting the scene\u2026", "Polishing surfaces\u2026", "Tuning the ambiance\u2026"],
  fr: ["Installation des lumi\xE8res\u2026", "Positionnement de la cam\xE9ra\u2026", "Placement des meubles\u2026", "Choix des tissus\u2026", "Ajustement des ombres\u2026", "Mise en place des accessoires\u2026", "Peinture des murs\u2026", "Ajout des touches finales\u2026", "Am\xE9nagement de la pi\xE8ce\u2026", "Perfectionnement de la sc\xE8ne\u2026", "Polissage des surfaces\u2026", "R\xE9glage de l\u2019ambiance\u2026"],
  it: ["Preparazione delle luci\u2026", "Posizionamento della fotocamera\u2026", "Disposizione dei mobili\u2026", "Scelta dei tessuti\u2026", "Regolazione delle ombre\u2026", "Allestimento degli accessori\u2026", "Pittura delle pareti\u2026", "Aggiunta dei dettagli finali\u2026", "Organizzazione della stanza\u2026", "Perfezionamento della scena\u2026", "Lucidatura delle superfici\u2026", "Sintonizzazione dell\u2019atmosfera\u2026"]
};
var PlannerAIRoom = function PlannerAIRoom() {
  var _i18n$language, _LOADING_MESSAGES$lan;
  var viewHandler = useViewHandler();
  var aiState = viewHandler.aiState;
  var _useTranslation = useTranslation(),
    i18n = _useTranslation.i18n,
    t = _useTranslation.t;
  var swiperRef = useRef(null);
  var _useState = useState(0),
    _useState2 = _slicedToArray(_useState, 2),
    messageIndex = _useState2[0],
    setMessageIndex = _useState2[1];
  var _useState3 = useState(0),
    _useState4 = _slicedToArray(_useState3, 2),
    activeSlide = _useState4[0],
    setActiveSlide = _useState4[1];
  var prevLengthRef = useRef(0);
  var lang = ((_i18n$language = i18n.language) !== null && _i18n$language !== void 0 ? _i18n$language : 'de').toLowerCase().slice(0, 2);
  var messages = (_LOADING_MESSAGES$lan = LOADING_MESSAGES[lang]) !== null && _LOADING_MESSAGES$lan !== void 0 ? _LOADING_MESSAGES$lan : LOADING_MESSAGES.de;
  var isGenerating = aiState.isAnyGenerationInProgress;
  var images = aiState.generatedImageHistory;
  var isVisible = viewHandler.productState.doShowAIRoom;
  var hasImages = images.length > 0;
  var totalSlides = images.length + (isGenerating ? 1 : 0);
  // Loading slide sits at index 0 when generating; real images are offset by 1.
  var imageIndexOffset = isGenerating ? 1 : 0;
  var isLoadingSlideActive = isGenerating && activeSlide === 0;
  useEffect(function () {
    var entry = images[activeSlide - imageIndexOffset];
    if (entry) {
      aiState.setCurrentlyVisibleRoom({
        key: entry.key,
        hash: entry.hash,
        src: entry.src
      });
    }
  }, [activeSlide, imageIndexOffset]);
  useEffect(function () {
    if (!isGenerating) {
      setMessageIndex(0);
      return;
    }
    var interval = setInterval(function () {
      setMessageIndex(function (prev) {
        return (prev + 1) % messages.length;
      });
    }, 3000);
    return function () {
      return clearInterval(interval);
    };
  }, [isGenerating]);
  useEffect(function () {
    if (images.length > prevLengthRef.current && swiperRef.current) {
      // Freshly generated images are prepended to the history; focus index 0 in the real image range.
      var targetIdx = isGenerating ? 1 : 0;
      if (swiperRef.current.params.loop) {
        swiperRef.current.slideToLoop(targetIdx, 300);
      } else {
        swiperRef.current.slideTo(targetIdx, 300);
      }
    }
    prevLengthRef.current = images.length;
  }, [images.length]);
  useEffect(function () {
    if (!aiState.currentlyVisibleRoom || !swiperRef.current) return;
    var imgIdx = images.findIndex(function (img) {
      var _aiState$currentlyVis;
      return img.src === ((_aiState$currentlyVis = aiState.currentlyVisibleRoom) === null || _aiState$currentlyVis === void 0 ? void 0 : _aiState$currentlyVis.src);
    });
    if (imgIdx < 0) return;
    var swiperIdx = imgIdx + imageIndexOffset;
    if (swiperIdx !== swiperRef.current.realIndex) {
      if (swiperRef.current.params.loop) {
        swiperRef.current.slideToLoop(swiperIdx, 300);
      } else {
        swiperRef.current.slideTo(swiperIdx, 300);
      }
    }
  }, [aiState.currentlyVisibleRoom, images, imageIndexOffset]);

  // Auto-navigate the gallery to the loading slide (index 0) whenever generation
  // starts or the style consultant explicitly asks for it (e.g. clicking the placeholder).
  useEffect(function () {
    if (!isGenerating || !swiperRef.current) return;
    if (swiperRef.current.params.loop) {
      swiperRef.current.slideToLoop(0, 300);
    } else {
      swiperRef.current.slideTo(0, 300);
    }
  }, [isGenerating, aiState.loadingSlideFocusRequest]);

  // Publish loading-slide visibility so the style consultant can mirror it in the history.
  useEffect(function () {
    aiState.setLoadingSlideActive(isLoadingSlideActive);
    return function () {
      return aiState.setLoadingSlideActive(false);
    };
  }, [isLoadingSlideActive]);
  return /*#__PURE__*/jsxs("div", {
    className: wcConfiguratorAiRoom,
    id: "ai-room-container",
    style: {
      visibility: isVisible ? 'visible' : 'hidden',
      pointerEvents: isVisible ? 'auto' : 'none'
    },
    children: [hasImages || isGenerating ? /*#__PURE__*/jsxs("div", {
      className: galleryContainer,
      children: [/*#__PURE__*/jsxs(Swiper, {
        modules: [Navigation],
        navigation: true,
        slidesPerView: 1,
        onSwiper: function onSwiper(swiper) {
          swiperRef.current = swiper;
        },
        onSlideChange: function onSlideChange(swiper) {
          return setActiveSlide(swiper.realIndex);
        },
        loop: totalSlides > 1,
        children: [isGenerating && /*#__PURE__*/jsx(SwiperSlide, {
          children: /*#__PURE__*/jsxs("div", {
            className: "".concat(gallerySlide, " ").concat(loadingOverlay),
            children: [/*#__PURE__*/jsx("div", {
              className: spinner
            }), /*#__PURE__*/jsx("p", {
              className: loadingText,
              children: messages[messageIndex]
            }, messageIndex)]
          })
        }, "loading-slide"), images.map(function (entry, idx) {
          return /*#__PURE__*/jsx(SwiperSlide, {
            children: /*#__PURE__*/jsx("div", {
              className: gallerySlide,
              children: /*#__PURE__*/jsx("img", {
                className: aiRoomImage,
                src: entry.src,
                alt: "AI Generated Room",
                draggable: false
              })
            })
          }, "".concat(entry.key, "-").concat(entry.hash, "-").concat(idx));
        })]
      }), images.length > 1 && !isLoadingSlideActive && /*#__PURE__*/jsxs("div", {
        className: slideCounter,
        children: [activeSlide - imageIndexOffset + 1, " / ", images.length]
      })]
    }) : aiState.currentlyVisibleRoom && /*#__PURE__*/jsx("div", {
      className: gallerySlide,
      children: /*#__PURE__*/jsx("img", {
        className: aiRoomImage,
        src: aiState.currentlyVisibleRoom.src,
        alt: "AI Generated Room",
        draggable: false
      })
    }), hasImages && !isGenerating && /*#__PURE__*/jsx("div", {
      className: aiWarningBadge,
      children: t('configurator.roomRendering.aiGenerated')
    })]
  });
};
var PlannerAIRoom$1 = observer(PlannerAIRoom);

export { PlannerAIRoom$1 as default };
