import{j as p}from"./query-ATBhtd3K.js";import{u as x,r as d}from"./vendor-EnoIVk-c.js";import{a as O,L as T}from"./routing-nZgBtxly.js";import{M as H,F as q,G as C,H as E,I as S,N as A,O as D}from"./en-IUV4ZXKH-BjYNERUx.js";import{C as K}from"./CookiePreferences-DxD0u90z.js";import{K as N}from"./privacy-QEJYcmMw.js";import{r as j,L as F}from"./routing-BgsGBuSe.js";import{u as M}from"./AuthContext-CYne_gJM.js";import{u as z}from"./KnowledgeBaseContext-CgnF8K-_.js";import{u as W}from"./i18n-BYxb14hm.js";import"./index-D4SjcYxX.js";var $={};const u=$.SEMIONT_GOOGLE_CLIENT_ID;function P(a){const e=a.trim();return/^https?:\/\//i.test(e)?e:`https://${e}`}function te(){const{t:a}=W(),e=r=>a(`AuthSignIn.${r}`),v=(r,o)=>a(`Footer.${r}`,o),[g]=x(),h=O(),l=d.useContext(N),{setSession:k}=M(),{knowledgeBases:B,addKnowledgeBase:U}=z(),b=g.get("callbackUrl")??"/know",f=g.get("workspaceId"),t=f?B.find(r=>r.id===f):void 0,I=t==null?void 0:t.backendUrl,[y,s]=d.useState(null),w=d.useRef(!1);d.useEffect(()=>{if(!u||w.current)return;const r=document.createElement("script");r.src="https://accounts.google.com/gsi/client",r.async=!0,r.defer=!0,document.head.appendChild(r),w.current=!0},[]);const G=async r=>{var n,i;if(!u){s(e("errorGoogleSignIn"));return}s(null);const o=P(r),m=new C({baseUrl:S(o),eventBus:new E});(n=window.google)==null||n.accounts.id.initialize({client_id:u,callback:async({credential:c})=>{try{const L=await m.authenticateGoogle(A(c));t||U({id:crypto.randomUUID(),label:new URL(o).hostname,backendUrl:o}),k({token:L.token,user:L.user}),h.push(b)}catch{s(e("errorGoogleSignIn"))}}}),(i=window.google)==null||i.accounts.id.prompt()},R=async(r,o,m)=>{s(null);const n=P(r),i=new C({baseUrl:S(n),eventBus:new E});try{const c=await i.authenticatePassword(D(o),m);t||U({id:crypto.randomUUID(),label:new URL(n).hostname,backendUrl:n}),k({token:c.token,user:c.user}),h.push(b)}catch{s(e("errorInvalidCredentials"))}},_={pageTitle:e("pageTitle"),welcomeBack:e("welcomeBack"),signInPrompt:e("signInPrompt"),continueWithGoogle:e("continueWithGoogle"),backendUrlLabel:e("backendUrlLabel"),backendUrlPlaceholder:e("backendUrlPlaceholder"),emailLabel:e("emailLabel"),emailPlaceholder:e("emailPlaceholder"),passwordLabel:e("passwordLabel"),passwordPlaceholder:e("passwordPlaceholder"),signInWithCredentials:e("signInWithCredentials"),or:e("or"),credentialsAuthEnabled:e("credentialsAuthEnabled"),approvedDomainsOnly:e("approvedDomainsOnly"),backToHome:e("backToHome"),learnMore:e("learnMore"),signUpInstead:e("signUpInstead"),errorBackendUrlRequired:e("errorBackendUrlRequired"),errorBackendUrlInvalid:e("errorBackendUrlInvalid"),errorBackendUrlUnreachable:e("errorBackendUrlUnreachable"),errorEmailRequired:e("errorEmailRequired"),errorPasswordRequired:e("errorPasswordRequired"),tagline:a("Home.tagline")};return p.jsxs("div",{className:"semiont-page-wrapper",children:[p.jsx(H,{...I!==void 0&&{backendUrl:I},onGoogleSignIn:u?G:void 0,onCredentialsSignIn:R,error:y,showCredentialsAuth:!0,isLoading:!1,Link:T,translations:_}),p.jsx(q,{Link:F,routes:j,t:v,CookiePreferences:K,...(l==null?void 0:l.openKeyboardHelp)&&{onOpenKeyboardHelp:l.openKeyboardHelp}})]})}export{te as default};
//# sourceMappingURL=page-DX3FJ71G.js.map
