import _defineProperty from '@babel/runtime/helpers/defineProperty';
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
import { s as styleInject, u as useViewHandler } from './index-bbdfb97a.js';
import classnames from 'classnames';
import { observer } from 'mobx-react-lite';
import { useState, useEffect } from 'react';
import { jsx, jsxs } from 'react/jsx-runtime';
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';

var paletteItem = "palette-item-sUeAp";
var container = "container-4qhuT";
var content = "content-PlGS7";
var labelsContainer = "labels-container-b90-e";
var minLabel = "min-label-V6PZW";
var maxLabel = "max-label-f0zP7";
var sliderContainer = "slider-container-0ZpeI";
var slider = "slider-KB5gQ";
var wcSliderButton = "wcSliderButton-OSCAA";
var wcSliderButtonLeft = "wcSliderButtonLeft-AUWb0";
var wcSliderButtonRight = "wcSliderButtonRight-wCBtH";
var css_248z = ".palette-item-sUeAp {\n  border-radius: var(--globalBorderRadius);\n  position: relative;\n  display: flex;\n  width: 100%;\n  z-index: 100;\n  transition: all 0.15s ease;\n}\n\n.container-4qhuT {\n  display: block;\n  width: 99%;\n}\n\n.content-PlGS7 {\n  margin: 10px;\n}\n\n.labels-container-b90-e {\n  width: 100%;\n  height: 1.2rem;\n}\n\n.min-label-V6PZW {\n  position: absolute;\n  left: 10px;\n}\n\n.max-label-f0zP7 {\n  position: absolute;\n  right: 10px;\n}\n\n.slider-container-0ZpeI {\n  width: 100%;\n  height: 2rem;\n  margin-top: 12px;\n  position: relative;\n}\n\n.slider-KB5gQ {\n  -webkit-appearance: none;\n  width: calc(100% - 3rem - 4px);\n  height: 25px;\n  background: #d3d3d3;\n  outline: none;\n  opacity: 0.7;\n  transition: opacity 0.2s;\n  border-radius: 12.5px;\n  position: absolute;\n  left: 1.5rem;\n}\n\n.slider-KB5gQ:hover {\n  opacity: 1;\n}\n\n.slider-KB5gQ::-webkit-slider-thumb {\n  -webkit-appearance: none;\n  appearance: none;\n  width: 25px;\n  height: 25px;\n  border-radius: 12.5px;\n  background: var(--primaryColor);\n  cursor: pointer;\n}\n\n.slider-KB5gQ::-moz-range-thumb {\n  width: 25px;\n  height: 25px;\n  border-radius: 5px;\n  background: var(--primaryColor);\n  cursor: pointer;\n}\n\n.wcSliderButton-OSCAA {\n  width: 1.5rem;\n  height: 1.5rem;\n  top: 3px;\n  position: absolute;\n  background-image: url(\"data:image/svg+xml,%3Csvg width%3D%2213%22 height%3D%2238%22 viewBox%3D%220 0 13 38%22 fill%3D%22none%22 xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath d%3D%22M12 1L0.999998 19.1818L12 37%22 stroke%3D%22%234B4B4B%22 stroke-width%3D%221.2%22 stroke-linecap%3D%22round%22 stroke-linejoin%3D%22round%22%2F%3E%3C%2Fsvg%3E\");\n  background-repeat: no-repeat;\n  background-size: contain;\n  background-position: center center;\n}\n.wcSliderButtonLeft-AUWb0 {\n  left: 0.15rem;\n}\n.wcSliderButtonRight-wCBtH {\n  transform: rotate(180deg);\n  right: 0.15rem;\n}\n";
styleInject(css_248z);

function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var Range = function Range(_ref) {
  var _palette$selectedElem;
  var paletteId = _ref.paletteId,
    itemP = _ref.item;
  var item = itemP;
  var _useState = useState(Number(item.freeText)),
    _useState2 = _slicedToArray(_useState, 2),
    curValue = _useState2[0],
    setCurValue = _useState2[1];
  var viewHandler = useViewHandler();
  var palette = viewHandler.settingsState.itemPalettes.get(paletteId);
  var _useState3 = useState(palette === null || palette === void 0 || (_palette$selectedElem = palette.selectedElements) === null || _palette$selectedElem === void 0 || (_palette$selectedElem = _palette$selectedElem[0]) === null || _palette$selectedElem === void 0 ? void 0 : _palette$selectedElem.codex),
    _useState4 = _slicedToArray(_useState3, 2),
    selectedOPV = _useState4[0],
    setSelectedOPV = _useState4[1];
  useEffect(function () {
    if (palette) {
      viewHandler.settingsState.updateItemPalette(paletteId, _objectSpread(_objectSpread({}, palette), {}, {
        numberInput: curValue,
        measureUnit: item.measureUnit
      }));
    }
  }, [curValue]);
  useEffect(function () {
    if (palette) {
      var _palette$selectedElem2;
      var codex = palette === null || palette === void 0 || (_palette$selectedElem2 = palette.selectedElements) === null || _palette$selectedElem2 === void 0 || (_palette$selectedElem2 = _palette$selectedElem2[0]) === null || _palette$selectedElem2 === void 0 ? void 0 : _palette$selectedElem2.codex;
      if (codex && selectedOPV !== codex) {
        setSelectedOPV(codex);
        setCurValue(Number(item.measureMinimum));
      } else if (palette.numberInput && palette.numberInput != curValue) {
        setCurValue(palette.numberInput);
      }
    }
  }, [palette, selectedOPV]);
  return /*#__PURE__*/jsx("div", {
    className: classnames(paletteItem, container),
    children: /*#__PURE__*/jsxs("div", {
      className: content,
      children: [/*#__PURE__*/jsxs("div", {
        className: labelsContainer,
        children: [/*#__PURE__*/jsx("a", {
          className: minLabel,
          children: item.measureMinimum + ' ' + item.measureUnit
        }), /*#__PURE__*/jsx("a", {
          className: maxLabel,
          children: item.measureMaximum + ' ' + item.measureUnit
        })]
      }), /*#__PURE__*/jsxs("div", {
        className: classnames(sliderContainer, 'no-swiping'),
        children: [/*#__PURE__*/jsx("div", {
          className: classnames(wcSliderButton, wcSliderButtonLeft),
          onClick: function onClick() {
            var newVal = Number(curValue) - Number(item.measureStep);
            if (newVal < Number(item.measureMinimum)) return;
            setCurValue(newVal);
            viewHandler.paletteViewHandler.onRangeClickChange(palette, item, newVal.toString(), true);
          }
        }), /*#__PURE__*/jsx("input", {
          type: "range",
          min: item.measureMinimum,
          max: item.measureMaximum,
          step: item.measureStep,
          value: curValue,
          className: slider,
          onChange: function onChange(event) {
            return setCurValue(Number(event.target.value));
          },
          onMouseUp: function onMouseUp(event) {
            return viewHandler.paletteViewHandler.onRangeClickChange(palette, item, event.target.value);
          },
          onTouchEnd: function onTouchEnd(event) {
            return viewHandler.paletteViewHandler.onRangeClickChange(palette, item, event.target.value);
          }
        }), /*#__PURE__*/jsx("div", {
          className: classnames(wcSliderButton, wcSliderButtonRight),
          onClick: function onClick() {
            var newVal = Number(curValue) + Number(item.measureStep);
            if (newVal > Number(item.measureMaximum)) return;
            setCurValue(newVal);
            viewHandler.paletteViewHandler.onRangeClickChange(palette, item, newVal.toString());
          }
        })]
      })]
    })
  });
};
var Range$1 = observer(Range);

export { Range$1 as default };
