/* eslint-disable @typescript-eslint/no-unused-vars */

/* eslint-disable react-hooks/exhaustive-deps */
import { useEffect } from 'react';
import { usePrice, useProductState } from '@sentecacommerce-theme/lib';
export var UpdateProductPrice = (_ref) => {
  var _selectedVariant$offe, _selectedVariant$offe2, _selectedVariant$offe3, _selectedVariant$offe4;

  var {
    updatePrice,
    priceState
  } = _ref;
  var {
    selectedVariant
  } = useProductState();
  var {
    price,
    discountPrice
  } = usePrice({
    price: selectedVariant == null ? void 0 : (_selectedVariant$offe = selectedVariant.offers) == null ? void 0 : (_selectedVariant$offe2 = _selectedVariant$offe[0]) == null ? void 0 : _selectedVariant$offe2.originalPrice,
    discountedPrice: selectedVariant == null ? void 0 : (_selectedVariant$offe3 = selectedVariant.offers) == null ? void 0 : (_selectedVariant$offe4 = _selectedVariant$offe3[0]) == null ? void 0 : _selectedVariant$offe4.discountedPrice
  });
  var priceValue = price.value;
  var discountPriceValue = discountPrice ? discountPrice == null ? void 0 : discountPrice.value : undefined;
  var statePriceValue = priceState.price;
  var stateDiscountValue = priceState.discountedPrice;
  useEffect(() => {
    if (!priceValue) return;

    if (priceValue && statePriceValue === priceValue && stateDiscountValue === discountPriceValue) {
      return;
    }

    updatePrice({
      price: priceValue,
      discountedPrice: discountPriceValue
    });
  }, [priceValue, discountPriceValue, stateDiscountValue, statePriceValue]);
  return null;
};
//# sourceMappingURL=index.js.map