1import{_ as i,T as S,$ as d,S as O}from"./storefrontApp.CsApItsi.min.js";import{e as m,n as V}from"./chunk-vendor-lit.NvY0u02.js";import{P as y}from"./chunk-product_price_changed_handler.BDV5fnm.js";import{P as A}from"./chunk-product_stock_changed_handler.C3zWS6V.js";import{S as q}from"./chunk-storefront_base_lit_element.lX23Jvc.js";import"./chunk-vendor-di.Bh23gdA.js";import"./chunk-storefront_settings_constants.DIF02Gz.js";import"./chunk-vendor-rxjs.Dp7kflo.js";import"./chunk-vendor-lodash.CWHFt7Z.js";import"./chunk-vendor-phoenix.cdKS79L.js";import"./chunk-product_events_constants.BHFu5GP.js";var D=Object.defineProperty,v=Object.getOwnPropertyDescriptor,$=(e,t,r,a)=>{for(var c=a>1?void 0:a?v(t,r):t,n=e.length-1,o;n>=0;n--)(o=e[n])&&(c=(a?o(t,r,c):o(c))||c);return a&&c&&D(t,r,c),c};let u=class extends q{constructor(){super(),this._handleProductPriceChanged=({body:e})=>{e&&(e.productId,this.productId)},this._handleProductStockChanged=({body:e})=>{if(!e||e.productId!==this.productId)return;const t=this._getPriceElements(i.grossPricesContainer),r=this._getPriceElements(i.netPricesContainer),a=e.price.gross,c=e.price.net,n=e.unitPriceCalculation?.unit,o=e.unitPriceCalculation?.gross,l=e.unitPriceCalculation?.net;this._hasSpecialOffer(a)?(this._showSpecialOfferPriceContainer(),e.specialOffer?.endDate.string&&this._updateSpecialOfferDuration(e.specialOffer?.endDate.string)):this._hideSpecialOfferPriceContainer(),this._updatePrice(t,a),this._updatePrice(r,c),n&&o?this._updateUnitPriceCalculation(t.$unitCalculationPrice,o,n):this._toggleUnitPriceCalculationVisibility(t.$unitCalculationPrice,!1),n&&l?this._updateUnitPriceCalculation(r.$unitCalculationPrice,l,n):this._toggleUnitPriceCalculationVisibility(r.$unitCalculationPrice,!1)},this.getApi(S.api).then(e=>{this._translationApi=e})}firstUpdated(e){super.firstUpdated(e),new y(this._handleProductPriceChanged),new A(this._handleProductStockChanged)}_hasSpecialOffer(e){return e.specialOffer!==void 0}_showSpecialOfferPriceContainer(){[...this.querySelectorAll(`.${i.specialOfferContainer}`)].forEach(e=>{e.removeAttribute("hidden")}),[...this.querySelectorAll(`.${i.noSpecialOfferContainer}`)].forEach(e=>{e.setAttribute("hidden","")})}_hideSpecialOfferPriceContainer(){[...this.querySelectorAll(`.${i.specialOfferContainer}`)].forEach(e=>{e.setAttribute("hidden","")}),[...this.querySelectorAll(`.${i.noSpecialOfferContainer}`)].forEach(e=>{e.removeAttribute("hidden")})}_getPriceElements(e){const t=this.querySelector(`.${e} .${i.priceContainer}`),r=this.querySelector(`.${e} .${i.currencyPriceContainer}`),a=t?.querySelector(`.${i.priceBase} .${i.priceValue}`),c=t?.querySelector(`.${i.specialOfferPriceValue}`),n=t?.querySelector(`.${i.specialOfferPercentageValue}`),o=t?.querySelector(`.${i.regularPrice} .${i.priceValueInactive}`),l=r?.querySelector(`.${i.priceBase} .${i.priceValue}`),f=r?.querySelector(`.${i.specialOfferPriceValue}`),P=t?.querySelector(`.${i.lowestHistoricalPriceContainer} .${i.priceValueInactive}`),s=t?.querySelector(`.${i.lowestHistoricalPriceContainer} .${i.lowestHistoricalPricePercentageValue}`),p=t?.querySelector(`.${i.unitCalculationPriceContainer} .${i.unitCalculationPrice}`);return{$basePrice:a,$specialOfferPrice:c,$specialOfferPercentage:n,$currencyBasePrice:l,$currencySpecialOfferPrice:f,$lowestHistoricalPrice:P,$inactiveRegularPrice:o,$lowestHistoricalPricePercentage:s,$unitCalculationPrice:p}}_updatePrice(e,t){const{$basePrice:r,$currencyBasePrice:a,$currencySpecialOfferPrice:c,$specialOfferPrice:n,$specialOfferPercentage:o,$lowestHistoricalPrice:l,$inactiveRegularPrice:f,$lowestHistoricalPricePercentage:P}=e,{base:s,currency:p,specialOffer:h,currencySpecialOffer:_,lowestHistoricalPrice:C,final:g}=t;r&&this._changePriceValueContent(r,s.text),h&&n&&this._changePriceValueContent(n,h.text),a&&p&&this._changePriceValueContent(a,p.text),c&&_&&this._changePriceValueContent(c,_.text),P&&C&&this._changePriceValueContent(P,this._getPercentageDiscountValue(C.float,g.float)),l&&C&&this._changePriceValueContent(l,C.text),o&&h&&this._changePriceValueContent(o,this._getPercentageDiscountValue(s.float,h.float)),f&&this._changePriceValueContent(f,s.text)}_updateUnitPriceCalculation(e,t,r){e&&(this._toggleUnitPriceCalculationVisibility(e,!0),this._changePriceValueContent(e,`${t.final.text} / ${r}`))}_toggleUnitPriceCalculationVisibility(e,t){if(!e)return;const r=e.closest(`.${i.unitCalculationPriceContainer}`);r&&(t?r.removeAttribute("hidden"):r.setAttribute("hidden",""))}_getPercentageDiscountValue(e,t){return e>=t?`-${Math.round((e-t)/e*100)}%`:`+${Math.round(t*100/e-100)}%`}_changePriceValueContent(e,t){e.innerHTML="",e.append(t)}_updateSpecialOfferDuration(e){[...this.querySelectorAll(`.${i.specialOfferDuration}
1`)].forEach(r=>{r.textContent=this._translationApi.translate("The promotion runs until {{ endDate }}",{endDate:e})})}};u.moduleName=d.component;$([m({type:Number,attribute:"product-id"})],u.prototype,"productId",2);u=$([V(d.component)],u);class L extends O{static{this.featureName=d.feature}static{this._components={productPrice:u}}}export{L as ProductPriceInitializer};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.