1import{g as P,c as A,r as t,s as m,aS as E,j as e,d as w,B as I,R as M,aT as U,T as q}from"./index-NwEFhPA0.js";import{A as k}from"./AdminLayout-BUGuISGX.js";import{A as c}from"./AdminStatCard-BNTrOreS.js";import{I as S}from"./input-CkVE8fp8.js";import{L as h}from"./label-D17oNgiY.js";import{T as z,a as B,b as x,c as o,d as _,e as i}from"./table-BX6naeN4.js";import{E as $}from"./eye-yDhxOkfo.js";import"./zap-CyU0R1qD.js";import"./log-out-CkU8Vx_b.js";import"./search-DLZpxukn.js";import"./upload-DhyafyxF.js";/** 2 * @license lucide-react v0.462.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 G=P("MousePointerClick",[["path",{d:"M14 4.1 12 6",key:"ita8i4"}],["path",{d:"m5.1 8-2.9-.8",key:"1go3kf"}],["path",{d:"m6 12-1.9 2",key:"mnht97"}],["path",{d:"M7.2 2.2 8 5.1",key:"1cfko1"}],["path",{d:"M9.037 9.69a.498.498 0 0 1 .653-.653l11 4.5a.5.5 0 0 1-.074.949l-4.349 1.041a1 1 0 0 0-.74.739l-1.04 4.35a.5.5 0 0 1-.95.074z",key:"s0h3yz"}]]),se=()=>{const u=A(),[C,L]=t.useState(!0),[p,g]=t.useState(!1),[a,T]=t.useState(null),[f,F]=t.useState(28),[j,R]=t.useState("/insights/"),[n,D]=t.useState("page");t.useEffect(()=>{(async()=>{const{data:{user:s}}=await m.auth.getUser();if(!s){u("/auth");return}const{data:r}=await m.from("user_roles").select("role").eq("user_id",s.id).eq("role","admin").maybeSingle();if(!r){u("/dashboard");return}await y()})()},[]);const y=async()=>{g(!0);try{const{data:s,error:r}=await m.functions.invoke("gsc-performance",{body:{days:f,dimensions:[n],pageFilter:j||void 0,rowLimit:100}});if(r)throw r;if(s!=null&&s.error)throw new Error(s.error);T(s)}catch(s){E({title:"Could not load Search Console data",description:s.message,variant:"destructive"})}finally{g(!1),L(!1)}};if(C)return e.jsx(k,{children:e.jsx("div",{className:"flex items-center justify-center min-h-[400px]",children:e.jsx(w,{className:"w-8 h-8 animate-spin text-muted-foreground"})})});const v=(a==null?void 0:a.rows)??[],l=a==null?void 0:a.totals;return e.jsx(k,{children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold font-display",children:"SEO Performance"}),e.jsxs("p",{className:"text-muted-foreground mt-1",children:["Google Search Console â ",a?`${a.startDate} â ${a.endDate}`:"loadingâ¦"]})]}),e.jsxs("div",{className:"bg-card border rounded-2xl p-4 flex flex-wrap gap-4 items-end",children:[e.jsxs("div",{className:"flex-1 min-w-[140px]",children:[e.jsx(h,{htmlFor:"days",children:"Days back"}),e.jsx(S,{id:"days",type:"number",min:1,max:90,value:f,onChange:s=>F(Number(s.target.value))})]}),e.jsxs("div",{className:"flex-1 min-w-[180px]",children:[e.jsx(h,{htmlFor:"filter",children:"URL contains"}),e.jsx(S,{id:"filter",value:j,onChange:s=>R(s.target.value),placeholder:"/insights/"})]}),e.jsxs("div",{className:"min-w-[160px]",children:[e.jsx(h,{htmlFor:"dim",children:"Group by"}),e.jsxs("select",{id:"dim",className:"w-full h-10 border rounded-md bg-background px-3 text-sm",value:n,onChange:s=>D(s.target.value),children:[e.jsx("option",{value:"page",children:"Page"}),e.jsx("option",{value:"query",children:"Query"})]})]}),e.jsxs(I,{onClick:y,disabled:p,children:[p?e.jsx(w,{className:"w-4 h-4 animate-spin mr-2"}):e.jsx(M,{className:"w-4 h-4 mr-2"}),"Refresh"]})]}),l&&e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4",children:[e.jsx(c,{title:"Clicks",value:l.clicks.toLocaleString(),icon:G}),e.jsx(c,{title:"Impressions",value:l.impressions.toLocaleString(),icon:$}),e.jsx(c,{title:"Avg CTR",value:`${(l.ctr*100).toFixed(2)}%`,icon:U}),e.jsx(c,{title:"Avg Position",value:l.position.toFixed(1),icon:q})]}),e.jsx("div",{className:"bg-card border rounded-2xl overflow-hidden",children:e.jsxs(z,{children:[e.jsx(B,{children:e.jsxs(x,{children:[e.jsx(o,{children:n==="page"?"URL":"Query"}),e.jsx(o,{className:"text-right",children:"Clicks"}),e.jsx(o,{className:"text-right",children:"Impr."}),e.jsx(o,{className:"text-right",children:"CTR"}),e.jsx(o,{className:"text-right",children:"Position"})]})}),e.jsxs(_,{children:[v.length===0&&e.jsx(x,{children:e.jsx(i,{colSpan:5,className:"text-center text-muted-foreground py-8",children:"No data for this range/filter yet."})}),v.map((s,r)=>{var b;const d=((b=s.keys)==null?void 0:b[0])??"â",N=n==="page"?d.replace("https://bizplanner.ai",""):d;return e.jsxs(x,{children:[e.jsx(i,{className:"font-mono text-xs max-w-md truncate",children:n==="page"?e.jsx("a",{href:d,target:"_blank",rel:"noreferrer",className:"hover:underline",children:N}):N}),e.jsx(i,{className:"text-right font-medium",children:s.clicks.toLocaleStr
6ing()}),e.jsx(i,{className:"text-right",children:s.impressions.toLocaleString()}),e.jsxs(i,{className:"text-right",children:[(s.ctr*100).toFixed(2),"%"]}),e.jsx(i,{className:"text-right",children:s.position.toFixed(1)})]},r)})]})]})})]})})};export{se 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.