var e=(e,t,s)=>new Promise((a,l)=>{var r=e=>{try{o(s.next(e))}catch(t){l(t)}},i=e=>{try{o(s.throw(e))}catch(t){l(t)}},o=e=>e.done?a(e.value):Promise.resolve(e.value).then(r,i);o((s=s.apply(e,t)).next())});import{j as t}from"./radix-ui-CVZWoPyd.js";import{r as s}from"./react-vendor-BmlOtb7g.js";import{u as a,L as l,B as r,s as i}from"./index-BCSgDlp8.js";import{S as o}from"./SEO-BGpcOjpb.js";import{c as n}from"./projects-BGLD7lLE.js";import{t as d,a as c}from"./analytics-CgKQjs6u.js";import{u}from"./index-CarSyuJM.js";import{u as m,a as x,N as p}from"./react-router-DzDVDRUd.js";import{A as h}from"./arrow-left-C1RZbPAl.js";import"./supabase-C8kocL5G.js";import"./utils-Ceo22G_t.js";function g(){var g,b,f,j,v,w;const y=m(),N="login"===(null==(g=y.state)?void 0:g.mode)||(null==(b=y.state)||b.mode,!1),[_,k]=s.useState(N),[S,C]=s.useState(!1),[E,F]=s.useState(""),[P,q]=s.useState(""),[A,I]=s.useState(""),[G,z]=s.useState(""),[M,$]=s.useState(""),[B,D]=s.useState(!1),[R,U]=s.useState(!1),[L,O]=s.useState(!1),Q=x(),{user:W,loading:J,signIn:T,signUp:V}=a();s.useEffect(()=>{var e,t;"login"===(null==(e=y.state)?void 0:e.mode)?k(!0):"signup"===(null==(t=y.state)?void 0:t.mode)&&k(!1)},[y.state]);const H=null==(f=y.state)?void 0:f.fromQuestionnaire,K=null==(j=y.state)?void 0:j.questionnaireVersion,X=H?null:"/app",Y=(null==(w=null==(v=y.state)?void 0:v.from)?void 0:w.pathname)||X;if(s.useEffect(()=>{if(W&&H&&!L){O(!0),$("");const t="v2"===K?sessionStorage:localStorage,s="v2"===K?"temp_questionnaire_answers_v2":"tempQuestionnaireAnswers",a=t.getItem(s);if(a)try{const e=JSON.parse(a);let l;l="v2"===K?{name:e.business_name||"Untitled Project",business_type:e.business_type||"",description:e.business_description||"",target_audience:e.target_audience||"",goals:e.marketing_goals||"",budget:e.budget||"",challenges:e.marketing_challenge||"",current_marketing:e.current_marketing||"",timeline:e.timeline||"",geographic_focus:e.geographic_focus||"",business_stage:e.business_stage||"",team_size:e.team_size||"",revenue_stage:e.revenue_stage||"",brand_personality:e.brand_personality||"",pricing_model:e.pricing_model||"",social_platforms:e.social_platforms||"",ad_platforms:e.ad_platforms||""}:{name:e.name||"Untitled Project",business_type:e.business_type||"",description:e.description||"",target_audience:e.target_audience||"",goals:e.goals||"",budget:e.budget||"",challenges:e.challenges||""},n(l,W).then(e=>{t.removeItem(s),Q(`/app/projects/${e.id}/documents`,{replace:!0})}).catch(e=>{console.error("Failed to create project post-auth:",e),$(e instanceof Error?`Project creation failed: ${e.message}`:"Failed to create project after sign-in."),O(!1)})}catch(e){console.error("Failed to parse stored answers for project creation:",e),$("Could not retrieve your questionnaire answers. Please try filling it out again."),t.removeItem(s),O(!1)}else $("Could not find your questionnaire answers. Redirecting to dashboard."),Q("/app",{replace:!0})}},[W,H,Q,L,K]),J||L)return t.jsxs("div",{className:"min-h-screen flex items-center justify-center",children:[t.jsx(l,{className:"h-8 w-8 animate-spin text-blue-600","aria-label":"Loading"}),L&&t.jsx("p",{className:"ml-2",children:"Finalizing your project..."})]});if(W&&!H&&!L)return t.jsx(p,{to:Y||"/app",replace:!0});return t.jsxs("div",{className:"min-h-screen flex",children:[t.jsx(o,{title:"Sign In",description:"Sign in to MarketingGuide AI to create or manage your marketing plans."}),t.jsx("div",{className:"lg:hidden fixed top-4 left-4 z-10",children:t.jsx("button",{onClick:()=>Q(-1),className:"p-2 rounded-full bg-white/80 backdrop-blur-sm shadow-lg border border-slate-200/60 text-slate-600 hover:text-blue-600 hover:bg-white hover:scale-105 transition-all duration-200",children:t.jsx(h,{className:"h-5 w-5"})})}),t.jsxs("div",{className:"hidden lg:flex lg:w-1/2 bg-blue-600 text-white p-12 flex-col",children:[t.jsxs("button",{onClick:()=>Q(-1),className:"flex items-center text-blue-100 hover:text-white hover:scale-105 transition-all duration-200",children:[t.jsx(h,{className:"h-5 w-5 mr-2"}),"Back"]}),t.jsxs("div",{className:"flex-1 flex flex-col justify-center max-w-lg",children:[t.jsx("div",{className:"h-12 w-12 bg-white/90 rounded-xl flex items-center justify-center mb-8 p-2",children:t.jsx("img",{src:"/logo-small.png",alt:"MarketingGuide AI",className:"h-8 w-8"})}),t.jsxs("h1",{className:"text-4xl sm:text-5xl md:text-6xl font-bold mb-4 leading-tight tracking-tight",children:["Welcome back to",t.jsx("br",{}),"MarketingGuide.ai"]}),t.jsx("p",{className:"text-lg text-blue-100 leading-relaxed",children:"Sign in to continue building your marketing strategy with AI-powered insights."}),t.jsx("div",{className:"mt-12 text-sm text-blue-200",children:"© 2025 MarketingGuide. All rights reserved."})]})]}),t.jsx("div",{className:"flex-1 flex items-center justify-center p-4 sm:p-8",children:t.jsxs("div",{className:"w-full max-w-md space-y-8",children:[t.jsxs("div",{className:"text-center lg:text-left",children:[t.jsx("h2",{className:"text-2xl sm:text-3xl font-semibold text-slate-800 leading-snug",children:S?"Reset your password":_?"Sign in to your account":"Create your account"}),t.jsx("p",{className:"mt-3 text-base text-slate-700 leading-relaxed",children:S?"Enter your email to receive a password reset link.":_?"Welcome back! Please enter your details.":"Get started with your marketing journey."})]}),S?t.jsxs("form",{className:"mt-8 space-y-6",onSubmit:t=>e(this,null,function*(){t.preventDefault(),$(""),U(!0);try{const{error:e}=yield i.auth.resetPasswordForEmail(P,{redirectTo:`${window.location.origin}/auth?mode=reset`});if(e)return void $(e.message);u.success("Password reset email sent! Check your inbox."),C(!1),q("")}catch(e){$(e instanceof Error?e.message:"Failed to send password reset email")}finally{U(!1)}}),children:[t.jsxs("div",{children:[t.jsx("label",{htmlFor:"resetEmail",className:"block text-sm font-medium text-slate-700 mb-2",children:"Email address"}),t.jsx("input",{id:"resetEmail",name:"resetEmail",type:"email",value:P,onChange:e=>q(e.target.value),autoComplete:"email",required:!0,className:"w-full px-6 py-4 border-2 border-blue-400/50 rounded-lg shadow-lg focus:outline-none focus:border-blue-500 focus:shadow-[0_0_15px_3px_rgba(59,130,246,0.3)] transition-all duration-200 text-slate-800 placeholder:text-slate-400 bg-white",placeholder:"you@example.com"})]}),M&&t.jsx("div",{className:"text-sm text-red-600 bg-red-50 border border-red-200 rounded-lg p-3",children:M}),t.jsx(r,{className:"w-full py-4 text-base font-medium bg-blue-600 hover:bg-blue-700 text-white rounded-lg shadow-lg hover:shadow-xl hover:scale-105 transition-all duration-200",type:"submit",disabled:R,children:R?t.jsx(l,{className:"h-5 w-5 animate-spin"}):"Send Reset Email"}),t.jsx("div",{className:"text-center",children:t.jsx("button",{type:"button",onClick:()=>{C(!1),$(""),q("")},className:"text-sm text-blue-600 hover:text-blue-700 transition-colors duration-200",children:"Back to sign in"})})]}):t.jsxs("form",{className:"mt-8 space-y-6",onSubmit:t=>e(this,null,function*(){t.preventDefault(),$(""),D(!0);try{_?(yield T(E,A),d("email",H),H||Q(Y||"/app",{replace:!0})):(yield V(E,A,G),c("email",H),H||Q("/app",{replace:!0}))}catch(e){$(e instanceof Error?e.message:"An error occurred")}finally{D(!1)}}),children:[t.jsxs("div",{className:"space-y-6",children:[!_&&t.jsxs("div",{children:[t.jsx("label",{htmlFor:"fullName",className:"block text-sm font-medium text-slate-700 mb-2",children:"Full Name"}),t.jsx("input",{id:"fullName",name:"fullName",type:"text",value:G,onChange:e=>z(e.target.value),required:!0,className:"w-full px-6 py-4 border-2 border-blue-400/50 rounded-lg shadow-lg focus:outline-none focus:border-blue-500 focus:shadow-[0_0_15px_3px_rgba(59,130,246,0.3)] transition-all duration-200 text-slate-800 placeholder:text-slate-400 bg-white",placeholder:"Enter your full name"})]}),t.jsxs("div",{children:[t.jsx("label",{htmlFor:"email",className:"block text-sm font-medium text-slate-700 mb-2",children:"Email address"}),t.jsx("input",{id:"email",name:"email",type:"email",value:E,onChange:e=>F(e.target.value),autoComplete:"email",required:!0,className:"w-full px-6 py-4 border-2 border-blue-400/50 rounded-lg shadow-lg focus:outline-none focus:border-blue-500 focus:shadow-[0_0_15px_3px_rgba(59,130,246,0.3)] transition-all duration-200 text-slate-800 placeholder:text-slate-400 bg-white",placeholder:"you@example.com"})]}),t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center justify-between mb-2",children:[t.jsx("label",{htmlFor:"password",className:"block text-sm font-medium text-slate-700",children:"Password"}),_&&t.jsx("button",{type:"button",onClick:()=>{C(!0),$("")},className:"text-sm text-blue-600 hover:text-blue-700 transition-colors duration-200",children:"Forgot password?"})]}),t.jsx("input",{id:"password",name:"password",type:"password",value:A,onChange:e=>I(e.target.value),autoComplete:"current-password",required:!0,className:"w-full px-6 py-4 border-2 border-blue-400/50 rounded-lg shadow-lg focus:outline-none focus:border-blue-500 focus:shadow-[0_0_15px_3px_rgba(59,130,246,0.3)] transition-all duration-200 text-slate-800 placeholder:text-slate-400 bg-white",placeholder:"••••••••"})]})]}),M&&t.jsx("div",{className:"text-sm text-red-600 bg-red-50 border border-red-200 rounded-lg p-3",children:M}),t.jsx(r,{className:"w-full py-4 text-base font-medium bg-blue-600 hover:bg-blue-700 text-white rounded-lg shadow-lg hover:shadow-xl hover:scale-105 transition-all duration-200",type:"submit",disabled:B,children:B?t.jsx(l,{className:"h-5 w-5 animate-spin"}):_?"Sign in":"Create account"}),t.jsx("div",{className:"text-center",children:t.jsx("button",{type:"button",onClick:()=>{k(!_),$("")},className:"text-sm text-blue-600 hover:text-blue-700 transition-colors duration-200",children:_?"Don't have an account? Sign up":"Already have an account? Sign in"})})]})]})})]})}export{g as default};