import{d as he}from"./chunk-SQMVZU4I.js";import{a as de}from"./chunk-FKH74CIW.js";import{H as ue}from"./chunk-CWWVHRJU.js";import{c as se}from"./chunk-TFQ3RBKD.js";import{a as ce}from"./chunk-3WPA6UNY.js";import{a as me}from"./chunk-YII4XRFM.js";import{a as le}from"./chunk-RU43IR5J.js";import{d as ne}from"./chunk-ZSVIZXE3.js";import{b as ae}from"./chunk-ISDPQX42.js";import{a as pe}from"./chunk-HBJ2IG4O.js";import{A as te,D as oe,e as M,f as X,g as Z,m as ee,q as ie,t as re}from"./chunk-DX7LHTFF.js";import{Aa as d,Ab as c,Ba as u,Cf as j,Df as z,E as S,Fb as A,H as R,Ha as U,Kb as g,Kd as G,Me as Q,Nd as L,Ob as C,Oe as O,Q as _,Sb as I,Tb as T,Ua as m,Ub as P,Wg as Y,Xg as H,Yb as f,Zb as B,_b as b,da as y,ga as x,gc as N,gf as W,ia as k,ic as D,n as V,o as F,ob as h,pa as i,qf as q,rc as s,rf as $,sc as n,ta as E,yh as J,zb as l,zh as K}from"./chunk-N6B2OJOY.js";function ge(p){if(!(p.access_token||p.expires_at))return!1;let a=parseInt(p.expires_at);if(Number.isNaN(a))return!1;let fe=new Date(a).getTime(),e=new Date().getTime();return fe>e}var ve=["email"],Se=["password"],be=()=>({cxRoute:"forgotPassword"}),je=(()=>{let a=class a{constructor(){this.authService=i(W),this.authStorageService=i(O),this.globalMessageService=i(z),this.fb=i(te),this.winRef=i(Q),this.permissionsService=i(le),this.eProcurementService=i(ue),this.routingService=i(pe),this.baseSiteService=i(ne),this.userAccountService=i(se),this.userService=i(he),this.statePersistenceService=i($),this.destroyRef=i(U),this.rememberMe=!1,this.loginPending=!1}ngOnInit(){this.eProcurementService.deactivateOCI(),this.form=this.fb.group({userId:["",[M.required],[me.regexpEmailAsyncValidator(this.baseSiteService)]],password:["",M.required]}),this.form.statusChanges.pipe(L(this.destroyRef),_()).subscribe(e=>{e==="INVALID"&&this.focusInvalidField()})}enableLogin(){this.loginPending=!1}onChangePassword(e){this.form.get("password").setValue(e)}login(){if(this.form.invalid){this.form.markAllAsTouched(),this.focusInvalidField();return}this.loginPending||(this.loginPending=!0,this.loginUser())}loginUser(){V(this.authService.loginWithCredentials(this.form.value.userId.toLowerCase(),this.form.value.password)).pipe(L(this.destroyRef),k(this.authStorageService.getToken(),this.authService.isUserLoggedIn()),S(([e,t,r])=>ge(t)&&r),_(),y(()=>this.userAccountService.get()),S(e=>!!e),x(e=>{this.persistRememberMe(),this.globalMessageService.remove(j.MSG_TYPE_ERROR)}),y(e=>R(F(e),this.baseSiteService.isLoggedInWrongCountry(e))),S(([e,t])=>!t)).subscribe(([e,t])=>{this.baseSiteService.switchCurrencyForUser(e),this.userService.isPasswordChangeNecessary(e)||(this.permissionsService.loadPermissions(),this.redirectToLastPage())})}redirectToLastPage(){let e=this.routingService.getLastUrl()??"/";e.startsWith("/checkout")&&(e="/cart"),this.routingService.goByUrl(e),this.eProcurementService.stopEProcurementSession()}toggleValue(e){this.rememberMe=e.target.checked}focusInvalidField(){this.form.get("userId").invalid?this.emailField.focus():this.form.get("password").invalid&&this.pwField.focus()}persistRememberMe(){this.statePersistenceService.syncWithStorage({key:"login",state$:F({rememberMe:this.rememberMe}),context$:this.baseSiteService.getActive(),storageType:q.LOCAL_STORAGE})}};a.\u0275fac=function(t){return new(t||a)},a.\u0275cmp=E({type:a,selectors:[["foerch-login-form"]],viewQuery:function(t,r){if(t&1&&(I(ve,5),I(Se,5)),t&2){let o;T(o=P())&&(r.emailField=o.first),T(o=P())&&(r.pwField=o.first)}},standalone:!0,features:[N],decls:27,vars:32,consts:[["email",""],["password",""],[3,"submit","formGroup"],[1,"h3","mb-2"],["formControlName","userId","inputId","loginUserId","type","email",3,"input","label","autofocus","errorMsg","noSpace","placeholder"],["formControlName","password","inputId","loginPassword",3,"input","valueChanged","label","placeholder"],["aria-controls","reset-password",1,"logReg-resetPassword",3,"routerLink"],[1,"row","align-items-center"],[1,"col-sm-6"],[1,"form-check","form-checkbox","mt-2","mb-3","my-sm-0"],["aria-checked","true","id","loginRememberMe","role","checkbox","type","checkbox",1,"form-check-input",3,"change"],["for","loginRememberMe",1,"form-check-label"],["type","submit",1,"btn","btn-block","btn-primary"]],template:function(t,r){if(t&1){let o=A();l(0,"form",2),g("submit",function(){return d(o),u(r.login())}),l(1,"div",3),f(2),s(3,"cxTranslate"),c(),l(4,"foerch-input",4,0),s(6,"cxTranslate"),s(7,"cxTranslate"),g("input",function(){return d(o),u(r.enableLogin())}),c(),l(8,"foerch-password",5,1),s(10,"cxTranslate"),s(11,"cxTranslate"),g("input",function(){return d(o),u(r.enableLogin())})("valueChanged",function(w){return d(o),u(r.onChangePassword(w))}),c(),l(12,"a",6),s(13,"cxUrl"),f(14),s(15,"cxTranslate"),c(),l(16,"div",7)(17,"div",8)(18,"div",9)(19,"input",10),g("change",function(w){return d(o),u(r.toggleValue(w))}),c(),l(20,"label",11),f(21),s(22,"cxTranslate"),c()()(),l(23,"div",8)(24,"button",12),f(25),s(26,"cxTranslate"),c()()()()}t&2&&(h("formGroup",r.form),m(2),b(" ",n(3,13,"loginForm.alreadyCustomerLabel")," "),m(2),C("label",n(6,15,"loginForm.emailAddress.label")),h("autofocus",!0)("errorMsg",r.form.controls.userId.invalid&&r.form.controls.userId.dirty?"common.wrongEmailFormat":"")("noSpace",!0)("placeholder",n(7,17,"loginForm.emailAddress.placeholder")),m(4),C("label",n(10,19,"loginForm.password.label")),h("placeholder",n(11,21,"loginForm.password.placeholder")),m(4),h("routerLink",n(13,23,D(31,be))),m(2),b("",n(15,25,"loginForm.forgotPassword")," "),m(7),B(n(22,27,"loginForm.rememberMe")),m(4),b(" ",n(26,29,"loginForm.signIn")," "))},dependencies:[de,ae,ce,K,J,oe,ee,X,Z,ie,re,G,H,Y],encapsulation:2,changeDetection:0});let p=a;return p})();export{ge as a,je as b};