import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
import { s as styleInject, u as useViewHandler, P as PricePreview } from './index-bbdfb97a.js';
import Dropdown from 'react-dropdown';
import { useState, useEffect } from 'react';
import { observer } from 'mobx-react-lite';
import classnames from 'classnames';
import InfoIcon from './index-04a7a9b4.js';
import MarqueeText from 'react-marquee-text';
import ReverseCheck from './index-755074ae.js';
import { jsxs, jsx } from 'react/jsx-runtime';
import '@babel/runtime/helpers/defineProperty';
import 'react-dynamic-multi-render';
import '@crystaldesign/diva-core';
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 'qrcode.react';
import '@babel/runtime/helpers/typeof';
import 'flat';
import 'react-switch';
import 'react-countup';
import '@mui/icons-material/Block';
import '@mui/icons-material/Warning';

var wcDropDownSelect = "wcDropDownSelect-RE7qJ";
var dropDownArea = "dropDownArea-yEewD";
var dropOption = "dropOption-i-M5T";
var row = "row-80qIj";
var title = "title-2mKgp";
var colum = "colum-cjf3n";
var dropdownWidth = "dropdownWidth-D5Fng";
var image = "image-7MOa9";
var text = "text-7Q0NH";
var wrapper = "wrapper-zYD5i";
var mobile = "mobile-8zC-a";
var tablet = "tablet-n0PoJ";
var css_248z$1 = ".wcDropDownSelect-RE7qJ {\n  padding: 8px 24px 8px 8px !important;\n  box-sizing: border-box !important;\n}\n\n.wcDropDownSelect-RE7qJ {\n  height: 2.4375rem;\n  padding: 0.5rem;\n  -webkit-appearance: none;\n  -moz-appearance: none;\n  appearance: none;\n  border: 1px solid #cacaca;\n  border-radius: 4px;\n  background-color: #fefefe;\n  font-family: inherit;\n  font-size: 13px;\n  line-height: 22px;\n  color: #0a0a0a;\n  background-origin: content-box;\n  background-position: right -1rem center;\n  background-repeat: no-repeat;\n  background-size: 9px 6px;\n  padding-right: 1.5rem;\n  transition:\n    box-shadow 0.5s,\n    border-color 0.25s ease-in-out;\n  font-weight: 300;\n}\n\n.dropDownArea-yEewD {\n  max-height: 520px !important;\n  width: -moz-fit-content !important;\n  width: fit-content !important;\n  display: inline-block !important;\n}\n\n.dropDownArea-yEewD {\n\n  right: 0;\n  min-width: 152px;\n  max-width: 370px;\n  letter-spacing: 0px;\n  font-size: 13px;\n  font-weight: 300;\n}\n.dropOption-i-M5T {\n  position: relative;\n}\n.dropDownArea-yEewD .dropOption-i-M5T {\n  white-space: nowrap;\n}\n.wcDropDownSelect-RE7qJ .dropOption-i-M5T {\n  width: 110px;\n  overflow: hidden;\n  white-space: nowrap;\n}\n.row-80qIj {\n  width: 100%;\n  height: -moz-fit-content;\n  height: fit-content;\n  position: relative;\n  display: flex;\n  padding-bottom: 4px;\n  padding-top: 4px;\n}\n\n.title-2mKgp {\n  text-align: left;\n  padding-bottom: 9px;\n  padding-top: 9px;\n  display: flex;\n  flex-direction: column;\n  justify-content: center;\n}\n\n.colum-cjf3n {\n  width: 50%;\n}\n.dropdownWidth-D5Fng {\n  width: 155px;\n  margin: 10px 15px;\n  display: flex;\n  justify-content: center;\n  align-items: center;\n  height: -moz-fit-content;\n  height: fit-content;\n}\n\n.image-7MOa9 {\n  width: 45%;\n}\n.text-7Q0NH {\n  padding-right: 64px;\n}\n\n.wrapper-zYD5i .Dropdown-root {\n  position: relative;\n}\n\n.wrapper-zYD5i .Dropdown-control {\n  position: relative;\n  overflow: hidden;\n  box-sizing: border-box;\n  color: #333;\n  cursor: default;\n  outline: none;\n  padding: 2px 24px 2px 10px;\n  transition: all 200ms ease;\n  background-color: #fff;\n  border-radius: var(--globalBorderRadius);\n  border: 1px solid #ccc;\n  font-size: 14px;\n}\n\n.mobile-8zC-a .Dropdown-control {\n  font-size: 12px;\n}\n\n.tablet-n0PoJ .Dropdown-control {\n  font-size: 15px;\n}\n\n.wrapper-zYD5i .Dropdown-control:hover {\n  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.06);\n}\n\n.wrapper-zYD5i .Dropdown-arrow {\n  border-color: #999 transparent transparent;\n  border-style: solid;\n  border-width: 5px 5px 0;\n  content: ' ';\n  display: block;\n  height: 0;\n  margin-top: -ceil(2.5);\n  position: absolute;\n  right: 8px;\n  top: 15px;\n  width: 0;\n}\n\n.wrapper-zYD5i .is-open .Dropdown-arrow {\n  border-color: transparent transparent #999;\n  border-width: 0 5px 5px;\n}\n\n.wrapper-zYD5i .Dropdown-menu {\n  background-color: white;\n  box-sizing: border-box;\n  margin-top: -1px;\n  border: 1px solid #ddd;\n  max-height: 200px;\n  overflow-y: auto;\n  position: absolute;\n  top: 100%;\n  width: 100%;\n  z-index: 1100;\n  -webkit-overflow-scrolling: touch;\n}\n\n.wrapper-zYD5i .Dropdown-menu .Dropdown-group > .Dropdown-title {\n  padding: 8px 10px;\n  color: rgba(51, 51, 51, 1);\n  font-weight: 300;\n  text-transform: capitalize;\n}\n\n.wrapper-zYD5i .Dropdown-option {\n  box-sizing: border-box;\n  color: rgba(51, 51, 51, 0.8);\n  cursor: pointer;\n  display: block;\n  padding: 8px 10px;\n}\n\n.wrapper-zYD5i .Dropdown-option:last-child {\n  border-bottom-right-radius: 2px;\n  border-bottom-left-radius: 2px;\n}\n\n.wrapper-zYD5i .Dropdown-option:hover {\n  background-color: #f2f9fc;\n}\n\n.wrapper-zYD5i .Dropdown-option.is-selected {\n  background-color: #f2f9fc;\n  color: #333;\n}\n\n.wrapper-zYD5i .Dropdown-noresults {\n  box-sizing: border-box;\n  color: #ccc;\n  cursor: default;\n  display: block;\n  padding: 8px 10px;\n}\n";
styleInject(css_248z$1);

