import{a as X,b as z}from"./chunk-I2S6XGNZ.js";import{d as K}from"./chunk-SQMVZU4I.js";import{f as W}from"./chunk-VLPXNKU4.js";import{a as M}from"./chunk-3UAMWNPB.js";import{a as n}from"./chunk-YII4XRFM.js";import{a as G,b as H,d as Y}from"./chunk-ZSVIZXE3.js";import{b as c,c as h}from"./chunk-A5VMGYDH.js";import{_d as F}from"./chunk-RQDYBYBM.js";import{e as f}from"./chunk-FBI7JGZC.js";import{a as j}from"./chunk-ILYMG6ZI.js";import{f as k,x as $}from"./chunk-MXUIPT66.js";import{A as L,e as i}from"./chunk-DX7LHTFF.js";import{Cf as B,Df as x,E as T,Ha as I,Ka as E,Me as U,N as C,Nd as g,Q as V,Yb as O,Yh as _,a as w,ba as q,d as y,pa as a,qg as P,s as p,t as R,ta as D}from"./chunk-N6B2OJOY.js";import{a as N,b as A}from"./chunk-GHL4OFBQ.js";var J=1e6,ye=(()=>{let m=class m{constructor(){this.isCordova=a(H),this.baseSiteService=a(Y),this.contentLinkService=a(z),this.userRegisterService=a(W),this.globalMessageService=a(x),this.salesDivisionsService=a(G),this.userAddressService=a(_),this.foerchUserService=a(K),this.languageService=a(P),this.breakpointService=a($),this.fb=a(L),this.winRef=a(U),this.destroyRef=a(I),this.registerSuccess=new E,this.termsAndConditionsUrl$=this.contentLinkService.getContentLinkForBaseSite(X.TERMS_AND_CONDITIONS).pipe(p(e=>[e.url])),this.salesDivisions$=this.salesDivisionsService.getAllSalesDivisions().pipe(p(e=>F(e,"name"))),this.isRequestPending$=new y(!1),this.countries$=new y([]),this.icons=j,this.MAX_EMPLOYEE_AMOUNT=J,this.shouldShowMore=!1,this.isAlreadyCustomer=!0,this.hasBeenSubmitted=!1,this.termsAndConditionLinkTarget=this.isCordova?"_self":"_blank",this.formFeatureConfig={isUstNumberRequired:!1,shouldShowUstNumber:!0,isUploadBusinessRegistrationRequired:!1,shouldShowUploadBusinessRegistration:!0,isTelephoneRequired:!1,shouldShowTelephone:!0,isIndustryGroupRequired:!1,shouldShowIndustryGroup:!1,isTitleRequired:!0,shouldShowTitle:!0},this.userRegistrationForm=this.fb.group({titleCode:[""],firstName:["",i.required],lastName:["",i.required],email:["",[i.required],[n.regexpEmailAsyncValidator(this.baseSiteService)]],password:["",[i.required,n.passwordValidator]],passwordconf:["",i.required],salesDivisionName:[null,i.required],industryName:[null],occupation:[null,i.required],newsletter:[!1],termsandconditions:[!1,i.requiredTrue],termsandconditions2:[!1,i.requiredTrue],employees:[null],customerNumber:["",[i.required],[n.regexpCustomerNumberAsyncValidator(this.baseSiteService)]],post1:[""],company:[""],streetAndHouseNumber:[""],extraToAddress:[""],post2:[""],place:[""],country:["",i.required],ustNumber:[""],uploadBusinessRegistration:[null],additionalTelephone:[""],telephone:[""],message:[""],tradeRegisterNumber:[""],branchNumber:[""],visitFromADM:[!1]},{validators:[this.matchPassword]}),this.subs$=new w,this.isMobile=!1}ngOnInit(){this.adjustFormValidatorsBasedOnCustomerStatus(!0),this.prepareFormFeaturesConfig(),this.getDeliveryCountries(),this.canSubscribeToNewsletter$=this.baseSiteService.getActive().pipe(p(e=>e===M.GERMANY)),this.breakpointService.isDown(k.sm).pipe(g(this.destroyRef)).subscribe(e=>this.isMobile=e)}ngOnDestroy(){this.subs$.unsubscribe()}adjustFormValidatorsBasedOnCustomerStatus(e){this.isAlreadyCustomer=e;let[s,t,o,u,r,l,b,v]=["customerNumber","post1","company","streetAndHouseNumber","post2","place","country","employees"].map(d=>this.userRegistrationForm.get(d));if(e){s.setValidators([i.required]),s.setAsyncValidators([n.regexpCustomerNumberAsyncValidator(this.baseSiteService)]),t.setValidators([i.required]),t.setAsyncValidators([n.regexpPostalCodeAsyncValidator(this.baseSiteService)]);for(let d of[o,u,r,l,b,v])d.setValidators(null)}else{s.setValidators(null),s.setAsyncValidators(null),t.setValidators(null),t.setAsyncValidators(null),v.setValidators([i.min(1),i.max(J),i.required]);for(let d of[o,u,l,b])d.setValidators([i.required]);r.setValidators([i.required,n.regexpPostalCodeValidator(this.userRegistrationForm.get("country").value.postalCodeRegex)])}for(let d of[s,o,u,t,r,l,b,v])d.updateValueAndValidity()}salesDivisionChanged(e){if(e){let s=e.PK;this.customerEmployeeOccupations$=this.salesDivisionsService.getCustomerEmployeesOccupations(s).pipe(p(t=>F(t,"name")))}this.userRegistrationForm.get("occupation").setValue(null)}isControlInvalid(e){let s=this.userRegistrationForm.get(e);return s?s.invalid&&(s.touched||s.dirty):!0}onCountryChanged(e){if(e){let s=this.userRegistrationForm.get("post2");s.setValidators([i.required,n.regexpPostalCodeValidator(e.postalCodeRegex)]),s.updateValueAndValidity()}}submit(){this.hasBeenSubmitted=!0,this.userRegistrationForm.invalid?(this.userRegistrationForm.markAllAsTouched(),this.scrollToFirstInvalidFormControl()):this.registerWithFormData()}scrollToFirstInvalidFormControl(){let e=this.winRef.nativeWindow.document.querySelector("ng-select.ng-invalid, foerch-input.ng-invalid");e&&e.scrollIntoView({behavior:"smooth",block:"center",inline:"center"})}transformFormValuesForSubmission(){this.emailToLowerCase();let e=this.userRegistrationForm.getRawValue(),s={firstName:e.firstName,lastName:e.lastName,uid:e.email,password:e.password,titleCode:e.titleCode,isFoerchCustomer:this.isAlreadyCustomer,salesDivision:e.salesDivisionName,occupation:e.occupation,industryGroup:e.industryName,isNewsLetter:e.newsletter,mobile:e.additionalTelephone,telephone:e.telephone,message:e.message,visitFromADM:e.visitFromADM};return this.isAlreadyCustomer?(s.customerNumber=e.customerNumber,s.postalCode=e.post1,this.formFeatureConfig.isUstNumberRequired&&e.ustNumber&&(s.ustIdNumber=e.ustNumber)):(s.company=e.company,s.streetname=e.streetAndHouseNumber.trim(),s.addressInfo=e.extraToAddress,s.town=e.place,s.postalCode=e.post2,s.ustIdNumber=e.ustNumber,s.uploadBusinessRegistration=e.uploadBusinessRegistration,s.employees=e.employees,s.tradeRegisterNumber=e.tradeRegisterNumber,s.branchNumber=e.branchNumber,s.countryIso=e.country&&e.country.isocode||""),this.isCordova?s.origin=f.APP:s.origin=this.isMobile?f.MOBILE:f.DESKTOP,s}registerWithFormData(){let e=this.transformFormValuesForSubmission();this.isRequestPending$.next(!0),this.userRegisterService.register(e).pipe(g(this.destroyRef)).subscribe({next:()=>{this.isRequestPending$.next(!1),this.globalMessageService.add({key:"register.postRegisterMessage"},B.MSG_TYPE_CONFIRMATION),this.registerSuccess.emit()},error:s=>{throw this.isRequestPending$.next(!1),new Error(`Error while registering new user: ${s.toString()}`)}})}emailToLowerCase(){this.userRegistrationForm.value.email=this.userRegistrationForm.value.email.toLowerCase()}matchPassword(e){if(e.get("password").value!==e.get("passwordconf").value)return{NotEqual:!0}}prepareFormFeaturesConfig(){R([this.baseSiteService.get(),this.foerchUserService.isADM()]).pipe(g(this.destroyRef),q(([e])=>!e.uid),C(1)).subscribe(([e,s])=>{let t=e.stores?.[0]??e.baseStore;this.formFeatureConfig=A(N({},this.formFeatureConfig),{isIndustryGroupRequired:c(t.registrationIndustryGroup),shouldShowIndustryGroup:s===!0||h(t.registrationIndustryGroup),isUstNumberRequired:c(t.registrationUstId),shouldShowUstNumber:h(t.registrationUstId),isUploadBusinessRegistrationRequired:c(t.registrationUploadBusinessRegistration),shouldShowUploadBusinessRegistration:h(t.registrationUploadBusinessRegistration),isTelephoneRequired:c(t.registrationTelephone),shouldShowTelephone:h(t.registrationTelephone),isTitleRequired:c(t.registrationTitle),shouldShowTitle:h(t.registrationTitle)}),this.adjustFormValidatorsBasedOnFeatureConfig()})}adjustFormValidatorsBasedOnFeatureConfig(){let[e,s,t,o,u]=["ustNumber","telephone","uploadBusinessRegistration","industryName","titleCode"].map(r=>this.userRegistrationForm.get(r));e.setAsyncValidators([n.regexpUstIdAsyncValidator(this.baseSiteService,this.formFeatureConfig.isUstNumberRequired)]),this.formFeatureConfig.isTelephoneRequired&&s.setValidators([i.required]),this.formFeatureConfig.isUploadBusinessRegistrationRequired&&t.setValidators([i.required]),this.formFeatureConfig.isIndustryGroupRequired&&o.setValidators([i.required]),this.formFeatureConfig.isTitleRequired&&u.setValidators([i.required]);for(let r of[e,s,t,o,u])r.updateValueAndValidity()}getDeliveryCountries(){this.userAddressService.loadDeliveryCountries(),R([this.userAddressService.getDeliveryCountries(),this.languageService.getActive()]).pipe(g(this.destroyRef),T(([e,s])=>e?.length>0&&!!s),V(),C(1)).subscribe(([e,s])=>{let t=new Intl.Collator(s.replace("_","-")),o=[...e].sort((r,l)=>t.compare(r.name,l.name)),u=s.split("_")[1];for(let r=0;r<o.length;r++)if(o[r].isocode===u){let l=o[r];o.splice(r,1),o.splice(0,0,l);break}this.countries$.next(o),this.userRegistrationForm.get("country").setValue(o[0])})}};m.\u0275fac=function(s){return new(s||m)},m.\u0275cmp=D({type:m,selectors:[["foerch-register-base"]],outputs:{registerSuccess:"registerSuccess"},decls:1,vars:0,template:function(s,t){s&1&&O(0,"DO NOT USE THIS COMPONENT DIRECTLY!")},encapsulation:2});let S=m;return S})();export{J as a,ye as b};