1import{c as P,r as a,u as _,a as J,j as e,G as K,C as Q,w as X,d as G,s as Z,b as ee,e as se}from"./index-BVWG9e6d.js";import{C as y}from"./check-circle-B8odza-O.js";import{L as U}from"./loader-2-BaQHybQA.js";/** 2 * @license lucide-react v0.344.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const te=P("ArrowRight",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]]);/** 7 * @license lucide-react v0.344.0 - ISC 8 * 9 * This source code is licensed under the ISC license. 10 * See the LICENSE file in the root directory of this source tree. 11 */const ne=P("Link",[["path",{d:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71",key:"1cjeqo"}],["path",{d:"M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71",key:"19qd67"}]]),ce=()=>{const[n,C]=a.useState(1),[j,E]=a.useState(""),[b,v]=a.useState(!1),{updateUserProfile:L,connectSearchConsole:F,fetchGoogleSearchConsoleSites:A,currentUser:w,userProfile:x}=_(),R=J(),[d,q]=a.useState([]),[u,B]=a.useState([]),[r,k]=a.useState(!1),[c,h]=a.useState(null),[S,I]=a.useState(""),[N,$]=a.useState(""),p=3;a.useEffect(()=>{x!=null&&x.searchConsoleConnected&&(v(!0),n===2&&d.length===0&&!r&&!c&&g())},[x,n,d.length,r,c]);const M=()=>{n<p?C(n+1):D()},O=()=>{n>1&&C(n-1)},D=async()=>{if(!w){console.error("User not found, cannot complete onboarding");return}try{await L({seoFocus:j,seoImportance:S,newPagesPerMonth:N,onboardingCompleted:!0});const s=X(G);let t=0;if(u.forEach(m=>{const o=m.siteUrl;if(!o||o.trim()===""){console.warn("Skipping selected GSC site with empty or whitespace URL:",m);return}let l,f;if(o.startsWith("sc-domain:")){const i=o.substring(10);l=i,f="https://"+i}else{let i=o;/^https?:\/\//i.test(i)||(i="https://"+i),f=i;try{l=new URL(f).hostname}catch(Y){if(console.warn(`Error parsing hostname from GSC site URL '${o}'. Attempting fallback. Error:`,Y),l=o.replace(/^https?:\/\//,"").split("/")[0],!l){console.error(`Could not determine a valid site name for GSC URL: ${o}. Skipping this site.`);return}}}if(l=l.trim(),!l){console.error(`Could not determine a valid site name for GSC URL: ${o} after attempting all parsing and fallbacks. Skipping this site.`);return}const H={userId:w.uid,name:l,url:f,sitemapUrl:"",gscProperty:o,createdAt:Z(),lastScan:null,totalPages:0,indexedPages:0},V=ee(se(G,"sites"));s.set(V,H),t++}),u.length>0&&t===0)throw console.error("Onboarding Error: None of the selected GSC sites could be processed. Please check their format in Google Search Console."),new Error("Failed to process any selected sites. Please ensure they are valid and try again.");t>0?(await s.commit(),console.log(`${t} GSC sites added to Firestore.`)):console.log("No GSC sites were processed to be added to Firestore."),R("/dashboard")}catch(s){console.error("Error completing onboarding:",s)}},T=async()=>{try{const s=await F();s?(v(!0),console.log("Search Console connected successfully."),g(s)):(console.error("Search Console connection failed. Access token not received."),h("Failed to connect Search Console. Please try again."))}catch(s){console.error("Error during Search Console connection process:",s),h("An error occurred while connecting to Search Console.")}},g=async s=>{k(!0),h(null);try{const t=await A(s);q(t),t.length===0&&h("No sites found in your Google Search Console account, or we couldn't access them. Please ensure you have sites verified in GSC and that you granted the necessary permissions during connection.")}catch(t){console.error("Error fetching GSC sites in OnboardingPage:",t),t instanceof Error?h(t.message):h("An unknown error occurred while fetching your sites. Please check your connection and permissions.")}finally{k(!1)}},W=s=>{B(t=>t.some(m=>m.siteUrl===s.siteUrl)?t.filter(m=>m.siteUrl!==s.siteUrl):[...t,s])},z=()=>n===1&&(!j||!S||!N)||n===2&&!b||n===3&&u.length===0;return e.jsxs("div",{className:"animate-fade-up",children:[e.jsxs("div",{className:"mb-8",children:[e.jsx("div",{className:"flex items-center justify-between",children:Array.from({length:p},(s,t)=>e.jsxs("div",{className:"relative flex items-center justify-center flex-1",children:[e.jsx("div",{className:`w-8 h-8 rounded-full flex items-center justify-center text-sm font-medium ${t+1===n?"bg-blue-600 text-white":t+1<n?"bg-blue-100 text-blue-800":"bg-slate-100 text-slate-400"}`,children:t+1<n?e.jsx(y,{className:"w-5 h-5"}):t+1}),t<p-1&&e.jsx("div",{className:`h-1 flex-1 mx-2 ${t+1<n?"bg-blue-600":"bg-slate-200"}`})]},t))}),e.jsxs("div",{className:"flex justify-between mt-2 text-xs text-slate-500",children:[e.jsx("span",{children:"Your Profile"}),e.jsx("span",{className:"text-center",children:"Connect Search Console"}),e.jsx("span",{className:"text-right",children:"Select Sites"})]})]}),e.jsxs("div",{className:"card p-8",children:[n===1&&e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold mb-6",children:"Tell us about your business"}),e.jsx("p",{className:"text-slate-600 mb-6",children:"This helps us optimize Index Checker for your specific needs."}),e.jsxs("div",{className:"space-y-6 mb-8",children:[" ",e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-sm font-medium text-slate-700",children:"What industry are you in?"}),e.jsxs("select",{value:j,onChange:s=>E(s.target.value),className:"input w-full mt-1",required:!0,children:[e.jsx("option",{value:"",disabled:!0,children:"Select your industry"}),e.jsx("option",{value:"ecommerce",children:"E-commerce"}),e.jsx("option",{value:"blog",children:"Blog / Content"}),e.jsx("option",{value:"saas",children:"SaaS / Software"}),e.jsx("option",{value:"local",children:"Local Business"}),e.jsx("option",{value:"enterprise",children:"Enterprise / Corporate"}),e.jsx("option",{value:"other",children:"Other"})]})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-sm font-medium text-slate-700",children:"How important is SEO to your growth?"}),e.jsxs("select",{value:S,onChange:s=>I(s.target.value),className:"input w-full mt-1",required:!0,children:[e.jsx("option",{value:"",disabled:!0,children:"Select importance"}),e.jsx("option",{value:"low",children:"Not very important"}),e.jsx("option",{value:"medium",children:"Somewhat important"}),e.jsx("option",{value:"high",children:"Very important"}),e.jsx("option",{value:"critical",children:"Critical"})]})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-sm font-medium text-slate-700",children:"How many new webpages do you add each month?"}),e.jsxs("select",{value:N,onChange:s=>$(s.target.value),className:"input w-full mt-1",required:!0,children:[e.jsx("option",{value:"",disabled:!0,children:"Select range"}),e.jsx("option",{value:"0-10",children:"0-10 pages"}),e.jsx("option",{value:"11-50",children:"11-50 pages"}),e.jsx("option",{value:"51-200",children:"51-200 pages"}),e.jsx("option",{value:"200+",children:"200+ pages"})]})]})]})]}),n===2&&e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold mb-6",children:"Connect Google Search Console"}),e.jsx("p",{className:"text-slate-600 mb-6",children:"Connect your Google Search Console account to allow Index Checker to access your sites."}),e.jsx("div",{className:"bg-slate-50 p-5 rounded-lg mb-8 border border-slate-200",children:e.jsxs("div",{className:"flex items-start",children:[e.jsx("div",{className:"mr-4 mt-1",children:e.jsx(ne,{className:"w-6 h-6 text-slate-400"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-medium text-slate-800 mb-1",children:"Search Console Access"}),e.jsx("p",{className:"text-sm text-slate-600 mb-4",children:"We need access to your Search Console to fetch your sites and later to check index status and request indexing."}),b?e.jsxs("div",{className:"flex items-center text-green-600",children:[e.jsx(y,{className:"w-5 h-5 mr-2"}),e.jsx("span",{className:"font-medium",children:"Successfully connected to Google Search Console!"})]}):e.jsx("button",{onClick:T,className:"btn-primary py-2",disabled:r,children:r?e.jsxs(e.Fragment,{children:[e.jsx(U,{className:"w-4 h-4 mr-2 animate-spin"})," Connecting..."]}):"Connect Search Console"}),c&&!b&&e.jsx("p",{className:"text-sm text-red-600 mt-2",children:c})]})]})})]}),n===3&&e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold mb-6",children:"Select Sites to Monitor"}),e.jsx("p",{className:"text-slate-600 mb-6",children:"Choose the sites from your Google Search Console account you want to monitor with Index Checker."}),r&&e.jsxs("div",{className:"flex items-center justify-center p-6",children:[e.jsx(U,{className:"w-8 h-8 text-blue-600 animate-spin mr-3"}),e.jsx("p",{className:"text-slate-600",children:"Loading your sites from Google Search Console..."})]}),c&&!r&&e.jsxs("div",{className:"bg-red-50 text-red-700 p-4 rounded-md mb-6",children:[c,d.length===0&&e.jsx("button",{onClick:()=>g(),className:"btn-secondary mt-3 text-sm",children:"Try fetching sites again"})]}),!r&&!c&&d.length===0&&e.jsxs("div",{className:"text-center p-6 bg-slate-50 rounded-lg",children:[e.jsx(K,{className:"w-12 h-12 text-slate-400 mx-auto mb-4"}),e.jsx("h3",{className:"text-lg font-medium text-slate-700 mb-2",children:"No Sites Found"}),e.jsx("p",{className:"text-sm text-slate-500 mb-4",children:"We couldn't find any sites in your Google Search Console account. Please ensure you have sites verified and that you granted the necessary permissions."}),e.jsx("button",{onClick:()=>g(),className:"btn-secondary text-sm",children:"Refresh Site List"})]}),!r&&d.length>0&&e.jsx("div",{className:"space-y-3 max-h-96 overflow-y-auto pr-2",children:d.map(s=>e.jsxs("div",{onClick:()=>W(s),className:`p-4 border rounded-lg cursor-pointer flex items-center justify-between hover:border-blue-500 transition-colors ${u.some(t=>t.siteUrl===s.siteUrl)?"bg-blue-50 border-blue-500 ring-2 ring-blue-500":"border-slate-200 bg-white"}`,children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-slate-800",children:s.siteUrl}),e.jsxs("p",{className:"text-xs text-slate-500",children:["Permission: ",s.permissionLevel]})]}),u.some(t=>t.siteUrl===s.siteUrl)&&e.jsx(y,{className:"w-5 h-5 text-blue-600"})]},s.siteUrl))})]}),e.jsxs("div",{className:"flex justify-between mt-8",children:[n>
111?e.jsx("button",{onClick:O,className:"btn-secondary",children:"Back"}):e.jsx("div",{}),e.jsx("button",{onClick:M,className:"btn-primary",disabled:z(),children:n<p?e.jsxs(e.Fragment,{children:["Next",e.jsx(Q,{className:"w-5 h-5 ml-1"})]}):e.jsxs(e.Fragment,{children:["Complete Setup",e.jsx(te,{className:"w-5 h-5 ml-1"})]})})]})]})]})};export{ce 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.