import{a as Y}from"./chunk-ZLKCSYK5.js";import{b as z}from"./chunk-3P6GZXAL.js";import{c as E}from"./chunk-72JDPJS6.js";import{g as X}from"./chunk-4ENQACUL.js";import{a as K}from"./chunk-LTUVDLS3.js";import{J as b}from"./chunk-CWWVHRJU.js";import{a as y}from"./chunk-RU43IR5J.js";import{a as A}from"./chunk-Y7IP5WLG.js";import{a as G}from"./chunk-LY6HB4BL.js";import{a as T}from"./chunk-SU6CJJJO.js";import{a as S}from"./chunk-HBJ2IG4O.js";import{L as a,T as J,c as Q,m as I}from"./chunk-FBI7JGZC.js";import{t as $}from"./chunk-MXUIPT66.js";import{Aa as _,Ab as u,Ba as g,Bb as x,Cb as L,Db as H,Dc as C,Fb as P,Gd as v,Kb as D,Lb as p,Q as w,Ua as h,Va as s,Xb as M,Xc as U,Yb as j,_b as B,a as R,ib as O,ob as d,rc as V,sc as N,t as F,ta as k,wc as q,yh as W,zb as f}from"./chunk-N6B2OJOY.js";var te=function(r,t,e,i){var o=arguments.length,n=o<3?t:i===null?i=Object.getOwnPropertyDescriptor(t,e):i,l;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")n=Reflect.decorate(r,t,e,i);else for(var m=r.length-1;m>=0;m--)(l=r[m])&&(n=(o<3?l(n):o>3?l(t,e,n):l(t,e))||n);return o>3&&n&&Object.defineProperty(t,e,n),n},ie=function(r,t){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(r,t)};function re(r,t){if(r&1){let e=P();L(0),f(1,"foerch-cart-body",3),D("markEntry",function(o){_(e);let n=p();return g(n.markCartEntry(o))}),u(),f(2,"foerch-cart-footer",4),D("applyBulkAction",function(o){_(e);let n=p();return g(n.applyBulkAction(o))})("markToggle",function(){_(e);let o=p();return g(o.toggleAll())}),u(),H()}if(r&2){let e=p();h(),d("cartConfig",e.cartConfig)("items",e.orderEntries)("selectionHelper",e.selectionHelper),h(),d("bulkOptions",e.bulkActionOptions)("footerConfig",e.footerConfig)("selectAll",e.selectionHelper.areAllSelected())("totalPrice",e.order.totalPrice)}}function oe(r,t){r&1&&(f(0,"div"),x(1,"cx-spinner"),u())}function ne(r,t){r&1&&(f(0,"div",6)(1,"div",7)(2,"div",8),j(3),V(4,"cxTranslate"),u()()()),r&2&&(h(3),B(" ",N(4,1,"orderDetails.emptyTable")," "))}function se(r,t){if(r&1&&O(0,ne,5,3,"div",5),r&2){let e=p();d("ngIf",e.isLoaded)}}var c,Z=(c=class{constructor(t,e,i,o,n,l,m,ee){this.activatedRoute=t,this.orderService=e,this.activeCartService=i,this.watchlistService=o,this.modalService=n,this.permissionService=l,this.routingService=m,this.cd=ee,this.orderEntries=[],this.isLoaded=!1,this.isLoading=!1,this.isEmptyList=!0,this.cartModes=I,this.selectionHelper=new K,this.cartConfig={isEditable:!1,cartMode:I.CART,showAddToCart:!1,showCCM:!0,showVPE:!0,showPrice:!0,showRememberedAt:!1,isSelectable:!0},this.footerConfig={addCoupon:!1,showCheckout:!1,showTotal:!1,disableAll:!1},this.bulkActionOptions=[a.ADD_TO_CART,a.ADD_TO_WATCH_LIST,a.ADD_TO_ORDER_TEMPLATE],this.subs$=new R,this.isCartLoading=!1}ngOnInit(){this.subs$.add(this.activatedRoute.paramMap.subscribe(t=>{this.currentOrderCode=t.get("code"),t.has("con")&&(this.currentConOrderId=t.get("con"),this.updateData(),this.cd.detectChanges())})),this.subs$.add(this.activeCartService.isLoading().subscribe(t=>this.isCartLoading=t)),this.subs$.add(F([this.orderService.get(),this.permissionService.getPermissionValueAsBoolean(J.COST_CENTER_MANAGEMENT_TOOL)]).pipe(w((t,e)=>JSON.stringify(t)===JSON.stringify(e))).subscribe(([t,e])=>{t&&(this.handleResults(t,e),this.cd&&!this.cd.destroyed&&this.cd.detectChanges())}))}ngOnDestroy(){this.subs$.unsubscribe(),this.orderService.reset()}handleResults(t,e){t.order&&(this.order=t.order,this.currentConOrderId?this.updateData():this.orderEntries=t.order.entries,this.selectionHelper.updateItems(this.orderEntries.filter(i=>!i.giveAway).map(i=>({id:i.pk,item:i})))),this.cartConfig.showCCM=e===!0&&this.orderEntries.some(i=>i.costCenter),this.isLoading=t.loading,this.isLoaded=t.loaded,this.isEmptyList=!this.orderEntries||this.orderEntries.length===0}markCartEntry(t){this.selectionHelper.toggleItemStatus(t.item.pk)}applyBulkAction(t){let e=this.selectionHelper.getSelectedItems().map(i=>i.item);if(e.length>0)switch(t){case a.ADD_TO_CART:{if(this.isCartLoading===!1){let i=this.createQuickAddEntryArray(e);this.activeCartService.addEntries({entries:i,targetType:Q.CARTS})}break}case a.ADD_TO_ORDER_TEMPLATE:{let i;this.modalRef=this.modalService.open(Y),i=this.modalRef.componentInstance,i.entries=e,i.sourceId=this.order.code;break}case a.ADD_TO_WATCH_LIST:{let i=this.createQuickAddEntryArray(e);this.watchlistService.addEntries(i);break}default:console.error("unimplemented option",t)}}createQuickAddEntryArray(t){let e=[];return t.forEach(i=>{e.push({code:i.product.code,qty:i.quantity?i.quantity:1,comment:i.comment,costCenterCode:i.costCenter?i.costCenter.code:null,orderReasonCode:i.orderReason?i.orderReason.code:null})}),e}updateData(){if(this.order){let t=(this.order.consignments||[]).find(e=>e.code===this.currentConOrderId);this.orderEntries=t?(t.entries||[]).map(e=>e.orderEntry):[]}}toggleAll(){this.selectionHelper.toggleAll(),this.selectionHelper=this.selectionHelper.clone()}},c.\u0275fac=function(e){return new(e||c)(s(v),s(E),s(b),s(T),s(A),s(y),s(S),s(C))},c.\u0275cmp=k({type:c,selectors:[["foerch-order-detail-table"]],decls:4,vars:3,consts:[["noArticles",""],[4,"ngIf","ngIfElse"],[4,"ngIf"],[3,"markEntry","cartConfig","items","selectionHelper"],[3,"applyBulkAction","markToggle","bulkOptions","footerConfig","selectAll","totalPrice"],["class","row emptyState",4,"ngIf"],[1,"row","emptyState"],[1,"col-12"],[1,"emptyState-text"]],template:function(e,i){if(e&1&&O(0,re,3,7,"ng-container",1)(1,oe,2,0,"div",2)(2,se,1,1,"ng-template",null,0,q),e&2){let o=M(3);d("ngIf",!i.isLoading&&!i.isEmptyList)("ngIfElse",o),h(),d("ngIf",i.isLoading)}},dependencies:[U,$,X,z,W],encapsulation:2}),c);Z=te([G(),ie("design:paramtypes",[v,E,b,T,A,y,S,C])],Z);export{Z as a};