import{_ as P,H as x,L as U,B as q,T as K,U as O,r as u,o as f,a as S,w as h,b as C,l as c,u as p,v as b,q as F,p as T,F as A}from"./main-DtyiNRRn.js";import{_ as M}from"./validatorsMixin.vue_vue_type_script_lang-BhpMiNHR.js";import{V as z}from"./validators-CuGrUx1P.js";import{E as N}from"./ErrorMessage-BodFsaDt.js";import{_ as H}from"./LoginFormFieldFi.vue_vue_type_script_setup_true_lang-VicmMK9g.js";import{_ as j}from"./loginMixin-Cx5hmsH9.js";import{R as W}from"./ReducedLayoutFi-Cf3QuM-0.js";import{e as G}from"./login-Bm3sVYhM.js";import"./pageScrolling-DKoKIacQ.js";import"./SelectInputFi-y7iX7osI.js";import"./BlockNotificationFi-BuUtmEX2.js";import"./ResultStatusFi-Azqh2Mdi.js";const R="dialog-redirect",B=i=>{const t=new URLSearchParams(i);return Object.fromEntries(t.entries())},J={name:"LoginFormPageFi",components:{ErrorMessage:N,HeadlineFi:x,LinkFi:U,LoadingIndicator:q,LoginFormFieldFi:H,ReducedLayoutFi:W,TextInputFi:K},mixins:[j,M],inject:["fields"],data(){return{form:{password:"",passwordValid:!1,usernameValid:!1,username:""},usernameChangedOrBlurred:!1,passwordChangedOrBlurred:!1,isLoading:!1,isLoginImpossible:!1,enableUserIdentifierValidation:!1,isLoginFailure:!1,brand:"",lang:"",interfaceLanguage:null,apiData:null,apiDataLoading:!0,isSubmitting:!1,isMounted:!1}},computed:{formValid(){return this.form.passwordValid&&this.form.usernameValid},rules(){var i;return z({get:t=>{var r;return{"online-Shop.Global-Labels.Error-Message-Required":(r=this.apiData)==null?void 0:r.Mandatory_Error}[t]||t}},{emailFieldValidationMsgInvalidFormat:{value:(i=this.apiData)==null?void 0:i.Invalid_Email_Error}})},submitDisabled(){return this.isSubmitting||this.isLoginImpossible||(this.passwordChangedOrBlurred||this.usernameChangedOrBlurred)&&(!this.formValid||this.form.password===null)},referrerData(){var t,r;this.logDebug("checking referrer data",this.referrer);const i=(r=(t=this.fields)==null?void 0:t.referrerData)==null?void 0:r.value;if(i)try{const e=JSON.parse(i)[this.referrer];if(e)return this.logDebug("got referrer data",e),e}catch(a){console.error(a,i)}else this.logDebug("no referrer data configured");return this.logDebug("no referrer data"),{}},referrer(){const[,i]=/^https?:\/\/([^/]+)(?:\/|$)/.exec(window.document.referrer)||[];return i}},mounted(){this.isMounted=!0},async created(){try{if(this.redirectFromOldService())return;const i=this.$fischer.query("brand");i&&!i.startsWith("http")&&(this.brand=i),await this.handleLoginRequest()||this.handleLoginFormPage()}catch(i){console.error("Error in login form page created hook",i)}},methods:{redirectFromOldService(){let i=String(window.location),t="https://services.ugfischer.com/",r="https://api.fischer.group/";for(let a=0;a<3;a+=1){const e=new RegExp(t.replace(/\./g,"\\."),"g");i=i.replace(e,r),t=encodeURIComponent(t),r=encodeURIComponent(r)}return String(window.location)!==i?(console.debug("old services detected, redirecting to new services"),window.location=i,!0):!1},getCookieName(){return"site-login"},async handleLoginRequest(){var L,y;if((y=(L=this.fields)==null?void 0:L.ssoPoc)!=null&&y.value)return this.loadApiData("de-DE","fite"),this.logDebug("not handlingg login request - sso poc"),!0;this.logDebug("handling login request");const i=B(window.location.hash.substr(1)),t=B(window.location.search.substr(1)),r={};t.login_hint&&["api_key","lang","brand"].forEach(o=>{const V=new RegExp(`(?:^|\\.)${o}-([^.]+)`).exec(t.login_hint);if(V){const[,I]=V;r[o]=I}});const{lang:a,brand:e,state:s,nonce:n,client_id:l,redirect_uri:_,api_key:m,scope:k="openid",response_type:E="id_token token",ui_locales:w,password:v,username:D}={...t,...r,...i},d=this.getCookies();if(a&&(d.lang=a.replace("_","-")),w){const[o]=w.split(" ");d.lang=o.replace("_","-")}e&&(d.brand=e),m&&(d.apiKey=m);let g=l||d.clientId;if(!g){const[o]=(d.lang||"de").split(/[_-]/);g=`fiwe-${o.toLowerCase()}`}if(g==="fite-de"&&(g="fite-int"),d.clientId=g,this.clientId=g,e!=null&&e.startsWith("http")){this.logDebug("redirecting back to custom login page");const o=new URLSearchParams(window.location.search);o.delete("state");const[V]=e.split(/[?#]/),I=`${V}?${o}${window.location.hash}`;return this.$cookies.set(R,I,0,"/",void 0,this.$fischer.isSecureConnection(),"None"),window.location.href=I,!0}else this.logDebug("not a custom login page",e),e&&(this.logDebug("removing login-redirect"),this.$cookies.remove(R));return await this.setCookies(d)?_&&s?D&&v?(this.logDebug("attempting to submit login in a second"),this.form.username=D,this.form.password=v,this.apiData={},this.apiDataLoading=!1,setTimeout(()=>{this.logDebug("attempting to submit login in a second"),this.$refs.loginForm?this.submit():console.error("no refs.loginForm")},1e3),!0):(this.initializeAuthorization(_,s,n,k,E),!0):(this.logDebug("Did not get login request from hash"),!1):!0},async loadApiData(i,t){var r,a;try{this.apiDataLoading=!0;const e=encodeURIComponent(i),s=(t||((r=this.fields.defaultApiKey)==null?void 0:r.value)||!1||"").replace(/[^A-Z0-9a-z-]/g,"");let n="/sso/api/app";n=`${n}?lang=${e}&apiKey=${s}`,this.logDebug("loading api data with apiKey",s);const{data:l}=await O.get(n);if(l.Submit)this.apiData=l,this.logDebug("got api data");else if(i!=="en")console.info(`Could not load data for '${i}' in '${t}', fallback to en`),await this.loadApiData("en",t);else throw new Error("Could not load en api data");(((a=this.apiData)==null?void 0:a.Available_Languages)||[]).some(m=>m.Value===i)&&(this.interfaceLanguage=i)}catch(e){this.criticalLoginFailure("Failed to load api",e)}finally{this.apiDataLoading=!1}},initializeAuthorization(i,t,r,a,e){return G(this.logDebugWrapper,this.clientId,this.authorizeRedirect,i,t,r,a,e)},handleLoginFormPage(){this.logDebug("handling login form page");const i=this.getCookies(),{brand:t="fiwe",clientId:r,apiKey:a,lang:e,username:s}={...i,...this.referrerData};this.brand=t,this.lang=e||this.getBrowserLang(),r?this.clientId=r:this.clientId=`${this.brand}-${this.lang.replace(/[_-].*/,"").toLowerCase()}`,this.logDebug(`determined brand="${t}" apiKey="${a}" clientId="${this.clientId}"`);const n=this.$fischer.query("username")||s;if(n&&(this.form.username=n),(t!==i.brand||this.clientId!==i.clientId||a!==i.apiKey||n!==s)&&(this.logDebug("updating cookie"),this.setCookies({...i,brand:t,clientId:this.clientId,apiKey:a,username:n,...e?{lang:e}:{}})),this.$fischer.query("authentication_error")==="true"){const l=this.$cookies.get(R);if(this.logDebug("authentication error",l),l&&l!=="null")return this.logDebug("authentication_error, redirecting"),window.location.href=l.replace("?","?authentication_error=true&"),!0;this.isLoginFailure=!0}return this.loadApiData(this.lang,a),this.logDebug("handled login form page successfully"),!0},onChangeUsername(i){this.form.username=i,this.usernameChangedOrBlurred=!0},onChangePassword(i){this.passwordChangedOrBlurred=!0,this.form.password=i},changeLanguage({value:i}){if(typeof i!="string")return;this.interfaceLanguage=i;const{apiKey:t}=this.getCookies();this.loadApiData(i,t)},getBrowserLang(){var n;const i="en",t=(n=this.apiData)==null?void 0:n.Available_Languages;if(!t)return i;const r=window.navigator.language;if(!r)return i;const a=t.find(l=>l.Value===r);if(a)return a.Value;const e=r.replace(/-.*/,""),s=t.find(l=>l.Value.startsWith(e));return s?s.Value:i},onEnterEmail(){this.form.username&&this.$refs.password.focus()},onEnterPassword(){if(!this.form.username||!this.form.password||!this.formValid){this.logDebug("cancelling password-enter",!!this.form.username,!!this.form.password,this.formValid);return}this.submit()},submit(){if(this.isSubmitting){console.error("already submitting");return}this.isSubmitting=!0;const i=this.getCookies();i.username!==this.form.username&&this.setCookies({...i,username:this.form.username}),this.$nextTick(()=>{this.$refs.loginForm.submit()})}}},Z={key:0},Q={key:1,id:"siteLoginStandalone",class:"login-form-page-fi__login"},X={class:"login-form-page-fi__form","data-test":"login-form"},Y={key:0},$={key:1,class:"login-form-page-fi__registration fi-text-size-df-18"};function ee(i,t,r,a,e,s){var D,d,g,L;const n=u("loading-indicator"),l=u("error-message"),_=u("login-form-field-fi"),m=u("headline-fi"),k=u("text-input-fi"),E=u("link-fi"),w=u("button-fi"),v=u("reduced-layout-fi");return f(),S(v,{class:"login-form-page-fi",brand:e.brand,"api-data":e.apiData,"logo-src":(d=(D=e.apiData)==null?void 0:D.Header_Logo)==null?void 0:d.Src,"logo-alt":(L=(g=e.apiData)==null?void 0:g.Header_Logo)==null?void 0:L.Alt,"interface-language":e.interfaceLanguage,onChangeLanguage:s.changeLanguage},{default:h(()=>{var y;return[!e.isMounted||e.apiDataLoading?(f(),S(n,{key:0,variant:"spinnerFullPageCover"})):(f(),C(A,{key:1},[e.isLoginFailure||e.isLoginImpossible?(f(),C("div",Z,[c(l,{ref:"errorMessage",title:((y=e.apiData)==null?void 0:y.Login_Failed_Title)||"Login failed","scroll-to":"siteLoginStandalone","data-test":"login-error"},{default:h(()=>{var o;return[p(b(((o=e.apiData)==null?void 0:o.Login_Failed_Error)||""),1)]}),_:1},8,["title"])])):F("",!0),e.isLoginImpossible?F("",!0):(f(),C("div",Q,[c(_,{ref:"loginForm",password:e.form.password,username:e.form.username},null,8,["password","username"]),T("div",X,[c(m,{class:"login-form-page-fi__headline fi-text-size-df-30","headline-tag":"h1"},{default:h(()=>[p(b(e.apiData.Headline),1)]),_:1}),c(k,{id:"email",ref:"username",modelValue:e.form.username,"onUpdate:modelValue":[t[0]||(t[0]=o=>e.form.username=o),s.onChangeUsername],modelModifiers:{trim:!0},class:"login-form-page-fi__username",autocomplete:"username",name:"username","data-test":"email-input",rules:i.userIdentifierRule(e.brand==="fite",e.form.username,e.enableUserIdentifierValidation),disabled:e.isLoginImpossible,label:e.apiData.Email_Placeholder,onKeyup:t[1]||(t[1]=o=>i.validateCharacters(e.form.username)),onBlur:t[2]||(t[2]=o=>e.enableUserIdentifierValidation=!0),onValidationChanged:t[3]||(t[3]=o=>{e.form.usernameValid=o}),onKeyupEnter:s.onEnterEmail},null,8,["modelValue","rules","disabled","label","onUpdate:modelValue","onKeyupEnter"]),c(k,{id:"password",ref:"password",modelValue:e.form.password,"onUpdate:modelValue":[t[4]||(t[4]=o=>e.form.password=o),s.onChangePassword],class:"login-form-page-fi__password",autocomplete:"current-password",name:"password",type:"password","data-test":"password-input",rules:e.passwordChangedOrBlurred?s.rules.required:[],disabled:e.isLoginImpossible,label:e.apiData.Password_Placeholder,onBlur:t[5]||(t[5]=o=>e.passwordChangedOrBlurred=!0),onValidationChanged:t[6]||(t[6]=o=>{e.form.passwordValid=o}),onKeyupEnter:s.onEnterPassword},null,8,["modelValue","rules","disabled","label","onUpdate:modelValue","onKeyupEnter"]),e.apiData.Password_Reset?(f(),C("div",Y,[c(E,{href:e.apiData.Password_Reset.Url,target:e.apiData.Password_Reset.Target,"data-test":"req-new-cred",class:"login-form-page-fi__password-reset fi-text-size-df-18"},{default:h(()=>[p(b(e.apiData.Password_Reset.Text),1)]),_:1},8,["href","target"])])):F("",!0),c(w,{type:"submit",class:"button-fi__primary button-fi--stretched button-fi--large","data-test":"login-button",loading:e.isLoading,disabled:s.submitDisabled,onClick:s.submit},{default:h(()=>[p(b(e.apiData.Submit),1)]),_:1},8,["loading","disabled","onClick"]),e.apiData.Registration?(f(),C("div",$,[p(b(e.apiData.Registration_Headline)+" ",1),c(w,{target:e.apiData.Registration.Target,href:e.apiData.Registration.Url,loading:e.isLoading,disabled:e.isLoginImpossible,class:"button-fi__tertiary button-fi--stretched button-fi--large login-form-page-fi__registration-btn","data-test":"registration-btn","natural-events":""},{default:h(()=>[p(b(e.apiData.Registration.Text),1)]),_:1},8,["target","href","loading","disabled"])])):F("",!0)])]))],64))]}),_:1},8,["brand","api-data","logo-src","logo-alt","interface-language","onChangeLanguage"])}const fe=P(J,[["render",ee],["__scopeId","data-v-91da5732"]]);export{fe as default};