import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
import _objectDestructuringEmpty from '@babel/runtime/helpers/objectDestructuringEmpty';
import _regeneratorRuntime from '@babel/runtime/regenerator';
import { s as styleInject, u as useViewHandler } from './index-bbdfb97a.js';
import { useRef, useEffect } from 'react';
import { observer } from 'mobx-react-lite';
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
import '@babel/runtime/helpers/defineProperty';
import 'react-dynamic-multi-render';
import '@crystaldesign/diva-core';
import '@babel/runtime/helpers/slicedToArray';
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 'classnames';
import 'qrcode.react';
import '@babel/runtime/helpers/typeof';
import 'flat';
import 'react-switch';
import 'react-countup';

var wcTextBoxInDialog = "wcTextBoxInDialog-cUykT";
var wcPopupWindowContainer = "wcPopupWindowContainer-RSZGf";
var wcClose = "wcClose-X1s6d";
var wcSubmit = "wcSubmit-Ax0lk";
var css_248z = ".wcTextBoxInDialog-cUykT {\n  width: 90%;\n  padding: 12px 20px;\n  margin: 8px 0;\n  display: inline-block;\n  border: 1px solid #ccc;\n  border-radius: 4px;\n  box-sizing: border-box;\n  float: left;\n}\n\n.wcPopupWindowContainer-RSZGf {\n  letter-spacing: 0.5px;\n  -webkit-text-stroke: 0.1px;\n  font-family: var(--diva-typography-font-family);\n  font-weight: 100;\n  z-index: 999;\n  width: 40em;\n  max-width: 70%;\n  max-height: 90%;\n  background-color: white;\n  padding: 1em 2em 0.5em 2em;\n  border-radius: 15px;\n  border: 1px solid #cbcbcb;\n  font-size: 14.4px;\n  color: #363636;\n  display: flex;\n  box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);\n  position: fixed;\n  top: 50%;\n  left: 50%;\n  transform: translate(-50%, -50%);\n}\n.wcPopupWindowContainer-RSZGf p {\n  font-size: 16px;\n  -webkit-text-stroke: 0.5px;\n}\n\n.wcPopupWindowContainer-RSZGf ul {\n  padding: 0;\n  margin: 0;\n}\n\n.wcPopupWindowContainer-RSZGf .wctooltext-G-oa5 {\n  width: calc(100% - 65px);\n  float: left;\n  padding: 8px 0 15px 10px;\n}\n\n.wcPopupWindowContainer-RSZGf li {\n  height: 40px;\n  width: 55px;\n  display: block;\n  background-repeat: no-repeat;\n  background-position: center;\n  float: left;\n  clear: both;\n  margin-bottom: 15px;\n}\n\n.wcClose-X1s6d {\n  border-radius: 20px;\n  position: absolute;\n  font-size: 22pt;\n  font-family: sans-serif;\n  font-weight: 50;\n  top: -20px;\n  right: -20px;\n  width: 40px;\n  height: 40px;\n  background-color: #fff;\n  color: #666;\n  border: 2px solid #666;\n  text-align: center;\n  padding-top: 0px;\n  content: 'X';\n}\n\n.wcClose-X1s6d:hover {\n  background-color: #aaa;\n  color: #000;\n  border: 2px solid #000;\n}\n.wcSubmit-Ax0lk {\n  border: 1px var(--secondaryColor) solid;\n  background-color: var(--secondaryColor);\n  color: #ffffff;\n  height: 41px;\n  width: 8%;\n  margin: 8px 0 7px;\n  float: right;\n  border-radius: var(--globalBorderRadius);\n  background-repeat: no-repeat;\n  background-position: center center;\n  background-image: url(\"data:image/svg+xml,%3C%3Fxml version%3D%221.0%22 encoding%3D%22utf-8%22%3F%3E%3C!-- Generator%3A Adobe Illustrator 22.0.0%2C SVG Export Plug-In . SVG Version%3A 6.00 Build 0)  --%3E%3Csvg version%3D%221.1%22 id%3D%22Ebene_1%22 xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22 xmlns%3Axlink%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxlink%22 x%3D%220px%22 y%3D%220px%22%09 viewBox%3D%220 0 8 13.5%22 style%3D%22enable-background%3Anew 0 0 8 13.5%3B%22 xml%3Aspace%3D%22preserve%22%3E%3Cstyle type%3D%22text%2Fcss%22%3E%09.st0%7Bfill%3A%23FFFFFF%3B%7D%3C%2Fstyle%3E%3Cg%3E%09%3Cpath class%3D%22st0%22 d%3D%22M6.5%2C11.7c-0.1%2C0-0.2%2C0-0.3-0.1l-5-4.3C1.1%2C7.2%2C1%2C7.1%2C1%2C7c0-0.1%2C0.1-0.3%2C0.2-0.4l5-4.7c0.2-0.2%2C0.5-0.2%2C0.7%2C0%09%09c0.2%2C0.2%2C0.2%2C0.5%2C0%2C0.7L2.3%2C6.9l4.6%2C3.9C7%2C11%2C7.1%2C11.4%2C6.9%2C11.6C6.8%2C11.7%2C6.7%2C11.7%2C6.5%2C11.7z%22%2F%3E%3C%2Fg%3E%3C%2Fsvg%3E\");\n  background-size: 16px;\n  transform: rotate(180deg);\n}\n";
styleInject(css_248z);

