var e=Object.defineProperty,s=Object.defineProperties,t=Object.getOwnPropertyDescriptors,r=Object.getOwnPropertySymbols,a=Object.prototype.hasOwnProperty,n=Object.prototype.propertyIsEnumerable,o=(s,t,r)=>t in s?e(s,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):s[t]=r,i=(e,s)=>{for(var t in s||(s={}))a.call(s,t)&&o(e,t,s[t]);if(r)for(var t of r(s))n.call(s,t)&&o(e,t,s[t]);return e},l=(e,r)=>s(e,t(r)),c=(e,s,t)=>new Promise((r,a)=>{var n=e=>{try{i(t.next(e))}catch(s){a(s)}},o=e=>{try{i(t.throw(e))}catch(s){a(s)}},i=e=>e.done?r(e.value):Promise.resolve(e.value).then(n,o);i((t=t.apply(e,s)).next())});import{j as d}from"./radix-ui-CVZWoPyd.js";import{r as u}from"./react-vendor-BmlOtb7g.js";import{u as m,B as g,L as p,b as h,D as x,R as b,c as f}from"./index-BCSgDlp8.js";import{c as v}from"./projects-BGLD7lLE.js";import{b as j,d as y,e as w}from"./analytics-CgKQjs6u.js";import{u as N}from"./use-mobile-onbIdywO.js";import k from"./NewProjectV2-DWXyvmHa.js";import{a as S,u as I}from"./react-router-DzDVDRUd.js";import{A as _}from"./arrow-left-C1RZbPAl.js";import{S as C}from"./sparkles-D1jOictl.js";import{A as P}from"./arrow-right-CcptuZBy.js";import{S as A}from"./shopping-bag-BIq4kDzF.js";import{B as $}from"./briefcase-Cj6O7NU7.js";import{V as O}from"./video-B-IvWYMZ.js";import{T as q}from"./trending-up-DMpQ-MB3.js";import{B as E}from"./building-BjJBE9bs.js";import{L as R}from"./lightbulb-Cbm4Avhv.js";import"./supabase-C8kocL5G.js";import"./utils-Ceo22G_t.js";import"./check-BhACZQ6I.js";const B=u.forwardRef(({value:e,onChange:s,placeholder:t},r)=>d.jsx("input",{type:"text",ref:r,value:e,onChange:e=>s(e.target.value),placeholder:t,className:"w-full max-w-xl mx-auto h-16 rounded-xl border-2 border-blue-200/50 bg-white/50 backdrop-blur-sm shadow-sm focus:border-blue-500 focus:ring-2 focus:ring-blue-500 focus:ring-opacity-50 px-6 text-lg transition-all duration-200 placeholder:text-gray-400 caret-blue-500"})),F=u.forwardRef(({value:e,onChange:s,placeholder:t},r)=>d.jsx("div",{className:"text-center",children:d.jsx("textarea",{ref:r,value:e,onChange:e=>s(e.target.value),placeholder:t,className:"w-full max-w-3xl mx-auto h-32 rounded-xl border-2 border-blue-200/50 bg-white/50 backdrop-blur-sm shadow-sm focus:border-blue-500 focus:ring-2 focus:ring-blue-500 focus:ring-opacity-50 px-6 py-4 text-lg transition-all duration-200 placeholder:text-gray-400 caret-blue-500",rows:4})})),z=[{id:"product_based",name:"Product Based",description:"e.g., E-commerce store, physical goods",icon:A},{id:"service_based",name:"Service Based",description:"e.g., Marketing agency, consultant, freelancer",icon:$},{id:"software_app",name:"Software or App",description:"e.g., SaaS platform, mobile application, desktop software",icon:h},{id:"content_media",name:"Content & Media",description:"e.g., Blogger, YouTuber, news website, podcast",icon:O}],L=[{id:"0-500",name:"$0 - $500",description:"Perfect for startups and small businesses taking their first marketing steps",icon:x},{id:"501-1000",name:"$501 - $1,000",description:"Ideal for businesses ready to expand their digital presence",icon:q},{id:"1001-5000",name:"$1,001 - $5,000",description:"For growing businesses seeking comprehensive marketing coverage",icon:b},{id:"10000+",name:"$10,000+",description:"Enterprise-level budget for maximum market impact",icon:E}],M={target_audience:["🎯 Analyzing your business to identify ideal customers...","👥 Generating personalized audience segments..."],goals:["🚀 Creating tailored marketing goals for your business...","📈 Identifying growth opportunities based on your profile..."],challenges:["🔍 Analyzing main challenges for your industry...","💡 Identifying potential obstacles and smart solutions..."]},G=u.forwardRef(({value:e,onChange:s,placeholder:t,suggestions:r,isLoading:a,onRefresh:n,questionId:o},i)=>{const l=a?o&&a&&M[o]||[]:r,c=l&&l.length>0;return d.jsxs("div",{className:"space-y-4 max-w-3xl mx-auto",children:[d.jsx("div",{className:"text-center",children:d.jsx("textarea",{ref:i,value:e,onChange:e=>s(e.target.value),placeholder:t,rows:Math.min(4,Math.max(2,e.split("\n").length)),className:"w-full max-w-3xl mx-auto rounded-xl border-2 border-blue-200/50 bg-white/50 backdrop-blur-sm shadow-sm focus:border-blue-500 focus:ring-2 focus:ring-blue-500 focus:ring-opacity-50 px-6 py-4 text-lg transition-all duration-200 placeholder:text-gray-400 caret-blue-500 resize-none",style:{minHeight:"4rem"}})}),c&&d.jsxs("div",{className:"space-y-4 max-w-3xl mx-auto",children:[d.jsxs("div",{className:"flex items-center justify-between",children:[d.jsxs("div",{className:"flex items-center gap-2 text-sm text-gray-700",children:[d.jsx(R,{className:"h-5 w-5 text-yellow-500"}),d.jsx("span",{className:"text-base",children:"AI Suggestions"})]}),d.jsxs(g,{variant:"ghost",size:"sm",className:"h-8 px-3 text-sm hover:bg-blue-50/80 hover:text-blue-600 disabled:opacity-50 disabled:cursor-wait",onClick:n,disabled:a,children:[a?d.jsx(p,{className:"h-4 w-4 mr-2 animate-spin"}):d.jsx(f,{className:"h-4 w-4 mr-2"}),a?"Generating...":"More Suggestions"]})]}),d.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:l.map((e,t)=>d.jsx("button",{onClick:()=>!a&&s(e),className:"text-left px-5 py-4 rounded-lg border-2 transition-all duration-200 group "+(a?"bg-blue-50/70 backdrop-blur-sm text-blue-700 cursor-default border-transparent":"bg-blue-50/70 backdrop-blur-sm hover:bg-blue-100/70 hover:border-blue-200/70 text-blue-700 cursor-pointer border-transparent"),children:d.jsx("div",{className:"flex flex-col",children:d.jsxs("div",{className:"mb-1 pr-6 relative",children:[d.jsx("span",{children:e}),!a&&d.jsx(P,{className:"h-4 w-4 absolute top-1 right-0 opacity-0 group-hover:opacity-100 transition-opacity duration-200"})]})})},`${a?"loading":"suggestion"}-${t}`))})]})]})}),J=[{id:"business_type",question:"Select your business type",component:({value:e,onChange:s})=>d.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4 max-w-4xl mx-auto",children:z.map(t=>{const r=t.icon,a=e===t.id;return d.jsxs("div",{onClick:()=>s(t.id),className:`flex items-start p-5 rounded-xl border-2 h-full ${a?"border-blue-500 bg-blue-50/70 backdrop-blur-sm shadow-sm":"border-gray-200 bg-white/70 hover:border-blue-300 hover:bg-blue-50/30"} cursor-pointer transition-all duration-200`,children:[d.jsx("div",{className:"flex items-center h-6 mr-3",children:d.jsx("div",{className:`h-5 w-5 rounded-full border ${a?"border-blue-500":"border-gray-300"} flex items-center justify-center`,children:a&&d.jsx("div",{className:"h-3 w-3 rounded-full bg-blue-500"})})}),d.jsxs("div",{className:"flex flex-col flex-grow",children:[d.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[d.jsx(r,{className:"h-6 w-6 flex-shrink-0 "+(a?"text-blue-600":"text-gray-500")}),d.jsx("div",{className:"text-lg font-medium "+(a?"text-blue-700":"text-gray-800"),children:t.name})]}),d.jsx("p",{className:"text-sm text-gray-600 leading-relaxed",children:t.description})]})]},t.id)})})},{id:"name",question:"What is your business name?",placeholder:"e.g., Maple Street Bakery, PixelPerfect Design, Summit Financial Advisors",component:B},{id:"description",question:"Describe your business in a few sentences",placeholder:"e.g., We create innovative software solutions...",component:F},{id:"target_audience",question:"Who is your target audience?",placeholder:"e.g., Small business owners, Young professionals...",component:G},{id:"goals",question:"What are your primary marketing goals?",placeholder:"e.g., Increase brand awareness, Generate leads...",component:G},{id:"challenges",question:"What are your biggest marketing challenges?",placeholder:"e.g., Limited resources, High competition...",component:G},{id:"budget",question:"What is your monthly marketing budget?",component:({value:e,onChange:s})=>d.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4 max-w-4xl mx-auto",children:L.map(t=>{const r=t.icon,a=e===t.name;return d.jsxs("div",{onClick:()=>s(t.name),className:`flex items-start p-5 rounded-xl border-2 h-full ${a?"border-blue-500 bg-blue-50/70 backdrop-blur-sm shadow-sm":"border-gray-200 bg-white/70 hover:border-blue-300 hover:bg-blue-50/30"} cursor-pointer transition-all duration-200`,children:[d.jsx("div",{className:"flex items-center h-6 mr-3",children:d.jsx("div",{className:`h-5 w-5 rounded-full border ${a?"border-blue-500":"border-gray-300"} flex items-center justify-center`,children:a&&d.jsx("div",{className:"h-3 w-3 rounded-full bg-blue-500"})})}),d.jsxs("div",{className:"flex flex-col flex-grow",children:[d.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[d.jsx(r,{className:"h-6 w-6 flex-shrink-0 "+(a?"text-blue-600":"text-gray-500")}),d.jsx("div",{className:"text-lg font-medium "+(a?"text-blue-700":"text-gray-800"),children:t.name})]}),d.jsx("p",{className:"text-sm text-gray-600 leading-relaxed",children:t.description})]})]},t.id)})})}],T="tempQuestionnaireAnswers";function W(){if(N())return d.jsx(k,{});const e=S(),s=I(),{user:t,loading:r}=m(),[a,n]=u.useState(0),[o,h]=u.useState({}),[x,b]=u.useState(!1),[f,A]=u.useState(null),[$,O]=u.useState([]),[q,E]=u.useState(!1),R=u.useRef([]);u.useEffect(()=>{const e=new URLSearchParams(s.search).get("initialDescription");if(t||r)e&&(console.log("Setting description from URL for logged in user:",e),h(s=>l(i({},s),{description:e})));else{let s={};const t=localStorage.getItem(T);if(t)try{s=JSON.parse(t)}catch(a){console.error("Failed to parse stored answers:",a),localStorage.removeItem(T),s={}}if(e&&(console.log("Setting description from URL:",e),s.description=e),(Object.keys(s).length>0||e)&&h(s),!t){j(e?"landing_page_cta":"direct")}}},[t,r,s.search]),u.useEffect(()=>{var e;if(!t&&!r&&Object.keys(o).length>0)try{const e=JSON.stringify(o);localStorage.setItem(T,e)}catch(s){console.warn("Failed to store temp answers, localStorage may be full:",s);try{localStorage.removeItem(T);const e={business_type:o.business_type,name:o.name,description:o.description&&o.description.length>300?o.description.substring(0,300)+"...":o.description,target_audience:o.target_audience&&o.target_audience.length>200?o.target_audience.substring(0,200)+"...":o.target_audience,goals:o.goals&&o.goals.length>200?o.goals.substring(0,200)+"...":o.goals,challenges:o.challenges&&o.challenges.length>200?o.challenges.substring(0,200)+"...":o.challenges,budget:o.budget};localStorage.setItem(T,JSON.stringify(e))}catch(a){console.error("Failed to store even optimized temp data:",a);try{const s={business_type:o.business_type,name:o.name,description:(null==(e=o.description)?void 0:e.substring(0,100))||""};localStorage.setItem(T,JSON.stringify(s))}catch(n){console.error("Failed to store even minimal temp data, localStorage completely full:",n)}}}t&&localStorage.getItem(T)},[o,t,r]);const z=J[a];u.useEffect(()=>{z&&y(a+1,z.id,"v1")},[a,z]);const L=u.useCallback(e=>c(this,null,function*(){if(e){E(!0),O([]);try{const s={business_type:o.business_type,name:o.name,description:o.description},t=yield((e,s)=>c(void 0,null,function*(){console.log(`Fetching suggestions for ${e} from API with context:`,s);try{const t=yield fetch("/api/generate-suggestions",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({questionId:e,context:s})});if(!t.ok){const e=yield t.json();throw new Error(e.error||`API request failed with status ${t.status}`)}const r=yield t.json();if(!r.suggestions||!Array.isArray(r.suggestions))throw console.error("Invalid suggestions format received from API:",r),new Error("Invalid suggestions format received from API.");return console.log("Received suggestions from API:",r.suggestions),r.suggestions}catch(f){return console.error("Error fetching suggestions from API:",f),["Could not load AI suggestions at this time."]}}))(e,s);O(t)}catch(s){console.error("Failed to fetch AI suggestions:",s),O(["❌ Could not load AI suggestions. Please try again."])}finally{E(!1)}}}),[o]);u.useEffect(()=>{var e;const s=null==(e=J[a])?void 0:e.id;["target_audience","goals","challenges"].includes(s)?L(s):(O([]),E(!1))},[a]),u.useEffect(()=>{if(z&&["name","description","target_audience","goals","challenges"].includes(z.id)){const e=setTimeout(()=>{var e;null==(e=R.current)||e.forEach(e=>{e&&e.id===z.id&&e.focus()})},100);return()=>clearTimeout(e)}},[a,z]);const M=()=>c(this,null,function*(){if(b(!0),A(null),console.log("Final answers:",o),w(o.business_type),!t)return localStorage.setItem(T,JSON.stringify(o)),e("/auth",{state:{fromQuestionnaire:!0}}),void b(!1);try{const s={name:o.name||"Untitled Project",business_type:o.business_type||"",description:o.description||"",target_audience:o.target_audience||"",goals:o.goals||"",budget:o.budget||"",challenges:o.challenges||""},r=yield v(s,t);localStorage.removeItem(T),e(`/app/projects/${r.id}/documents`)}catch(s){console.error("Failed to create project:",s),A(s.message||"An unknown error occurred while creating the project.")}finally{b(!1)}});return d.jsxs("div",{className:"min-h-full w-full relative overflow-hidden",children:[d.jsx("div",{className:"absolute top-0 left-1/2 -translate-x-1/2 w-[70%] h-[65%] bg-blue-500/15 rounded-full blur-3xl pointer-events-none"}),d.jsx("div",{className:"absolute top-1/3 right-0 w-[50%] h-[50%] bg-indigo-500/15 rounded-full blur-3xl pointer-events-none"}),d.jsx("div",{className:"absolute bottom-1/4 left-0 w-[40%] h-[35%] bg-purple-500/10 rounded-full blur-3xl pointer-events-none"}),d.jsx("header",{className:"bg-transparent relative z-10",children:d.jsx("div",{className:"mx-auto max-w-7xl px-4 py-6 sm:px-6 lg:px-8",children:d.jsx("div",{className:"flex items-center",children:d.jsx("button",{onClick:()=>{0===a?e(-1):n(e=>e-1)},className:"text-gray-600 hover:text-gray-900","aria-label":0===a?"Back to dashboard":"Back to previous question",children:d.jsx(_,{className:"h-8 w-8"})})})})}),d.jsx("main",{className:"mx-auto max-w-6xl px-4 pt-1 pb-8 sm:px-6 lg:px-8 relative z-10",children:d.jsx("div",{className:"backdrop-blur-sm rounded-lg px-6 pt-4 pb-8",children:x?d.jsxs("div",{className:"text-center py-10",children:[d.jsx(p,{className:"h-16 w-16 animate-spin text-blue-600 mx-auto"}),d.jsx("h2",{className:"mt-6 text-2xl font-semibold",children:d.jsx("span",{className:"text-gradient",children:"Creating Your Project"})}),d.jsx("p",{className:"mt-3 text-base text-gray-700",children:"Setting up your documents and workspace..."})]}):d.jsxs(d.Fragment,{children:[d.jsxs("div",{className:"mb-8",children:[d.jsxs("div",{className:"flex justify-between items-center mb-2",children:[d.jsxs("span",{className:"text-base font-medium text-gray-700",children:["Question ",a+1," of ",J.length]}),d.jsxs("span",{className:"text-base font-medium text-blue-600",children:[Math.round((a+1)/J.length*100),"%"]})]}),d.jsx("div",{className:"w-full bg-gray-200/50 backdrop-blur-sm rounded-full h-3",children:d.jsx("div",{className:"bg-blue-600 h-3 rounded-full transition-all duration-300",style:{width:(a+1)/J.length*100+"%"}})})]}),d.jsxs("div",{className:"space-y-8 max-w-4xl mx-auto",children:[d.jsx("h2",{className:"text-3xl font-semibold text-center",children:d.jsx("span",{className:"text-gradient",children:z.question})}),d.jsx("div",{className:"mx-auto",children:(()=>{var e,s,t;if(z.component){const r=z.component,a=["target_audience","goals","challenges"].includes(z.id),n={value:o[z.id]||"",onChange:e=>h(s=>l(i({},s),{[z.id]:e})),placeholder:z.placeholder||""};if(r===G){const s=l(i({},n),{suggestions:a?$:[],isLoading:!!a&&q,onRefresh:a?()=>L(z.id):()=>{},questionId:z.id});return d.jsx(r,l(i({},s),{ref:null==(e=R.current)?void 0:e.find(e=>(null==e?void 0:e.id)===z.id)}))}if(r===B){const e=i({},n);return d.jsx("div",{className:"text-center",children:d.jsx(r,l(i({},e),{ref:null==(s=R.current)?void 0:s.find(e=>(null==e?void 0:e.id)===z.id)}))})}if(r===F){const e=i({},n);return d.jsx(r,l(i({},e),{ref:null==(t=R.current)?void 0:t.find(e=>(null==e?void 0:e.id)===z.id)}))}{const e={value:n.value,onChange:n.onChange};return d.jsx(r,i({},e))}}return d.jsx("textarea",{value:o[z.id]||"",onChange:e=>h(s=>l(i({},s),{[z.id]:e.target.value})),placeholder:z.placeholder,rows:4,className:"w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500"})})()}),d.jsxs("div",{className:"flex flex-col items-center gap-2 mt-4",children:[d.jsx(g,{onClick:()=>{a<J.length-1?n(e=>e+1):M()},disabled:!o[z.id],className:"bg-gradient-to-r from-blue-500 to-blue-700 hover:from-blue-600 hover:to-blue-800 text-white px-8 py-2 rounded-lg shadow-md disabled:opacity-50 disabled:cursor-not-allowed",children:a===J.length-1?d.jsxs("span",{className:"flex items-center gap-2",children:["Generate Plan ",d.jsx(C,{className:"h-4 w-4"})]}):d.jsxs("span",{className:"flex items-center gap-2",children:["Next ",d.jsx(P,{className:"h-4 w-4"})]})}),"name"!==z.id&&"description"!==z.id&&d.jsx("button",{onClick:()=>{const e=J[a];let s="";switch(e.id){case"name":break;case"business_type":s="General Business";break;case"description":s="A business focused on providing quality products and services to customers.";break;case"target_audience":s="General consumers and potential customers interested in our offerings.";break;case"goals":s="Increase brand awareness and grow customer base.";break;case"challenges":s="Reaching the right audience and standing out in a competitive market.";break;case"budget":s="Small Budget ($0 - $1,000/month)";break;default:s="Information to be determined."}s&&(h(t=>l(i({},t),{[e.id]:s})),y(a+1,e.id,"v1")),a<J.length-1?n(e=>e+1):M()},className:"text-sm text-gray-500 hover:text-gray-700 underline",children:"Skip"})]})]})]})})})]})}export{W as default};