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

var container = "container-5GMrB";
var buttonDropdown = "button-dropdown-hJTTc";
var open = "open-cFdzA";
var icon = "icon-7uXLI";
var column = "column-SanUs";
var button = "button-qcl7w";
var actionButton = "action-button-nTgLc";
var actionButtonDisabled = "action-button-disabled--LWWq";
var secondButton = "second-button-KGVxc";
var row = "row-bjrma";
var iconColor = "icon-color-hyBQn";
var saveIcon = "save-icon-s5mPx";
var sendIcon = "send-icon-O6d2-";
var css_248z = ".container-5GMrB {\n  display: flex;\n  flex-direction: row;\n  margin-left: 16px;\n}\n\n.button-dropdown-hJTTc {\n  border: 1px solid #cacaca;\n  border-radius: 4px;\n  position: absolute;\n  bottom: 105%;\n  left: 0;\n  right: -5px;\n  padding: 0.84em 1em;\n  color: #000;\n  color: initial;\n  display: none;\n  flex-direction: column;\n}\n\n.button-dropdown-hJTTc.open-cFdzA {\n  display: flex;\n}\n\n.button-dropdown-hJTTc .icon-7uXLI {\n  filter: brightness(0.1);\n}\n.button-dropdown-hJTTc .column-SanUs:hover {\n  color: var(--primaryColor);\n}\n\n.button-qcl7w {\n  position: relative;\n  font-weight: 100;\n  border-radius: 32px;\n  transition: background-color 0.25s ease-out, color 0.25s ease-out;\n  font-size: 0.9rem;\n  line-height: 18px;\n  text-align: center;\n  cursor: pointer;\n  box-sizing: border-box;\n  display: inline-block;\n  vertical-align: middle;\n  margin: 0 0.5rem 1rem 0;\n  padding: 0.85em 1em;\n  -webkit-appearance: none;\n  border: 1px solid transparent;\n}\n\n.action-button-nTgLc {\n  background-color: var(--primaryColor);\n  color: #fefefe;\n}\n\n.action-button-disabled--LWWq {\n  opacity: 0.25;\n  cursor: not-allowed;\n}\n\n.action-button-nTgLc:hover {\n  filter: brightness(0.9);\n}\n\n.second-button-KGVxc {\n  background-color: transparent;\n  border-color: var(--primaryColor);\n  color: var(--primaryColor);\n  padding: 0.85em 1em 0.85em 0.25em;\n}\n\n.second-button-KGVxc:hover {\n  fill: #202020 !important;\n}\n\n.second-button-KGVxc:hover {\n  border-color: #202020;\n  color: #202020;\n}\n\n.row-bjrma {\n  float: left;\n}\n.second-button-KGVxc .row-bjrma {\n  padding-left: 0.5em;\n}\n\n.column-SanUs {\n  margin: 0.5em 0;\n}\n\n.icon-7uXLI {\n  background-repeat: no-repeat;\n  background-position: center center;\n  background-size: contain;\n  width: 20px;\n  height: 20px;\n}\n.icon-color-hyBQn {\n  fill: var(--primaryColor);\n  transition: fill 0.25s ease-out, color 0.25s ease-out;\n}\n\n.second-button-KGVxc:hover .icon-color-hyBQn {\n  fill: black;\n}\n\n.save-icon-s5mPx {\n  background-image: url(\"data:image/svg+xml,%3Csvg width%3D%2242%22 height%3D%2242%22 viewBox%3D%220 0 3400 3400%22 xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E  %3Cpath    fill%3D%22white%22    transform%3D%22scale(1%2C-1) translate(450%2C-2600)%22    strokeWidth%3D%221%22    d%3D%22M783 255l-325 325l-70 70l-391 391q-14 15 -14 35.5t14 35.5l325 325q14 14 35 14t35 -14l391 -391q15 -15 35.5 -15t35.5 15l1049 1049q15 15 35.5 15t35.5 -15l327 -322q15 -15 15 -35q0 -21 -15 -35l-1447 -1448q-15 -14 -35.5 -14t-35.5 14z%22     %2F%3E%3C%2Fsvg%3E\");\n}\n.send-icon-O6d2- {\n  background-image: url(\"data:image/svg+xml,%3Csvg width%3D%2242%22 height%3D%2242%22 viewBox%3D%220 0 3400 3400%22 xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E  %3Cpath    fill%3D%22white%22    transform%3D%22scale(1%2C-1) translate(450%2C-2600)%22    strokeWidth%3D%221%22d%3D%22M921 89q-43 -54 -75 -54q-22 0 -34 25.5t-12 72.5v767h-708q-91 0 -91 31q0 26 63 65l2063 1278q42 26 79 26q42 0 68 -32t26 -88v-1800q0 -57 -26.5 -89.5t-69.5 -32.5q-37 0 -78 25l-712 425zM1000 480l1186 1700l-1186 -1300v-400z%22%2F%3E%3C%2Fsvg%3E\");\n}\n\n.reset-icon-HqNs3 path {\n  background-color: var(--primaryColor);\n}\n";
styleInject(css_248z);

