"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

exports.__esModule = true;
exports.ActionsWrapper = void 0;

var _taggedTemplateLiteralLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteralLoose"));

var _react = _interopRequireDefault(require("react"));

var _styledComponents = _interopRequireDefault(require("styled-components"));

var _lib = require("@sentecacommerce-theme/lib");

var _Components = require("./Components");

var _Common = require("../../../Common");

var _reactIntersectionObserver = require("react-intersection-observer");

var _templateObject, _templateObject2;

var ActionsWrapper = function ActionsWrapper(_ref) {
  var _selectedVariant$quan, _selectedVariant$offe, _selectedVariant$offe2;

  var onAddToBasket = _ref.onAddToBasket,
      isSizeSelected = _ref.isSizeSelected,
      show = _ref.show;

  var _useInView = (0, _reactIntersectionObserver.useInView)(),
      basketRef = _useInView[0],
      BasketIsInView = _useInView[1];

  var _useConfigState = (0, _lib.useConfigState)(),
      views = _useConfigState.views;

  var _useUIFunctions = (0, _lib.useUIFunctions)(),
      enqueueView = _useUIFunctions.enqueueView;

  var labels = (0, _lib.useLocalLabels)();

  var onAddCallback = function onAddCallback() {
    if (!isSizeSelected) {
      onAddToBasket == null ? void 0 : onAddToBasket();
    } else {
      enqueueView(views.bagModal, {
        selectedVariant: selectedVariant,
        metaData: metaData,
        modalState: {
          isOpen: true,
          type: 'basket'
        }
      });
    }
  };

  var _useProductState = (0, _lib.useProductState)(),
      metaData = _useProductState.metaData,
      selectedVariant = _useProductState.selectedVariant;

  var availableQuantity = (_selectedVariant$quan = selectedVariant == null ? void 0 : selectedVariant.quantity) != null ? _selectedVariant$quan : 0;
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(Container, {
    className: "row g-2"
  }, availableQuantity < 5 && availableQuantity > 0 && /*#__PURE__*/_react["default"].createElement(HurryUpMessage, null, labels.hurryUp, " ", availableQuantity, ' ', availableQuantity === 1 ? labels.item : labels.items, ' '), /*#__PURE__*/_react["default"].createElement("div", {
    className: "col-12",
    ref: basketRef
  }, /*#__PURE__*/_react["default"].createElement(_Components.AddToBasketButton, {
    productId: metaData._id,
    variantId: selectedVariant == null ? void 0 : selectedVariant._id,
    offerId: selectedVariant == null ? void 0 : (_selectedVariant$offe = selectedVariant.offer) == null ? void 0 : _selectedVariant$offe._id,
    isSizeSelected: isSizeSelected,
    onAddCallback: onAddCallback,
    metaData: metaData
  })), /*#__PURE__*/_react["default"].createElement("div", {
    className: "col-9 mt-1 pt-2"
  }, /*#__PURE__*/_react["default"].createElement(_Common.Button, {
    variant: "primary",
    onClick: function onClick() {
      return enqueueView(views.bagModal, {
        selectedVariant: selectedVariant,
        metaData: metaData,
        modalState: {
          isOpen: true,
          type: 'basket'
        }
      });
    },
    fullWidth: true,
    bordered: true,
    borderRadius: "large"
  }, labels.quickBuy)), /*#__PURE__*/_react["default"].createElement("div", {
    className: "col-3 pt-2 mt-1"
  }, /*#__PURE__*/_react["default"].createElement(_lib.WishlistButton, {
    productId: metaData._id,
    collapseKey: selectedVariant == null ? void 0 : selectedVariant.collapseKey,
    onAddCallback: function onAddCallback() {
      return enqueueView(views.bagModal, {
        selectedVariant: selectedVariant,
        metaData: metaData,
        modalState: {
          isOpen: true,
          type: 'wishlist'
        }
      });
    }
  }, /*#__PURE__*/_react["default"].createElement(_Components.AddToFavoritesButton, null))), /*#__PURE__*/_react["default"].createElement(_Components.StickyAddToBasket, {
    show: show && !BasketIsInView
  }, /*#__PURE__*/_react["default"].createElement(_Components.AddToBasketButton, {
    productId: metaData._id,
    variantId: selectedVariant == null ? void 0 : selectedVariant._id,
    offerId: selectedVariant == null ? void 0 : (_selectedVariant$offe2 = selectedVariant.offer) == null ? void 0 : _selectedVariant$offe2._id,
    isSizeSelected: isSizeSelected,
    onAddCallback: onAddCallback,
    metaData: metaData,
    isSticky: true
  }))));
};

exports.ActionsWrapper = ActionsWrapper;

var Container = _styledComponents["default"].div(_templateObject || (_templateObject = (0, _taggedTemplateLiteralLoose2["default"])([""])));

var HurryUpMessage = (0, _styledComponents["default"])(_Common.Typography).attrs({})(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteralLoose2["default"])(["\n  color: ", ";\n"])), function (_ref2) {
  var theme = _ref2.theme;
  return theme.palette.danger;
});
//# sourceMappingURL=index.js.map