import{a as e,c as t,d as n,l as r,m as i,n as a,p as o}from"./apiFetch-C4rLkcBG.js";var s=/^\+?[0-9]\d{6,14}$/;function c(e){return e.replace(/[\s.\-()]/g,``)}function l(e){return e?s.test(c(e)):!1}var u=`+33 6 12 34 56 78`,d=o();function f(e){e.access_token&&i.set(n.COOKIE_NAME,e.access_token,{expires:n.EXPIRY_DAYS,secure:n.SECURE_COOKIES,sameSite:n.SAME_SITE}),e.refresh_token&&i.set(n.REFRESH_COOKIE_NAME,e.refresh_token,{expires:n.EXPIRY_DAYS,secure:n.SECURE_COOKIES,sameSite:n.SAME_SITE})}var p={login:async n=>{let r=await a(`${d}${t.AUTH.LOGIN}`,{method:`POST`,body:n,timeout:e.TIMEOUTS.AUTH});return r.requires_2fa||f(r),r},loginVerify2FA:async(t,n)=>{let i=await a(`${r.API_BASE}/auth/login/2fa`,{method:`POST`,body:{challenge_token:t,totp_code:n},timeout:e.TIMEOUTS.AUTH});return f(i),i},register:async n=>a(`${d}${t.AUTH.REGISTER}`,{method:`POST`,body:n,timeout:e.TIMEOUTS.AUTH}),registerComplete:async n=>{let r={...n,terms_accepted_at:new Date().toISOString(),privacy_accepted_at:new Date().toISOString()};n.avatar_data&&n.avatar_filename&&typeof n.avatar_data==`string`&&(r.avatar_data=Uint8Array.from(atob(n.avatar_data),e=>e.charCodeAt(0)));let i=await a(`${d}${t.AUTH.REGISTER}`,{method:`POST`,body:r,timeout:e.TIMEOUTS.AUTH});return f(i),i},refreshToken:async()=>{let r=i.get(n.REFRESH_COOKIE_NAME);if(!r)throw Error(`Aucun refresh token disponible`);let o=await a(`${d}${t.AUTH.REFRESH_TOKEN}`,{method:`POST`,body:{refresh_token:r},timeout:e.TIMEOUTS.AUTH});return f(o),o.access_token},logout:async()=>{try{await a(`${d}${t.AUTH.LOGOUT}`,{method:`POST`,body:{}})}finally{i.remove(n.COOKIE_NAME),i.remove(n.REFRESH_COOKIE_NAME)}},loginWithGoogle:async t=>{let n=await a(`${r.API_BASE}/auth/google`,{method:`POST`,body:{id_token:t},timeout:e.TIMEOUTS.AUTH,withAuth:!1});return f(n),n},loginWithFacebook:async t=>{let n=await a(`${r.API_BASE}/auth/facebook`,{method:`POST`,body:{access_token:t},timeout:e.TIMEOUTS.AUTH,withAuth:!1});return f(n),n},loginWithDiscord:async(t,n)=>{let i=await a(`${r.API_BASE}/auth/discord`,{method:`POST`,body:{code:t,redirect_uri:n},timeout:e.TIMEOUTS.AUTH,withAuth:!1});return f(i),i},forgotPassword:async t=>{await a(`${r.API_BASE}/auth/forgot-password`,{method:`POST`,body:{email:t},timeout:e.TIMEOUTS.AUTH,withAuth:!1})},resetPassword:async(t,n)=>{await a(`${r.API_BASE}/auth/reset-password`,{method:`POST`,body:{token:t,new_password:n},timeout:e.TIMEOUTS.AUTH,withAuth:!1})},verifyEmail:async t=>{await a(`${r.API_BASE}/auth/verify-email`,{method:`POST`,body:{token:t},timeout:e.TIMEOUTS.AUTH})},resendVerification:async()=>{await a(`${r.API_BASE}/auth/resend-verification`,{method:`POST`,body:{},timeout:e.TIMEOUTS.AUTH})},changeEmail:async(e,t)=>{await a(`${d}/auth/change-email`,{method:`PUT`,body:{current_password:e,new_email:t}})},get2FAStatus:async()=>a(`${r.API_BASE}/auth/2fa/status`,{timeout:e.TIMEOUTS.AUTH}),generate2FASecret:async()=>a(`${r.API_BASE}/auth/2fa/generate-secret`,{method:`POST`,body:{},timeout:e.TIMEOUTS.AUTH}),enable2FA:async(t,n)=>a(`${r.API_BASE}/auth/2fa/enable`,{method:`POST`,body:{totp_code:t,secret:n},timeout:e.TIMEOUTS.AUTH}),disable2FA:async t=>{await a(`${r.API_BASE}/auth/2fa/disable`,{method:`POST`,body:{totp_code:t},timeout:e.TIMEOUTS.AUTH})},verify2FACode:async t=>{await a(`${r.API_BASE}/auth/2fa/verify`,{method:`POST`,body:{totp_code:t},timeout:e.TIMEOUTS.AUTH})},isAuthenticated:()=>!!i.get(n.COOKIE_NAME),getToken:()=>i.get(n.COOKIE_NAME),validateCompleteRegisterData:e=>{let t=[];return(!e.firstname||e.firstname.trim().length<2)&&t.push(`Le prénom doit contenir au moins 2 caractères`),(!e.lastname||e.lastname.trim().length<2)&&t.push(`Le nom doit contenir au moins 2 caractères`),(!e.pseudonyme||e.pseudonyme.trim().length<3)&&t.push(`Le pseudonyme doit contenir au moins 3 caractères`),(!e.email||!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e.email))&&t.push(`L'adresse email n'est pas valide`),(!e.password||e.password.length<8)&&t.push(`Le mot de passe doit contenir au moins 8 caractères`),l(e.phone_number)||t.push(`Le numéro de téléphone n'est pas valide (ex. +33 6 12 34 56 78)`),(!e.bio||e.bio.trim().length<10)&&t.push(`La biographie doit contenir au moins 10 caractères`),e.bio&&e.bio.length>500&&t.push(`La biographie ne peut pas dépasser 500 caractères`),(!e.location||e.location.trim().length<3)&&t.push(`La localisation doit contenir au moins 3 caractères`),{isValid:t.length===0,errors:t}},formatCompleteRegisterData:e=>({...e,firstname:e.firstname.trim(),lastname:e.lastname.trim(),pseudonyme:e.pseudonyme.trim(),email:e.email.toLowerCase().trim(),phone_number:e.phone_number.replace(/\s/g,``),bio:e.bio.trim(),location:e.location.trim()})};export{u as n,l as r,p as t};