import _defineProperty from '@babel/runtime/helpers/defineProperty';
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
import { u as useViewHandler, G as GenericToolTip, P as PricePreview } from './index-bbdfb97a.js';
import classnames from 'classnames';
import { observer } from 'mobx-react-lite';
import { useState } from 'react';
import { w as wcSize, d as wcSizeSmall, e as wcImagePlaceHolder, b as wcImage, t as textContainer, f as big, c as wcConfiguratorSettingsTitle, m as metaData, g as ccConstructionWarning, p as paletteItem, s as sel } from './index.module-fe49e10f.js';
import { w as wcFavoriteSel, a as wcFavorite } from './index.module-25687dd9.js';
import { useTranslation, useDivaCore } from '@crystaldesign/diva-core';
import IsActive from './index-3f40a92d.js';
import { useHover, useLayer } from 'react-laag';
import MetaData from './index-7635bafb.js';
import InfoIcon from './index-04a7a9b4.js';
import ReverseCheck from './index-755074ae.js';
import { jsxs, 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';
import '@mui/icons-material/Block';
import '@mui/icons-material/Warning';

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 Option = function Option(_ref) {
  var _renderLayer;
  var itemP = _ref.item,
    paletteId = _ref.paletteId,
    hidePricePreview = _ref.hidePricePreview,
    namePostFix = _ref.namePostFix;
  var item = itemP;
  var viewHandler = useViewHandler();
  var _useTranslation = useTranslation(),
    t = _useTranslation.t;
  var onClick = function onClick() {
    if (item.doShowFav) {
      viewHandler.paletteViewHandler.clickedOnFavIcon(item);
    }
    viewHandler.paletteViewHandler.clickedOnConfigPalette(item, undefined, paletteId);
  };
  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: 1500,
    hideOnScroll: true
  });
  var tooltip = useLayer({
    isOpen: hover[0],
    auto: true,
    placement: viewHandler.getViewConfig().tooltipPosition || 'left-center'
  });
  if (!isMobile && !isTablet && !viewHandler.getViewConfig().hideTooltip && (item.image || item.hexColor) && !item.contentItemId) {
    isOver = hover[0];
    hoverProps = hover[1];
    triggerProps = tooltip.triggerProps;
    layerProps = tooltip.layerProps;
    renderLayer = tooltip.renderLayer;
  }
  return /*#__PURE__*/jsxs("div", _objectSpread(_objectSpread(_objectSpread({
    id: item.codex,
    "data-test-id": "plannerPaletteItem",
    className: classnames(paletteItem, item.sel ? sel : undefined),
    onClick: onClick
  }, triggerProps), hoverProps), {}, {
    children: [/*#__PURE__*/jsxs("div", {
      className: classnames(wcSize, wcSizeSmall),
      children: [item.sel && /*#__PURE__*/jsx(IsActive, {
        listenToOptionVariables: true
      }), item.contentItemId && /*#__PURE__*/jsx(InfoIcon, {
        item: item,
        style: {
          bottom: 8
        }
      }, item.codex), item.layout == 'TEXT' && /*#__PURE__*/jsx("div", {
        className: wcImagePlaceHolder
      }), !(item.layout == 'TEXT') && /*#__PURE__*/jsx("div", {
        className: wcImage,
        style: {
          backgroundImage: "url(".concat(item.image, ")")
        }
      }), /*#__PURE__*/jsxs("div", {
        className: classnames(textContainer, item.layout == 'TEXT' ? big : undefined),
        children: [/*#__PURE__*/jsx("div", {
          className: classnames(wcConfiguratorSettingsTitle, metaDataVisible !== '' ? metaData : undefined),
          dangerouslySetInnerHTML: {
            __html: item.text + (namePostFix ? namePostFix : '')
          }
        }), /*#__PURE__*/jsx(MetaData, {
          style: {
            position: 'relative',
            "float": 'left'
          },
          metaData: item.metaData,
          visible: [metaDataVisible, setMetaDataVisible]
        }, item.codex)]
      }), isOver && ((_renderLayer = renderLayer) === null || _renderLayer === void 0 ? void 0 : _renderLayer(/*#__PURE__*/jsx(GenericToolTip, {
        text: item.text + (item.freeText ? item.freeText : '') + (namePostFix ? namePostFix : ''),
        desciption: metaDataVisible,
        image: item.image,
        hexColor: item.hexColor,
        pricePreviewPromise: item.pricePreviewPromise,
        layerProps: layerProps
      }, item.codex))), item.doShowFav && /*#__PURE__*/jsx("div", {
        className: item.isFav ? wcFavoriteSel : wcFavorite
      })]
    }), !hidePricePreview && item.pricePreviewPromise !== undefined && /*#__PURE__*/jsx(PricePreview, {
      asyncPricePreview: item.pricePreviewPromise,
      sel: item.sel
    }), item.checkForReversingChanges !== undefined && /*#__PURE__*/jsx(ReverseCheck, {
      item: item,
      paletteId: paletteId
    }), item.disabledByConstructionRule && /*#__PURE__*/jsx("div", {
      className: classnames(ccConstructionWarning),
      title: t('configurator.' + item.disabledByConstructionRule)
    })]
  }));
};
var Option$1 = observer(Option);

export { Option$1 as default };
