1import{G as V,z as C,as as w,ak as b,al as u,aG as N,b9 as F,I as v,i as J,ax as S,ao as U,e as g,y as $,r as l}from"./BA2cZanY.js";import{j}from"./BI5BN1rn.js";import{a as y}from"./zypciNv-.js";import{n as P,i as k}from"./tn3b78NZ.js";const A={class:"auth-terms-checkbox"},B={class:"well auth-terms-checkbox-well"},O={class:"auth-terms-consent mandatory"},T=["id"],R=["for"],q={class:"auth-privacy-policy-action"},D=["href"],G={key:0,class:"alert alert-danger auth-terms-error"},Y=V({__name:"AuthTermsCheckbox",props:{modelValue:{type:Boolean,default:!1},inputId:{type:String,default:"auth-terms-checkbox"},error:{type:String,default:""}},emits:["update:modelValue"],setup(e,{emit:r}){const c=e,n=r,{$translate:a,$store:t}=C(),s=$(),p=g(()=>(t.locale||"fi_FI")==="fi_FI"?s.public.privacyPolicyUrlFi||"https://johku.fi/fi/tietosuoja":s.public.privacyPolicyUrlEn||"https://johku.fi/en/privacy"),i=g({get:()=>c.modelValue,set:d=>n("update:modelValue",d)});return(d,h)=>(w(),b("div",A,[u("div",B,[u("div",O,[N(u("input",{id:e.inputId,"onUpdate:modelValue":h[0]||(h[0]=_=>J(i)?i.value=_:null),type:"checkbox",class:"inline-checkbox auth-terms-consent-checkbox","aria-required":"true"},null,8,T),[[F,v(i)]]),u("label",{for:e.inputId,class:"auth-terms-consent-label"},S(v(a)("I agree to the processing of my personal data in accordance with the Johku Privacy Policy.")),9,R),u("div",q,[u("a",{href:v(p),class:"btn btn-default btn-sm",target:"_blank",rel:"noopener noreferrer"},S(v(a)("Johku Privacy Policy")),9,D)])]),e.error?(w(),b("div",G,S(e.error),1)):U("",!0)])]))}}),L=j(Y,[["__scopeId","data-v-b1e535f0"]]);function Q(){const{$translate:e}=C(),r=y.useSession(),c=l(!1),n=l(""),a=l(""),t=l(!1),s=l(!1),p=l(""),i=()=>{c.value=!1,n.value="",a.value="",p.value="",t.value=!1,s.value=!1},d=async()=>{if(!c.value)return n.value=e("You must accept the processing of your personal data in accordance with Johku's privacy principles."),"error";n.value="";try{return await $fetch("/api/auth/accept-terms",{method:"POST",credentials:"include"}),await r.value?.refetch(),"ok"}catch(o){return k(o)?"expired":(a.value=e("Failed to complete signup. Please try again."),"error")}},h=async o=>{const m=(o.name??p.value).trim();if(o.requireName&&!m){a.value=e("Please enter your name and accept the Johku terms and conditions to finish creating your account.");return}if(!c.value){n.value=e("You must accept the processing of your personal data in accordance with Johku's privacy principles.");return}if(t.value||s.value)return;t.value=!0,a.value="",n.value="";const x=await d();if(x==="expired"){t.value=!1,await o.onExpired();return}if(x==="error"){t.value=!1;return}if(m){const{error:f}=await y.updateUser({name:m});if(f){a.value=e(f.message),t.value=!1;return}await r.value?.refetch()}try{await o.onSuccess()}catch(f){if(k(f)){t.value=!1,await o.onExpired();return}a.value=e("Failed to complete signup. Please try again.")}finally{t.value=!1}},_=async o=>{if(!(t.value||s.value)){s.value=!0,a.value="",n.value="";try{await $fetch("/api/auth/cancel-signup",{method:"POST",credentials:"include"})}catch(m){if(!k(m)){a.value=e("Something went wrong. Please try again."),s.value=!1;return}}try{await y.signOut()}catch{}try{await r.value?.refetch()}catch{}i(),await o.onSuccess()}},E=g(()=>P(r.value?.data?.user)),I=g(()=>r.value?.data?.user?.name?.trim()||"");return{session:r,termsAccepted:c,termsError:n,completeSignupError:a,isCompletingSignup:t,isCancelingSignup:s,collectNameValue:p,resetCompleteSignupForm:i,submitCompleteSignup:h,cancelIncompleteSignup:_,userNeedsSignupCompletion:E,oauthNamePrefill:I,needsSignupCompletion:P}}function W(){return{handleSignupExpired:async r=>{try{await y.signOut()}catch{}r()}}}export{L as _,W as a,Q as u};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.