1import{w as v,a as i,p as e,v as r}from"./chunk-6CSD65Y2-B9EdUb7a.js";import{B as A}from"./Button-B5mWdm47.js";/* empty css */import"./index-CCCltmCc.js";import{P as u}from"./PageMeta-DAbMhs77.js";import{supabase as m}from"./supabase-y7-6yKvl.js";import{A as d,a as S,S as C,b as E,c as f,d as k,e as N}from"./AuthShell-BDVUMNBb.js";/* empty css */import"./LogoIcon-TjMDZPsr.js";const w=typeof window<"u"&&window.location.hostname==="localhost"?"http://localhost:8787":"https://api.motion.dev",W=v(function(){const[l,x]=i.useState(""),[h,j]=i.useState(""),[p,n]=i.useState(""),[c,o]=i.useState("idle");i.useEffect(()=>{m.auth.getSession().then(({data:{session:t}})=>{t&&g(t)})},[]);async function g(t){if(!t.user.email){n("No email associated with this account"),o("idle");return}const s=await fetch(`${w}/cssstudio/account-state`,{headers:{Authorization:`Bearer ${t.access_token}`}});if(!s.ok){n("Could not verify your account. Please try again."),o("idle");return}const{hasLicense:P}=await s.json();if(!P){o("no-purchase");return}await b(t.access_token,t.refresh_token)}function y(){return typeof window>"u"?null:new URLSearchParams(window.location.search).get("cs_session")}async function b(t,a){window.opener&&window.opener.postMessage({type:"auth-token",token:t,refreshToken:a},"*");const s=y();if(s)try{await fetch(`${w}/cssstudio/auth/deposit`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({session:s,accessToken:t,refreshToken:a})})}catch{}if(o("success"),window.opener)try{window.close()}catch{}}async function L(t){t.preventDefault(),n(""),o("loading");const{data:a,error:s}=await m.auth.signInWithPassword({email:l,password:h});if(s){n(s.message),o("idle");return}a.session&&await g(a.session)}return c==="success"?e.jsxs(d,{children:[e.jsx(u,{title:"Log in | CSS Studio"}),e.jsx(S,{icon:e.jsx(C,{}),heading:"You're logged in",children:e.jsxs("p",{style:{textWrap:"balance"},children:["Read the ",e.jsx(r,{to:"/learn",children:"Get started"})," docs to install CSS Studio on your site."]})})]}):c==="no-purchase"?e.jsxs(d,{children:[e.jsx(u,{title:"Log in | CSS Studio"}),e.jsxs(S,{heading:"Purchase required",variant:"error",children:[e.jsx("p",{children:"You're logged in, but you need to purchase CSS Studio."}),e.jsx(A,{to:"/pricing",className:"auth-btn",children:"View pricing"})]})]}):e.jsxs(d,{children:[e.jsx(u,{title:"Log in | CSS Studio"}),e.jsxs(E,{heading:"Log in",subtitle:"Sign in to continue to CSS Studio.",onSubmit:L,children:[e.jsx(f,{label:"Email",type:"email",value:l,onChange:t=>x(t.target.value),placeholder:"[email protected]",required:!0,autoFocus:!0}),e.jsx(f,{label:"Password",type:"password",value:h,onChange:t=>j(t.target.value),required:!0,aux:e.jsx(r,{to:"/forgot-password",className:"auth-field-aux",children:"Forgot?"})}),e.jsx(k,{action:p?e.jsx(r,{to:"/forgot-password",children:"Reset password?"}):void 0,children:p}),e.jsx(N,{loading:c==="loading",loadingLabel:"Logging in...",children:"Log in"})]}),e.jsxs("p",{className:"auth-switch",children:["Don't have an account? ",e.jsx(r,{to:"/register",children:"Sign up"})]})]})});export{W as default};
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.