import{e as Q,r as m,f as W,j as e,P as R,g as T,h as Z,i as ee,k as te,b as M,s as z,u as re,d as se,a as _,B as S}from"./index-BL0y_fpc.js";import{I as U}from"./input-C0ZJbgJ-.js";import{L as I}from"./label-PZFLDDFg.js";import{C as D,a as B,b as oe,c as ne,d as ie}from"./card-CmTQIX9U.js";import{u as ae}from"./index-BzvWNLev.js";import{C as ce}from"./check-bfncYjgZ.js";import{l as le}from"./lionpost_logo-D5RcADIY.js";import{L as de}from"./loader-circle-CPVHBfFt.js";import{C as ue}from"./circle-check-big-RLYwyypV.js";import{M as me}from"./mail-sgluXWmA.js";var P="Checkbox",[he,$e]=Q(P),[fe,O]=he(P);function pe(t){const{__scopeCheckbox:s,checked:o,children:i,defaultChecked:a,disabled:r,form:h,name:u,onCheckedChange:c,required:w,value:p="on",internal_do_not_use_render:f}=t,[b,k]=te({prop:o,defaultProp:a??!1,onChange:c,caller:P}),[n,d]=m.useState(null),[v,l]=m.useState(null),g=m.useRef(!1),E=n?!!h||!!n.closest("form"):!0,x={checked:b,disabled:r,setChecked:k,control:n,setControl:d,name:u,form:h,value:p,hasConsumerStoppedPropagationRef:g,required:w,defaultChecked:j(a)?!1:a,isFormControl:E,bubbleInput:v,setBubbleInput:l};return e.jsx(fe,{scope:s,...x,children:ge(f)?f(x):i})}var $="CheckboxTrigger",G=m.forwardRef(({__scopeCheckbox:t,onKeyDown:s,onClick:o,...i},a)=>{const{control:r,value:h,disabled:u,checked:c,required:w,setControl:p,setChecked:f,hasConsumerStoppedPropagationRef:b,isFormControl:k,bubbleInput:n}=O($,t),d=W(a,p),v=m.useRef(c);return m.useEffect(()=>{const l=r==null?void 0:r.form;if(l){const g=()=>f(v.current);return l.addEventListener("reset",g),()=>l.removeEventListener("reset",g)}},[r,f]),e.jsx(R.button,{type:"button",role:"checkbox","aria-checked":j(c)?"mixed":c,"aria-required":w,"data-state":Y(c),"data-disabled":u?"":void 0,disabled:u,value:h,...i,ref:d,onKeyDown:T(s,l=>{l.key==="Enter"&&l.preventDefault()}),onClick:T(o,l=>{f(g=>j(g)?!0:!g),n&&k&&(b.current=l.isPropagationStopped(),b.current||l.stopPropagation())})})});G.displayName=$;var L=m.forwardRef((t,s)=>{const{__scopeCheckbox:o,name:i,checked:a,defaultChecked:r,required:h,disabled:u,value:c,onCheckedChange:w,form:p,...f}=t;return e.jsx(pe,{__scopeCheckbox:o,checked:a,defaultChecked:r,disabled:u,required:h,onCheckedChange:w,name:i,form:p,value:c,internal_do_not_use_render:({isFormControl:b})=>e.jsxs(e.Fragment,{children:[e.jsx(G,{...f,ref:s,__scopeCheckbox:o}),b&&e.jsx(X,{__scopeCheckbox:o})]})})});L.displayName=P;var V="CheckboxIndicator",q=m.forwardRef((t,s)=>{const{__scopeCheckbox:o,forceMount:i,...a}=t,r=O(V,o);return e.jsx(Z,{present:i||j(r.checked)||r.checked===!0,children:e.jsx(R.span,{"data-state":Y(r.checked),"data-disabled":r.disabled?"":void 0,...a,ref:s,style:{pointerEvents:"none",...t.style}})})});q.displayName=V;var K="CheckboxBubbleInput",X=m.forwardRef(({__scopeCheckbox:t,...s},o)=>{const{control:i,hasConsumerStoppedPropagationRef:a,checked:r,defaultChecked:h,required:u,disabled:c,name:w,value:p,form:f,bubbleInput:b,setBubbleInput:k}=O(K,t),n=W(o,k),d=ae(r),v=ee(i);m.useEffect(()=>{const g=b;if(!g)return;const E=window.HTMLInputElement.prototype,y=Object.getOwnPropertyDescriptor(E,"checked").set,C=!a.current;if(d!==r&&y){const N=new Event("click",{bubbles:C});g.indeterminate=j(r),y.call(g,j(r)?!1:r),g.dispatchEvent(N)}},[b,d,r,a]);const l=m.useRef(j(r)?!1:r);return e.jsx(R.input,{type:"checkbox","aria-hidden":!0,defaultChecked:h??l.current,required:u,disabled:c,name:w,value:p,form:f,...s,tabIndex:-1,ref:n,style:{...s.style,...v,position:"absolute",pointerEvents:"none",opacity:0,margin:0,transform:"translateX(-100%)"}})});X.displayName=K;function ge(t){return typeof t=="function"}function j(t){return t==="indeterminate"}function Y(t){return j(t)?"indeterminate":t?"checked":"unchecked"}const J=m.forwardRef(({className:t,...s},o)=>e.jsx(L,{ref:o,className:M("peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",t),...s,children:e.jsx(q,{className:M("flex items-center justify-center text-current"),children:e.jsx(ce,{className:"h-4 w-4"})})}));J.displayName=L.displayName;var xe="authorization_response",be="/~oauth/initiate",we=["https://oauth.lovable.app","https://lovable.dev"],ve="lovable://oauth-callback",ke="http://127.0.0.1/iframe-oauth/callback",Ce=500,ye=12e4;function je(t){let s;const o=new Promise(r=>{s=r}),i=r=>{if(!t.some(c=>r.origin===c))return;const u=r.data;!u||typeof u!="object"||u.type===xe&&s(u.response)},a=()=>{window.removeEventListener("message",i)};return window.addEventListener("message",i),{cleanup:a,messagePromise:o}}function _e(t){const s=window.screenX!==0||window.screenY!==0||!t,o=s?window.outerWidth*.5:window.screen.width*.5,i=s?window.outerHeight*.5:window.screen.height*.5,a=s?window.screenX+(window.outerWidth-o)/2:(window.screen.width-o)/2,r=s?window.screenY+(window.outerHeight-i)/2:(window.screen.height-i)/2;return{width:o,height:i,left:a,top:r}}function F(t,s){return t.state!==s?{error:new Error("State is invalid")}:t.error?t.error==="legacy_flow"?{error:new Error("This flow is not supported in Preview mode. Please open the app in a new tab to sign in.")}:{error:new Error(t.error_description??"Sign in failed")}:!t.access_token||!t.refresh_token?{error:new Error("No tokens received")}:{tokens:{access_token:t.access_token,refresh_token:t.refresh_token},error:null}}function Ee(){const t=navigator.userAgent;return!!(/iPhone|iPad|iPod|Android/i.test(t)||/Macintosh/i.test(t)&&navigator.maxTouchPoints>1)}function Ne(){return typeof crypto<"u"&&crypto.getRandomValues?[...crypto.getRandomValues(new Uint8Array(16))].map(t=>t.toString(16).padStart(2,"0")).join(""):Math.random().toString(36).substring(2)+Date.now().toString(36)}function Se(t={}){const s=t.oauthBrokerUrl??be,o=t.supportedOAuthOrigins??we;async function i(a,r={}){let h=!1;try{h=window.self!==window.top}catch{h=!0}const u=navigator.userAgent,c=/LovableApp\//.test(u),w=!c&&/lovable/i.test(u),p=Ne();let f=r.redirect_uri??window.location.origin;c&&h?f=ve:w&&h&&(f=ke);const b=new URLSearchParams({...r.extraParams,provider:a,redirect_uri:f,state:p});if(!h)return window.location.href=`${s}?${b.toString()}`,{error:null,redirected:!0};!c&&!w&&b.set("response_mode","web_message");const k=`${s}?${b.toString()}`,n=w?[...o,window.location.origin]:o,{messagePromise:d,cleanup:v}=je(n);let l;if(Ee())l=window.open(k,"_blank");else{const{width:x,height:y,left:C,top:N}=_e(h);l=window.open(k,"oauth",`width=${x},height=${y},left=${C},top=${N}`)}if(!l&&(c||w)){let x;const y=new Promise((C,N)=>{x=setTimeout(()=>{N(new Error("OAuth timed out waiting for response"))},ye)});try{const C=await Promise.race([d,y]);return F(C,p)}catch(C){return{error:C instanceof Error?C:new Error(String(C))}}finally{x&&clearTimeout(x),v()}}if(!l)return v(),{error:new Error("Popup was blocked")};let g;const E=new Promise((x,y)=>{g=setInterval(()=>{l.closed&&(clearInterval(g),y(new Error("Sign in was cancelled")))},Ce)});try{const x=await Promise.race([d,E]);return F(x,p)}catch(x){return{error:x instanceof Error?x:new Error(String(x))}}finally{clearInterval(g),v(),l==null||l.close()}}return{signInWithOAuth:i}}var Pe={name:"@lovable.dev/cloud-auth-js",version:"1.1.1",description:"Lovable Cloud Auth JS",main:"./dist/index.cjs",module:"./dist/index.js",types:"./dist/index.d.ts",type:"module",files:["dist"],scripts:{build:"tsup src/index.ts --format cjs,esm --dts --outDir dist",dev:"tsup src/index.ts --format cjs,esm --dts --watch",test:"vitest run",typecheck:"tsgo --noEmit",prepublishOnly:"npm run clean && npm run build",clean:"rimraf dist"},keywords:["lovable","oauth","authentication"],license:"MIT",devDependencies:{"@types/node":"^22",jsdom:"^26",rimraf:"^5.0.0",tsup:"^7.2.0",typescript:"^5",vitest:"^4.1.0"}};typeof window<"u"&&(window.__lovable_cloud_auth_js_version=Pe.version);function Ie(t={}){return Se(t)}const Ae=Ie(),H={auth:{signInWithOAuth:async(t,s)=>{const o=await Ae.signInWithOAuth(t,{redirect_uri:s==null?void 0:s.redirect_uri,extraParams:{...s==null?void 0:s.extraParams}});if(o.redirected||o.error)return o;try{await z.auth.setSession(o.tokens)}catch(i){return{error:i instanceof Error?i:new Error(String(i))}}return o}}},Re=new Set(["lionpost.com","www.lionpost.com"]),Oe="https://lionpost-card-studio.lovable.app",A=()=>{const{origin:t,hostname:s}=window.location;if(Re.has(s)){const o=new URL("/auth",Oe);return o.searchParams.set("return_to",t),o.toString()}return`${t}/auth`};function Ge(){const[t,s]=m.useState(""),[o,i]=m.useState(""),[a,r]=m.useState(!1),[h,u]=m.useState(!1),[c,w]=m.useState(()=>localStorage.getItem("lionpost_remember_me")!=="false"),p=re(),{user:f,loading:b}=se();m.useEffect(()=>{localStorage.setItem("lionpost_remember_me",String(c))},[c]),m.useEffect(()=>{f&&(console.log("User authenticated, checking for draft card"),localStorage.getItem("lionpost_draft_card")?(_.success("Saving your card..."),p("/editor?restore_draft=true")):(console.log("No draft card, redirecting to dashboard"),p("/dashboard")))},[f,p]);const k=async n=>{if(n.preventDefault(),r(!0),o){console.log("Bot detected via honeypot"),r(!1);return}try{const d=A();console.log("Sending magic link with redirect:",d),localStorage.setItem("lionpost_session_persist",c?"persistent":"session");const{error:v}=await z.auth.signInWithOtp({email:t,options:{emailRedirectTo:d,shouldCreateUser:!0}});if(v)throw v;u(!0),_.success("Magic link sent! Check your email.")}catch(d){console.error("Auth error:",d),_.error(d.message||"Failed to send magic link")}finally{r(!1)}};return b?e.jsxs("div",{className:"min-h-screen flex items-center justify-center p-4 relative overflow-hidden",children:[e.jsx("video",{autoPlay:!0,loop:!0,muted:!0,playsInline:!0,className:"absolute inset-0 w-full h-full object-cover",children:e.jsx("source",{src:"/auth-background.mp4",type:"video/mp4"})}),e.jsx("div",{className:"absolute inset-0 bg-background/40 backdrop-blur-sm"}),e.jsx(D,{className:"w-full max-w-md border-2 shadow-xl relative z-10",children:e.jsxs(B,{className:"flex flex-col items-center justify-center py-12",children:[e.jsx(de,{className:"w-12 h-12 animate-spin text-primary mb-4"}),e.jsx("p",{className:"text-lg font-medium",children:"Signing you in..."})]})})]}):e.jsxs("div",{className:"min-h-screen flex items-center justify-center p-4 relative overflow-hidden",children:[e.jsx("video",{autoPlay:!0,loop:!0,muted:!0,playsInline:!0,className:"absolute inset-0 w-full h-full object-cover",children:e.jsx("source",{src:"/auth-background.mp4",type:"video/mp4"})}),e.jsx("div",{className:"absolute inset-0 bg-background/40 backdrop-blur-sm"}),e.jsxs(D,{className:"w-full max-w-md border-2 shadow-xl relative z-10",children:[e.jsxs(oe,{className:"text-center space-y-4",children:[e.jsx("div",{className:"mx-auto w-32 h-32 rounded-full overflow-hidden border-4 border-primary shadow-lg cursor-pointer",onClick:()=>p("/"),children:e.jsx("img",{src:le,alt:"LionPost",className:"w-full h-full object-cover"})}),e.jsxs("div",{children:[e.jsx(ne,{className:"text-3xl font-bold text-primary",children:"LionPost"}),e.jsx(ie,{className:"text-lg",children:"Unlimited digital greetings cards for every occasion"})]})]}),e.jsx(B,{children:h?e.jsxs("div",{className:"text-center space-y-4 py-4",children:[e.jsx(ue,{className:"w-16 h-16 text-green-500 mx-auto"}),e.jsx("h3",{className:"text-xl font-semibold",children:"Check your email!"}),e.jsxs("p",{className:"text-muted-foreground",children:["We've sent a magic link to ",e.jsx("strong",{children:t})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Click the link in the email to sign in."}),e.jsx("p",{className:"text-sm font-semibold text-primary",children:"Don't forget to check your spam folder!"}),e.jsx(S,{variant:"outline",onClick:()=>{u(!1),s("")},className:"mt-4",children:"Use a different email"})]}):e.jsxs("form",{onSubmit:k,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(I,{htmlFor:"email",className:"flex items-center gap-2",children:[e.jsx(me,{className:"w-4 h-4"}),"Email"]}),e.jsx(U,{id:"email",type:"email",placeholder:"your@email.com",value:t,onChange:n=>s(n.target.value),required:!0,disabled:a})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(J,{id:"remember-me",checked:c,onCheckedChange:n=>w(n===!0)}),e.jsx(I,{htmlFor:"remember-me",className:"text-sm font-normal cursor-pointer",children:"Remember me on this device"})]}),e.jsxs("div",{className:"absolute -left-[9999px]","aria-hidden":"true",children:[e.jsx(I,{htmlFor:"website",children:"Website"}),e.jsx(U,{id:"website",type:"text",name:"website",tabIndex:-1,autoComplete:"off",value:o,onChange:n=>i(n.target.value)})]}),e.jsx(S,{type:"submit",className:"w-full",disabled:a,children:a?"Sending...":"Send Magic Link"}),e.jsx("p",{className:"text-sm text-muted-foreground text-center",children:"We'll email you a magic link to sign in instantly — no long sign up required!"}),e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-0 flex items-center",children:e.jsx("span",{className:"w-full border-t"})}),e.jsx("div",{className:"relative flex justify-center text-xs uppercase",children:e.jsx("span",{className:"bg-card px-2 text-muted-foreground",children:"Or continue with"})})]}),e.jsxs(S,{type:"button",variant:"outline",className:"w-full",disabled:a,onClick:async()=>{r(!0);try{const n=A(),{error:d}=await H.auth.signInWithOAuth("google",{redirect_uri:n});d&&_.error(d.message||"Failed to sign in with Google")}catch(n){_.error(n.message||"Failed to sign in with Google")}finally{r(!1)}},children:[e.jsxs("svg",{className:"w-5 h-5 mr-2",viewBox:"0 0 24 24",children:[e.jsx("path",{fill:"currentColor",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"}),e.jsx("path",{fill:"currentColor",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"}),e.jsx("path",{fill:"currentColor",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.93l2.85-2.22.81-.62z"}),e.jsx("path",{fill:"currentColor",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"})]}),"Sign in with Google"]}),e.jsxs(S,{type:"button",variant:"outline",className:"w-full",disabled:a,onClick:async()=>{r(!0);try{const n=A(),{error:d}=await H.auth.signInWithOAuth("apple",{redirect_uri:n});d&&_.error(d.message||"Failed to sign in with Apple")}catch(n){_.error(n.message||"Failed to sign in with Apple")}finally{r(!1)}},children:[e.jsx("svg",{className:"w-5 h-5 mr-2",viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("path",{d:"M17.05 20.28c-.98.95-2.05.8-3.08.35-1.09-.46-2.09-.48-3.24 0-1.44.62-2.2.44-3.06-.35C2.79 15.25 3.51 7.59 9.05 7.31c1.35.07 2.29.74 3.08.8 1.18-.24 2.31-.93 3.57-.84 1.51.12 2.65.72 3.4 1.8-3.12 1.87-2.38 5.98.48 7.13-.57 1.5-1.31 2.99-2.54 4.09l.01-.01zM12.03 7.25c-.15-2.23 1.66-4.07 3.74-4.25.29 2.58-2.34 4.5-3.74 4.25z"})}),"Sign in with Apple"]})]})})]})]})}export{Ge as default};