var css_248z = "/*\n@ts-ignore\n*/\n@keyframes marqueeScroll {\n  to {\n    transform: translate3d(0, 0, 0);\n  }\n}\n";
styleInject(css_248z);

function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
var DropDowmText = function DropDowmText(_ref) {
  var _item$selectedElement;
  var item = _ref.item,
    paletteId = _ref.paletteId,
    style = _ref.style;
  var viewHandler = useViewHandler();
  var allItemsP = item.groups.flatMap(function (group) {
    return group.items;
  });
  var allItems = allItemsP;
  var sel = allItems.find(function (item) {
    return item.sel;
  });
  var _useState = useState(sel === null || sel === void 0 ? void 0 : sel.text),
    _useState2 = _slicedToArray(_useState, 2),
    actValue = _useState2[0],
    setActValue = _useState2[1];
  var _useState3 = useState(false),
    _useState4 = _slicedToArray(_useState3, 2),
    forceClick = _useState4[0],
    setForceClick = _useState4[1];
  useEffect(function () {
    var val = allItems.find(function (item) {
      return item.codex == actValue;
    });
    if (val) viewHandler.paletteViewHandler.clickedOnConfigPalette(val, undefined, paletteId);
  }, [actValue, forceClick]);
  var selOption = undefined;
  var options = [];
  var onChange = function onChange(val) {
    setActValue(val.value);
    setForceClick(!forceClick);
  };
  var _iterator = _createForOfIteratorHelper(allItems),
    _step;
  try {
    for (_iterator.s(); !(_step = _iterator.n()).done;) {
      var _item = _step.value;
      var option = {
        label: /*#__PURE__*/jsxs("div", {
          className: dropOption,
          children: [/*#__PURE__*/jsx("div", {
            className: text,
            dangerouslySetInnerHTML: {
              __html: _item.text
            }
          }), _item.pricePreviewPromise !== undefined && /*#__PURE__*/jsx(PricePreview, {
            asyncPricePreview: _item.pricePreviewPromise,
            sel: _item.sel
          }), _item.checkForReversingChanges !== undefined && /*#__PURE__*/jsx(ReverseCheck, {
            item: _item,
            paletteId: paletteId
          })]
        }),
        text: _item.text,
        value: _item.codex
      };
      if (_item.sel) {
        selOption = {
          label: _item.text.length > 16 ? /*#__PURE__*/jsx(MarqueeText, {
            direction: "right",
            duration: 8,
            textSpacing: '8px',
            children: _item.text
          }) : /*#__PURE__*/jsx("div", {
            className: dropOption,
            dangerouslySetInnerHTML: {
              __html: _item.text
            }
          }),
          text: _item.text,
          value: _item.codex
        };
      }
      options.push(option);
    }
  } catch (err) {
    _iterator.e(err);
  } finally {
    _iterator.f();
  }
  var contentItem = (_item$selectedElement = item.selectedElements) !== null && _item$selectedElement !== void 0 && _item$selectedElement[0].contentItemId ? item.selectedElements[0] : item.optionContentItemId ? {
    contentItemId: item.optionContentItemId,
    codex: item.configStepKey
  } : undefined;
  return /*#__PURE__*/jsxs("div", {
    className: classnames(row, wrapper, viewHandler.uiState.isInMobileView ? mobile : undefined, viewHandler.uiState.isTablet ? tablet : undefined),
    ref: function ref(_ref2) {
      return item.htmlRef = _ref2;
    },
    style: style,
    children: [/*#__PURE__*/jsx("div", {
      className: classnames(colum, title),
      children: item.name
    }), /*#__PURE__*/jsx(Dropdown, {
      className: dropdownWidth,
      controlClassName: wcDropDownSelect,
      menuClassName: dropDownArea,
      options: options,
      value: selOption,
      placeholderClassName: dropOption,
      onChange: onChange
    }), item.type == 'DROPDOWN_IMAGE' && (sel === null || sel === void 0 ? void 0 : sel.image) && /*#__PURE__*/jsx("img", {
      className: image,
      src: sel.image.replace('_gal.', '.')
    }), contentItem && /*#__PURE__*/jsx(InfoIcon, {
      item: contentItem,
      style: {
        bottom: '24px',
        right: '20px'
      }
    }, item.configStepKey)]
  });
};
var index = observer(DropDowmText);

export { index as default };
