Liferay.Loader.define("commerce-frontend-js@4.0.75/components/price/Price",["module","exports","require","liferay!frontend-js-react-web$classnames","liferay!frontend-js-react-web$prop-types","liferay!frontend-js-react-web$react","../../utilities/eventsDefinitions","./util/index"],(function(e,t,r){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var a=_interopRequireDefault(r("liferay!frontend-js-react-web$classnames")),n=(_interopRequireDefault(r("liferay!frontend-js-react-web$prop-types")),function _interopRequireWildcard(e){if(e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=_getRequireWildcardCache();if(t&&t.has(e))return t.get(e);var r={},a=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var n in e)if(Object.prototype.hasOwnProperty.call(e,n)){var c=a?Object.getOwnPropertyDescriptor(e,n):null;c&&(c.get||c.set)?Object.defineProperty(r,n,c):r[n]=e[n]}r.default=e,t&&t.set(e,r);return r}(r("liferay!frontend-js-react-web$react"))),c=r("../../utilities/eventsDefinitions"),i=r("./util/index");function _getRequireWildcardCache(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return _getRequireWildcardCache=function _getRequireWildcardCache(){return e},e}function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function ownKeys(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,a)}return r}function _objectSpread(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?ownKeys(Object(r),!0).forEach((function(t){_defineProperty(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):ownKeys(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function _defineProperty(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function Price({compact:e,displayDiscountLevels:t,namespace:r,netPrice:l,price:o,standalone:u}){const[s,p]=(0,n.useState)((0,i.adaptLegacyPriceModel)(o)),f=t?(0,i.collectDiscountLevels)(s):[],d=(0,i.isNonnull)(s.discountPercentage,...f),m=(0,i.isNonnull)(s.promoPrice),updatePrice=({cpInstance:e})=>p((t=>_objectSpread(_objectSpread({},t),(0,i.adaptLegacyPriceModel)(e.prices))));(0,n.useEffect)((()=>(r&&Liferay.on("".concat(r).concat(c.CP_INSTANCE_CHANGED),updatePrice),()=>{r&&Liferay.detach("".concat(r).concat(c.CP_INSTANCE_CHANGED),updatePrice)})),[r]),(0,n.useEffect)((()=>{p((0,i.adaptLegacyPriceModel)(o))}),[o]);const y=n.default.createElement(n.default.Fragment,null,n.default.createElement("span",{className:"price-label"},Liferay.Language.get("list-price")),n.default.createElement("span",{className:(0,a.default)({"price-value":!0,"price-value-inactive":m||d})},s.priceFormatted),m&&n.default.createElement(n.default.Fragment,null,n.default.createElement("span",{className:"price-label"},Liferay.Language.get("promotion-price")),n.default.createElement("span",{className:(0,a.default)("price-value price-value-promo",d&&"price-value-inactive")},s.promoPriceFormatted)),d&&n.default.createElement(n.default.Fragment,null,n.default.createElement("span",{className:"price-label"},Liferay.Language.get("discount")),n.default.createElement("span",{className:"price-value price-value-discount"},t?f.map(((e,t)=>n.default.createElement("span",{className:"price-value-percentages",key:t},"00"===e.slice(-2)?e.slice(0,e.length-3):e))):n.default.createElement("span",{className:"price-value-percentage"},"–",s.discountPercentage,"%")),n.default.createElement("span",{className:"price-label"},l?Liferay.Language.get("net-price"):Liferay.Language.get("gross-price")),n.default.createElement("span",{className:"price-value price-value-final"},s.finalPriceFormatted)));return u?y:n.default.createElement("div",{className:(0,a.default)({compact:e,price:!0})},y)}Price.defaultProps={compact:!1,displayDiscountLevels:!1,namespace:"",netPrice:!0,standalone:!1};var l=Price;t.default=l}}));
//# sourceMappingURL=Price.js.map