import{b as de}from"./chunk-SSXIUBOK.js";import{b as le}from"./chunk-5RG27LZ2.js";import{a as ce}from"./chunk-WSZCTDHN.js";import{a as se}from"./chunk-UB23RF7S.js";import{J as ae}from"./chunk-CWWVHRJU.js";import{a as ie,c as oe}from"./chunk-QMZQK3O6.js";import{a as ne}from"./chunk-6IGMG2LM.js";import{a as te}from"./chunk-RU43IR5J.js";import{a as re}from"./chunk-Y7IP5WLG.js";import{a as ee}from"./chunk-SU6CJJJO.js";import{T as Z,g as X,m as Y}from"./chunk-FBI7JGZC.js";import{r as J}from"./chunk-MXUIPT66.js";import{I as z,f as K,l as G}from"./chunk-DX7LHTFF.js";import{Aa as h,Ab as c,Ba as u,Bb as b,Cb as I,Db as E,Dc as L,Fb as y,Gd as j,Kb as C,Kd as U,Lb as d,N as F,Sb as O,Tb as D,Ua as r,Ub as R,Va as _,Wg as Q,Xc as N,Yb as f,_b as T,bd as W,cc as H,dc as V,ec as B,gb as w,gf as q,ib as g,ic as M,kc as P,ob as a,rc as p,sc as m,ta as A,yh as $,zb as l}from"./chunk-N6B2OJOY.js";var me=["templateNameEl"],he=()=>({cxRoute:"orderTemplate"}),ue=(o,s)=>({costCenters:o,purchaseReasons:s});function _e(o,s){if(o&1){let n=y();l(0,"div",15)(1,"div",10)(2,"div",11),f(3),p(4,"cxTranslate"),c(),l(5,"div",12)(6,"div",16)(7,"ng-select",17),p(8,"cxTranslate"),C("change",function(t){h(n);let i=d(2);return u(i.costCenterChanged(t))}),c()(),l(9,"div",16)(10,"ng-select",18),p(11,"cxTranslate"),B("ngModelChange",function(t){h(n);let i=d(2);return V(i.selectedPurchaseReasonValue,t)||(i.selectedPurchaseReasonValue=t),u(t)}),C("change",function(t){h(n);let i=d(2);return u(i.purchaseReasonChanged(t))}),c()(),l(12,"button",19),C("click",function(){h(n);let t=d(2);return u(t.applyCostCenterToOrderTemplate(!0))}),f(13),p(14,"cxTranslate"),c(),l(15,"button",20),C("click",function(){h(n);let t=d(2);return u(t.applyCostCenterToOrderTemplate(!1))}),f(16),p(17,"cxTranslate"),c()()()()}if(o&2){let n=d().ngIf,e=d();r(3),T(" ",m(4,13,"cartDetails.editCostCenter")," "),r(4),a("clearable",!1)("items",n.costCenters)("placeholder",m(8,15,"cartDetails.selectCostCenterPlaceHolder")),r(3),a("clearable",!1)("disabled",!((n.purchaseReasons==null?null:n.purchaseReasons.length)>0))("items",n.purchaseReasons)("placeholder",m(11,17,"cartDetails.selectPurchaseReasonPlaceHolder")),H("ngModel",e.selectedPurchaseReasonValue),r(2),a("disabled",!e.selectedCostCenter),r(),T(" ",m(14,19,"cartHeader.applyCostCenter")," "),r(2),a("disabled",!e.selectedCostCenter),r(),T(" ",m(17,21,"cartHeader.applyForSelected")," ")}}function Ce(o,s){if(o&1){let n=y();I(0),l(1,"button",21),C("click",function(){h(n);let t=d(2);return u(t.openWatchlistDialogToAddInOrderTemplate())}),b(2,"cx-icon",1),f(3),p(4,"cxTranslate"),c(),E()}if(o&2){let n=d(2);r(2),a("type",n.iconTypes.WATCHLIST),r(),T(" ",m(4,2,"cartHeader.searchWatchlist")," ")}}function fe(o,s){if(o&1){let n=y();l(0,"div",7),g(1,_e,18,23,"div",8),l(2,"div",9)(3,"div",10)(4,"div",11),f(5),p(6,"cxTranslate"),c(),l(7,"div",12)(8,"foerch-quick-add-entry",13),C("addToCart",function(t){h(n);let i=d();return u(i.quickAddEntriesToCart(t))}),c(),l(9,"foerch-cart-file-upload",14),C("articlesAdded",function(){h(n);let t=d();return u(t.loadCart())}),c(),g(10,Ce,5,4,"ng-container",6),c()()()()}if(o&2){let n=s.ngIf,e=d();r(),a("ngIf",!e.isEmptyCart&&e.headerConfig.showCCM&&n.costCenters.length),r(4),T(" ",m(6,7,"cartHeader.addArticle")," "),r(3),a("cartMode",e.cartMode)("disableAddButton",!e.canAddArticles),r(),a("buttonClasses","btn btn-link cartBox-link")("cartId",e.orderTemplateCode),r(),a("ngIf",e.watchlistItems.length>0)}}function Te(o,s){if(o&1&&b(0,"foerch-checkout-info",22),o&2){let n=d();a("checkoutInfo",n.checkoutInfo)}}function ve(o,s){o&1&&(I(0),l(1,"div",23)(2,"div",24)(3,"div",25),f(4),p(5,"cxTranslate"),c()()(),E()),o&2&&(r(4),T(" ",m(5,1,"orderTemplateList.noEntries")," "))}var Ye=(()=>{let s=class s extends de{constructor(e,t,i,v,x,S,pe,k){super(e,t,i,v,x,S,k),this.activeCartService=e,this.watchlistService=t,this.orderTemplateService=i,this.modalService=v,this.authService=x,this.cd=S,this.activatedRoute=pe,this.permissionService=k,this.orderTemplateEntries=[],this.isEmptyWatchList=!0,this.canAddArticles=!1,this.checkoutInfo=null,this.cartMode=Y.ORDER_TEMPLATE_DETAILS,this.hasAddedArticles=!1}ngOnInit(){super.ngOnInit(),this.orderTemplateCode=this.activatedRoute.snapshot.params.code,this._subs$.add(this.orderTemplateService.getOrderTemplate().subscribe(e=>{e&&(this.orderTemplate=e,this.orderTemplateEntries=e.entries?e.entries:[],this.isEmptyCart=this.orderTemplateEntries.length===0,this.canAddArticles=!0,this.checkForNonPurchasableEntries(),this.cd.markForCheck())})),this._subs$.add(this.watchlistService.getEntries().subscribe(e=>{this.watchlistItems=e,this.isEmptyWatchList=!e||e.length===0})),this._subs$.add(this.permissionService.getPermissionValueAsBoolean(Z.COST_CENTER_MANAGEMENT_TOOL).subscribe(e=>this.headerConfig.showCCM=e))}updateEntryTemplateName(e){e!=this.orderTemplate.name&&this.orderTemplateService.changeTemplateName(this.orderTemplateCode,e)}quickAddEntriesToCart(e){this.hasAddedArticles||(this._subs$.add(this.orderTemplateService.isOrderTemplateItemDataLoaded().pipe(F(1)).subscribe(t=>{this.canAddArticles=t,this.cd.markForCheck()})),this.hasAddedArticles=!0),this.orderTemplateService.addEntries({cartId:this.orderTemplateCode,entries:e})}applyCostCenterToOrderTemplate(e){let t=this.orderTemplateEntries.map(i=>i.pk);this.orderTemplateService.applyCostCenter({code:this.orderTemplateCode,costCenter:this.selectedCostCenter.code,costReason:this.selectedPurchaseReason?this.selectedPurchaseReason.code:null,PKs:t,toAll:e})}openWatchlistDialogToAddInOrderTemplate(){let e={scrollable:!0},i=this.modalService.open(le,e).componentInstance;i.isWatchList=!0,i.addToOrderTemplate=!0,i.orderTemplateCode=this.orderTemplateCode,i.watchlistItems=this.watchlistItems}loadCart(){this.orderTemplateService.loadOrderTemplateById(this.orderTemplateCode)}checkForNonPurchasableEntries(){this.orderTemplateEntries.some(e=>e.product?.saleability?.purchasable===!1)?this.checkoutInfo={allowed:!1,reason:X.NOT_PURCHASABLE_ORDER_TEMPLATE}:this.checkoutInfo=null}};s.\u0275fac=function(t){return new(t||s)(_(ae),_(ee),_(se),_(re),_(q),_(L),_(j),_(te))},s.\u0275cmp=A({type:s,selectors:[["foerch-order-template-detail-head"]],viewQuery:function(t,i){if(t&1&&O(me,5),t&2){let v;D(v=R())&&(i.templateNameField=v.first)}},features:[w],decls:12,vars:21,consts:[[1,"btn","btn-tertiary","btn-back",3,"routerLink"],[3,"type"],[1,"orderTemplateDetailHead"],[3,"valueChanged","allowModeToggle","showEditButton","value"],["class","row g-0",4,"ngIf"],["class","mt-2",3,"checkoutInfo",4,"ngIf"],[4,"ngIf"],[1,"row","g-0"],["class","col-sm-6 pe-2",4,"ngIf"],[1,"col-sm-6"],[1,"cartBox"],[1,"cartBox-head"],[1,"cartBox-body"],[3,"addToCart","cartMode","disableAddButton"],[3,"articlesAdded","buttonClasses","cartId"],[1,"col-sm-6","pe-2"],[1,"form-group"],["bindLabel","name","bindValue","PK","labelForId","costCenters",3,"change","clearable","items","placeholder"],["bindLabel","name","bindValue","PK","labelForId","purchaseReasons",3,"ngModelChange","change","clearable","disabled","items","placeholder","ngModel"],["type","button",1,"btn","btn-secondary","btn-block",3,"click","disabled"],[1,"btn","btn-secondary","btn-block","mt-2",3,"click","disabled"],["type","button",1,"btn","btn-link","cartBox-link",3,"click"],[1,"mt-2",3,"checkoutInfo"],[1,"row","emptyState"],[1,"col-12"],[1,"emptyState-text"]],template:function(t,i){t&1&&(l(0,"a",0),p(1,"cxUrl"),b(2,"cx-icon",1),f(3),p(4,"cxTranslate"),c(),l(5,"div",2)(6,"foerch-inline-edit",3),C("valueChanged",function(x){return i.updateEntryTemplateName(x)}),c(),g(7,fe,11,9,"div",4),p(8,"async"),p(9,"async"),c(),g(10,Te,1,1,"foerch-checkout-info",5)(11,ve,6,3,"ng-container",6)),t&2&&(a("routerLink",m(1,9,M(17,he))),r(2),a("type",i.iconTypes.ARROW_LEFT),r(),T(" ",m(4,11,"common.back"),`
`),r(3),a("allowModeToggle",!0)("showEditButton",!0)("value",i.orderTemplate==null?null:i.orderTemplate.name),r(),a("ngIf",P(18,ue,m(8,13,i.costCenters$),m(9,15,i.purchaseReasons$))),r(3),a("ngIf",i.checkoutInfo),r(),a("ngIf",i.isEmptyCart))},dependencies:[K,G,N,z,J,U,ce,ne,ie,oe,W,$,Q],encapsulation:2,changeDetection:0});let o=s;return o})();export{Ye as a};