import{a as H}from"./chunk-64JTGTPA.js";import{c as D}from"./chunk-72JDPJS6.js";import{g as he}from"./chunk-4ENQACUL.js";import{a as _e}from"./chunk-LTUVDLS3.js";import{b as j}from"./chunk-5OZTUYJC.js";import{J as M}from"./chunk-CWWVHRJU.js";import{a as B}from"./chunk-RU43IR5J.js";import{a as ue}from"./chunk-6JC3FZFK.js";import{a as R}from"./chunk-Y7IP5WLG.js";import{a as me}from"./chunk-LY6HB4BL.js";import{r as L}from"./chunk-L7CU4UNF.js";import{T as pe,c as le,m as se}from"./chunk-FBI7JGZC.js";import{a as de}from"./chunk-ILYMG6ZI.js";import{r as ce,t as ae}from"./chunk-MXUIPT66.js";import{b as ie,f as ne,l as oe}from"./chunk-DX7LHTFF.js";import{Aa as u,Ab as l,Ba as _,Bb as A,Cb as T,Db as k,Dc as P,Eb as G,Fb as b,Gd as F,Kb as y,Lb as s,Ua as c,Va as f,Wc as Q,Xb as I,Xc as X,Yb as d,Zb as O,_b as g,a as $,ad as Z,bd as ee,cc as Y,dc as z,ec as J,gd as te,ib as v,kc as K,lc as N,ob as p,qb as q,rc as m,rg as V,sc as h,ta as W,vc as U,wc as w,yh as re,zb as a}from"./chunk-N6B2OJOY.js";import{a as E}from"./chunk-GHL4OFBQ.js";var xe=function(i,t,e,r){var n=arguments.length,o=n<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,e):r,x;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")o=Reflect.decorate(i,t,e,r);else for(var S=i.length-1;S>=0;S--)(x=i[S])&&(o=(n<3?x(o):n>3?x(t,e,o):x(t,e))||o);return n>3&&o&&Object.defineProperty(t,e,o),o},be=function(i,t){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(i,t)},Se=(i,t)=>({currencyCode:i,localeCode:t}),ve=(i,t,e)=>[i,t,"symbol","1.2",e];function Oe(i,t){i&1&&(a(0,"div"),A(1,"cx-spinner",12),l())}function Ee(i,t){i&1&&G(0)}function Ae(i,t){if(i&1&&(a(0,"div",23)(1,"div",15)(2,"span",28),d(3),l()(),a(4,"div",15)(5,"span",29),d(6),l()()()),i&2){let e=t.$implicit;c(3),g("",e.type.name,":"),c(3),g(" ",e.value==null?null:e.value.formattedValue," ")}}function Te(i,t){if(i&1&&(T(0),v(1,Ae,7,2,"div",27),k()),i&2){let e=s(4);c(),p("ngForOf",e.order.fees)("ngForTrackBy",e.trackByIndex)}}function ke(i,t){if(i&1&&(a(0,"div",23)(1,"div",15)(2,"span",24),d(3),m(4,"cxTranslate"),l()(),a(5,"div",15)(6,"span",25),d(7),l()()(),v(8,Te,2,2,"ng-container",3),a(9,"div",26)(10,"div",15)(11,"span",24),d(12),m(13,"cxTranslate"),l()(),a(14,"div",15)(15,"strong",25),d(16),m(17,"currency"),l()()()),i&2){let e=s().ngIf,r=s(2);q("mb-1",(r.order.fees==null?null:r.order.fees.length)>0),c(3),g("",h(4,7,"checkout.sum"),":"),c(4),O(r.order.subTotal==null?null:r.order.subTotal.formattedValue),c(),p("ngIf",(r.order.fees==null?null:r.order.fees.length)>0),c(4),g("",h(13,9,"checkout.total"),":"),c(4),O((r.order.totalPrice==null?null:r.order.totalPrice.formattedValue)||U(17,11,N(17,ve,r.order.totalPrice==null?null:r.order.totalPrice.value,e.currencyCode,e.localeCode)))}}function Ie(i,t){if(i&1&&(a(0,"div",30)(1,"div",15)(2,"span",24),d(3),m(4,"cxTranslate"),l()(),a(5,"div",15)(6,"strong",25),d(7),m(8,"currency"),l()()()),i&2){let e=s().ngIf,r=s(2);c(3),g("",h(4,2,"common.netTotal"),":"),c(4),O((r.order.totalPrice==null?null:r.order.totalPrice.formattedValue)||U(8,4,N(10,ve,r.order.totalPrice==null?null:r.order.totalPrice.value,e.currencyCode,e.localeCode)))}}function we(i,t){if(i&1){let e=b();T(0),a(1,"div",14)(2,"div",5)(3,"div",15)(4,"div",16)(5,"input",17),J("ngModelChange",function(n){u(e);let o=s(2);return z(o.areAllEntriesSelected,n)||(o.areAllEntriesSelected=n),_(n)}),y("click",function(){u(e);let n=s(2);return _(n.toggleSelectAll())}),l(),a(6,"label",18),d(7),m(8,"cxTranslate"),l()()(),a(9,"div",19)(10,"button",20),y("click",function(){u(e);let n=s(2);return _(n.deleteBulkAction())}),d(11),m(12,"cxTranslate"),l()(),a(13,"div",21),v(14,Ee,1,0,"ng-container",22),l()()(),v(15,ke,18,21,"ng-template",null,1,w)(17,Ie,9,14,"ng-template",null,2,w),k()}if(i&2){let e=I(16),r=I(18),n=s(2);c(5),p("disabled",n.isLoading),Y("ngModel",n.areAllEntriesSelected),c(2),O(h(8,5,"common.selectAll")),c(4),g(" ",h(12,7,"common.delete")," "),c(3),p("ngTemplateOutlet",n.order.fees?e:r)}}function Pe(i,t){if(i&1){let e=b();T(0),a(1,"foerch-cart-body",13),y("applyCostCenterToEntry",function(n){u(e);let o=s();return _(o.applyCcmToEntry(n))})("markEntry",function(n){u(e);let o=s();return _(o.markCartEntry(n))})("removeEntry",function(n){u(e);let o=s();return _(o.deleteOrderEntry(n))})("updateComment",function(n){u(e);let o=s();return _(o.updateEntryComment(n))})("vpeChange",function(n){u(e);let o=s();return _(o.onVpeChange(n))}),l(),v(2,we,19,9,"ng-container",3),m(3,"async"),m(4,"async"),k()}if(i&2){let e=s();c(),p("cartConfig",e.cartConfig)("isLoading$",e.isOrderLoading$)("items",e.orderEntries)("selectionHelper",e.selectionHelper),c(),p("ngIf",K(9,Se,h(3,5,e.currencyCode$),h(4,7,e.localeCode$)))}}function Fe(i,t){if(i&1){let e=b();a(0,"button",31),y("click",function(){u(e);let n=s();return _(n.approveOrder(!1))}),A(1,"cx-icon",32),d(2),m(3,"cxTranslate"),l()}if(i&2){let e=s();p("disabled",e.isLoading),c(),p("type",e.icons.CLOSE),c(),g(" ",h(3,3,"approval.rejectOrder")," ")}}function Ve(i,t){if(i&1){let e=b();a(0,"button",33),y("click",function(){u(e);let n=s();return _(n.approveOrder(!0))}),A(1,"cx-icon",32),d(2),m(3,"cxTranslate"),l()}if(i&2){let e=s();p("disabled",e.shouldDisableApproveButton),c(),p("type",e.icons.SUCCESS),c(),g(" ",h(3,3,"approval.approveOrder")," ")}}function Be(i,t){i&1&&(a(0,"div",35)(1,"div",36)(2,"div",37),d(3),m(4,"cxTranslate"),l()()()),i&2&&(c(3),g(" ",h(4,1,"approval.emptyTable")," "))}function Re(i,t){if(i&1&&v(0,Be,5,3,"div",34),i&2){let e=s();p("ngIf",e.isLoaded)}}var C,fe=(C=class{get areApprovalButtonsVisible(){return this.order&&this.order.status==="PENDING_APPROVAL"||!1}constructor(t,e,r,n,o,x,S,ge,Ce,ye){this.activatedRoute=t,this.orderService=e,this.activeCartService=r,this.permissionService=n,this.modalService=o,this.cd=x,this.unitsService=S,this.currencyService=ge,this.currencyLocaleService=Ce,this.checkoutInfoPipe=ye,this.orderEntries=[],this.isLoaded=!1,this.isLoading=!1,this.isEmptyList=!0,this.targetType=le.ORDER,this.previousOrderCode=null,this.icons=de,this.selectionHelper=new _e,this.areAllEntriesSelected=!1,this.bulkActionOptions=[],this.isOrderLoading$=this.orderService.isOrderLoading(),this.currencyCode$=this.currencyService.getActive(),this.localeCode$=this.currencyLocaleService.getActiveLocaleForCurrencyPipe(),this.cartConfig={isEditable:!0,cartMode:se.ORDER,showAddToCart:!1,showCCM:!1,showVPE:!0,showPrice:!0,showRememberedAt:!1,isSelectable:!0},this.subs$=new $}ngOnInit(){this.subs$.add(this.activatedRoute.paramMap.subscribe(t=>{let e=t.get("code");e!==this.previousOrderCode&&this.onChangedOrderCode(),this.previousOrderCode=this.currentOrderCode,this.currentOrderCode=e})),this.loadOrder(),this.subs$.add(this.orderService.get().subscribe(t=>{t&&(this.handleResults(t),this.cd&&!this.cd.destroyed&&this.cd.detectChanges())})),this.subs$.add(this.permissionService.getPermissionValueAsBoolean(pe.COST_CENTER_MANAGEMENT_TOOL).subscribe(t=>this.cartConfig.showCCM=t))}ngOnDestroy(){this.subs$.unsubscribe()}trackByIndex(t){return t}handleResults(t){t.order&&(this.order=t.order,this.orderEntries=this.order.entries,this.selectionHelper.updateItems(this.orderEntries.map(e=>({id:e.pk,item:e})))),this.isLoading=t.loading,this.isLoaded=t.loaded,this.isEmptyList=!this.orderEntries||this.orderEntries.length===0,this.shouldDisableApproveButton=this.isLoading||this.checkoutInfoPipe.transform(this.order?.checkoutInfo)}markCartEntry(t){this.selectionHelper.toggleItemStatus(t.item.pk),this.applyMarkToOrder()}toggleSelectAll(){this.selectionHelper.toggleAll(),this.areAllEntriesSelected=this.selectionHelper.areAllSelected(),this.applyMarkToOrder()}deleteBulkAction(){let t=this.selectionHelper.getSelectedItems().map(e=>e.item);this.delete(t)}deleteOrderEntry(t){this.delete([t.item])}delete(t){let e=this.modalService.open(ue,{centered:!0});if(e){let r=t.length===1;e.componentInstance.title="approval.dialog.delete",e.componentInstance.description=r?"approval.dialog.deleteConfirmation":"approval.dialog.bulkDeleteConfirmation",r?e.componentInstance.name=t[0].product&&t[0].product.baseProductName?t[0].product.baseProductName:"":e.componentInstance.name=t.length,e.result.then(n=>{n&&(r?this.removeEntries([t[0]]):this.removeEntries(t))}).catch(()=>{})}}removeEntries(t){this.orderService.removeOrderEntries(this.currentOrderCode,t)}cancel(){this.order={},this.orderService.navigateToOrdersOverview()}approveOrder(t){this.orderService.updateApproval(this.order.code,t),this.orderService.navigateToOrdersOverview()}applyCcmToEntry(t){this.activeCartService.applyCostCenterForEntries({cartId:this.currentOrderCode,costCenter:t.costCenter,costReason:t.orderReason,entries:[t.item],targetType:this.targetType})}updateEntryComment(t){let e=E({},t.item);e.comment=t.comment,this.orderService.updateOrderEntry(this.currentOrderCode,e)}onVpeChange(t){let e=E({},this.orderEntries.find(o=>o.pk===t.code)),r=E({},e.product),n=r.packagingUnits.find(o=>o.numberContentUnit===t.selectedVPE);n&&n.materialCode&&(r.code=n.materialCode),e.quantity=t.quantity,e.product=r,this.orderService.updateOrderEntry(this.currentOrderCode,e)}loadOrder(){}onChangedOrderCode(){}applyMarkToOrder(){let t=this.selectionHelper.getSelectedItems().map(e=>e.item.pk);this.orderService.addMarkToOrderState(t)}},C.\u0275fac=function(e){return new(e||C)(f(F),f(D),f(M),f(B),f(R),f(P),f(H),f(V),f(j),f(L))},C.\u0275cmp=W({type:C,selectors:[["foerch-order-approval-products"]],decls:15,vars:8,consts:[["noArticles",""],["withFees",""],["withoutFees",""],[4,"ngIf"],[4,"ngIf","ngIfElse"],[1,"row","align-items-center"],[1,"col-md-auto","ms-auto"],[1,"btn","btn-link_secondary",3,"click"],[1,"col-md-auto"],[1,"mt-3","mt-md-0","mw-sm-down-400"],["class","btn btn-danger btn-block btn-icon_left","type","button",3,"disabled","click",4,"ngIf"],["class","btn btn-success btn-block btn-icon_left","type","button",3,"disabled","click",4,"ngIf"],[1,"mb-5"],[3,"applyCostCenterToEntry","markEntry","removeEntry","updateComment","vpeChange","cartConfig","isLoading$","items","selectionHelper"],[1,"bulkEdit","container"],[1,"col-auto"],[1,"form-check","form-checkbox"],["id","markAllDesktop","name","markAllDesktop","type","checkbox","role","checkbox",1,"form-check-input",3,"ngModelChange","click","disabled","ngModel"],["for","markAllDesktop",1,"form-check-label"],[1,"col-auto","pe-2"],["type","button",1,"btn","btn-secondary",3,"click"],[1,"col-auto","ms-auto","pe-0","align-self-start"],[4,"ngTemplateOutlet"],[1,"row","justify-content-between"],[1,"orderSummary-label"],[1,"orderSummary-price"],[1,"row","justify-content-between","mt-1"],["class","row justify-content-between",4,"ngFor","ngForOf","ngForTrackBy"],[1,"orderSummary-label","orderSummary-label-fee"],[1,"orderSummary-price","orderSummary-price-fee"],[1,"row","justify-content-between","mt-6"],["type","button",1,"btn","btn-danger","btn-block","btn-icon_left",3,"click","disabled"],[3,"type"],["type","button",1,"btn","btn-success","btn-block","btn-icon_left",3,"click","disabled"],["class","row emptyState",4,"ngIf"],[1,"row","emptyState"],[1,"col-12"],[1,"emptyState-text"]],template:function(e,r){if(e&1){let n=b();v(0,Oe,2,0,"div",3)(1,Pe,5,12,"ng-container",4),a(2,"div",5)(3,"div",6)(4,"a",7),y("click",function(){return u(n),_(r.cancel())}),d(5),m(6,"cxTranslate"),l()(),a(7,"div",8)(8,"div",9),v(9,Fe,4,5,"button",10),l()(),a(10,"div",8)(11,"div",9),v(12,Ve,4,5,"button",11),l()()(),v(13,Re,1,1,"ng-template",null,0,w)}if(e&2){let n=I(14);p("ngIf",r.isLoading),c(),p("ngIf",!r.isEmptyList)("ngIfElse",n),c(4),g(" ",h(6,6,"approval.back")," "),c(4),p("ngIf",r.areApprovalButtonsVisible),c(3),p("ngIf",r.areApprovalButtonsVisible)}},dependencies:[Q,X,Z,ce,ie,ne,oe,ae,he,ee,te,re],encapsulation:2}),C);fe=xe([me(),be("design:paramtypes",[F,D,M,B,R,P,H,V,j,L])],fe);export{fe as a};