1import{ax as L,r as T,n as w}from"./-DLWNC6n.js";import{e as S}from"./poOW0nuE.js";import{y as U,a as x,n as g,k as O,F,a1 as q,u as B,p as $,i as z}from"#entry";import{l as D}from"./C90W3vFq.js";import{r as p}from"./CfVdlt2c.js";import{a as A}from"./KXDfhFVj.js";import{u as H}from"./BX4v9dxa.js";const k="gooya:auth-back-home-once";function J(){const n=U(),i=x();function h(){{if(sessionStorage.getItem(k)==="1"){sessionStorage.removeItem(k),g(i("/"));return}const c=window.history.state;if(c!=null&&c.back!=null&&c.back!==""){n.back();return}}g(i("/"))}return{goAuthBack:h}}let d=null;function V(){const n=O(),i=F(),h=L(),c=H(),{syncFromProfileApi:m}=q(),C=z(),{locale:y}=B(),u=T(!1),f=T(null);function s(r,o,e){return String(y.value)==="ar"?A(o)||A(r):String(y.value)==="en"?o:r}async function E(r,o){u.value=!0,f.value=null;try{const e=await $fetch("/api/auth/login/",{method:"POST",body:{username:r.identifier.trim(),password:r.password}}),t=e.tokens?.access||e.access||"",a=e.tokens?.refresh||e.refresh||"";if(!t||!a)throw new Error(s("تÙÚ©Ù Ø§ØØ±Ø§Ø² ÙÙÛØª Ø¯Ø±ÛØ§Ùت ÙØ´Ø¯","Authentication token was not received"));n.setTokens(t,a),e.user&&n.setUser(e.user),await m({force:!0}),i.addToast({type:"success",title:s("Ø®ÙØ´ Ø¢Ù
Ø¯ÛØ¯","Welcome")}),await w();const l=p(n,o);await g(c(l),{replace:!0})}catch(e){const t=D(e);f.value=t,i.addToast({type:"error",title:s("خطا","Error"),description:t})}finally{u.value=!1}}async function b(r,o){u.value=!0,f.value=null;try{const e=await $fetch("/api/auth/register/",{method:"POST",body:r}),t=e.tokens?.access||e.access||"",a=e.tokens?.refresh||e.refresh||"";if(t&&a&&n.setTokens(t,a),e.user&&n.setUser(e.user),i.addToast({type:"success",title:s("ثبتâÙØ§Ù
Ù
ÙÙÙ","Registration successful")}),await w(),t&&a){await m({force:!0});const l=p(n,o);await g(c(l),{replace:!0})}else await g(c(o||"/"),{replace:!0})}catch(e){const t=S(e).message;f.value=t,i.addToast({type:"error",title:s("خطا","Error"),description:t})}finally{u.value=!1}}function P(){return window.google?.accounts?Promise.resolve():d||(d=new Promise((r,o)=>{const e=document.createElement("script");e.src="https://accounts.google.com/gsi/client",e.async=!0,e.defer=!0,e.onload=()=>r(),e.onerror=()=>o(new Error(s("Ø¨Ø§Ø±Ú¯Ø°Ø§Ø±Û Ø³Ø±ÙÛØ³ Ú¯ÙÚ¯Ù ÙØ§Ù
ÙÙÙ Ø¨ÙØ¯","Google sign-in service failed to load"))),document.head.appendChild(e)}),d)}async function _(){const r=String(C.public.googleClientId||"").trim();if(!r)throw new Error(s("Google Client ID ØªÙØ¸ÛÙ
ÙØ´Ø¯Ù است","Google Client ID is not configured"));await P();const o=window.google;if(!o?.accounts?.oauth2?.initTokenClient)throw new Error(s("سرÙÛØ³ ÙØ±Ùد Ú¯Ùگ٠در دسترس ÙÛØ³Øª","Google sign-in service is not available"));return await new Promise((e,t)=>{o.accounts.oauth2.initTokenClient({client_id:r,scope:"openid email profile",callback:l=>{if(!l||l.error){t(new Error(s("Ø¯Ø±ÛØ§Ùت تÙÚ©Ù Ú¯ÙÚ¯Ù ÙØ§Ù
ÙÙÙ Ø¨ÙØ¯","Failed to receive Google token")));return}const v=String(l.access_token||"").trim();if(!v){t(new Error(s("تÙÚ©Ù Ú¯Ùگ٠خاÙÛ Ø§Ø³Øª","Google token is empty")));return}e(v)}}).requestAccessToken({prompt:"select_account"})})}async function G(r){u.value=!0,f.value=null;try{const o=await _(),e=await $fetch("/api/auth/social/google/",{method:"POST",body:{access_token:o,platform:"web",redirect_uri:window.location.origin}}),t=e.tokens?.access||e.access||"",a=e.tokens?.refresh||e.refresh||"";if(!t||!a)throw new Error(s("تÙÚ©Ù Ø§ØØ±Ø§Ø² ÙÙÛØª Ø¯Ø±ÛØ§Ùت ÙØ´Ø¯","Authentication token was not received"));n.setTokens(t,a),e.user&&n.setUser(e.user),await m({force:!0}),i.addToast({type:"success",title:s("ÙØ±Ùد با Ú¯ÙÚ¯Ù Ø§ÙØ¬Ø§Ù
شد","Signed in with Google")}),await w();const l=p(n,r);return await g(c(l),{replace:!0}),!0}catch(o){const e=S(o).message;return f.value=e,i.addToast({type:"error",title:s("خطا","Error"),description:e}),!1}finally{u.value=!1}}async function I(){try{const r=$("refresh_token").value}catch{}finally{n.clearAuth(),h.clear(),sessionStorage.setItem(k,"1"),await g(c("/auth/required-login"),{replace:!0})}}return{login:E,register:b,loginWithGoogle:G,logout:I,isLoading:u,error:f}}export{V as a,J 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.