import{d as N,u as O,ah as j,ct as F,ae as G,r as d,e as P,w as T,f as r,h as o,x as l,v as c,g as e,bi as M,aG as x,aJ as z,bB as J,i as y,F as V,y as W,B as U,bM as H,aI as K,C as Q,z as X,a0 as Y,n as Z,o as a,cv as ee}from"./BxiWQxwE.js";import{j as se,A as i}from"./DqhAcXWn.js";import{_ as S}from"./Mgz3HV5C.js";const oe={class:"login-form"},te={key:0},re={class:"login-form__input-field"},ae={for:"username"},ne={key:0},le={class:"login-form__input-field__wrapper"},ie=["placeholder"],ue={class:"login-form__input-field"},de={for:"password"},ce={key:0},me={class:"login-form__input-field__wrapper"},pe=["type","placeholder"],fe={key:1,class:"login-form__errors"},_e={class:"login-form__flex-wrapper"},we={key:0,for:"remember"},he=["disabled"],be=N({__name:"CloudLogin",props:{messages:{type:Object,default:()=>({})},showTitles:{type:Boolean,default:!0},showLabels:{type:Boolean,default:!1},showIcons:{type:Boolean,default:!0},togglePasswordVisibility:{type:Boolean,default:!0}},async setup(u){let f,_;const C=u,w=O(),{currentSiteIso:B}=j(),{messages:L}=F(C),{login:$,isAuthenticated:A}=G(),E=d(!1),h=d(!1),b=d(!1),g=d(!0),v=d(!1),k=d([]),m=d({username:"",password:""}),R=P(()=>`${ee(B.value)}?returnUrl=${(w.query.returnUrl??w.path).toString()}`);A.value&&([f,_]=T(()=>Z(w.query.returnUrl??"/")),await f,_()),[f,_]=T(()=>se(B.value)),await f,_();const n=P(()=>({username:i("auth.username"),password:i("auth.password"),login:i("auth.login"),forgotPassword:i("auth.lostPassword"),send:i("auth.send"),loginTitle:i("auth.login"),loginErrorMessage:i("auth.invalidLogin"),rememberMe:i("auth.rememberMe"),...L.value})),q=()=>{b.value=!1,k.value=[]},I=async()=>{v.value=!0;const{username:p,password:s}=m.value;if(q(),!p||!s){k.value.push(n.value.loginErrorMessage),b.value=!0;return}await $({credentials:m.value,returnUrl:w.query.returnUrl,rememberMe:g.value}),v.value=!1};return(p,s)=>{const D=Y;return a(),r("div",oe,[o("form",{onSubmit:s[4]||(s[4]=X(t=>I(),["prevent"]))},[u.showTitles?(a(),r("h1",te,c(e(n).loginTitle),1)):l("",!0),o("div",re,[o("label",ae,[u.showLabels?(a(),r("span",ne,c(e(n).username),1)):l("",!0),o("div",le,[u.showIcons?M(p.$slots,"user-icon",{key:0},()=>[y(S,{icon:"user"})]):l("",!0),x(o("input",{id:"username","onUpdate:modelValue":s[0]||(s[0]=t=>e(m).username=t),type:"text",placeholder:e(n).username,"aria-required":"true",autocomplete:"username"},null,8,ie),[[z,e(m).username]])])])]),o("div",ue,[o("label",de,[u.showLabels?(a(),r("span",ce,c(e(n).password),1)):l("",!0),o("div",me,[u.showIcons?M(p.$slots,"password-icon",{key:0},()=>[y(S,{icon:"key"})]):l("",!0),x(o("input",{id:"password","onUpdate:modelValue":s[1]||(s[1]=t=>e(m).password=t),type:e(h)?"text":"password",placeholder:e(n).password,"aria-required":"true",maxlength:"1024",autocomplete:"current-password"},null,8,pe),[[J,e(m).password]]),u.togglePasswordVisibility?(a(),r("button",{key:1,type:"button",onClick:s[2]||(s[2]=t=>h.value=!e(h))},[y(S,{icon:e(h)?"visibility-off":"visibility"},null,8,["icon"])])):l("",!0)])])]),e(b)?(a(),r("div",fe,[o("ul",null,[(a(!0),r(V,null,W(e(k),t=>(a(),r("li",{key:t,role:"alert",class:"error"},c(t),1))),128))])])):l("",!0),o("div",_e,[e(E)?l("",!0):(a(),r("label",we,[x(o("input",{id:"remember","onUpdate:modelValue":s[3]||(s[3]=t=>K(g)?g.value=t:null),type:"checkbox"},null,512),[[H,e(g)]]),U(" "+c(e(n).rememberMe),1)])),y(D,{to:e(R)},{default:Q(()=>[U(c(e(n).forgotPassword),1)]),_:1},8,["to"])]),o("button",{type:"submit",disabled:e(v)},[e(v)?M(p.$slots,"loader",{key:0},()=>[s[5]||(s[5]=o("span",{class:"login-form__loader"},null,-1))]):(a(),r(V,{key:1},[U(c(e(n).login),1)],64))],8,he)],32)])}}});export{be as default};