var LOG = getLogger('Planner', 'BasketActionSerious');
var BasketActionSerious = function BasketActionSerious(_ref) {
  var saveIsDisabled = _ref.saveIsDisabled,
    sendEmailIsDisabled = _ref.sendEmailIsDisabled,
    onSave = _ref.onSave;
  var viewHandler = useViewHandler();
  var _useTranslation = useTranslation(),
    t = _useTranslation.t;
  var _useState = useState(false),
    _useState2 = _slicedToArray(_useState, 2),
    openDropdown = _useState2[0],
    setOpen = _useState2[1];
  var _useDivaCore = useDivaCore(),
    _useDivaCore$actions = _useDivaCore.actions,
    userHasPermission = _useDivaCore$actions.userHasPermission,
    openSnackBar = _useDivaCore$actions.openSnackBar;
  var onClickReset = function onClickReset() {
    var _viewHandler$actions;
    (_viewHandler$actions = viewHandler.actions) === null || _viewHandler$actions === void 0 || _viewHandler$actions.openModal({
      title: t('modals.reset'),
      accept: true,
      reject: true,
      text: t('modals.are_you_sure_to_reset'),
      callback: function callback(accepted) {
        if (accepted) {
          viewHandler.productState.onClickReset();
        }
      }
    });
  };
  var onClickSave = /*#__PURE__*/function () {
    var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(type) {
      var _viewHandler$getViewC, _viewHandler$getViewC2, _viewHandler$divaWebP, url, _viewHandler$getViewC3, _viewHandler$getViewC4;
      return _regeneratorRuntime.wrap(function _callee$(_context) {
        while (1) switch (_context.prev = _context.next) {
          case 0:
            _context.t0 = type;
            _context.next = _context.t0 === 'email' ? 3 : _context.t0 === 'save' ? 8 : 13;
            break;
          case 3:
            if (!(!saveIsDisabled && !sendEmailIsDisabled)) {
              _context.next = 7;
              break;
            }
            onSave();
            _context.next = 7;
            return viewHandler.actionButtonState.onClickAddToBasket(viewHandler, 'onSendEmail');
          case 7:
            return _context.abrupt("break", 13);
          case 8:
            if (saveIsDisabled) {
              _context.next = 12;
              break;
            }
            onSave();
            _context.next = 12;
            return viewHandler.actionButtonState.onClickAddToBasket(viewHandler);
          case 12:
            return _context.abrupt("break", 13);
          case 13:
            if (!viewHandler.getViewConfig().showPdfQR) {
              _context.next = 22;
              break;
            }
            if (!(typeof viewHandler.getViewConfig().showPdfQR == 'boolean')) {
              _context.next = 18;
              break;
            }
            if (viewHandler.divaWebPlanner.getBasket().PDFDocumentURL) {
              openSnackBar({
                type: 'big',
                qrCode: viewHandler.divaWebPlanner.getBasket().PDFDocumentURL,
                message: t('basket.checkout.pdfqr'),
                autoHideDuration: (_viewHandler$getViewC = viewHandler.getViewConfig().pdfQRAutoHideDuration) !== null && _viewHandler$getViewC !== void 0 ? _viewHandler$getViewC : 1000 * 60 * 2,
                clickable: !((_viewHandler$getViewC2 = viewHandler.getViewConfig().pdfQRNotClickable) !== null && _viewHandler$getViewC2 !== void 0 ? _viewHandler$getViewC2 : false),
                qrCodeSize: 312
              });
            } else {
              LOG.warn('Basket is missing a pdf, no QR-Code displayed');
            }
            _context.next = 22;
            break;
          case 18:
            _context.next = 20;
            return (_viewHandler$divaWebP = viewHandler.divaWebPlanner.actSet()) === null || _viewHandler$divaWebP === void 0 ? void 0 : _viewHandler$divaWebP.api.createBasketReport(viewHandler.divaWebPlanner.getBasket(), viewHandler.getViewConfig().showPdfQR, viewHandler.getViewConfig().savePdfQR);
          case 20:
            url = _context.sent;
            if (url) {
              openSnackBar({
                type: 'big',
                qrCode: url,
                qrCodeSize: 312,
                message: t('basket.checkout.pdfqr'),
                autoHideDuration: (_viewHandler$getViewC3 = viewHandler.getViewConfig().pdfQRAutoHideDuration) !== null && _viewHandler$getViewC3 !== void 0 ? _viewHandler$getViewC3 : 1000 * 60 * 2,
                clickable: !((_viewHandler$getViewC4 = viewHandler.getViewConfig().pdfQRNotClickable) !== null && _viewHandler$getViewC4 !== void 0 ? _viewHandler$getViewC4 : false)
              });
            } else {
              LOG.warn('Could not generate PDF, no QR-Code displayed');
            }
          case 22:
          case "end":
            return _context.stop();
        }
      }, _callee);
    }));
    return function onClickSave(_x) {
      return _ref2.apply(this, arguments);
    };
  }();
  var onClickFavorites = function onClickFavorites() {
    var _viewHandler$actions2;
    (_viewHandler$actions2 = viewHandler.actions) === null || _viewHandler$actions2 === void 0 || _viewHandler$actions2.openModal({
      title: t('modals.favorite'),
      accept: true,
      reject: true,
      text: t('modals.are_you_sure_favorite'),
      callback: function () {
        var _callback = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(accepted) {
          var _viewHandler$actions3;
          return _regeneratorRuntime.wrap(function _callee2$(_context2) {
            while (1) switch (_context2.prev = _context2.next) {
              case 0:
                if (!accepted) {
                  _context2.next = 5;
                  break;
                }
                onSave();
                _context2.next = 4;
                return viewHandler.actionButtonState.onClickAddToBasket(viewHandler, 'onSaveProduct');
              case 4:
                (_viewHandler$actions3 = viewHandler.actions) === null || _viewHandler$actions3 === void 0 || _viewHandler$actions3.openModal({
                  title: t('modals.favorite'),
                  accept: true,
                  text: t('modals.favorites_saved')
                });
              case 5:
              case "end":
                return _context2.stop();
            }
          }, _callee2);
        }));
        function callback(_x2) {
          return _callback.apply(this, arguments);
        }
        return callback;
      }()
    });
  };
  return /*#__PURE__*/jsxs("div", {
    className: container,
    children: [/*#__PURE__*/jsxs("div", {
      className: classnames(button, actionButton, saveIsDisabled ? actionButtonDisabled : undefined),
      onClick: function onClick() {
        if (!saveIsDisabled) setOpen(!openDropdown);
      },
      children: [/*#__PURE__*/jsx("div", {
        className: classnames(row, icon, saveIcon)
      }), /*#__PURE__*/jsxs("div", {
        className: classnames(row),
        children: [" ", t('configurator.ADD_TO_BASKET')]
      }), /*#__PURE__*/jsxs("div", {
        className: classnames(openDropdown ? open : undefined, buttonDropdown),
        children: [/*#__PURE__*/jsxs("div", {
          className: column,
          onClick: function onClick() {
            return onClickSave('save');
          },
          id: "wcConfigurator-action-tobasket",
          children: [/*#__PURE__*/jsx("div", {
            className: classnames(row, icon, saveIcon)
          }), /*#__PURE__*/jsxs("div", {
            className: classnames(row),
            children: [" ", t('configurator.ADD_TO_BASKET')]
          })]
        }), /*#__PURE__*/jsxs("div", {
          className: classnames(column, sendEmailIsDisabled ? actionButtonDisabled : undefined),
          onClick: function onClick() {
            return onClickSave('email');
          },
          children: [/*#__PURE__*/jsx("div", {
            className: classnames(row, icon, sendIcon)
          }), /*#__PURE__*/jsxs("div", {
            className: classnames(row),
            children: [" ", t('configurator.SendToClient')]
          })]
        })]
      })]
    }), /*#__PURE__*/jsxs("div", {
      onClick: onClickReset,
      className: classnames(button, secondButton),
      children: [/*#__PURE__*/jsx("div", {
        className: classnames(row, icon),
        children: /*#__PURE__*/jsx("svg", {
          width: "26",
          height: "22",
          viewBox: "0 0 3400 3400",
          xmlns: "http://www.w3.org/2000/svg",
          children: /*#__PURE__*/jsx("path", {
            className: iconColor,
            transform: "scale(1,-1) translate(450,-2600)",
            strokeWidth: "1",
            d: "M935 2061l-114 277q135 45 279 57v-300q-85 -9 -165 -34zM1435 2069q-71 19 -135 26v300q131 -11 251 -48zM615 1884l-211 212q119 105 260 176l114 -276q-87 -47 -163 -112zM1737 1921q-43 32 -89 59l115 279q99 -53 187 -125zM2007 -3l-148 204l-6 -4 q-146 -95 -321 -145t-332 -51q-172 0 -331.5 43t-291 120.5t-240 188t-182.5 242.5t-114.5 287t-40.5 318q0 225 80 429.5t224 367.5l212 -212q-103 -120 -159.5 -270t-56.5 -314q0 -123 32 -239.5t90 -215t140.5 -181.5t181.5 -141t216 -90.5t240 -31.5q146 0 256.5 34 t226.5 109l-151 212q-8 11 -8 20q0 20 29 19h683q17 0 27.5 -10t10.5 -25q0 -6 -3 -13l-220 -644q-7 -22 -22 -22q-12 0 -22 15zM1964 1673q-20 32 -43 64l213 213q61 -75 109 -161zM2085 1400q-4 0 -10 27l279 126q4 -14 8.5 -35.5t8 -41t6.5 -37.5t6 -28.5t5 -10.5h-303z "
          })
        })
      }), /*#__PURE__*/jsxs("div", {
        className: classnames(row),
        children: [" ", t('configurator.ConfigReset')]
      })]
    }), userHasPermission('favorites_lueck') && /*#__PURE__*/jsxs("div", {
      onClick: onClickFavorites,
      className: classnames(button, secondButton),
      children: [/*#__PURE__*/jsx("div", {
        className: classnames(row, icon),
        children: /*#__PURE__*/jsx("svg", {
          width: "26",
          height: "22",
          viewBox: "0 0 3400 3400",
          xmlns: "http://www.w3.org/2000/svg",
          children: /*#__PURE__*/jsx("path", {
            className: iconColor,
            transform: "scale(1,-1) translate(450,-2600)",
            strokeWidth: "1",
            d: "M2491 1500l-765 -541l291 -885l-768 551l-764 -554l291 883l-776 546h958l294 900h3l292 -900h944zM484 68h-3l4 3z"
          })
        })
      }), /*#__PURE__*/jsxs("div", {
        className: classnames(row),
        children: [" ", t('configurator.Favorites')]
      })]
    })]
  });
};
var BasketActionSerious$1 = observer(BasketActionSerious);

export { BasketActionSerious$1 as default };