var Inputbox = function Inputbox(_ref) {
  _objectDestructuringEmpty(_ref);
  var viewHandler = useViewHandler();
  var inputBox = useRef(null);
  useEffect(function () {
    var _viewHandler$settings, _viewHandler$settings2, _inputBox$current;
    viewHandler.settingsState.setInputBoxValue((_viewHandler$settings = (_viewHandler$settings2 = viewHandler.settingsState.inputBoxItem) === null || _viewHandler$settings2 === void 0 ? void 0 : _viewHandler$settings2.freeText) !== null && _viewHandler$settings !== void 0 ? _viewHandler$settings : '');
    (_inputBox$current = inputBox.current) === null || _inputBox$current === void 0 || _inputBox$current.focus();
  }, []);
  useEffect(function () {
    var _viewHandler$settings3;
    if ((_viewHandler$settings3 = viewHandler.settingsState.inputBoxItem) !== null && _viewHandler$settings3 !== void 0 && _viewHandler$settings3.freeText) {
      viewHandler.settingsState.setInputBoxValue(viewHandler.settingsState.inputBoxItem.freeText);
    }
  }, [viewHandler.settingsState.inputBoxItem]);
  if (!viewHandler.settingsState.inputBoxItem) return /*#__PURE__*/jsx(Fragment, {});
  var title = viewHandler.settingsState.inputBoxItem.text;
  if (title.includes(':')) title = title.slice(0, title.lastIndexOf(':'));
  var onSubmit = /*#__PURE__*/function () {
    var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
      return _regeneratorRuntime.wrap(function _callee$(_context) {
        while (1) switch (_context.prev = _context.next) {
          case 0:
            if (!viewHandler.settingsState.inputBoxItem) {
              _context.next = 6;
              break;
            }
            viewHandler.settingsState.inputBoxItem.freeText = viewHandler.settingsState.inputBoxValue;
            _context.next = 4;
            return viewHandler.paletteViewHandler.clickedOnConfigPalette(viewHandler.settingsState.inputBoxItem, 'inputbox');
          case 4:
            viewHandler.settingsState.updateInputBoxValues(false, undefined);
            viewHandler.uiState.setConfiguratorDisabled(false);
          case 6:
            if (viewHandler.settingsState.inputBoxVisible) {
              viewHandler.uiState.setConfiguratorDisabled(true);
            } else {
              viewHandler.uiState.setConfiguratorDisabled(false);
            }
          case 7:
          case "end":
            return _context.stop();
        }
      }, _callee);
    }));
    return function onSubmit() {
      return _ref2.apply(this, arguments);
    };
  }();
  var isNumberBox = !!viewHandler.settingsState.inputBoxItem.measureUnit;
  var keyDownFunction = function keyDownFunction(e) {
    if (!viewHandler) return;
    if (e.key === 'Enter') {
      onSubmit();
      e.stopPropagation();
    }
  };
  return /*#__PURE__*/jsx("div", {
    children: /*#__PURE__*/jsxs("div", {
      className: wcPopupWindowContainer,
      children: [/*#__PURE__*/jsx("span", {
        onClick: function onClick() {
          return viewHandler.settingsState.inputBoxVisible = false;
        },
        className: wcClose,
        children: "\u2716"
      }), /*#__PURE__*/jsxs("div", {
        style: {
          width: '100%'
        },
        children: [/*#__PURE__*/jsx("p", {
          style: {
            marginTop: '2px'
          },
          children: title
        }), /*#__PURE__*/jsx("input", {
          ref: inputBox,
          onKeyDown: function onKeyDown(e) {
            return keyDownFunction(e);
          },
          className: wcTextBoxInDialog,
          type: isNumberBox ? 'number' : 'text',
          onChange: function onChange(event) {
            return viewHandler.settingsState.setInputBoxValue(event.target.value);
          },
          value: viewHandler.settingsState.inputBoxValue
        }), /*#__PURE__*/jsx("button", {
          className: wcSubmit,
          onClick: onSubmit
        })]
      })]
    })
  });
};
var Inputbox$1 = observer(Inputbox);

export { Inputbox$1 as default };
