import _taggedTemplateLiteralLoose from "@babel/runtime/helpers/taggedTemplateLiteralLoose";

var _templateObject, _templateObject2;

import React from 'react';
import styled from 'styled-components';
import { useProductState, WishlistButton, useUIFunctions, useConfigState, useLocalLabels } from '@sentecacommerce-theme/lib';
import { AddToFavoritesButton, AddToBasketButton, StickyAddToBasket } from './Components';
import { Button, Typography } from '../../../Common';
import { useInView } from 'react-intersection-observer';
export var ActionsWrapper = (_ref) => {
  var _selectedVariant$quan, _selectedVariant$offe, _selectedVariant$offe2;

  var {
    onAddToBasket,
    isSizeSelected,
    show
  } = _ref;
  var [basketRef, BasketIsInView] = useInView();
  var {
    views
  } = useConfigState();
  var {
    enqueueView
  } = useUIFunctions();
  var labels = useLocalLabels();

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

  var {
    metaData,
    selectedVariant
  } = useProductState();
  var availableQuantity = (_selectedVariant$quan = selectedVariant == null ? void 0 : selectedVariant.quantity) != null ? _selectedVariant$quan : 0;
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Container, {
    className: "row g-2"
  }, availableQuantity < 5 && availableQuantity > 0 && /*#__PURE__*/React.createElement(HurryUpMessage, null, labels.hurryUp, " ", availableQuantity, ' ', availableQuantity === 1 ? labels.item : labels.items, ' '), /*#__PURE__*/React.createElement("div", {
    className: "col-12",
    ref: basketRef
  }, /*#__PURE__*/React.createElement(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.createElement("div", {
    className: "col-9 mt-1 pt-2"
  }, /*#__PURE__*/React.createElement(Button, {
    variant: "primary",
    onClick: () => enqueueView(views.bagModal, {
      selectedVariant: selectedVariant,
      metaData: metaData,
      modalState: {
        isOpen: true,
        type: 'basket'
      }
    }),
    fullWidth: true,
    bordered: true,
    borderRadius: "large"
  }, labels.quickBuy)), /*#__PURE__*/React.createElement("div", {
    className: "col-3 pt-2 mt-1"
  }, /*#__PURE__*/React.createElement(WishlistButton, {
    productId: metaData._id,
    collapseKey: selectedVariant == null ? void 0 : selectedVariant.collapseKey,
    onAddCallback: () => enqueueView(views.bagModal, {
      selectedVariant: selectedVariant,
      metaData: metaData,
      modalState: {
        isOpen: true,
        type: 'wishlist'
      }
    })
  }, /*#__PURE__*/React.createElement(AddToFavoritesButton, null))), /*#__PURE__*/React.createElement(StickyAddToBasket, {
    show: show && !BasketIsInView
  }, /*#__PURE__*/React.createElement(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
  }))));
};
var Container = styled.div(_templateObject || (_templateObject = _taggedTemplateLiteralLoose([""])));
var HurryUpMessage = styled(Typography).attrs({})(_templateObject2 || (_templateObject2 = _taggedTemplateLiteralLoose(["\n  color: ", ";\n"])), (_ref2) => {
  var {
    theme
  } = _ref2;
  return theme.palette.danger;
});
//# sourceMappingURL=index.js.map