import{b as J}from"./chunk-5RG27LZ2.js";import{a as Te}from"./chunk-WSZCTDHN.js";import{a as W}from"./chunk-UB23RF7S.js";import{b as be}from"./chunk-5OZTUYJC.js";import{J as R}from"./chunk-CWWVHRJU.js";import{c as Ce}from"./chunk-TFQ3RBKD.js";import{b as Se}from"./chunk-QMZQK3O6.js";import{a as ge}from"./chunk-GFXONX4P.js";import{a as ye}from"./chunk-6IGMG2LM.js";import{a as L}from"./chunk-RU43IR5J.js";import{a as N}from"./chunk-Y7IP5WLG.js";import{a as xe}from"./chunk-LY6HB4BL.js";import{a as O}from"./chunk-SU6CJJJO.js";import{T as fe,d as M,m as z}from"./chunk-FBI7JGZC.js";import{a as j}from"./chunk-ILYMG6ZI.js";import{r as D}from"./chunk-MXUIPT66.js";import{I as ve,f as _e,l as ue}from"./chunk-DX7LHTFF.js";import{$b as re,Aa as f,Ab as l,Ba as g,Bb as I,Cb as y,Db as b,Dc as B,E as te,Fb as F,Ka as G,Kb as S,Lb as s,Og as he,Ua as o,Va as _,Vc as le,Xc as E,Yb as v,_b as C,a as X,bd as P,ca as ie,cc as oe,dc as ae,ec as ce,ga as ne,gd as de,gf as H,ib as x,ic as Q,jc as se,kc as pe,lc as w,o as Z,ob as c,rc as d,rg as me,s as ee,sc as m,t as A,ta as V,vc as Y,yh as k,zb as p}from"./chunk-N6B2OJOY.js";import{a as q}from"./chunk-GHL4OFBQ.js";var He=(n,t,e)=>({approvalSettings:n,currencyCode:t,locale:e}),Ie=(n,t,e)=>[n,t,"symbol","1.2",e];function ke(n,t){if(n&1&&(p(0,"div",8)(1,"div",9),v(2),d(3,"cxTranslate"),l(),p(4,"div")(5,"span",10)(6,"foerch-price-info",13),v(7),d(8,"currency"),l()()()()),n&2){let e=s(3).ngIf;o(2),C(" ",m(3,5,"cartHeader.approvalBox.budgetRemainingHeading")," "),o(4),c("popoverText","cartHeader.approvalBox.budgetRemainingPopoverText")("price",e.approvalSettings.remainingBudget)("shouldShowPriceAndInfo",!0),o(),C(" ",Y(8,7,w(13,Ie,e.approvalSettings.remainingBudget,e.currencyCode,e.locale))," ")}}function De(n,t){if(n&1&&(y(0),p(1,"div",7)(2,"div",8)(3,"div",9),v(4),d(5,"cxTranslate"),l(),p(6,"div")(7,"span",10),v(8),d(9,"currency"),l(),p(10,"span"),v(11),d(12,"cxTranslate"),l()()(),x(13,ke,9,17,"div",11),l(),I(14,"div",12),b()),n&2){let e=s(2).ngIf;o(4),C(" ",m(5,5,"cartHeader.approvalBox.budgetHeading")," "),o(4),C(" ",Y(9,7,w(15,Ie,e.approvalSettings.approvalProcessValue,e.currencyCode,e.locale))," "),o(3),re(" ",m(12,13,"cartHeader.approvalBox.budgetReferencePer")," ",e.approvalSettings.approvalProcessReferenceValue," "),o(2),c("ngIf",e.approvalSettings.shouldSeeRemainingBudget)}}function Me(n,t){if(n&1&&(p(0,"div",2),x(1,De,15,19,"ng-container",0),p(2,"div",3)(3,"div",4),I(4,"cx-icon",5),p(5,"div",6),v(6),d(7,"cxTranslate"),l()()()()),n&2){let e=s().ngIf,i=s();o(),c("ngIf",e.approvalSettings.shouldSeeApprovalBudget),o(3),c("type",i.iconTypes.WARNING),o(2),C(" ",m(7,3,"cartHeader.approvalBox.infoText")," ")}}function je(n,t){if(n&1&&(y(0),x(1,Me,8,5,"div",1),b()),n&2){let e=t.ngIf;o(),c("ngIf",e.approvalSettings==null?null:e.approvalSettings.shouldSeeApprovalBox)}}var Fe=(()=>{let t=class t{constructor(i,r,a,u,h,$){this._userAccountService=i,this._currencyService=r,this._currencyLocaleService=a,this._approvalRefValService=u,this._translationService=h,this._activeCartService=$,this.iconTypes=j,this.currencyCode$=this._currencyService.getActive(),this.locale$=this._currencyLocaleService.getActiveLocaleForCurrencyPipe()}ngOnInit(){this.approvalSettings$=A([this._userAccountService.get().pipe(ie({approvalProcessType:M.No_Approval})),this._approvalRefValService.getApprovalReferenceValues(),this._translationService.translate("common.notAvailableShorthand"),this._activeCartService.getEntries()]).pipe(te(([i])=>!!i),ee(([i,r,a,u])=>{let h=i,$=u&&u.length>0,U=!!h.approvalProcessType,K=h.approvalProcessType===M.Approval_With_Value;return{shouldSeeApprovalBox:$&&U&&h.approvalProcessType!==M.No_Approval,shouldSeeApprovalBudget:U&&K,shouldSeeRemainingBudget:U&&K&&h.approvalProcessReferenceValue!=="ORDER",approvalProcessReferenceValue:this.getReferenceValueName(r,h.approvalProcessReferenceValue,a),approvalProcessValue:h.approvalProcessValue,remainingBudget:h.remainingBudget}}))}getReferenceValueName(i,r,a){let u=(i||[]).find(h=>h.code===r);return u?u.name:a}};t.\u0275fac=function(r){return new(r||t)(_(Ce),_(me),_(be),_(ge),_(he),_(R))},t.\u0275cmp=V({type:t,selectors:[["foerch-approval-box"]],decls:4,vars:11,consts:[[4,"ngIf"],["class","approval-box",4,"ngIf"],[1,"approval-box"],[1,"approval-box-item","text-item"],[1,"approval-info"],[3,"type"],[1,"approval-info-text"],[1,"approval-box-item","budget-item"],[1,"approval-budget"],[1,"approval-budget-heading"],[1,"approval-budget-amount"],["class","approval-budget",4,"ngIf"],[1,"marker-item"],[3,"popoverText","price","shouldShowPriceAndInfo"]],template:function(r,a){r&1&&(x(0,je,2,1,"ng-container",0),d(1,"async"),d(2,"async"),d(3,"async")),r&2&&c("ngIf",w(7,He,m(1,1,a.approvalSettings$),m(2,3,a.currencyCode$),m(3,5,a.locale$)))},dependencies:[D,E,Se,k,P,de],encapsulation:2,changeDetection:0});let n=t;return n})();var Le=function(n,t,e,i){var r=arguments.length,a=r<3?t:i===null?i=Object.getOwnPropertyDescriptor(t,e):i,u;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")a=Reflect.decorate(n,t,e,i);else for(var h=n.length-1;h>=0;h--)(u=n[h])&&(a=(r<3?u(a):r>3?u(t,e,a):u(t,e))||a);return r>3&&a&&Object.defineProperty(t,e,a),a},Ne=function(n,t){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(n,t)},We=(n,t)=>({costCenters:n,purchaseReasons:t}),Ae=()=>[],$e=n=>({"offset-sm-3":n});function Ue(n,t){n&1&&I(0,"foerch-approval-box")}function qe(n,t){if(n&1){let e=F();p(0,"div",6)(1,"div",7)(2,"div",8),v(3),d(4,"cxTranslate"),l(),p(5,"div",9)(6,"div",10)(7,"div",11)(8,"div",12)(9,"ng-select",13),d(10,"cxTranslate"),S("change",function(r){f(e);let a=s(3);return g(a.costCenterChanged(r))}),l()()(),p(11,"div",14)(12,"div",12)(13,"ng-select",15),d(14,"cxTranslate"),ce("ngModelChange",function(r){f(e);let a=s(3);return ae(a.selectedPurchaseReasonValue,r)||(a.selectedPurchaseReasonValue=r),g(r)}),S("change",function(r){f(e);let a=s(3);return g(a.purchaseReasonChanged(r))}),l()()()(),p(15,"div",10)(16,"div",16)(17,"button",17),S("click",function(){f(e);let r=s(3);return g(r.applyCostCenter(!0))}),v(18),d(19,"cxTranslate"),l()(),p(20,"div",18)(21,"button",19),S("click",function(){f(e);let r=s(3);return g(r.applyCostCenter(!1))}),v(22),d(23,"cxTranslate"),l()()()()()()}if(n&2){let e=s().ngIf,i=s(2);o(3),C(" ",m(4,13,"cartDetails.editCostCenter")," "),o(6),c("clearable",!1)("items",e.costCenters)("placeholder",m(10,15,"cartDetails.selectCostCenterPlaceHolder")),o(4),c("clearable",!1)("disabled",(e.purchaseReasons||Q(23,Ae)).length===0)("items",e.purchaseReasons)("placeholder",m(14,17,"cartDetails.selectPurchaseReasonPlaceHolder")),oe("ngModel",i.selectedPurchaseReasonValue),o(4),c("disabled",!i.selectedCostCenter),o(),C(" ",m(19,19,"cartHeader.applyCostCenter")," "),o(3),c("disabled",!i.selectedCostCenter),o(),C(" ",m(23,21,"cartHeader.applyForSelected")," ")}}function Ge(n,t){if(n&1&&(y(0),x(1,qe,24,24,"div",5),b()),n&2){let e=t.ngIf,i=s(2);o(),c("ngIf",!i.isEmptyCart&&i.headerConfig.showCCM&&(e.costCenters||Q(1,Ae)).length)}}function Qe(n,t){if(n&1&&(y(0),x(1,Ge,2,2,"ng-container",1),d(2,"async"),d(3,"async"),b()),n&2){let e=s();o(),c("ngIf",pe(5,We,m(2,1,e.costCenters$),m(3,3,e.purchaseReasons$)))}}function Ye(n,t){if(n&1){let e=F();p(0,"div",20)(1,"foerch-quick-add-entry",21),S("addToCart",function(r){f(e);let a=s();return g(a.onAddToCart(r))}),l()()}if(n&2){let e=s();o(),c("disableAddButton",!e.isCartRefreshed)}}function ze(n,t){if(n&1){let e=F();y(0),p(1,"button",24),S("click",function(){f(e);let r=s(2);return g(r.openWatchlistDialog())}),I(2,"cx-icon",25),v(3),d(4,"cxTranslate"),l(),b()}if(n&2){let e=s(2);o(2),c("type",e.iconTypes.WATCHLIST),o(),C(" ",m(4,2,"cartHeader.searchWatchlist")," ")}}function Je(n,t){if(n&1){let e=F();y(0),p(1,"button",24),S("click",function(){f(e);let r=s(2);return g(r.openOrderTemplateDialog())}),I(2,"cx-icon",25),v(3),d(4,"cxTranslate"),l(),b()}if(n&2){let e=s(2);o(2),c("type",e.iconTypes.SAVE),o(),C(" ",m(4,2,"cartDialog.useOrderTemplate")," ")}}function Ke(n,t){if(n&1){let e=F();p(0,"div",22)(1,"div",7)(2,"div",8),v(3),d(4,"cxTranslate"),l(),p(5,"div",9)(6,"foerch-quick-add-entry",21),S("addToCart",function(r){f(e);let a=s();return g(a.onAddToCart(r))}),l(),p(7,"foerch-cart-file-upload",23),S("articlesAdded",function(){f(e);let r=s();return g(r.loadCart())}),l(),x(8,ze,5,4,"ng-container",1)(9,Je,5,4,"ng-container",1),l()()()}if(n&2){let e=s();c("ngClass",se(8,$e,e.isEmptyCart)),o(3),C(" ",m(4,6,"cartHeader.addArticle")," "),o(3),c("disableAddButton",!e.isCartRefreshed),o(),c("buttonClasses","btn btn-link cartBox-link"),o(),c("ngIf",e.isLoggedIn&&e.watchlistItems.length>0),o(),c("ngIf",e.isLoggedIn&&e.orderTemplates.length>0)}}var T,Re=(T=class{set headerConfig(t){this._headerConfig=q(q({},this._headerConfig),t)}get headerConfig(){return this._headerConfig}constructor(t,e,i,r,a,u,h){this.activeCartService=t,this.watchlistService=e,this.orderTemplateService=i,this.modalService=r,this.authService=a,this.cd=u,this.permissionService=h,this.iconTypes=j,this.cartModes=z,this.quickEntry="",this.isEmptyCart=!0,this.isCartRefreshed=!0,this.applyCCM=new G,this.addToCart=new G,this.isLoggedIn=!1,this.selectedCostCenter=null,this.selectedPurchaseReason=null,this.selectedPurchaseReasonValue=null,this.watchlistItems=[],this.orderTemplates=[],this._subs$=new X,this._headerConfig={showCCM:!0,showDialogLinks:!0,showQuickAddInBox:!0}}ngOnInit(){this._subs$.add(A([this.authService.isUserLoggedIn(),this.permissionService.getPermissionValueAsBoolean(fe.VISITING_CUSTOMER)]).subscribe(([t,e])=>{this.isLoggedIn=t,t?(this.costCenters$=this.activeCartService.getAllCostCentersAndOrderReasons(),this._subs$.add(this.watchlistService.getEntries().subscribe(i=>{this.watchlistItems=i,this.cd.markForCheck()})),this.headerConfig.cartMode===z.CART&&e===!1&&(this._subs$.add(this.orderTemplateService.get().subscribe(i=>{i&&(this.orderTemplates=i.results,this.cd.markForCheck())})),this.orderTemplateService.loadAll())):(this.watchlistItems=[],this.orderTemplates=[],this.cd.markForCheck())}))}ngOnDestroy(){this._subs$.unsubscribe()}costCenterChanged(t){this.selectedPurchaseReason=null,this.selectedPurchaseReasonValue=null,this.selectedCostCenter=null,this.purchaseReasons$=Z([]);let e=t;e&&e.code&&(this.selectedCostCenter=e,this.purchaseReasons$=this.activeCartService.getOrderReasonsByCostCenter({id:t.code}).pipe(ne(i=>{i&&i.length>0&&(this.selectedPurchaseReason=i[0],this.selectedPurchaseReasonValue=i[0].code)})))}purchaseReasonChanged(t){t&&t.code?this.selectedPurchaseReason=t:this.selectedPurchaseReason=null}applyCostCenter(t){this.applyCCM.emit({costCenter:this.selectedCostCenter,purchaseReason:this.selectedPurchaseReason,toAll:t})}openWatchlistDialog(){let t={scrollable:!0},i=this.modalService.open(J,t).componentInstance;i.isWatchList=!0,i.watchlistItems=this.watchlistItems}openOrderTemplateDialog(){let t={scrollable:!0},i=this.modalService.open(J,t).componentInstance;i.isWatchList=!1,i.orderTemplateItems=this.orderTemplates}onAddToCart(t){this.addToCart.emit(t)}loadCart(){this.activeCartService.loadCart()}},T.\u0275fac=function(e){return new(e||T)(_(R),_(O),_(W),_(N),_(H),_(B),_(L))},T.\u0275cmp=V({type:T,selectors:[["foerch-cart-head"]],inputs:{quickEntry:"quickEntry",isEmptyCart:"isEmptyCart",isCartRefreshed:"isCartRefreshed",headerConfig:"headerConfig"},outputs:{applyCCM:"applyCCM",addToCart:"addToCart"},decls:6,vars:4,consts:[[1,"cartHeaderContainer"],[4,"ngIf"],[1,"row","cart-box-row"],["class","col-sm-7",4,"ngIf"],["class","col-sm-6 mt-2 mt-sm-0",3,"ngClass",4,"ngIf"],["class","col-sm-6",4,"ngIf"],[1,"col-sm-6"],[1,"cartBox"],[1,"cartBox-head"],[1,"cartBox-body"],[1,"row","g-0"],[1,"col","col-md-6","pe-2"],[1,"form-group","mb-0"],["bindLabel","name","bindValue","code","labelForId","costCenters",3,"change","clearable","items","placeholder"],[1,"col","col-md-6"],["bindLabel","name","bindValue","code","labelForId","purchaseReasons",3,"ngModelChange","change","clearable","disabled","items","placeholder","ngModel"],[1,"col-12","col-md-6","pe-2"],["type","button",1,"btn","btn-secondary","btn-block","mt-2",3,"click","disabled"],[1,"col-12","col-md-6"],[1,"btn","btn-secondary","btn-block","mt-2",3,"click","disabled"],[1,"col-sm-7"],[3,"addToCart","disableAddButton"],[1,"col-sm-6","mt-2","mt-sm-0",3,"ngClass"],[3,"articlesAdded","buttonClasses"],["type","button",1,"btn","btn-link","cartBox-link",3,"click"],[3,"type"]],template:function(e,i){e&1&&(p(0,"div",0),x(1,Ue,1,0,"foerch-approval-box",1),p(2,"div",2),x(3,Qe,4,8,"ng-container",1)(4,Ye,2,1,"div",3)(5,Ke,10,10,"div",4),l()()),e&2&&(o(),c("ngIf",i.headerConfig.cartMode===i.cartModes.CART),o(2),c("ngIf",i.costCenters$),o(),c("ngIf",!i.headerConfig.showDialogLinks),o(),c("ngIf",i.headerConfig.showDialogLinks))},dependencies:[_e,ue,le,E,ve,D,ye,Fe,Te,P,k],encapsulation:2,changeDetection:0}),T);Re=Le([xe(),Ne("design:paramtypes",[R,O,W,N,H,B,L])],Re);export{Fe as a,Re as b};