import _defineProperty from '@babel/runtime/helpers/defineProperty';
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
import { s as styleInject, u as useViewHandler, G as GenericToolTip } from './index-bbdfb97a.js';
import { observer } from 'mobx-react-lite';
import { useState, createElement } from 'react';
import { useHover, useLayer } from 'react-laag';
import { useTranslation, useDivaCore } from '@crystaldesign/diva-core';
import classnames from 'classnames';
import MetaData from './index-7635bafb.js';
import { jsx, Fragment, jsxs } 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 wrapper = "wrapper-q2VFw";
var textWrapper = "text-wrapper-Th9kS";
var element = "element-e6pDX";
var elementText = "element-text-Lfswv";
var image = "image-p37Vz";
var hexColor = "hexColor-JQ-dp";
var text = "text-DX9ZX";
var deleteButton = "delete-button-sXPbV";
var css_248z = ".wrapper-q2VFw {\n  position: relative;\n}\n\n.text-wrapper-Th9kS {\n  width: 48%;\n}\n.element-e6pDX {\n  position: relative;\n  display: flex;\n  width: 30px;\n  height: 30px;\n  border-radius: 50%;\n  border: 2px solid var(--primaryColor);\n  overflow: hidden;\n  cursor: pointer;\n  background-color: #fff;\n}\n\n.element-text-Lfswv {\n  border-radius: 0px;\n  border: 0px solid #fff;\n  width: calc(100% - 26px);\n  margin-top: 5px;\n  height: 64px;\n  flex-direction: column;\n  justify-content: center;\n  padding-left: 26px;\n}\n\n.image-p37Vz {\n  width: 100%;\n  height: auto;\n}\n\n.hexColor-JQ-dp {\n  width: 100%;\n  height: 100%;\n}\n\n.text-DX9ZX {\n  line-height: 20px;\n  width: 100%;\n  font-size: 15px;\n  white-space: nowrap;\n}\n\n.delete-button-sXPbV {\n  position: absolute;\n  top: 0px;\n  right: -8px;\n  border-radius: 50%;\n  width: 14px;\n  height: 14px;\n  background-color: red;\n  background-repeat: no-repeat;\n  background-size: 80%;\n  background-position: center center;\n  background-image: url(\"data:image/svg+xml,%3Csvg xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22 height%3D%2248%22 viewBox%3D%220 -960 960 960%22 width%3D%2248%22 fill%3D%22%23fff%22%3E%3Cpath d%3D%22m249-207-42-42 231-231-231-231 42-42 231 231 231-231 42 42-231 231 231 231-42 42-231-231-231 231Z%22%2F%3E%3C%2Fsvg%3E\");\n}\n\n.delete-button-sXPbV:hover {\n  cursor: pointer;\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 Item = function Item(_ref) {
  var _renderLayer, _selectedElement$meta;
  var selectedElement = _ref.selectedElement,
    paletteId = _ref.paletteId;
  var viewHandler = useViewHandler();
  var _useTranslation = useTranslation(),
    t = _useTranslation.t;
  var _useDivaCore = useDivaCore(),
    _useDivaCore$state$di = _useDivaCore.state.dimensions,
    isMobile = _useDivaCore$state$di.isMobile,
    isTablet = _useDivaCore$state$di.isTablet;
  var _useState = useState(''),
    _useState2 = _slicedToArray(_useState, 2),
    metaDataVisible = _useState2[0],
    setMetaDataVisible = _useState2[1];
  /* tool tip stuff*/
  var triggerProps = {};
  var layerProps = {};
  var renderLayer = undefined;
  var isOver = false;
  var hoverProps = {};
  var hover = useHover({
    delayEnter: 600,
    hideOnScroll: true
  });
  var tooltip = useLayer({
    isOpen: hover[0],
    auto: true,
    placement: viewHandler.getViewConfig().tooltipPosition || 'left-center'
  });
  if (!isMobile && !isTablet && !viewHandler.getViewConfig().hideTooltip) {
    isOver = hover[0];
    hoverProps = hover[1];
    triggerProps = tooltip.triggerProps;
    layerProps = tooltip.layerProps;
    renderLayer = tooltip.renderLayer;
  }
  var notRelevant = selectedElement.codex.includes('OPV_NICHT_RELEVANT');
  var isTextElement = !selectedElement.image && !selectedElement.hexColor;
  if (notRelevant) return /*#__PURE__*/jsx(Fragment, {});
  return /*#__PURE__*/jsxs("div", {
    className: classnames(wrapper, isTextElement ? textWrapper : undefined),
    children: [/*#__PURE__*/createElement("div", _objectSpread(_objectSpread(_objectSpread({}, triggerProps), hoverProps), {}, {
      key: selectedElement.codex,
      className: classnames(element, isTextElement ? elementText : undefined),
      onClick: function onClick() {
        return viewHandler.paletteViewHandler.scrollToOPV(paletteId, selectedElement.codex);
      },
      title: t('configurator.scroll_there', 'hier hin scrollen')
    }), selectedElement.image ? /*#__PURE__*/jsx("img", {
      className: image,
      src: selectedElement.image
    }) : selectedElement.hexColor ? /*#__PURE__*/jsx("div", {
      className: hexColor,
      style: {
        backgroundColor: '#' + selectedElement.hexColor
      }
    }) : /*#__PURE__*/jsxs(Fragment, {
      children: [/*#__PURE__*/jsx("div", {
        className: text,
        children: selectedElement.text
      }), /*#__PURE__*/jsx(MetaData, {
        metaData: selectedElement.metaData,
        visible: [metaDataVisible, setMetaDataVisible]
      }, selectedElement.codex)]
    }), isOver && ((_renderLayer = renderLayer) === null || _renderLayer === void 0 ? void 0 : _renderLayer(/*#__PURE__*/jsx(GenericToolTip, {
      text: selectedElement.text,
      codex: (_selectedElement$meta = selectedElement.metaData) === null || _selectedElement$meta === void 0 || (_selectedElement$meta = _selectedElement$meta.find(function (m) {
        return m.codex === 'codex';
      })) === null || _selectedElement$meta === void 0 ? void 0 : _selectedElement$meta.values[0],
      image: selectedElement.image,
      hexColor: selectedElement.hexColor,
      layerProps: layerProps
    }, selectedElement.codex)))), /*#__PURE__*/jsx("div", {
      onClick: function onClick() {
        return viewHandler.paletteViewHandler.clickedOnConfigPalette(selectedElement, undefined, paletteId);
      },
      className: deleteButton,
      title: t('configurator.remove_selection', 'Auswahl entfernen')
    })]
  });
};
var Item$1 = observer(Item);

export { Item$1 as default };
