import{_ as U,I as P,M as G,L as q,R as z,k as H,r as m,o as u,a as I,w as f,p as y,v as _,b as R,q as b,l as h,u as N,n as W,Z as j,d as J,aW as K,ah as Y,au as Z,ak as Q,K as X,B as ee,at as ne,ai as te,J as oe}from"./main-DtyiNRRn.js";import{R as ie}from"./ReducedLayoutFi-Cf3QuM-0.js";import{c as se,l as ae,d as le,i as ce,u as re}from"./login-Bm3sVYhM.js";import{d as de}from"./giveConsent-BTiZCCLQ.js";import{_ as fe}from"./consentMixin-DJPQeQzl.js";import"./SelectInputFi-y7iX7osI.js";import"./BlockNotificationFi-BuUtmEX2.js";import"./ResultStatusFi-Azqh2Mdi.js";import"./getConsentTemplates-lXPog8i8.js";const ue={name:"ConsentDialogFi",components:{IconFi:P,DialogModalFi:G,LinkFi:q,RichtextFi:z},mixins:[H],props:{fields:{type:Object,default:()=>({})}},emits:["confirm"],methods:{open(){this.$refs.dialogModal.open()},close(){this.$refs.dialogModal.close()},confirm(){this.$emit("confirm")}}},ge={class:"consent-dialog-fi__headline"},_e={class:"consent-dialog-fi__content"},me={key:0,class:"consent-dialog-fi__content__info"},he={key:1,class:"consent-dialog-fi__content__item"},ke={class:"consent-dialog-fi__content__title"},ve={key:2,class:"consent-dialog-fi__content__item"},Ce={class:"consent-dialog-fi__content__title"},Te={class:"consent-dialog-fi__actions"};function we(t,a,e,T,d,i){const k=m("richtext-fi"),o=m("link-fi"),L=m("button-fi"),O=m("icon-fi"),E=m("dialog-modal-fi");return u(),I(E,{ref:"dialogModal",class:"consent-dialog-fi","only-body-scrollable":"","prevent-close-on-click-outside":"","pulse-on-block":"","hide-close-button":""},{header:f(()=>{var c;return[y("h2",ge,_((c=e.fields.consentDialogHeadline)==null?void 0:c.value),1)]}),body:f(()=>{var c,v,w,x,S,p,C;return[y("div",_e,[(c=e.fields.consentDialogInfotext)!=null&&c.value?(u(),R("div",me,_(e.fields.consentDialogInfotext.value),1)):b("",!0),(v=e.fields.consentDialogTermsAndConditionsTitle)!=null&&v.value&&((w=e.fields.consentDialogTermsAndConditionsText)!=null&&w.value)?(u(),R("div",he,[y("h3",ke,_(e.fields.consentDialogTermsAndConditionsTitle.value),1),h(k,{class:"consent-dialog-fi__content__text","html-content":e.fields.consentDialogTermsAndConditionsText},null,8,["html-content"]),(x=e.fields.consentDialogTermsAndConditionsLink)!=null&&x.value&&(e.fields.consentDialogTermsAndConditionsLink.value.url||e.fields.consentDialogTermsAndConditionsLink.value.href)?(u(),I(o,{key:0,class:"consent-dialog-fi__content__link",href:e.fields.consentDialogTermsAndConditionsLink.value.url||e.fields.consentDialogTermsAndConditionsLink.value.href,external:!!e.fields.consentDialogTermsAndConditionsLink.value.url,primary:"",target:"_blank"},{default:f(()=>[N(_(e.fields.consentDialogTermsAndConditionsLink.value.text),1)]),_:1},8,["href","external"])):b("",!0)])):b("",!0),(S=e.fields.consentDialogTermsOfUseTitle)!=null&&S.value&&((p=e.fields.consentDialogTermsOfUseText)!=null&&p.value)?(u(),R("div",ve,[y("h3",Ce,_(e.fields.consentDialogTermsOfUseTitle.value),1),h(k,{class:"consent-dialog-fi__content__text","html-content":e.fields.consentDialogTermsOfUseText},null,8,["html-content"]),(C=e.fields.consentDialogTermsOfUseLink)!=null&&C.value&&(e.fields.consentDialogTermsOfUseLink.value.url||e.fields.consentDialogTermsOfUseLink.value.href)?(u(),I(o,{key:0,class:"consent-dialog-fi__content__link",href:e.fields.consentDialogTermsOfUseLink.value.url||e.fields.consentDialogTermsOfUseLink.value.href,external:!!e.fields.consentDialogTermsOfUseLink.value.url,target:"_blank",primary:""},{default:f(()=>[N(_(e.fields.consentDialogTermsOfUseLink.value.text),1)]),_:1},8,["href","external"])):b("",!0)])):b("",!0)])]}),footer:f(()=>[y("div",Te,[h(L,{class:W({"consent-dialog-fi__button button-fi__primary":!0,"button-fi--large":t.isSM}),type:"button",onClick:j(i.confirm,["prevent"])},{default:f(()=>{var c;return[N(_((c=e.fields.consentDialogButton)==null?void 0:c.value),1)]}),_:1},8,["class","onClick"])])]),button:f(()=>[h(O,{icon:"close"})]),_:1},512)}const De=U(ue,[["render",we]]),ye=J({name:"SiteLoginStandalone",__name:"SiteLoginStandalone",emits:["logged-in"],setup(t,{emit:a}){const e=()=>oe(()=>import("./mergeCart-BkuZX4nb.js"),[]),{clearHandlingFeeLimitCookie:T}=K(),{criticalLoginFailure:d,setDevToken:i,initializeAuthorization:k,logDebug:o,getCookies:L,setCookies:O,postAccessTokenInSession:E,notifyLogin:c}=se(),v=Y(),{cookies:w}=Z(),x=a,S=async(n,s,l)=>{try{if(!l||l==="current")return o("not merging cart, cartId",l),null;o("started merging carts...");const r=(await e()).default,{mutate:g}=te(r);return await g({variables:{cartId:l,accessToken:n,idToken:s,baseSiteId:v.baseSiteId()},onError:D=>console.error("Could not merge carts",D)}),o("finished merging carts"),!0}catch(r){return console.error("Could not merge cart",r,l),!1}},p=async n=>{const s=L(),l=s[`state-${n}`];delete s[`state-${n}`];const{value:r,validUntil:g}=s[`nonce-${n}`]||{};return delete s[`nonce-${n}`],g&&(s[`nonce-${n}`]={value:"used",validUntil:g}),await O(s)?[r,l]:[]},C=n=>!n||n.startsWith(window.location.pathname)||n.startsWith(`${window.location.origin}/${window.location.pathname}`)?!1:n,V=async()=>{if(/(?:^#|&)brand=http/.test(window.location.hash)||/(?:^\?|&)brand=http/.test(window.location.search)){const A=w.get(ae);if(!A)return console.error("no login dialog"),!1;const B=`${v.hostUrlBase()}${A}${window.location.search}${window.location.hash}`;return o("redirecting to dialog page",B),v.query("debug-no-redirect")?console.debug("no redirect flag set"):window.location.href=B,!0}const n=String(window.location.hash);if(o("handling login callback",!!n),!n)return o("got no hash, not a login callback"),!1;const[,s]=/[#&]id_token=([^&]+)/.exec(n)||[],[,l]=/[#&]access_token=([^&]+)/.exec(n)||[],[,r]=new RegExp(`[#&]state=([${le}]+)`).exec(n)||[];if(!r)return console.error("state not found in hash"),!1;if(r==="retry")return o("got request to retry login - most likely bookmarked login page"),!1;const[g,D]=await p(r);if(g==="used")return console.info("Nonce for state already used, re-attempting login"),!1;if(!D)return d("Could not restore state",D),!0;if(ce(s,g))return d("Nonce failed"),!0;const{redirect:M,cartId:$}=D;let F;T(),w.remove(re);{const A=S(l,s,$);try{o("posting token to sitecore"),F=await E(l,s)}catch{return o("error occured when posting to sitecore, not redirecting"),!0}await A}return c(),ne(),o("redirecting to login-success-page",M,C(M)),x("logged-in",{redirect:C(M)||C(F)||"/",accessToken:l}),!0};return Q(async()=>{try{await V()||k()}catch(n){console.error("error in created hook",n)}}),(n,s)=>(u(),I(ie,{"api-data":void 0,"interface-language":void 0},{default:f(()=>[h(X(ee),{variant:"spinnerFullPageCover"})]),_:1}))}}),be=U(ye,[["__scopeId","data-v-7ae59507"]]),Le={name:"MyAccountLogin",components:{ConsentDialogFi:De,SiteLoginStandalone:be},mixins:[fe],inject:["fields"],async created(){window.location.protocol!=="https:"&&window.location.replace(`https:${window.location.href.substring(window.location.protocol.length)}`)},methods:{async loggedInStandalone(t){await this.checkNewConsents(t.accessToken)?this.successRedirect=t.redirect:this.redirectTo(t.redirect)},async checkNewConsents(t){var a;if(!((a=this.fields.enableConsentDialog)!=null&&a.value))return!1;try{const T=(await this.getConsentTemplates(t)).filter(i=>i.id===`REGISTRATION_DATA_PRIVACY_${this.$fischer.baseSiteId()}`||i.id===`REGISTRATION_TERMS_AND_CONDITIONS_${this.$fischer.baseSiteId()}`);let d=!1;return T.forEach(i=>{i.currentConsent||(d=!0,this.newConsentTemplates.push({id:i.id,version:i.version}))}),d&&(this.$refs.consentDialog.open(),this.acceptConsent(t)),d}catch(e){return console.error(e),!1}},async acceptConsent(t){await this.newConsentTemplates.forEach(async a=>{await this.$apollo.mutate({mutation:de,variables:{baseSiteId:this.$fischer.baseSiteId(),accessToken:t,userId:"current",consentTemplateId:a.id,consentTemplateVersion:a.version,lang:this.$fischer.language_639_1()}})})},redirectTo(t){window.location.href=t}}},xe={class:"my-account-login"};function Se(t,a,e,T,d,i){const k=m("consent-dialog-fi"),o=m("site-login-standalone");return u(),R("div",xe,[h(k,{ref:"consentDialog",fields:i.fields,onConfirm:a[0]||(a[0]=L=>i.redirectTo(t.successRedirect))},null,8,["fields"]),h(o,{onLoggedIn:i.loggedInStandalone},null,8,["onLoggedIn"])])}const Fe=U(Le,[["render",Se],["__scopeId","data-v-446dcdc8"]]);export{Fe as default};