1import{j as e,a as y,b as w,r as u,C as D,c as P,d as E,e as k,f as I,L as v,B as f,g as O,s as b,u as C,_ as F}from"./index-DVrL3xID.js";import{D as T,a as _,b as A,c as L,d as M,L as B}from"./Layout-By6nV2kW.js";import{I as g}from"./input-BbuQ1qqy.js";import{P as Y,O as W}from"./OAuthButtons-CpPB8k_8.js";import{L as x}from"./label-CobuJheF.js";import{U as q,T as H}from"./avatar-D_VCVAB1.js";import{M as N}from"./mail-Dq7Z9Tcv.js";import{B as z}from"./building-rpEtkgej.js";import{T as G}from"./target-BLXbKPmt.js";import"./index-CRlXEeIp.js";import"./check-DfmPE1HZ.js";import"./sparkles-DfyS1GyF.js";import"./users-Cy3sXXAx.js";import"./trending-up-HNiDSAZu.js";import"./eye-off-D1tlRRC6.js";import"./eye-DEHf5viq.js";const R=()=>e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"absolute inset-0 bg-cover bg-center bg-no-repeat",style:{backgroundImage:"url('https://images.unsplash.com/photo-1506905925346-21bda4d32df4?ixlib=rb-4.0.3&auto=format&fit=crop&w=2000&q=80')"}}),e.jsx("div",{className:"absolute inset-0 bg-black/30"})]}),U=()=>e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"w-20 h-20 rounded-full flex items-center justify-center mx-auto mb-4",children:e.jsx("img",{src:"/lovable-uploads/f4afec24-3d33-4213-8ed0-05536d352f89.png",alt:"PureGreenAI Logo",className:"w-20 h-20 object-contain rounded-full"})}),e.jsxs("h2",{className:"mt-6 text-3xl font-sans font-extrabold text-white drop-shadow-lg",children:["Welcome back to Pure",e.jsx("span",{className:"text-green-400",children:"Green"}),"AI"]}),e.jsx("p",{className:"mt-2 text-sm text-white/80 drop-shadow-md",children:"Sign in to your account"})]}),J=({isLoading:t,setIsLoading:i})=>{const{login:m}=y(),{toast:s}=w(),[a,r]=u.useState({email:"",password:""}),l=c=>{const{name:o,value:n}=c.target;r(d=>({...d,[o]:n}))},p=async c=>{var o,n;if(c.preventDefault(),!a.email||!a.password){s({title:"Missing information",description:"Please enter both email and password.",variant:"destructive"});return}i(!0);try{console.log("Attempting login with:",a.email),await m(a.email,a.password),s({title:"Welcome back!",description:"You have successfully logged in."})}catch(d){console.error("Login error:",d);let h="Please check your credentials and try again.";(o=d.message)!=null&&o.includes("Invalid login credentials")?h="Invalid email or password. Please check your credentials.":(n=d.message)!=null&&n.includes("Email not confirmed")&&(h="Please check your email and confirm your account before logging in."),s({title:"Login failed",description:h,variant:"destructive"})}finally{i(!1)}};return e.jsxs(D,{className:"bg-card/80 backdrop-blur-md shadow-xl border-white/20",children:[e.jsxs(P,{children:[e.jsx(E,{children:"Sign In"}),e.jsx(k,{children:"Enter your credentials to access your account"})]}),e.jsxs(I,{children:[e.jsxs("form",{onSubmit:p,className:"space-y-4",children:[a.email!==""&&a.password!==""&&t===!1&&e.jsx(e.Fragment,{}),e.jsxs("div",{children:[e.jsx(x,{htmlFor:"email",children:"Email"}),e.jsx(g,{id:"email",name:"email",type:"email",value:a.email,onChange:l,placeholder:"Enter your email",required:!0,disabled:t,autoComplete:"email",className:"mt-1",inputMode:"email"})]}),e.jsxs("div",{children:[e.jsx(x,{htmlFor:"password",children:"Password"}),e.jsx(Y,{id:"password",name:"password",value:a.password,onChange:l,placeholder:"Enter your password",required:!0,disabled:t,autoComplete:"current-password",className:"mt-1"})]}),e.jsx("div",{className:"text-right",children:e.jsx(v,{to:"/forgot-password",className:"text-sm text-primary hover:text-accent hover:underline",children:"Forgot your password?"})}),e.jsxs(f,{type:"submit",className:"w-full",disabled:t||!a.email||!a.password,children:[t&&e.jsx(O,{className:"mr-2 h-4 w-4 animate-spin"}),t?"Signing in...":"Sign In"]})]}),e.jsx("div",{className:"mt-6",children:e.jsx(W,{isLoading:t,setIsLoading:i})}),e.jsx("div",{className:"mt-6 text-center",children:e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Don't have an account?"," ",e.jsx(v,{to:"/signup",className:"font-medium text-primary hover:text-accent",children:"Sign up here"})]})})]})]})};function K({isOpen:t,onClose:i,onContinueDemo:m}){const[s,a]=u.useState({email:"",name:"",company:"",useCase:""}),[r,l]=u.useState(!1),{toast:p}=w(),c=async o=>{if(o.preventDefault(),!s.email||!s.email.includes("@")){p({title:"Email Required",description:"Please enter a valid email address to access the demo.",variant:"destructive"});return}l(!0);try{const{data:n,error:d}=await b.functions.invoke("capture-demo-email",{body:{email:s.email,name:s.name||null,company:s.company||null,useCase:s.useCase||null}});if(d)throw d;await b.functions.invoke("track-engagement",{body:{metric_type:"demo_completion"}}),p({title:"Demo Access Granted!",description:"Check your email for helpful tips while you explore."}),m()}catch(n){console.error("Error saving demo email:",n),p({title:"Error",description:"Failed to save email. Please try again.",variant:"destructive"})}finally{l(!1)}};return e.jsx(T,{open:t,onOpenChange:o=>{o||i()},children:e.jsxs(_,{className:"sm:max-w-md",children:[e.jsxs(A,{children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs(L,{className:"flex items-center gap-2",children:[e.jsx(N,{className:"h-5 w-5 text-primary"}),"Welcome to the Demo!"]})}),e.jsx(M,{children:"Enter your email to access our demo and see how PureGreen can help grow your sustainable business."})]}),e.jsxs("form",{onSubmit:c,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs(x,{htmlFor:"email",className:"flex items-center gap-2",children:[e.jsx(N,{className:"h-4 w-4"}),"Email Address *"]}),e.jsx(g,{id:"email",type:"email",placeholder:"[email protected]",value:s.email,onChange:o=>a(n=>({...n,email:o.target.value})),required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(x,{htmlFor:"name",className:"flex items-center gap-2",children:[e.jsx(q,{className:"h-4 w-4"}),"Name (optional)"]}),e.jsx(g,{id:"name",placeholder:"Your name",value:s.name,onChange:o=>a(n=>({...n,name:o.target.value}))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(x,{htmlFor:"company",className:"flex items-center gap-2",children:[e.jsx(z,{className:"h-4 w-4"}),"Company (optional)"]}),e.jsx(g,{id:"company",placeholder:"Your company",value:s.company,onChange:o=>a(n=>({...n,company:o.target.value}))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(x,{htmlFor:"useCase",className:"flex items-center gap-2",children:[e.jsx(G,{className:"h-4 w-4"}),"What brings you here? (optional)"]}),e.jsx(H,{id:"useCase",placeholder:"Tell us about your use case or what you're hoping to achieve...",rows:3,value:s.useCase,onChange:o=>a(n=>({...n,useCase:o.target.value}))})]}),e.jsx("div",{className:"flex flex-col gap-2 pt-4",children:e.jsx(f,{type:"submit",disabled:r||!s.email,className:"w-full",children:r?"Starting Demo...":"Access Demo"})})]}),e.jsx("div",{className:"text-xs text-muted-foreground text-center pt-2",children:"We respect your privacy. Your information is only used to improve your experience."})]})})}
1const j="demoEmailPopupLastShown",S=14;function V(){const[t,i]=u.useState({isPopupOpen:!1,hasShownPopup:!1});u.useEffect(()=>{try{const r=localStorage.getItem(j);if(r){const l=parseInt(r,10);(Date.now()-l)/(1e3*60*60*24)<S&&i(c=>({...c,hasShownPopup:!0}))}}catch{}},[]);const m=u.useCallback(()=>{try{localStorage.setItem(j,Date.now().toString())}catch{}i(r=>({...r,isPopupOpen:!0,hasShownPopup:!0}))},[]),s=u.useCallback(()=>{i(r=>({...r,isPopupOpen:!1}))},[]),a=u.useCallback(()=>{if(!t.hasShownPopup)try{const r=localStorage.getItem(j);if(!r)return!0;const l=parseInt(r,10);return(Date.now()-l)/(1e3*60*60*24)>=S}catch{return!0}return!1},[t.hasShownPopup]);return{isPopupOpen:t.isPopupOpen,hasShownPopup:t.hasShownPopup,showEmailPopup:m,hideEmailPopup:s,shouldShowPopup:a}}const Q=({isLoading:t})=>{const i=C(),{setDemoMode:m}=y(),{toast:s}=w(),{isPopupOpen:a,showEmailPopup:r,hideEmailPopup:l,shouldShowPopup:p}=V(),c=(d="moderate")=>{F(async()=>{const{DemoSessionManager:h}=await import("./demo-session-manager-Bc-YiF31.js");return{DemoSessionManager:h}},[]).then(({DemoSessionManager:h})=>{h.startDemoSession(d,"affiliate"),m(!0),s({title:"Demo Mode",description:"You're now in demo mode with realistic sample data."}),i("/demo-dashboard")})},o=()=>{p()?r():c()},n=()=>{l(),c()};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mt-6",children:[e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"absolute inset-0 flex items-center",children:e.jsx("div",{className:"w-full border-t border-gray-300"})}),e.jsx("div",{className:"relative flex justify-center text-sm",children:e.jsx("span",{className:"px-2 bg-white text-gray-500",children:"Or"})})]}),e.jsxs("div",{className:"space-y-2 mt-4",children:[e.jsx(f,{type:"button",variant:"outline",className:"w-full",onClick:o,disabled:t,children:"Try Interactive Demo"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(f,{type:"button",variant:"ghost",size:"sm",className:"flex-1 text-xs",onClick:()=>c("struggling"),disabled:t,children:"Beginner Journey"}),e.jsx(f,{type:"button",variant:"ghost",size:"sm",className:"flex-1 text-xs",onClick:()=>c("successful"),disabled:t,children:"Success Story"})]})]})]}),e.jsx(K,{isOpen:a,onClose:l,onContinueDemo:n})]})};function pe(){const t=C(),{isAuthenticated:i,isInitialized:m,user:s}=y(),[a,r]=u.useState(!1);return u.useEffect(()=>{if(i&&m&&s){console.log("User is authenticated, redirecting based on role:",s.role);const l=s.role==="merchant"?"/dashboard-vendor":"/dashboard-affiliate";t(l)}},[i,m,s,t]),i&&m?null:e.jsx(B,{children:e.jsxs("div",{className:"min-h-screen bg-muted/30 flex items-center justify-center py-12 px-4 sm:px-6 lg:px-8 relative overflow-hidden",children:[e.jsx(R,{}),e.jsxs("div",{className:"max-w-md w-full space-y-8 relative z-10",children:[e.jsx(U,{}),e.jsx(J,{isLoading:a,setIsLoading:r}),e.jsx("div",{className:"bg-card/80 backdrop-blur-md shadow-xl rounded-lg p-6 border border-white/20",children:e.jsx(Q,{isLoading:a})}),e.jsx("div",{className:"text-center",children:e.jsx(v,{to:"/",className:"text-foreground/80 hover:text-foreground underline drop-shadow-md",children:"â Back to Home"})})]})]})})}export{pe 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.