import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
import { s as styleInject, u as useViewHandler, P as PricePreview, S as SettingsHeader } from './index-bbdfb97a.js';
import { useDivaCore } from '@crystaldesign/diva-core';
import { useState, useEffect } from 'react';
import Dropdown from 'react-dropdown';
import MobileDropdown from './index-95da7966.js';
import { observer } from 'mobx-react-lite';
import InfoIcon from './index-04a7a9b4.js';
import ReverseCheck from './index-755074ae.js';
import { jsx, jsxs } 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';
import './index-69271b96.js';
import '@mui/icons-material/Block';
import '@mui/icons-material/Warning';

var iconWrapper = "icon-wrapper-uXqGb";
var wcDropDownSelect = "wcDropDownSelect-sB9TS";
var dropDownArea = "dropDownArea-2LjDI";
var image = "image-Ox-79";
var label = "label-l3TV3";
var wrapper = "wrapper-xpzd5";
var css_248z = ".icon-wrapper-uXqGb {\n  display: flex;\n  position: relative;\n}\n.wcDropDownSelect-sB9TS {\n  padding: 10.2px 24px 7px 16px !important;\n}\n.wcDropDownSelect-sB9TS {\n  height: 39px;\n  padding: 8px;\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  letter-spacing: 0pt;\n  color: #0a0a0a;\n  background-origin: content-box;\n  background-position: right -16px center;\n  background-repeat: no-repeat;\n  background-size: 9px 6px;\n  padding-right: 24px;\n  transition:\n    box-shadow 0.5s,\n    border-color 0.25s ease-in-out;\n\n  font-weight: 300;\n}\n\n.wcDropDownSelect-sB9TS > div > div {\n  text-overflow: ellipsis;\n  overflow: hidden;\n  white-space: nowrap;\n}\n\n.dropDownArea-2LjDI {\n  max-height: 520px;\n\n  right: 0;\n  width: 100%;\n  min-width: 150px;\n  letter-spacing: 0px;\n  font-size: 13px;\n  font-weight: 300;\n}\n\n.dropDownArea-2LjDI .dropOption-lwWxd {\n  white-space: nowrap;\n}\n\n.row-fy2V4 {\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-KdLW7 {\n  text-align: right;\n  padding-bottom: 9px;\n  padding-top: 9px;\n}\n\n.colum-yG36- {\n  width: 50%;\n  margin: 15px;\n}\n\n.image-Ox-79 {\n  width: 45%;\n}\n\n.label-l3TV3 {\n  position: relative;\n  padding-right: 64px;\n}\n\n.wrapper-xpzd5 .Dropdown-root {\n  position: relative;\n}\n\n.wrapper-xpzd5 .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  font-size: 14px;\n}\n\n.mobile-XuD0m .Dropdown-control {\n  font-size: 12px;\n}\n\n.tablet-yL-Pt .Dropdown-control {\n  font-size: 15px;\n}\n\n.wrapper-xpzd5 .Dropdown-control:hover {\n  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.06);\n}\n\n.wrapper-xpzd5 .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-xpzd5 .is-open .Dropdown-arrow {\n  border-color: transparent transparent #999;\n  border-width: 0 5px 5px;\n}\n\n.wrapper-xpzd5 .Dropdown-menu {\n  background-color: white;\n  box-sizing: border-box;\n  border: 1px solid #ddd;\n  margin-top: -1px;\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-xpzd5 .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-xpzd5 .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-xpzd5 .Dropdown-option:last-child {\n  border-bottom-right-radius: 2px;\n  border-bottom-left-radius: 2px;\n}\n\n.wrapper-xpzd5 .Dropdown-option:hover {\n  background-color: #f2f9fc;\n}\n\n.wrapper-xpzd5 .Dropdown-option.is-selected {\n  background-color: #f2f9fc;\n  color: #333;\n}\n\n.wrapper-xpzd5 .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);

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 _useDivaCore = useDivaCore(),
    isMobile = _useDivaCore.state.dimensions.isMobile;
  var _useState = useState(undefined),
    _useState2 = _slicedToArray(_useState, 2),
    actValue = _useState2[0],
    setActValue = _useState2[1];
  var _useState3 = useState([]),
    _useState4 = _slicedToArray(_useState3, 2),
    allItems = _useState4[0],
    setAllItems = _useState4[1];
  var _useState5 = useState(undefined),
    _useState6 = _slicedToArray(_useState5, 2),
    sel = _useState6[0],
    setSel = _useState6[1];
  var _useState7 = useState([]),
    _useState8 = _slicedToArray(_useState7, 2),
    mobileOptions = _useState8[0],
    setMobileOptions = _useState8[1];
  var _useState9 = useState(undefined),
    _useState10 = _slicedToArray(_useState9, 2),
    selectedMobileOption = _useState10[0],
    setSelectedMobileOption = _useState10[1];
  var _useState11 = useState([]),
    _useState12 = _slicedToArray(_useState11, 2),
    options = _useState12[0],
    setOptions = _useState12[1];
  var _useState13 = useState(undefined),
    _useState14 = _slicedToArray(_useState13, 2),
    selOption = _useState14[0],
    setSelOption = _useState14[1];
  useEffect(function () {
    var allItemsP = item.groups.flatMap(function (group) {
      return group.items;
    });
    var items = allItemsP;
    setAllItems(items);
    var sel = items.find(function (item) {
      return item.sel;
    });
    if (actValue !== (sel === null || sel === void 0 ? void 0 : sel.text)) setActValue(sel === null || sel === void 0 ? void 0 : sel.text);
    setSel(sel);
  }, [item]);
  var onChange = function onChange(val) {
    setActValue(val.value);
  };
  var onChangeMobile = function onChangeMobile(e) {
    setActValue(e.target.value);
  };
  useEffect(function () {
    var val = allItems.find(function (item) {
      return item.codex == actValue;
    });
    if (val) {
      setSelOption({
        label: /*#__PURE__*/jsx("div", {
          className: label,
          children: val.text
        }),
        value: val.codex
      });
      viewHandler.paletteViewHandler.clickedOnConfigPalette(val, undefined, paletteId);
    }
  }, [actValue]);
  useEffect(function () {
    var mobileOptions = [];
    var selectedMobileOption = undefined;
    var opts = [];
    var _iterator = _createForOfIteratorHelper(allItems),
      _step;
    try {
      for (_iterator.s(); !(_step = _iterator.n()).done;) {
        var _item = _step.value;
        mobileOptions.push({
          text: _item.text,
          codex: _item.codex
        });
        var option = {
          label: /*#__PURE__*/jsxs("div", {
            className: label,
            children: [_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) {
          setSelOption(option);
          selectedMobileOption = _item.codex;
        }
        opts.push(option);
      }
    } catch (err) {
      _iterator.e(err);
    } finally {
      _iterator.f();
    }
    setOptions(opts);
    setMobileOptions(mobileOptions);
    setSelectedMobileOption(selectedMobileOption);
  }, [allItems]);
  var paletteIsLastPalette = false;
  if (paletteId) {
    var nextPalette = viewHandler.settingsState.itemPalettes.get(paletteId + 1);
    if (!(nextPalette !== null && nextPalette !== void 0 && nextPalette.visible)) {
      paletteIsLastPalette = true;
    }
  }
  return /*#__PURE__*/jsxs("div", {
    ref: function ref(_ref2) {
      return item.htmlRef = _ref2;
    },
    style: style,
    className: wrapper,
    children: [/*#__PURE__*/jsxs("div", {
      className: iconWrapper,
      children: [/*#__PURE__*/jsx(SettingsHeader, {
        isInScroller: true,
        isSettingsHeader: false,
        item: item
      }), ((_item$selectedElement = item.selectedElements) === null || _item$selectedElement === void 0 ? void 0 : _item$selectedElement[0].contentItemId) && /*#__PURE__*/jsx(InfoIcon, {
        item: item.selectedElements[0],
        style: {
          position: 'relative',
          bottom: -16
        }
      }, item.selectedElements[0].codex)]
    }), isMobile ? /*#__PURE__*/jsx(MobileDropdown, {
      id: 'wcConfigurator-mobiledropdown-' + item.id,
      onChange: onChangeMobile,
      mobileOptions: mobileOptions,
      selectedOption: selectedMobileOption
    }) : /*#__PURE__*/jsx(Dropdown, {
      className: 'wcConfigurator-dropdown-' + item.id,
      controlClassName: wcDropDownSelect,
      menuClassName: dropDownArea,
      options: options,
      value: selOption,
      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.', '.')
    }), paletteIsLastPalette && /*#__PURE__*/jsx("div", {
      style: {
        height: options.length * 32 + 10
      }
    })]
  });
};
var index = observer(DropDowmText);

export { index as default };
