import{a as ie}from"./chunk-B4H3G55F.js";import{b as oe}from"./chunk-5OZTUYJC.js";import{a as ee}from"./chunk-FKH74CIW.js";import{a as Z}from"./chunk-A4CGO3WV.js";import{J as te}from"./chunk-CWWVHRJU.js";import{a as B}from"./chunk-ILYMG6ZI.js";import{U as W,V as X,r as w,s as M}from"./chunk-MXUIPT66.js";import{Aa as S,Ab as l,Ba as F,Bb as v,E as L,Fb as g,Ha as V,Ka as O,Kb as b,Lb as m,Nd as J,Ua as r,Yb as u,Zb as Y,_b as C,bd as $,d as T,gc as I,gd as q,ib as h,jc as j,kc as z,lc as H,ob as f,pa as _,qb as x,qc as U,rc as c,rg as Q,s as R,sc as s,t as A,ta as y,tc as G,ub as p,vc as K,xb as k,yb as N,yh as D,zb as d,zh as E}from"./chunk-N6B2OJOY.js";var se=(e,i)=>({currency:e,locale:i}),de=(e,i,t)=>[e,i,"symbol","1.0",t];function me(e,i){if(e&1&&(d(0,"button",7),v(1,"cx-icon",8),l()),e&2){let t=m(3);r(),f("type",t.icons.SUCCESS)}}function pe(e,i){if(e&1){let t=g();d(0,"button",9),b("click",function(){S(t);let n=m(3);return F(n.addPromotionItemToCart())}),v(1,"cx-icon",8),l()}if(e&2){let t=m(3);f("disabled",!t.isAvailableForSelection),r(),f("type",t.icons.CART)}}function he(e,i){if(e&1&&(d(0,"div",0),v(1,"cx-media",1),l(),d(2,"div",2),u(3),l(),d(4,"div",3)(5,"div",4)(6,"span",5),u(7),c(8,"cxTranslate"),l(),d(9,"span",6),u(10),c(11,"currency"),l()()(),h(12,me,2,1,"button",7)(13,pe,2,2)),e&2){let t,o=i,n=m(2);r(),x("is-missing",!(n.freeProduct.images!=null&&n.freeProduct.images.PRIMARY)),f("container",(t=n.freeProduct.images==null?null:n.freeProduct.images.PRIMARY)!==null&&t!==void 0?t:null),r(2),C(" ",n.freeProduct.name," "),r(2),x("is-wide",n.freeProduct.validFrom>999),r(2),C(" ",s(8,9,"promotionItem.validFrom")," "),r(3),C(" ",K(11,11,H(17,de,n.freeProduct.validFrom,o.currency,o.locale))," "),r(2),p(12,n.isSelected?12:13)}}function fe(e,i){if(e&1&&(h(0,he,14,21),c(1,"async"),c(2,"async")),e&2){let t,o=m();p(0,(t=z(5,se,s(1,1,o.currency$),s(2,3,o.locale$)))?0:-1,t)}}var ne=(()=>{let i=class i{constructor(){this._currencyService=_(Q),this._currencyLocaleService=_(oe),this.addToCart=new O,this.icons=B,this.currency$=this._currencyService.getActive(),this.locale$=this._currencyLocaleService.getActiveLocaleForCurrencyPipe()}addPromotionItemToCart(){this.isAvailableForSelection&&this.addToCart.emit()}};i.\u0275fac=function(n){return new(n||i)},i.\u0275cmp=y({type:i,selectors:[["foerch-potential-promotion-item"]],inputs:{freeProduct:"freeProduct",isSelected:"isSelected",isAvailableForSelection:"isAvailableForSelection"},outputs:{addToCart:"addToCart"},standalone:!0,features:[I],decls:1,vars:1,consts:[[1,"promotionItem-img"],["format","thumbnail",3,"container"],[1,"promotionItem-name"],[1,"promotionBadge-wrapper"],[1,"promotionBadge-ribbon"],["foerchDynamicFontSize","12",1,"valid-from-wording"],[1,"valid-from-price"],["disabled","","type","button",1,"btn","btn-commerce"],[3,"type"],["type","button",1,"btn","btn-commerce",3,"click","disabled"]],template:function(n,a){n&1&&h(0,fe,3,8),n&2&&p(0,a.freeProduct?0:-1)},dependencies:[$,q,ee,Z,E,D,M,w,X,W],encapsulation:2,changeDetection:0});let e=i;return e})();var ue=(e,i)=>i.code,_e=(e,i,t,o,n,a,P,re)=>({actualTotal:e,nextPromoThreshold:i,nextPromoThresholdDiff:t,freeProducts:o,giveawayCode:n,canSelect:a,isCartLoading:P,isFirstPromoThresholdReached:re}),Ce=e=>({thresholdDiff:e});function Pe(e,i){if(e&1&&(d(0,"div",0)(1,"div",5),v(2,"cx-icon",6),l()()),e&2){let t=m(3);r(2),f("type",t.icons.MARKER)}}function ve(e,i){e&1&&(d(0,"p",3),u(1),c(2,"cxTranslate"),l()),e&2&&(r(),C(" ",s(2,1,"promotion.itemSelection")," "))}function xe(e,i){if(e&1&&(d(0,"p",3),u(1),c(2,"cxTranslate"),l()),e&2){let t=m(2);r(),C(" ",G(2,1,t.isFirstPromoThresholdReached?"promotion.campaignProgress":"promotion.campaignProgressFirstPromo",j(4,Ce,t.nextPromoThresholdDiff==null?null:t.nextPromoThresholdDiff.formattedValue))," ")}}function Te(e,i){if(e&1){let t=g();d(0,"div",4)(1,"foerch-potential-promotion-item",7),b("addToCart",function(){let n=S(t).$implicit,a=m(3);return F(a.onAddToCart(n.code))}),l()()}if(e&2){let t=i.$implicit,o=m(2);r(),f("freeProduct",t)("isAvailableForSelection",!o.isCartLoading&&t.validFrom<=o.actualTotal)("isSelected",t.code===o.giveawayCode)}}function ye(e,i){if(e&1&&(h(0,Pe,3,1,"div",0),d(1,"div",0)(2,"div",1)(3,"div",2),u(4),c(5,"cxTranslate"),l(),h(6,ve,3,3,"p",3)(7,xe,3,6,"p",3),l()(),d(8,"div",0),k(9,Te,2,3,"div",4,ue),l()),e&2){let t=m(),o=m();p(0,o.isMobile?-1:0),r(),x("mt-3",o.isMobile),r(3),Y(s(5,6,"promotion.campaign")),r(2),p(6,t.canSelect===!0?6:-1),r(),p(7,t.canSelect===!1?7:-1),r(2),N(t.freeProducts)}}function Se(e,i){if(e&1&&h(0,ye,11,8),e&2){let t=i;p(0,(t.freeProducts==null?null:t.freeProducts.length)>0&&t.nextPromoThresholdDiff?0:-1)}}var Qe=(()=>{let i=class i{constructor(){this._promotionsService=_(ie),this._activeCartService=_(te),this._destroyRef=_(V),this.isMobile=!1,this.icons=B,this.actualTotal$=new T(null),this.nextPromoThreshold$=new T(null),this.nextPromoThresholdDiff$=new T(null),this.giveawayCode$=this._promotionsService.getGiveawayProductCode(),this.isCartLoading$=this._activeCartService.isLoading()}ngOnInit(){this.freeProducts$=this._promotionsService.getFreeProductsFromPotentialOrderPromotions(),this.isFirstPromoThresholdReached$=this._promotionsService.isFirstPromoThresholdReached(),this.canSelect$=A([this.freeProducts$,this.isFirstPromoThresholdReached$]).pipe(R(([o,n])=>o.length>0&&n||!1)),this._promotionsService.getNextValidPotentialOrderPromotion().pipe(J(this._destroyRef),L(o=>!!o&&!!o.threshold&&isNaN(o.threshold.value)===!1&&!!o.thresholdDifference&&isNaN(o.thresholdDifference.value)===!1)).subscribe(o=>{let n=o.threshold,a=o.thresholdDifference,P=n.value-a.value;this.nextPromoThreshold$.next(n),this.nextPromoThresholdDiff$.next(a),this.actualTotal$.next(P)})}onAddToCart(o){this._activeCartService.addPromotionCodeToCart(o)}};i.\u0275fac=function(n){return new(n||i)},i.\u0275cmp=y({type:i,selectors:[["foerch-potential-promotions"]],inputs:{isMobile:"isMobile"},standalone:!0,features:[I],decls:9,vars:26,consts:[[1,"row"],[1,"col-12"],[1,"h4"],[1,"text-small"],[1,"col-6","col-md-4","col-lg-2","mb-2"],[1,"col-12","promotions-marker"],[1,"promotions-marker",3,"type"],[3,"addToCart","freeProduct","isAvailableForSelection","isSelected"]],template:function(n,a){if(n&1&&(h(0,Se,1,1),c(1,"async"),c(2,"async"),c(3,"async"),c(4,"async"),c(5,"async"),c(6,"async"),c(7,"async"),c(8,"async")),n&2){let P;p(0,(P=U(17,_e,s(1,1,a.actualTotal$),s(2,3,a.nextPromoThreshold$),s(3,5,a.nextPromoThresholdDiff$),s(4,7,a.freeProducts$),s(5,9,a.giveawayCode$),s(6,11,a.canSelect$),s(7,13,a.isCartLoading$),s(8,15,a.isFirstPromoThresholdReached$)))?0:-1,P)}},dependencies:[$,ne,E,D,M,w],encapsulation:2,changeDetection:0});let e=i;return e})();export{Qe as a};