import{b as $}from"./chunk-3P6GZXAL.js";import{b as z}from"./chunk-SSXIUBOK.js";import{g as j}from"./chunk-4ENQACUL.js";import{a as N}from"./chunk-LTUVDLS3.js";import{a as M}from"./chunk-ISCIGLF2.js";import{J as P}from"./chunk-CWWVHRJU.js";import{a as R}from"./chunk-SU6CJJJO.js";import{L as C,N as u,c as O,m as v}from"./chunk-FBI7JGZC.js";import{Aa as l,Ab as f,Ba as h,Cb as y,Db as E,Dc as H,Fb as L,Kb as g,Lb as a,Ua as s,Va as _,Xc as V,Yb as w,Zb as D,_b as F,a as S,ga as b,ib as k,ob as m,pa as I,rc as T,sb as x,sc as A,ta as W,yh as B,zb as p}from"./chunk-N6B2OJOY.js";function U(r,o){if(r&1){let n=L();y(0),p(1,"foerch-cart-body",6),g("addEntryToCart",function(i){l(n);let e=a();return h(e.onAddEntryToCart(i))})("markEntry",function(i){l(n);let e=a();return h(e.onToggleEntry(i))})("removeEntry",function(i){l(n);let e=a();return h(e.onRemoveEntry(i))})("updateComment",function(i){l(n);let e=a();return h(e.onUpdateComment(i))}),f(),p(2,"foerch-cart-footer",7),g("applyBulkAction",function(i){l(n);let e=a();return h(e.applyBulkAction(i))})("markToggle",function(){l(n);let i=a();return h(i.toggleAll())}),f(),E()}if(r&2){let n=a();s(),m("cartConfig",n.cartConfig)("isLoading$",n.isCartLoading$)("items",n.watchlistItems)("selectionHelper",n.selectionHelper),s(),m("bulkOptions",n.bulkActionOptions)("footerConfig",n.footerConfig)("hasAnyDeletedArticle",n.hasAnyDeletedArticle)("selectAll",n.selectionHelper.areAllSelected())}}function q(r,o){r&1&&(y(0),p(1,"div",8)(2,"div",2)(3,"div",9),w(4),T(5,"cxTranslate"),f()()(),E()),r&2&&(s(4),F(" ",A(5,1,"watchlistView.noArticlesOnWatchlist")," "))}var ft=(()=>{let o=class o{constructor(t,i,e){this.watchlistService=t,this.activeCartService=i,this.cd=e,this.styleClasses="watchlist",this.cartConfig={isEditable:this.watchlistService.cartEditable,cartMode:v.WATCHLIST,showAddToCart:!0,showCCM:!1,showPrice:!1,showVPE:!1,showRememberedAt:!0},this.headerConfig={showCCM:!1,showDialogLinks:!1,showQuickAddInBox:!1,cartMode:v.WATCHLIST},this.footerConfig={addCoupon:!1,showCheckout:!1,showPromotions:!1,showTotal:!1},this.watchlistItems=[],this.selectionHelper=new N,this.isInitialized=!1,this.isEmptyWatchlist=!1,this.isWatchlistLoading=!1,this.bulkActionOptions=[C.ADD_TO_CART,C.DELETE],this.hasAnyDeletedArticle=!1,this.isCartLoading$=this.activeCartService.isLoading().pipe(b(c=>this.isCartLoading=c)),this.subs$=new S,this.isCartLoading=!1,this.addablePipe=I(M)}ngOnInit(){this.subs$.add(this.watchlistService.getEntries().subscribe(t=>{if(this.isEmptyWatchlist=!t||t.length===0,t){this.watchlistItems=this.processWatchlistItems(t);let i=[u.DELETED,u.UNAVAILABLE,u.ONLY_AVAILABLE_WITHIN_ASSORTMENT];this.hasAnyDeletedArticle=this.watchlistItems.some(e=>i.includes(e.product?.saleability?.status)),this.selectionHelper.updateItems(this.isEmptyWatchlist?[]:this.watchlistItems.map(e=>({id:e.pk,item:e}))),this.isInitialized=!0}this.cd.detectChanges()})),this.subs$.add(this.watchlistService.isLoading().subscribe(t=>this.isWatchlistLoading=t))}ngOnDestroy(){this.subs$.unsubscribe()}onAddEntriesToWatchlist(t){this.watchlistService.addEntries(t)}onUpdateComment(t){this.watchlistService.updateEntryComment({pk:t.item.pk,comment:t.comment})}onRemoveEntry(t){this.watchlistService.removeEntries({entries:[t.item]})}onToggleEntry(t){this.selectionHelper.toggleItemStatus(t.item.pk)}onAddEntryToCart(t){this.addablePipe.transform(t.item?.product?.saleability)&&this.watchlistService.addEntryToCart(t.item)}applyBulkAction(t){let i=this.selectionHelper.getSelectedItems().map(e=>e.item.pk);if(i.length>0){let e=this.watchlistItems.filter(c=>i.indexOf(c.pk)!==-1);switch(t){case C.DELETE:{this.watchlistService.removeEntries({entries:e});break}case C.ADD_TO_CART:{if(this.isCartLoading===!1){let c=e.filter(d=>this.addablePipe.transform(d.product?.saleability));c.length>0&&this.activeCartService.addEntries({entries:c.map(d=>({code:d.product.code,qty:1,comment:d.comment})),targetType:O.CARTS})}break}default:console.error("unimplemented option",t)}}}toggleAll(){this.selectionHelper.toggleAll(),this.selectionHelper=this.selectionHelper.clone()}processWatchlistItems(t){return t}};o.\u0275fac=function(i){return new(i||o)(_(R),_(P),_(H))},o.\u0275cmp=W({type:o,selectors:[["foerch-watchlist"]],hostVars:2,hostBindings:function(i,e){i&2&&x(e.styleClasses)},decls:9,vars:8,consts:[[1,"watchlistHead"],[1,"row"],[1,"col-12"],[1,"h3"],[3,"addToCart","headerConfig","isCartRefreshed","isEmptyCart"],[4,"ngIf"],[3,"addEntryToCart","markEntry","removeEntry","updateComment","cartConfig","isLoading$","items","selectionHelper"],[3,"applyBulkAction","markToggle","bulkOptions","footerConfig","hasAnyDeletedArticle","selectAll"],[1,"row","emptyState"],[1,"emptyState-text"]],template:function(i,e){i&1&&(p(0,"div",0)(1,"div",1)(2,"div",2)(3,"div",3),w(4),T(5,"cxTranslate"),f()()()(),p(6,"foerch-cart-head",4),g("addToCart",function(d){return e.onAddEntriesToWatchlist(d)}),f(),k(7,U,3,8,"ng-container",5)(8,q,6,3,"ng-container",5)),i&2&&(s(4),D(A(5,6,"watchlistView.watchlist")),s(2),m("headerConfig",e.headerConfig)("isCartRefreshed",!e.isWatchlistLoading)("isEmptyCart",e.isEmptyWatchlist),s(),m("ngIf",!e.isEmptyWatchlist),s(),m("ngIf",e.isInitialized&&e.isEmptyWatchlist))},dependencies:[V,z,j,$,B],encapsulation:2,changeDetection:0});let r=o;return r})();export{ft as a};