UNPKG

@commercelayer/react-components

Version:
2 lines 1.29 kB
"use client"; "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getPriceByCode=getPriceByCode,exports.getPricesComponent=getPricesComponent,exports.default=getPrices;const tslib_1=require("tslib"),react_1=require("react"),jsx_runtime_1=require("react/jsx-runtime"),lodash_1=require("lodash"),PriceTemplate_1=tslib_1.__importDefault(require("../components/utils/PriceTemplate"));function getPriceByCode(skuPrices,code=""){return code?(0,lodash_1.first)(skuPrices.filter(p=>p.currency_code===code)):(0,lodash_1.first)(skuPrices)}function getPricesComponent(skuPrices,props){return(0,lodash_1.isEmpty)(skuPrices)?(0,jsx_runtime_1.jsx)(PriceTemplate_1.default,Object.assign({},props)):skuPrices.map((p,k)=>{const showCompare=typeof props.showCompare>"u"&&p?.compare_at_amount_cents!=null&&p?.compare_at_amount_cents>p?.amount_cents||props.showCompare;return(0,react_1.createElement)(PriceTemplate_1.default,Object.assign({},props,{key:k,showCompare,formattedAmount:p.formatted_amount,formattedCompare:p.formatted_compare_at_amount,skuCode:p.sku_code}))})}function getPrices(prices){const obj={};return(0,lodash_1.isArray)(prices)&&prices.forEach(p=>{var _a;const sku=(_a=p?.sku_code)!==null&&_a!==void 0?_a:"";(0,lodash_1.has)(obj,sku)?obj[sku].push(p):obj[sku]=[p]}),obj}