"use strict";

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

exports.__esModule = true;
exports.VariantsLoader = 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 _ColorsPreview = require("../ColorsPreview");

var _SizesPreview = require("../SizesPreview");

var _UpdateProductPrice = require("../UpdateProductPrice");

var _templateObject, _templateObject2;

var VariantsLoader = function VariantsLoader(_ref) {
  var slug = _ref.slug,
      updateImages = _ref.updateImages,
      updatePrice = _ref.updatePrice,
      priceState = _ref.priceState,
      showVariants = _ref.showVariants;

  var _productsApi$useProdu = _lib.productsApi.useProduct(slug),
      data = _productsApi$useProdu.data,
      isLoading = _productsApi$useProdu.isLoading;

  if (!data || isLoading) return null;
  return /*#__PURE__*/_react["default"].createElement(_lib.ProductProvider, {
    product: data
  }, /*#__PURE__*/_react["default"].createElement(_ColorsPreview.ColorsPreview, {
    masterVariantId: data.masterVariantId,
    updateImages: updateImages
  }), /*#__PURE__*/_react["default"].createElement(FadeIn, {
    isVisible: showVariants
  }, /*#__PURE__*/_react["default"].createElement(OnlyWhenHover, null, showVariants && /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_SizesPreview.SizesPreview, null), /*#__PURE__*/_react["default"].createElement(_UpdateProductPrice.UpdateProductPrice, {
    priceState: priceState,
    updatePrice: updatePrice
  })))));
};

exports.VariantsLoader = VariantsLoader;

var FadeIn = _styledComponents["default"].div(_templateObject || (_templateObject = (0, _taggedTemplateLiteralLoose2["default"])(["\n  transition: opacity 0.4s cubic-bezier(0.25, 0.1, 0.25, 1);\n  transition-delay: ", ";\n  opacity: ", ";\n"])), function (props) {
  return props.isVisible ? '0.3s' : 0;
}, function (props) {
  return props.isVisible ? 1 : 0;
});

var OnlyWhenHover = _styledComponents["default"].div(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteralLoose2["default"])(["\n  display: none;\n\n  @media (hover: hover) {\n    display: block;\n    position: relative;\n    z-index: 1;\n  }\n"])));
//# sourceMappingURL=index.js.map