1import{r as n,j as e}from"./vendor-react-BBy2ZWQs.js";import{h as T,s as d}from"./index-Bj7licZY.js";import"./vendor-misc-UQ56Iyoi.js";import"./vendor-supabase-B4HII3_u.js";import"./vendor-ui-BxcOQNql.js";const z="0x4AAAAAADkziG-qWDY0deWY",R="desktopAuthPort",F=[{id:"google",label:"Google",color:"hover:border-[#4285F4]/50 hover:bg-[#4285F4]/10",icon:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",children:[e.jsx("path",{d:"M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z",fill:"#4285F4"}),e.jsx("path",{d:"M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z",fill:"#34A853"}),e.jsx("path",{d:"M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l3.66-2.84z",fill:"#FBBC05"}),e.jsx("path",{d:"M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z",fill:"#EA4335"})]})},{id:"discord",label:"Discord",color:"hover:border-[#5865F2]/50 hover:bg-[#5865F2]/10",icon:e.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("path",{d:"M20.317 4.37a19.791 19.791 0 0 0-4.885-1.515.074.074 0 0 0-.079.037c-.21.375-.444.864-.608 1.25a18.27 18.27 0 0 0-5.487 0 12.64 12.64 0 0 0-.617-1.25.077.077 0 0 0-.079-.037A19.736 19.736 0 0 0 3.677 4.37a.07.07 0 0 0-.032.027C.533 9.046-.32 13.58.099 18.057c.002.022.015.04.03.052a19.9 19.9 0 0 0 5.993 3.03.078.078 0 0 0 .084-.028 13.998 13.998 0 0 0 1.226-1.994.076.076 0 0 0-.041-.106 13.107 13.107 0 0 1-1.872-.892.077.077 0 0 1-.008-.128 10.2 10.2 0 0 0 .372-.292.074.074 0 0 1 .077-.01c3.928 1.793 8.18 1.793 12.062 0a.074.074 0 0 1 .078.01c.12.098.246.198.373.292a.077.077 0 0 1-.006.127 12.299 12.299 0 0 1-1.873.892.077.077 0 0 0-.041.107c.36.698.772 1.362 1.225 1.993a.076.076 0 0 0 .084.028 19.839 19.839 0 0 0 6.002-3.03.077.077 0 0 0 .032-.054c.5-5.177-.838-9.674-3.549-13.66a.061.061 0 0 0-.031-.03zM8.02 15.33c-1.183 0-2.157-1.085-2.157-2.419 0-1.333.956-2.419 2.157-2.419 1.21 0 2.176 1.096 2.157 2.42 0 1.333-.956 2.418-2.157 2.418zm7.975 0c-1.183 0-2.157-1.085-2.157-2.419 0-1.333.955-2.419 2.157-2.419 1.21 0 2.176 1.096 2.157 2.42 0 1.333-.946 2.418-2.157 2.418z"})})},{id:"twitch",label:"Twitch",color:"hover:border-[#9146FF]/50 hover:bg-[#9146FF]/10",icon:e.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("path",{d:"M11.571 4.714h1.715v5.143H11.57zm4.715 0H18v5.143h-1.714zM6 0L1.714 4.286v15.428h5.143V24l4.286-4.286h3.428L22.286 12V0zm14.571 11.143l-3.428 3.428h-3.429l-3 3v-3H6.857V1.714h13.714z"})})}];function L(){const{port:f}=T.useSearch(),y=`http://localhost:${f}/session`,[o,i]=n.useState("checking"),[g,N]=n.useState(""),[b,S]=n.useState(""),[u,j]=n.useState(!1),[m,v]=n.useState(null),[x,l]=n.useState(""),[h,c]=n.useState(null),p=n.useRef(null),a=n.useRef(null);n.useEffect(()=>{d.auth.getSession().then(({data:t})=>{i(t.session?"connected":"login")})},[]),n.useEffect(()=>{if(o!=="login")return;const t=()=>{const s=window.turnstile;if(!s||!p.current){setTimeout(t,200);return}if(a.current)try{s.remove(a.current)}catch{}a.current=s.render(p.current,{sitekey:z,callback:r=>c(r),"expired-callback":()=>c(null),"error-callback":()=>c(null),theme:"dark"})};if(!window.turnstile&&!document.getElementById("cf-turnstile-script")){const s=document.createElement("script");s.id="cf-turnstile-script",s.src="https://challenges.cloudflare.com/turnstile/v0/api.js",s.async=!0,document.head.appendChild(s)}return t(),()=>{if(a.current&&window.turnstile){try{window.turnstile.remove(a.current)}catch{}a.current=null}}},[o]);async function w(t){i("sending");try{await fetch(y,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),i("done")}catch{l("Impossible de contacter l'application Windows. Assurez-vous qu'elle est lancée."),i("error")}}async function k(){const{data:t}=await d.auth.getSession();t.session&&await w(t.session)}async function C(t){v(t),sessionStorage.setItem(R,String(f));const{error:s}=await d.auth.signInWithOAuth({provider:t,options:{redirectTo:`${window.location.origin}/callback`,scopes:t==="discord"?"identify email":void 0}});s&&(l(s.message),v(null))}async function E(t){if(t.preventDefault(),!!h){j(!0),l("");try{const{data:s,error:r}=await d.auth.signInWithPassword({email:g,password:b,options:{captchaToken:h}});if(r)throw r;s.session&&await w(s.session)}catch(s){l(s.message||"Identifiants incorrects");const r=window.turnstile;r&&a.current&&(r.reset(a.current),c(null))}finally{j(!1)}}}return e.jsx("div",{className:"relative flex min-h-screen items-center justify-center bg-background px-4",style:{backgroundImage:"var(--gradient-hero)"},children:e.jsxs("div",{className:"w-full max-w-md",children:[e.jsx("div",{className:"mb-8 flex justify-center",children:e.jsx("img",{src:"/Logo RTK.png",alt:"ReadingTK",style:{width:180,height:"auto",mixBlendMode:"lighten",clipPath:"inset(3px 3px 3px 3px)"}})}),e.jsxs("div",{className:"rounded-2xl border border-border/60 bg-card/80 p-8 backdrop-blur",style:{boxShadow:"var(--shadow-card)"},children:[o==="checking"&&e.jsx("div",{className:"flex justify-center py-8",children:e.jsx("span",{className:"h-6 w-6 animate-spin rounded-full border-2 border-accent border-t-transparent"})}),o==="connected"&&e.jsxs(e.Fragment,{children:[e.jsx("h1",{className:"text-2xl font-semibold",children:"Application Windows"}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground mb-6",children:"Vous êtes déjà c
1onnecté. Cliquez pour autoriser l'application."}),e.jsx("button",{onClick:k,className:"w-full rounded-md py-2.5 text-sm font-semibold text-primary-foreground",style:{background:"var(--gradient-primary)",boxShadow:"var(--shadow-glow)"},children:"Connecter l'application"})]}),o==="login"&&e.jsxs(e.Fragment,{children:[e.jsx("h1",{className:"text-2xl font-semibold",children:"Connexion"}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Pour l'application Windows ReadingTK"}),e.jsx("div",{className:"mt-6 flex flex-col gap-3",children:F.map(({id:t,label:s,icon:r,color:A})=>e.jsxs("button",{onClick:()=>C(t),disabled:m!==null||u,className:`flex w-full items-center justify-center gap-3 rounded-md border border-border bg-card/50 px-4 py-2.5 text-sm font-medium transition-colors disabled:opacity-50 ${A}`,children:[m===t?e.jsx("span",{className:"h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}):r,"Continuer avec ",s]},t))}),e.jsxs("div",{className:"my-6 flex items-center gap-3",children:[e.jsx("div",{className:"h-px flex-1 bg-border"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"ou"}),e.jsx("div",{className:"h-px flex-1 bg-border"})]}),e.jsxs("form",{onSubmit:E,className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-muted-foreground",children:"Email"}),e.jsx("input",{type:"email",required:!0,value:g,onChange:t=>N(t.target.value),className:"mt-1 w-full rounded-md border border-input bg-input/50 px-3 py-2 text-sm outline-none focus:border-ring focus:ring-1 focus:ring-ring"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs font-medium text-muted-foreground",children:"Mot de passe"}),e.jsx("input",{type:"password",required:!0,value:b,onChange:t=>S(t.target.value),className:"mt-1 w-full rounded-md border border-input bg-input/50 px-3 py-2 text-sm outline-none focus:border-ring focus:ring-1 focus:ring-ring"})]}),e.jsx("div",{ref:p,className:"flex justify-center"}),x&&e.jsx("p",{className:"text-sm text-destructive",children:x}),e.jsx("button",{type:"submit",disabled:u||m!==null||!h,className:"w-full rounded-md py-2.5 text-sm font-semibold text-primary-foreground disabled:opacity-60",style:{background:"var(--gradient-primary)",boxShadow:"var(--shadow-glow)"},children:u?"Connexionâ¦":"Se connecter"})]})]}),o==="sending"&&e.jsxs("div",{className:"flex flex-col items-center gap-3 py-8",children:[e.jsx("span",{className:"h-6 w-6 animate-spin rounded-full border-2 border-accent border-t-transparent"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Connexion à l'applicationâ¦"})]}),o==="done"&&e.jsxs("div",{className:"flex flex-col items-center gap-3 py-6 text-center",children:[e.jsx("div",{className:"text-5xl",children:"â"}),e.jsx("h1",{className:"text-xl font-semibold",children:"Connecté !"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Vous pouvez fermer cet onglet et revenir à l'application Windows."})]}),o==="error"&&e.jsxs("div",{className:"flex flex-col items-center gap-3 py-6 text-center",children:[e.jsx("div",{className:"text-5xl",children:"â"}),e.jsx("p",{className:"text-sm text-destructive mb-2",children:x}),e.jsx("button",{onClick:()=>i("connected"),className:"text-sm text-accent hover:underline",children:"Réessayer"})]})]})]})})}export{L as component};
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.