1import{B as Tt,D as xt,K as bt,k as vt}from"./chunk-LGOXL4AK.js";import{$ as P,$g as _t,Aa as o,Dc as W,Df as O,Dh as gt,E as _,Ed as tt,Ee as ot,Eg as ht,Fa as x,Gb as h,Hb as k,Ia as m,Ib as I,Jc as Y,Ka as F,La as B,Nd as et,Ob as U,Od as A,Of as rt,Pa as C,Pb as j,Pf as st,Qb as G,Ta as Q,Tf as ct,Vf as dt,_e as at,a as w,ab as a,ae as it,ah as yt,bb as u,ca as y,cb as f,db as b,dg as pt,ec as s,eg as ut,fa as g,fc as c,fg as lt,ga as v,hb as q,ib as N,kg as mt,l as E,mb as S,mg as Ct,ng as ft,pd as z,qe as nt,rb as T,rc as H,rd as J,tb as r,ud as X,vc as K,w as D,wd as Z,xb as M,xc as $,yb as L,za as R,zb as V}from"./chunk-P2Y7QZOJ.js";import"./chunk-QWWW7GFA.js";var At=["addToCartDialogTriggerEl"];function Ot(i,l){if(i&1&&b(0,"cx-item-counter",10),i&2){let t=r(3);a("max",t.maxQuantity)("control",t.addToCartForm.get("quantity"))("ariaDescribedById","add-to-card-stock-info")}}function wt(i,l){if(i&1&&(u(0,"span"),h(1),f()),i&2){let t=r(3);o(),k(t.getInventory())}}function Et(i,l){if(i&1&&(u(0,"div",6)(1,"label"),h(2),s(3,"cxTranslate"),f(),u(4,"div",7),C(5,Ot,1,3,"cx-item-counter",8),u(6,"span",9),C(7,wt,2,1,"span",4),s(8,"async"),h(9),s(10,"cxTranslate"),s(11,"cxTranslate"),f()()()),i&2){let t=r(2);o(2),k(c(3,4,"addToCart.quantityFull")),o(3),a("ngIf",t.hasStock),o(2),a("ngIf",c(8,6,t.showInventory$)),o(2),I(" ",t.hasStock?c(10,8,"addToCart.inStock"):c(11,10,"addToCart.outOfStock"))}}function Dt(i,l){}function Pt(i,l){if(i&1){let t=S();q(0),C(1,Dt,0,0,"ng-template",11),G("cxComponentRefChange",function(n){g(t);let d=r(2);return j(d.pickupOptionCompRef,n)||(d.pickupOptionCompRef=n),v(n)}),T("cxComponentRefChange",function(){g(t);let n=r(2);return v(n.onPickupOptionsCompLoaded())}),N()}if(i&2){let t=r(2);o(),a("cxOutlet",t.CartOutlets.ADD_TO_CART_PICKUP_OPTION),U("cxComponentRef",t.pickupOptionCompRef)}}function Rt(i,l){if(i&1&&(u(0,"span",15),b(1,"cx-icon",16),f()),i&2){let t=r(3);o(),a("type",t.iconTypes.REPEAT)}}function Ft(i,l){if(i&1&&(u(0,"button",12,0),s(2,"cxTranslate"),s(3,"cxTranslate"),C(4,Rt,2,1,"span",13),s(5,"cxTranslate"),u(6,"span",14),s(7,"cxTranslate"),h(8),s(9,"cxTranslate"),s(10,"cxTranslate"),f()()),i&2){let t=r(2);a("ngClass",t.options!=null&&t.options.displayAddToCart?"btn btn-tertiary":"btn btn-primary btn-block")("disabled",t.disabled||t.quantity<=0||t.quantity>t.maxQuantity||t.unavailable),Q("aria-label",t.product!=null&&t.product.name?c(2,6,"addToCart.addToCart")+", "+(t.product==null?null:t.product.name):c(3,8,"addToCart.addToCart")),o(4),a("ngIf",(t.options==null?null:t.options.addToCartString)===c(5,10,"addToCart.buyItAgain")&&!t.unavailable),o(2),a("ngClass",(t.options==null?null:t.options.addToCartString)===c(7,12,"addToCart.buyItAgain")?"buyItAgainLink":""),o(2),I(" ",t.unavailable?c(9,14,"addToCart.unavailable"):(t.options==null?null:t.options.addToCartString)??c(10,16,"addToCart.addToCart")," ")}}function Bt(i,l){if(i&1){let t=S();u(0,"form",2),T("submit",function(){g(t);let n=r();return v(n.addToCart())}),C(1,Et,12,12,"div",3)(2,Pt,2,2,"ng-container",4)(3,Ft,11,18,"button",5),f()}if(i&2){let t=r();a("formGroup",t.addToCartForm),o(),a("ngIf",t.showQuantity),o(),a("ngIf",t.hasStock),o(),a("ngIf",t.hasStock)}}var St=(()=>{class i{handleKeyboardEvent(t){let e=t.target,n=e.ariaLabel==="Quantity"&&e.tagName==="INPUT";t.key==="Enter"&&n&&t.preventDefault()}constructor(t,e,n,d,p,kt){this.currentProductService=t,this.cd=e,this.activeCartService=n,this.component=d,this.eventService=p,this.productListItemContext=kt,this.showQuantity=!0,this.disabled=!1,this.hasStock=!1,this.inventoryThreshold=!1,this.showInventory$=this.component?.data$.pipe(E(It=>It.inventoryDisplay)),this.unavailable=!1,this.quantity=1,this.subscription=new w,this.addToCartForm=new J({quantity:new X(1,{updateOn:"blur"})}),this.CartOutlets=bt,this.iconTypes=pt,this.productAvailabilityService=y(ct),this.productCatalogService=y(dt),this.realTimeStockEnabled=!!y(Tt).cart?.showRealTimeStockInPDP?.enabled}ngOnInit(){if(this.product)this.productCode=this.product.code??"",this.setStockInfo(this.product),this.unavailable=!this.productCatalogService.isProductInCatalog(this.product);
1else if(this.productCode)this.quantity=1,this.hasStock=!0,this.cd.markForCheck();else{let t;this.productListItemContext?t=this.productListItemContext.product$:this.realTimeStockEnabled?t=this.currentProductService.getProduct([O.UNIT,O.DETAILS]):t=this.currentProductService.getProduct(),this.subscription.add(t.pipe(D(nt)).subscribe(e=>{this.productCode=e.code??"",this.product=e,this.setStockInfo(e),this.unavailable=!this.productCatalogService.isProductInCatalog(e)}))}}setStockInfo(t){this.quantity=1,this.addToCartForm.controls.quantity.setValue(1),this.inventoryThreshold=t.stock?.isValueRounded??!1,this.productListItemContext&&(this.showQuantity=!1),this.realTimeStockEnabled&&t.sapUnit?.sapCode?this.productAvailabilityService.getRealTimeStock(this.productCode,t.sapUnit?.sapCode).pipe(_(1)).subscribe(({quantity:e,status:n})=>{this.maxQuantity=Number(e),this.hasStock=!!(n&&n!=="OUT_OF_STOCK"),this.cd.markForCheck()}):(this.hasStock=t.stock?.stockLevelStatus!=="outOfStock",this.hasStock&&t.stock?.stockLevel&&(this.maxQuantity=t.stock.stockLevel),this.cd.markForCheck())}getInventory(){if(this.hasStock){let t=this.maxQuantity?this.maxQuantity.toString():"";return this.inventoryThreshold?t+"+":t}else return""}updateCount(t){this.quantity=t}addToCart(){let t=0;this.savedCart?t=this.getQuantityFromSavedCart(this.productCode):t=this.addToCartForm.get("quantity")?.value,!(!this.productCode||t<=0)&&(this.pickupOptionCompRef instanceof x&&this.pickupOptionCompRef.instance.intendedPickupLocation$.pipe(_(1)).subscribe(e=>{this.pickupStore=e?.pickupOption==="pickup"?e.name:void 0}),this.activeCartService.getEntries().pipe(_(1)).subscribe(e=>{this.activeCartService.addEntry(this.productCode,t,this.pickupStore),this.eventService.dispatch(this.createCartUiEventAddToCart(this.productCode,t,e.length,this.pickupStore))}))}createCartUiEventAddToCart(t,e,n,d){let p=new vt;return p.productCode=t,p.quantity=e,p.numberOfEntriesBeforeAdd=n,p.pickupStoreName=d,p.triggerElementRef=this.addToCartDialogTriggerEl,p}onPickupOptionsCompLoaded(){this.pickupOptionCompRef instanceof x&&this.subscription.add(this.pickupOptionCompRef.instance.intendedPickupChange.subscribe(t=>{this.disabled=t?.pickupOption==="pickup"&&!t.displayName}))}getQuantityFromSavedCart(t){return this.savedCart?.entries?.find(e=>e?.product?.code===t)?.quantity??0}ngOnDestroy(){this.subscription.unsubscribe()}static{this.\u0275fac=function(e){return new(e||i)(m(ht),m(H),m(xt),m(ft),m(ot),m(gt,8))}}static{this.\u0275cmp=F({type:i,selectors:[["cx-add-to-cart"]],viewQuery:function(e,n){if(e&1&&M(At,5),e&2){let d;L(d=V())&&(n.addToCartDialogTriggerEl=d.first)}},hostBindings:function(e,n){e&1&&T("keydown",function(p){return n.handleKeyboardEvent(p)},R)},inputs:{productCode:"productCode",showQuantity:"showQuantity",options:"options",pickupStore:"pickupStore",savedCart:"savedCart",product:"product"},decls:1,vars:1,consts:[["addToCartDialogTriggerEl",""],[3,"formGroup","submit",4,"ngIf"],[3,"submit","formGroup"],["class","quantity",4,"ngIf"],[4,"ngIf"],["type","submit",3,"ngClass","disabled",4,"ngIf"],[1,"quantity"],[1,"cx-counter-stock"],[3,"max","control","ariaDescribedById",4,"ngIf"],["id","add-to-card-stock-info",1,"info"],[3,"max","control","ariaDescribedById"],[3,"cxComponentRefChange","cxOutlet","cxComponentRef"],["type","submit",3,"ngClass","disabled"],["class","repeat-icon",4,"ngIf"],[3,"ngClass"],[1,"repeat-icon"],[3,"type"]],template:function(e,n){e&1&&C(0,Bt,4,4,"form",1),e&2&&a("ngIf",n.productCode)},dependencies:[$,et,Z,z,A,tt,_t,mt,K,ut,W,rt],encapsulation:2,changeDetection:0})}}return i})(),ie=(()=>{class i{static{this.\u0275fac=function(e){return new(e||i)}}static{this.\u0275mod=B({type:i})}static{this.\u0275inj=P({providers:[it({cmsComponents:{ProductAddToCartComponent:{component:St,data:{inventoryDisplay:!1}}}})],imports:[Y,A,st,lt,yt,Ct,at,St]})}}return i})();export{St as AddToCartComponent,ie as AddToCartModule};
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.