UNPKG

@shopgate/engage

Version:
7 lines 1.6 kB
function _extends(){_extends=Object.assign||function(target){for(var i=1;i<arguments.length;i++){var source=arguments[i];for(var key in source){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key];}}}return target;};return _extends.apply(this,arguments);}/* eslint-disable react/prop-types */import React from'react';import TimeBoundary from"../../components/TimeBoundary";import{useWidgetSettings}from"../../core";/** * @param {Function|React.Component} PriceComponent price component with product price shape * @returns {Function} */var withMapPricing=function withMapPricing(PriceComponent){return function(props){var settings=useWidgetSettings('@shopgate/engage/product/MapPrice');if(!settings.show){return React.createElement(PriceComponent,props);}// price is null OR no map pricing if(!props.price||!props.price.mapPricing){return React.createElement(PriceComponent,props);}// Same logic as in selector var mapPrice=[].concat(props.price.mapPricing)[0];if(!mapPrice){return React.createElement(PriceComponent,props);}// Show original when map is equal or less if(props.price.unitPrice>=mapPrice.price){return React.createElement(PriceComponent,props);}return React.createElement(TimeBoundary,{start:new Date(mapPrice.startDate),end:new Date(mapPrice.endDate)},function(_ref){var between=_ref.between;if(!between){return React.createElement(PriceComponent,props);}return React.createElement(PriceComponent,_extends({},props,{price:_extends({},props.price,{unitPriceStriked:mapPrice.price})}));});};};export default withMapPricing;/* eslint-enable react/prop-types */