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 { observer } from 'mobx-react-lite';
import { useState, useRef } from 'react';
import classnames from 'classnames';
import { useTranslation } from '@crystaldesign/diva-core';
import Draggable from 'react-draggable';
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
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 'qrcode.react';
import '@babel/runtime/helpers/typeof';
import 'flat';
import 'react-switch';
import 'react-countup';

var container = "container-ulbgy";
var wrapper = "wrapper-CDDb8";
var door = "door-MAV8k";
var first = "first-flj9W";
var last = "last-joL72";
var handle = "handle-uyqn6";
var short1 = "short1-1RTH5";
var short2 = "short2-ELqSF";
var short3 = "short3-YuCyl";
var shortLeft = "short-left-3AMc0";
var shortRight = "short-right-ElG0J";
var left = "left-rt3Dw";
var right = "right-ziERh";
var invisibleDragger = "invisible-dragger-CYEX3";
var visibleDragger = "visible-dragger-GTq6j";
var isOkay = "is-okay-xl784";
var notOkay = "not-okay-7XIp7";
var css_248z = ".container-ulbgy,\n.container-ulbgy * {\n  -webkit-user-select: text;\n     -moz-user-select: text;\n          user-select: text;\n}\n\n.container-ulbgy {\n  overflow-x: auto;\n  width: calc(100% - 20px);\n  height: 100%;\n  position: relative;\n  padding: 0;\n  margin: 10px;\n  float: left;\n}\n.wrapper-CDDb8 {\n  width: -moz-max-content;\n  width: max-content;\n  height: 100%;\n}\n\n.door-MAV8k {\n  display: inline-block;\n  word-break: break-word;\n  background: #eee;\n  box-sizing: border-box;\n  border: 1px solid black;\n  position: relative;\n  width: 50px;\n  height: 150px;\n}\n\n.first-flj9W {\n  border-left: 3px solid black;\n}\n\n.last-joL72 {\n  border-right: 3px solid black;\n}\n\n.handle-uyqn6 {\n  position: absolute;\n  top: 47%;\n  height: 20px;\n  width: 30px;\n  left: calc(50% - 17px);\n  pointer-events: none;\n}\n\n.short1-1RTH5,\n.short2-ELqSF,\n.short3-YuCyl {\n  position: absolute;\n  height: 0px;\n  width: 50px;\n  pointer-events: none;\n  border: 1px solid black;\n  z-index: 10;\n}\n\n.short-left-3AMc0,\n.short-right-ElG0J {\n  background-color: #eee;\n  height: 30%;\n  position: absolute;\n  bottom: 0px;\n  width: 4px;\n}\n\n.short-left-3AMc0 {\n  left: 100%;\n}\n.short-right-ElG0J {\n  right: 100%;\n}\n\n.short1-1RTH5 {\n  bottom: 30%;\n}\n.short2-ELqSF {\n  bottom: 20%;\n}\n.short3-YuCyl {\n  bottom: 10%;\n}\n\n.first-flj9W .short1-1RTH5,\n.first-flj9W .short2-ELqSF,\n.first-flj9W .short3-YuCyl {\n  width: 48px;\n  left: 2px;\n}\n\n.last-joL72 .short1-1RTH5,\n.last-joL72 .short2-ELqSF,\n.last-joL72 .short3-YuCyl {\n  width: 48px;\n  right: 2px;\n}\n\n.left-rt3Dw {\n  border-left: solid 3px black;\n}\n.right-ziERh {\n  border-right: solid 3px black;\n}\n\n.invisible-dragger-CYEX3 {\n  height: 150px;\n  opacity: 0;\n  position: absolute;\n  z-index: 100;\n}\n\n.visible-dragger-GTq6j {\n  opacity: 1;\n  border: 1px solid black;\n  cursor: ew-resize;\n}\n\n.is-okay-xl784 {\n  border: 1px solid green;\n  background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMwAAACTCAYAAADC+vbQAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4wUCBxMSqfSiKAAAAAd0RVh0QXV0aG9yAKmuzEgAAAAMdEVYdERlc2NyaXB0aW9uABMJISMAAAAKdEVYdENvcHlyaWdodACsD8w6AAAADnRFWHRDcmVhdG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dMHDeEieWeroMBo5f5sRSU7fBwHFLnVjq6joY2H+5E0tt3QcD+y15YqkvwfyxddkTSx8SzDtrlz6x9CPBfLB0+RNLXxLMHXMjSCz9STAPvIohsfQpwTzxKIrE0q8E88LHOBJL3xLMDGMkiSX+BwO4O2CqgnENAAAAAElFTkSuQmCC);\n  background-repeat: no-repeat;\n  background-size: 60%;\n  background-position: center 30%;\n}\n\n.not-okay-7XIp7 {\n  border: 1px solid red;\n  background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJIAAACSCAYAAACue5OOAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4wUCBxMapy8qGgAAAAd0RVh0QXV0aG9yAKmuzEgAAAAMdEVYdERlc2NyaXB0aW9uABMJISMAAAAKdEVYdENvcHlyaWdodACsD8w6AAAADnRFWHRDcmVhdGlvbiB0aW1lADX3DwkAAAAJdEVYdFNvZnR3YXJlAF1w/zoAAAALdEVYdERpc2NsYWltZXIAt8C0jwAAAAh0RVh0V2FybmluZwDAG+aHAAAAB3RFWHRTb3VyY2UA9f+D6wAAAAh0RVh0Q29tbWVudAD2zJa/AAAABnRFWHRUaXRsZQCo7tInAAAF50lEQVR4nO3dW3ITMRSE4fZkA05lKewgWbeX4KVQeAFQ4SE14NhzkTSSTp+j/p+AQEaXjxDbGnP6/PxEaX8+Pv794ZfL5VT8iZRZtfZwqjGApZ8r/mruYRGktQsKk59q72E2pL0LCRN/LfYwC1LqBYSJt1Z7mAwp9xMLE18t9zAJUikKYeKp9R7uQjqKQZjs67GHm5BqIRAmu3rt4Sqk2psvTP3ruYeLkFptujD1q/cePkFqvdnC1D6LPZz2fkOvgag6We3htPaB3gNRx7Pcw8liAEsDUcey3sPT7/d3883UEZRjMfyFLD5GUjOGhfAay9pNb9frq/UgAJ4F8RTLmr1dr6/T7Xa7CZO/WNbq7Xp9vd1utwkAhMlXLGs0IwLuvkcSJh+xrM09IuDhm21h4o5lTR4RAQuP2oSJM5a1WEIErDz8F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Kk6JCFaLjqmqpCEaLvImKpBEqK0omKqAkmI8oqI6TAkISorGqZDkIToWJEwFUMSojpFwVQESYjqFgFTNiQhapN3TFmQhKhtnjElQxKiPnnFlARJiPrmEdMuJCGyyRumTUhCZJsnTKuQhIgjL5gWIQkRVx4wPUESIs7YMU17v8EiIVqOGdO09gGrhGg7VkzT4y9YJkRpMWI6/X5/FyKnnc/nM8t/A2/+RluAEJXG9JXJHJIQHYsF0/RyuZysLi5EdbLG9HK5nKb5B70vLkR1s8I025kef6FHQtSm3pjuzUxrH2iVELWtF6ZHK0/fbLfEJER9ao1pycjio7YWmISob60wrdlYffhfE5MQ2VQb05aJzeeRamASIttqYdqzsPuE5BFMQsTRUUwpBpKe2S7BJERclWJK3fvkl0hyMAkRZ7mYcvY867W2lE8sRNylYsr9Vyj7RdutCwiRj/YwlXwrU/Tq/9KFhMhXa5hKH1wVHyO5v6AQ+ewR05FH6H8B5Ihh9gBsjDAAAAAASUVORK5CYII=);\n  background-repeat: no-repeat;\n  background-size: 60%;\n  background-position: center 30%;\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 DoorPlanner = function DoorPlanner(_ref) {
  var item = _ref.item;
  var viewHandler = useViewHandler();
  var _useTranslation = useTranslation(),
    t = _useTranslation.t;
  var DOOR_WIDTH = 50;
  var doors = item.groups[0].items;
  var _useState = useState({
      x: 0,
      y: 0
    }),
    _useState2 = _slicedToArray(_useState, 2),
    position = _useState2[0],
    setPosition = _useState2[1];
  var _useState3 = useState(undefined),
    _useState4 = _slicedToArray(_useState3, 2),
    selectedDoor = _useState4[0],
    setSelectedDoor = _useState4[1];
  var scroller = useRef(null);
  var draggable = useRef(null); // https://github.com/react-grid-layout/react-draggable/blob/v4.4.2/lib/DraggableCore.js#L159-L171

  var _useState5 = useState(false),
    _useState6 = _slicedToArray(_useState5, 2),
    doorSwapPossible = _useState6[0],
    setDoorSwapPossible = _useState6[1];
  var handleStart = function handleStart(e) {
    var offset = getEventOffsetX(e);
    var xPos = offset - offset % DOOR_WIDTH;
    setPosition({
      y: 0,
      x: xPos
    });
    setSelectedDoor(doors[xPos / DOOR_WIDTH]);
  };
  var handleDrag = function handleDrag(e) {
    var offset = getEventOffsetX(e);
    var index = (offset - offset % DOOR_WIDTH) / DOOR_WIDTH;
    if (index >= 0 && index < doors.length) {
      if ((selectedDoor === null || selectedDoor === void 0 ? void 0 : selectedDoor.key) != doors[index].key && (selectedDoor === null || selectedDoor === void 0 ? void 0 : selectedDoor.currentDoor.StrictType) === doors[index].currentDoor.StrictType) {
        setDoorSwapPossible(true);
      } else {
        setDoorSwapPossible(false);
      }
    }
    scrollLeftOrRight(e);
  };
  var handleStop = function handleStop(e) {
    var offset = getEventOffsetX(e);
    var index = (offset - offset % DOOR_WIDTH) / DOOR_WIDTH;
    if (doorSwapPossible && selectedDoor && index >= 0 && index < doors.length) {
      viewHandler.divaWebPlanner.moveDoors(selectedDoor.door, doors[index].door);
    }
    setSelectedDoor(undefined);
    setDoorSwapPossible(false);
    setPosition({
      y: 0,
      x: 0
    });
  };
  var scrollLeftOrRight = function scrollLeftOrRight(e) {
    var _e$layerX, _viewHandler$settings, _viewHandler$settings2;
    if (!scroller.current) return;
    var offset = (_e$layerX = e.layerX) !== null && _e$layerX !== void 0 ? _e$layerX : e.changedTouches[0].clientX - ((_viewHandler$settings = (_viewHandler$settings2 = viewHandler.settingsState.settingsScrollerElement) === null || _viewHandler$settings2 === void 0 ? void 0 : _viewHandler$settings2.getBoundingClientRect().x) !== null && _viewHandler$settings !== void 0 ? _viewHandler$settings : 0);
    if (offset < scroller.current.getBoundingClientRect().width / 100 * 5) {
      //scroll left
      scroller.current.scrollTo({
        left: scroller.current.scrollLeft - 10
      });
    } else if (offset > scroller.current.getBoundingClientRect().width / 100 * 95) {
      //scroll right
      scroller.current.scrollTo({
        left: scroller.current.scrollLeft + 10
      });
    }
  };
  var getEventOffsetX = function getEventOffsetX(e) {
    var _e$clientX, _viewHandler$settings3, _viewHandler$settings4, _scroller$current$scr, _scroller$current;
    return ((_e$clientX = e.clientX) !== null && _e$clientX !== void 0 ? _e$clientX : e.changedTouches[0].clientX) - ((_viewHandler$settings3 = (_viewHandler$settings4 = viewHandler.settingsState.settingsScrollerElement) === null || _viewHandler$settings4 === void 0 ? void 0 : _viewHandler$settings4.getBoundingClientRect().x) !== null && _viewHandler$settings3 !== void 0 ? _viewHandler$settings3 : 0) + ((_scroller$current$scr = (_scroller$current = scroller.current) === null || _scroller$current === void 0 ? void 0 : _scroller$current.scrollLeft) !== null && _scroller$current$scr !== void 0 ? _scroller$current$scr : 0);
  };
  var dragHandlers = {
    onStart: handleStart,
    onDrag: handleDrag,
    onStop: handleStop
  };
  return /*#__PURE__*/jsxs(Fragment, {
    children: [t('configurator.DoorPlanner_Description'), /*#__PURE__*/jsx("div", {
      ref: scroller,
      className: classnames(container, 'box'),
      children: /*#__PURE__*/jsxs("div", {
        className: classnames(wrapper, 'no-swiping'),
        children: [/*#__PURE__*/jsx(Draggable, _objectSpread(_objectSpread({
          nodeRef: draggable,
          bounds: "parent",
          position: position
        }, dragHandlers), {}, {
          axis: "x",
          defaultClassName: invisibleDragger,
          defaultClassNameDragging: classnames(visibleDragger, doorSwapPossible ? isOkay : notOkay),
          children: /*#__PURE__*/jsx("div", {
            ref: draggable,
            className: "box cursor-x",
            style: {
              width: !!selectedDoor ? DOOR_WIDTH : DOOR_WIDTH * doors.length
            }
          })
        })), doors.map(function (item, index) {
          return /*#__PURE__*/jsxs("div", {
            className: classnames(door, index == 0 ? first : undefined, index === doors.length - 1 ? last : undefined),
            children: [item.type.includes('TUER_L') && /*#__PURE__*/jsx("div", {
              className: classnames(handle, right)
            }), item.type.includes('TUER_R') && /*#__PURE__*/jsx("div", {
              className: classnames(handle, left)
            }), item.type == 'TUER_L_SHORT' && /*#__PURE__*/jsx("div", {
              className: classnames(shortLeft)
            }), item.type == 'TUER_R_SHORT' && /*#__PURE__*/jsx("div", {
              className: classnames(shortRight)
            }), item.type.includes('SHORT') && /*#__PURE__*/jsxs(Fragment, {
              children: [/*#__PURE__*/jsx("div", {
                className: classnames(short1)
              }), /*#__PURE__*/jsx("div", {
                className: classnames(short2)
              }), /*#__PURE__*/jsx("div", {
                className: classnames(short3)
              })]
            })]
          });
        })]
      })
    })]
  });
};
var index = observer(DoorPlanner);

export { index as default };
