1var us=a=>{throw TypeError(a)};var _e=(a,t,i)=>t.has(a)||us("Cannot "+i);var L=(a,t,i)=>(_e(a,t,"read from private field"),i?i.call(a):t.get(a)),V=(a,t,i)=>t.has(a)?us("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(a):t.set(a,i),M=(a,t,i,n)=>(_e(a,t,"write to private field"),n?n.call(a,i):t.set(a,i),i),$=(a,t,i)=>(_e(a,t,"access private method"),i);import{y as Ks,bM as Ms,bN as Ze,bO as As,bP as Ss,bx as Os,bQ as Qs,bR as Gs,r as p,bS as Bs,bT as Us,bU as zs,bV as Vs,bW as ps,bX as gs,bY as $s,bZ as Ws,au as le,aT as Ls,j as e,$ as W,a0 as H,a1 as _,a2 as X,a3 as l,B as Ge,L as Te,aC as Hs,ab as Je,bK as _s,l as Xs,aB as js,d as Ne,e as Ce,f as Se,bI as ys,g as Le,h as De,b_ as Ys,aA as Zs,T as Js,ah as et,b6 as st,bt as Ds,aI as tt,o as Be,bk as Ts,bl as Rs,bq as pe,bo as ge,W as it,I as at,a as rt}from"./index-DwBWDKUZ.js";import{a as nt}from"./AdminLayout-CUJ1KAUs.js";import{T as Q,a as G,b as k,c as x,d as B,e as o}from"./table-Cc_Zjg_s.js";import{u as Fs}from"./gscWindow-Nrt5hF9_.js";import{G as fs}from"./globe-5NMmuIgN.js";import{S as bs}from"./smartphone-BSYP7gEm.js";import{M as ot}from"./mouse-pointer-CNjB2sLZ.js";import{T as lt}from"./target-sTphCb1S.js";import{R as es}from"./ResponsiveContainer-DhRT-7hS.js";import{C as ct}from"./ComposedChart-D6FK6W7H.js";import{C as ss}from"./CartesianGrid-Cg0Z4r4D.js";import{X as ts,Y as je,T as is,L as as,B as dt}from"./generateCategoricalChart-CkYdcMCi.js";import{A as xt}from"./Area-DPWkIFjZ.js";import{L as mt}from"./layers-DYWtuYCF.js";import{A as ht}from"./arrow-up-right-DCliOP7D.js";import{A as ut}from"./arrow-down-right-CBv3Pnci.js";import{I as pt}from"./info-CSda9mCy.js";import{L as ws,a as Me}from"./LineChart-DlimvCMR.js";import{A as gt}from"./arrow-up-down-CefljeKK.js";import"./separator-3IJlx7Jr.js";import"./radio-CYrbeFui.js";import"./shopping-cart-BS4tH7dF.js";import"./ban-2u0CnJmK.js";import"./message-square-ClqgYCnY.js";import"./qr-code-c27LO0Y3.js";import"./zap-B9JmuJoQ.js";import"./useDebounce-Dswy9wwM.js";import"./undo-2-DrAGwRTv.js";import"./gift-DTSOrbmf.js";import"./store-bkBmVJSB.js";import"./book-open-zG6yZAjB.js";import"./circle-plus-q9MabApK.js";import"./link-2-yb_9D2cc.js";import"./index-EBeZJwww.js";import"./database-CSQWWsVg.js";import"./arrow-left-right-CBpwBwL4.js";import"./layout-dashboard-Bx09MTND.js";import"./privateRealtimeChannels-LIJV5W85.js";import"./external-link-aOCC2dcc.js";import"./index-CvvDEDzH.js";import"./index-Cj1mIu5t.js";import"./calendar-days-D-EDctJU.js";import"./shield-86TK9aig.js";import"./index-VSm7vcrh.js";import"./index-Dh4i1-J3.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 jt=Ks("Crosshair",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"22",x2:"18",y1:"12",y2:"12",key:"l9bcsi"}],["line",{x1:"6",x2:"2",y1:"12",y2:"12",key:"13hhkx"}],["line",{x1:"12",x2:"12",y1:"6",y2:"2",key:"10w3f3"}],["line",{x1:"12",x2:"12",y1:"22",y2:"18",key:"15g9kq"}]]);function vs(a,t){const i=new Set(t);return a.filter(n=>!i.has(n))}function yt(a,t,i){const n=a.slice(0);return n[t]=i,n}var ye,U,fe,be,z,ae,Re,Fe,Ee,P,rs,ns,os,ls,cs,Cs,ft=(Cs=class extends Ms{constructor(t,i,n){super();V(this,P);V(this,ye);V(this,U);V(this,fe);V(this,be);V(this,z);V(this,ae);V(this,Re);V(this,Fe);V(this,Ee,[]);M(this,ye,t),M(this,be,n),M(this,fe,[]),M(this,z,[]),M(this,U,[]),this.setQueries(i)}onSubscribe(){this.listeners.size===1&&L(this,z).forEach(t=>{t.subscribe(i=>{$(this,P,ls).call(this,t,i)})})}onUnsubscribe(){this.listeners.size||this.destroy()}destroy(){this.listeners=new Set,L(this,z).forEach(t=>{t.destroy()})}setQueries(t,i){M(this,fe,t),M(this,be,i),Ze.batch(()=>{const n=L(this,z),m=$(this,P,os).call(this,L(this,fe));M(this,Ee,m),m.forEach(c=>c.observer.setOptions(c.defaultedQueryOptions));const h=m.map(c=>c.observer),g=h.map(c=>c.getCurrentResult()),f=h.some((c,v)=>c!==n[v]);n.length===h.length&&!f||(M(this,z,h),M(this,U,g),this.hasListeners()&&(vs(n,h).forEach(c=>{c.destroy()}
6),vs(h,n).forEach(c=>{c.subscribe(v=>{$(this,P,ls).call(this,c,v)})}),$(this,P,cs).call(this)))})}getCurrentResult(){return L(this,U)}getQueries(){return L(this,z).map(t=>t.getCurrentQuery())}getObservers(){return L(this,z)}getOptimisticResult(t,i){const n=$(this,P,os).call(this,t),m=n.map(h=>h.observer.getOptimisticResult(h.defaultedQueryOptions));return[m,h=>$(this,P,ns).call(this,h??m,i),()=>$(this,P,rs).call(this,m,n)]}},ye=new WeakMap,U=new WeakMap,fe=new WeakMap,be=new WeakMap,z=new WeakMap,ae=new WeakMap,Re=new WeakMap,Fe=new WeakMap,Ee=new WeakMap,P=new WeakSet,rs=function(t,i){return i.map((n,m)=>{const h=t[m];return n.defaultedQueryOptions.notifyOnChangeProps?h:n.observer.trackResult(h,g=>{i.forEach(f=>{f.observer.trackProp(g)})})})},ns=function(t,i){return i?((!L(this,ae)||L(this,U)!==L(this,Fe)||i!==L(this,Re))&&(M(this,Re,i),M(this,Fe,L(this,U)),M(this,ae,As(L(this,ae),i(t)))),L(this,ae)):t},os=function(t){const i=new Map(L(this,z).map(m=>[m.options.queryHash,m])),n=[];return t.forEach(m=>{const h=L(this,ye).defaultQueryOptions(m),g=i.get(h.queryHash);g?n.push({defaultedQueryOptions:h,observer:g}):n.push({defaultedQueryOptions:h,observer:new Ss(L(this,ye),h)})}),n},ls=function(t,i){const n=L(this,z).indexOf(t);n!==-1&&(M(this,U,yt(L(this,U),n,i)),$(this,P,cs).call(this))},cs=function(){var t;if(this.hasListeners()){const i=L(this,ae),n=$(this,P,rs).call(this,L(this,U),L(this,Ee)),m=$(this,P,ns).call(this,n,(t=L(this,be))==null?void 0:t.combine);i!==m&&Ze.batch(()=>{this.listeners.forEach(h=>{h(L(this,U))})})}},Cs);function bt({queries:a,...t},i){const n=Os(),m=Qs(),h=Gs(),g=p.useMemo(()=>a.map(w=>{const j=n.defaultQueryOptions(w);return j._optimisticResults=m?"isRestoring":"optimistic",j}),[a,n,m]);g.forEach(w=>{Bs(w),Us(w,h)}),zs(h);const[f]=p.useState(()=>new ft(n,g,t)),[c,v,D]=f.getOptimisticResult(g,t.combine),T=!m&&t.subscribed!==!1;p.useSyncExternalStore(p.useCallback(w=>T?f.subscribe(Ze.batchCalls(w)):Vs,[f,T]),()=>f.getCurrentResult(),()=>f.getCurrentResult()),p.useEffect(()=>{f.setQueries(g,t)},[g,t,f]);const b=c.some((w,j)=>ps(g[j],w))?c.flatMap((w,j)=>{const N=g[j];if(N){const A=new Ss(n,N);if(ps(N,w))return gs(N,A,h);$s(w,m)&&gs(N,A,h)}return[]}):[];if(b.length>0)throw Promise.all(b);const y=c.find((w,j)=>{const N=g[j];return N&&Ws({result:w,errorResetBoundary:h,throwOnError:N.throwOnError,query:n.getQueryCache().get(N.queryHash),suspense:N.suspense})});if(y!=null&&y.error)throw y.error;return v(D())}const Es="sc-domain:simbacarhire.com.au",wt={1:.298,2:.158,3:.099,4:.072,5:.054,6:.041,7:.033,8:.027,9:.022,10:.019};function ks(a){const t=Math.max(1,Math.min(10,Math.round(a)));return wt[t]??.01}function Xe(a,t,i=[]){const n=[...i];return a&&a!=="all"&&n.push({dimension:"country",expression:a}),t&&t!=="all"&&n.push({dimension:"device",expression:t}),n.length?[{groupType:"and",filters:n}]:[]}async function ue(a){const{data:t,error:i}=await Be.functions.invoke("search-console",{body:{siteUrl:Es,...a}});if(i)throw new Error(i.message);if(t!=null&&t.error)throw new Error(t.error);return(t==null?void 0:t.data)||[]}async function Ns(a){const{data:t,error:i}=await Be.functions.invoke("search-console",{body:{siteUrl:Es,...a}});if(i)throw new Error(i.message);if(t!=null&&t.error)throw new Error(t.error);return{rows:(t==null?void 0:t.data)||[],totals:(t==null?void 0:t.totals)||null}}function Z(a,t,i){const n=c=>{const v=String(c??"");return/[",\n]/.test(v)?`"${v.replace(/"/g,'""')}"`:v},m=[t.join(","),...i.map(c=>c.map(n).join(","))].join(` 7`),h=new Blob([m],{type:"text/csv;charset=utf-8;"}),g=URL.createObjectURL(h),f=document.createElement("a");f.href=g,f.download=a,f.click(),URL.revokeObjectURL(g)}const vt=()=>{var ds,xs,ms,hs;const[a,t]=p.useState("28"),[i,n]=p.useState("all"),[m,h]=p.useState("all"),[g,f]=p.useState(!1),[c,v]=p.useState(new Set),D=parseInt(a),{window:T,maxAvailableDate:q,isLoading:b}=Fs(D),y=T??{startDate:"",endDate:"",prevStartDate:"",prevEndDate:"",maxAvailableDate:""},w=p.useMemo(()=>Xe(i,m),[i,m]),j=[y.startDate,y.endDate,i,m],N=le({queryKey:["gsc-daily",...j],queryFn:()=>
7Ns({startDate:y.startDate,endDate:y.endDate,dimensions:["date"],rowLimit:500,dimensionFilterGroups:w}),enabled:!!T,staleTime:5*60*1e3}),A=le({queryKey:["gsc-prev-daily",...j],queryFn:()=>Ns({startDate:y.prevStartDate,endDate:y.prevEndDate,dimensions:["date"],rowLimit:500,dimensionFilterGroups:w}),enabled:!!T,staleTime:5*60*1e3}),re=bt({queries:[{queryKey:["gsc-queries",...j],enabled:!!T,queryFn:()=>ue({startDate:y.startDate,endDate:y.endDate,dimensions:["query"],rowLimit:5e3,dimensionFilterGroups:w}),staleTime:5*60*1e3},{queryKey:["gsc-pages",...j],enabled:!!T,queryFn:()=>ue({startDate:y.startDate,endDate:y.endDate,dimensions:["page"],rowLimit:1e3,dimensionFilterGroups:w}),staleTime:5*60*1e3},{queryKey:["gsc-query-page",...j],enabled:!!T,queryFn:()=>ue({startDate:y.startDate,endDate:y.endDate,dimensions:["query","page"],rowLimit:5e3,dimensionFilterGroups:w}),staleTime:5*60*1e3},{queryKey:["gsc-country",...j],enabled:!!T,queryFn:()=>ue({startDate:y.startDate,endDate:y.endDate,dimensions:["country"],rowLimit:50,dimensionFilterGroups:Xe(void 0,m)}),staleTime:5*60*1e3},{queryKey:["gsc-device",...j],enabled:!!T,queryFn:()=>ue({startDate:y.startDate,endDate:y.endDate,dimensions:["device"],rowLimit:10,dimensionFilterGroups:Xe(i,void 0)}),staleTime:5*60*1e3},{queryKey:["gsc-prev-queries",...j],enabled:!!T,queryFn:()=>ue({startDate:y.prevStartDate,endDate:y.prevEndDate,dimensions:["query"],rowLimit:5e3,dimensionFilterGroups:w}),staleTime:5*60*1e3}]}),[R,I,ce,de,F,xe]=re,we=b||N.isLoading,ne=()=>{N.refetch(),A.refetch(),re.forEach(s=>s.refetch()),tt.success("Refreshing GSC data...")},ee=((ds=N.data)==null?void 0:ds.rows)||[],ve=((xs=A.data)==null?void 0:xs.rows)||[],te=(ms=N.data)==null?void 0:ms.totals,d=(hs=A.data)==null?void 0:hs.totals,Pe=p.useMemo(()=>ee.map(s=>({date:s.keys[0],dateLabel:Ls(s.keys[0],{month:"short",day:"numeric"}),clicks:s.clicks,impressions:s.impressions,ctr:s.ctr*100,position:s.position})).sort((s,r)=>new Date(s.date).getTime()-new Date(r.date).getTime()),[ee]),qe=s=>{const r=s.reduce((K,S)=>K+S.clicks,0),u=s.reduce((K,S)=>K+S.impressions,0),C=u>0?r/u:0,O=u>0?s.reduce((K,S)=>K+S.position*S.impressions,0)/u:0;return{clicks:r,impressions:u,ctr:C,position:O}},Ie=te?{clicks:te.clicks,impressions:te.impressions,ctr:te.ctr*100,position:te.position}:{...qe(ee),ctr:qe(ee).ctr*100},Ke=d?{clicks:d.clicks,impressions:d.impressions,ctr:d.ctr*100,position:d.position}:{...qe(ve),ctr:qe(ve).ctr*100},Y=p.useMemo(()=>(R.data||[]).filter(r=>r.position>=10.5&&r.position<=20.5&&r.impressions>=50).map(r=>{const u=ks(5),C=Math.max(0,r.impressions*u-r.clicks);return{...r,recoverable:C}}).sort((r,u)=>u.impressions-r.impressions).slice(0,25),[R.data]),qs=p.useMemo(()=>Math.round(Y.reduce((s,r)=>s+r.recoverable,0)),[Y]),Ue=p.useMemo(()=>(R.data||[]).filter(r=>r.position<=10.5&&r.impressions>=100).map(r=>{const u=ks(r.position),C=u-r.ctr,O=Math.max(0,r.impressions*C);return{...r,expected:u,recoverable:O}}).filter(r=>r.ctr<r.expected*.6&&r.recoverable>=5).sort((r,u)=>u.recoverable-r.recoverable).slice(0,25),[R.data]),me=p.useMemo(()=>{const s=new Map((R.data||[]).map(S=>[S.keys[0],S])),r=new Map((xe.data||[]).map(S=>[S.keys[0],S])),u=new Set([...s.keys(),...r.keys()]),C=[];for(const S of u){const E=s.get(S),oe=r.get(S),he=(E==null?void 0:E.clicks)??0,se=(oe==null?void 0:oe.clicks)??0;he<3&&se<3||C.push({keyword:S,clicks:he,prevClicks:se,delta:he-se,posDelta:((oe==null?void 0:oe.position)??100)-((E==null?void 0:E.position)??100),currentPos:(E==null?void 0:E.position)??0})}const O=[...C].sort((S,E)=>E.delta-S.delta).filter(S=>S.delta>0).slice(0,20),K=[...C].sort((S,E)=>S.delta-E.delta).filter(S=>S.delta<0).slice(0,20);return{rising:O,declining:K}},[R.data,xe.data]),ze=p.useMemo(()=>[...I.data||[]].sort((s,r)=>r.clicks-s.clicks).slice(0,25),[I.data]),Ve=p.useMemo(()=>(I.data||[]).filter(s=>s.impressions>=500&&s.ctr<.015).sort((s,r)=>r.impressions-s.impressions).slice(0,20),[I.data]),Is=/^(what|how|why|where|which|when|can|is|are|best|cheap|cheapest|do|does|should)\b/i,$e=p.useMemo(()=>(R.data||[]).filter(s=>Is.test(s.keys[0])).sort((s,r)=>r.impressions-s.impressions).slice(0,20),[R.data]),We=p.useMemo(()=>{const s=new Map;for(const u of ce.data||[]){const C=u.keys[0],O=u.keys[1];if(u.impressions<50||u.position>20)continue;const K=s.get(C)??[];K.push({page:O,impressions:u.impressions,clicks:u.clicks,position:u.position}),s.set(C,K)}const r=[];for(const[u,C]of s){if(!g&&/simba/i.test(u)||C.length<2)continue;const O=[...C].sort((se,ke)=>ke.impressions-se.impressions),K=O.reduce((se,ke)=>se+ke.impressions,0),S=O.reduce((se,ke)=>se+ke.clicks,0);if(K<200)continue;const E=O[0];if(O[1].impressions<E.impressions*.2)continue;const he=E.impressions/K;r.push({keyword:u,pages:O.length,impressions:K,clicks:S,topPage:E.page,topShare:he,severity:K*(1-he),pageList:O})}return r.sort((u,C)=>C.severity-u.severity).slice(0,20)},[ce.data,g]),ie=p.useMemo(()=>{const s={clicks:0,impressions:0,count:0},r={clicks:0,impressions:0,count:0};for(const u of R.data||[]){const C=/simba/i.test(u.keys[0])?s:r;C.clicks+=u.clicks,C.impressions+=u.impressions,C.count+=1}return{brand:s,nonBrand:r}},[R.data]),He=p.useMemo(()=>[...de.data||[]].sort((s,r)=>r.clicks-s.clicks).slice(0,10),[de.data]);return e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs(W,{value:a,onValueChange:t,children:[e.jsx(H,{className:"h-11 w-[160px] rounded-full bg-card shadow-sm px-4 text-sm font-medium",children:e.jsx(_,{})}),e.jsxs(X,{children:[e.jsx(l,{value:"7",children:"Last 7 days"}),e.jsx(l,{value:"14",children:"Last 14 days"}),e.jsx(l,{value:"28",children:"Last 28 days"}),e.jsx(l,{value:"90",children:"Last 90 days"}),e.jsx(l,{value:"180",children:"Last 180 days"}),e.jsx(l,{value:"365",children:"Last 12 months"})]})]}
7),e.jsxs(W,{value:i,onValueChange:n,children:[e.jsxs(H,{className:"h-11 w-[170px] rounded-full bg-card shadow-sm px-4 text-sm font-medium",children:[e.jsx(fs,{className:"h-4 w-4 mr-2 text-muted-foreground"}),e.jsx(_,{placeholder:"Country"})]}),e.jsxs(X,{children:[e.jsx(l,{value:"all",children:"All countries"}),e.jsx(l,{value:"aus",children:"Australia"}),e.jsx(l,{value:"nzl",children:"New Zealand"}),e.jsx(l,{value:"usa",children:"United States"}),e.jsx(l,{value:"gbr",children:"United Kingdom"}),e.jsx(l,{value:"can",children:"Canada"}),e.jsx(l,{value:"ind",children:"India"}),e.jsx(l,{value:"sgp",children:"Singapore"}),e.jsx(l,{value:"deu",children:"Germany"}),e.jsx(l,{value:"fra",children:"France"}),e.jsx(l,{value:"idn",children:"Indonesia"}),e.jsx(l,{value:"phl",children:"Philippines"}),e.jsx(l,{value:"mys",children:"Malaysia"}),e.jsx(l,{value:"are",children:"United Arab Emirates"})]})]}),e.jsxs(W,{value:m,onValueChange:h,children:[e.jsxs(H,{className:"h-11 w-[160px] rounded-full bg-card shadow-sm px-4 text-sm font-medium",children:[e.jsx(bs,{className:"h-4 w-4 mr-2 text-muted-foreground"}),e.jsx(_,{placeholder:"Device"})]}),e.jsxs(X,{children:[e.jsx(l,{value:"all",children:"All devices"}),e.jsx(l,{value:"MOBILE",children:"Mobile"}),e.jsx(l,{value:"DESKTOP",children:"Desktop"}),e.jsx(l,{value:"TABLET",children:"Tablet"})]})]}),e.jsxs(Ge,{onClick:ne,variant:"outline",size:"sm",className:"ml-auto rounded-full shadow-sm",disabled:we,children:[we?e.jsx(Te,{className:"h-4 w-4 mr-1.5 animate-spin"}):e.jsx(Hs,{className:"h-4 w-4 mr-1.5"}),"Refresh"]}),e.jsx(Je,{variant:"outline",className:"text-xs",children:"Google Search Console"})]}),e.jsx("p",{className:"text-xs text-muted-foreground -mt-2",children:q?e.jsxs(e.Fragment,{children:["Window ends ",e.jsx("span",{className:"font-medium text-foreground",children:q}),` - the latest day Google Search Console has data for. Matches GSC's own "Last `,a,' days" view.']}):e.jsx(e.Fragment,{children:"Resolving latest available GSC date..."})}),e.jsx("div",{className:"rounded-2xl border bg-card p-5 md:p-6 shadow-sm",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("span",{className:"inline-flex items-center justify-center w-11 h-11 rounded-full bg-primary/10 text-primary shrink-0",children:e.jsx(_s,{className:"h-5 w-5"})}),e.jsx("div",{className:"flex-1 min-w-0",children:Y.length>0?e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"text-lg md:text-xl font-semibold leading-snug",children:["You have ",e.jsxs("span",{className:"text-primary",children:[Y.length," striking-distance keywords"]})," sitting on page 2."]}),e.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:["Pushing them onto page 1 could recover an estimated"," ",e.jsxs("span",{className:"font-semibold text-foreground",children:["~",qs.toLocaleString()," extra clicks"]})," ","over this ",a,"-day window. Top opportunity:"," ",e.jsx("span",{className:"font-mono text-foreground",children:Y[0].keys[0]})," ","(pos ",Y[0].position.toFixed(1),", ",Y[0].impressions.toLocaleString()," impressions)."]})]}):R.isLoading?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Analysing your Search Console dataâ¦"}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"No striking-distance opportunities found in this window."})})]})}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsx(Ae,{title:"Clicks",value:Ie.clicks,previous:Ke.clicks,icon:ot,dateRange:a}),e.jsx(Ae,{title:"Impressions",value:Ie.impressions,previous:Ke.impressions,icon:Xs,dateRange:a}),e.jsx(Ae,{title:"CTR",value:Ie.ctr,previous:Ke.ctr,icon:js,dateRange:a,format:"percent"}),e.jsx(Ae,{title:"Avg Position",value:Ie.position,previous:Ke.position,icon:lt,dateRange:a,format:"position",invert:!0})]}),e.jsxs(Ne,{className:"rounded-2xl shadow-sm",children:[e.jsxs(Ce,{children:[e.jsxs(Se,{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(ys,{className:"h-5 w-5 text-primary"}),"Traffic Overview"]}),e.jsx(Le,{children:"Daily clicks and impressions from organic search."})]}),e.jsx(De,{children:e.jsx("div",{className:"h-[320px]",children:Pe.length===0?e.jsx("div",{className:"h-full flex items-center justify-center text-sm text-muted-foreground",children:we?e.jsx(Te,{className:"h-5 w-5 animate-spin"}):"No data for this window."}):e.jsx(es,{width:"100%",height:"100%",children:e.jsxs(ct,{data:Pe,children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"clicksGrad",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",
7stopColor:"hsl(var(--primary))",stopOpacity:.3}),e.jsx("stop",{offset:"95%",stopColor:"hsl(var(--primary))",stopOpacity:0})]})}),e.jsx(ss,{strokeDasharray:"3 3",className:"opacity-30"}),e.jsx(ts,{dataKey:"dateLabel",tick:{fontSize:11},tickLine:!1}),e.jsx(je,{yAxisId:"left",tick:{fontSize:11},tickLine:!1,axisLine:!1}),e.jsx(je,{yAxisId:"right",orientation:"right",tick:{fontSize:11},tickLine:!1,axisLine:!1}),e.jsx(is,{contentStyle:{backgroundColor:"hsl(var(--card))",border:"1px solid hsl(var(--border))",borderRadius:"8px"}}),e.jsx(as,{}),e.jsx(xt,{yAxisId:"left",type:"monotone",dataKey:"clicks",name:"Clicks",stroke:"hsl(var(--primary))",fill:"url(#clicksGrad)",strokeWidth:2}),e.jsx(dt,{yAxisId:"right",dataKey:"impressions",name:"Impressions",fill:"hsl(var(--muted-foreground))",opacity:.3,radius:[4,4,0,0]})]})})})})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-5",children:[e.jsx(J,{icon:e.jsx(jt,{className:"h-4 w-4"}),title:"Striking-distance keywords",caption:"Page 2 keywords (pos 11â20). Small content or internal-link tweaks push these onto page 1.",loading:R.isLoading,empty:Y.length===0,onExport:()=>Z("striking-distance.csv",["Keyword","Position","Clicks","Impressions","Recoverable"],Y.map(s=>[s.keys[0],s.position.toFixed(1),s.clicks,s.impressions,Math.round(s.recoverable)])),children:e.jsxs(Q,{children:[e.jsx(G,{children:e.jsxs(k,{children:[e.jsx(x,{children:"Keyword"}),e.jsx(x,{className:"text-right w-[80px]",children:"Pos"}),e.jsx(x,{className:"text-right w-[100px]",children:"Impr."}),e.jsx(x,{className:"text-right w-[110px]",children:"Recoverable"})]})}),e.jsx(B,{children:Y.slice(0,10).map(s=>e.jsxs(k,{children:[e.jsx(o,{className:"font-mono text-xs max-w-[280px] truncate",title:s.keys[0],children:s.keys[0]}),e.jsx(o,{className:"text-right tabular-nums",children:s.position.toFixed(1)}),e.jsx(o,{className:"text-right tabular-nums",children:s.impressions.toLocaleString()}),e.jsxs(o,{className:"text-right tabular-nums text-primary font-medium",children:["+",Math.round(s.recoverable).toLocaleString()]})]},s.keys[0]))})]})}),e.jsx(J,{icon:e.jsx(Ys,{className:"h-4 w-4"}),title:"Low-CTR opportunities",caption:"Page 1 keywords clicking below their expected rate. Rewrite titles & meta descriptions to recover clicks.",loading:R.isLoading,empty:Ue.length===0,onExport:()=>Z("low-ctr.csv",["Keyword","Position","CTR","Expected","Recoverable"],Ue.map(s=>[s.keys[0],s.position.toFixed(1),(s.ctr*100).toFixed(2)+"%",(s.expected*100).toFixed(2)+"%",Math.round(s.recoverable)])),children:e.jsxs(Q,{children:[e.jsx(G,{children:e.jsxs(k,{children:[e.jsx(x,{children:"Keyword"}),e.jsx(x,{className:"text-right w-[70px]",children:"Pos"}),e.jsx(x,{className:"text-right w-[80px]",children:"CTR"}),e.jsx(x,{className:"text-right w-[100px]",children:"vs Expected"})]})}),e.jsx(B,{children:Ue.slice(0,10).map(s=>e.jsxs(k,{children:[e.jsx(o,{className:"font-mono text-xs max-w-[260px] truncate",title:s.keys[0],children:s.keys[0]}),e.jsx(o,{className:"text-right tabular-nums",children:s.position.toFixed(1)}),e.jsxs(o,{className:"text-right tabular-nums",children:[(s.ctr*100).toFixed(1),"%"]}),e.jsxs(o,{className:"text-right tabular-nums text-amber-600 dark:text-amber-400",children:[(s.expected*100).toFixed(1),"%"]})]},s.keys[0]))})]})}),e.jsx(J,{icon:e.jsx(js,{className:"h-4 w-4 text-green-600"}),title:"Rising keywords",caption:"Keywords gaining the most clicks vs the previous period. Double down with more content.",loading:R.isLoading||xe.isLoading,empty:me.rising.length===0,onExport:()=>Z("rising.csv",["Keyword","Clicks","Prev","Delta","Position"],me.rising.map(s=>[s.keyword,s.clicks,s.prevClicks,s.delta,s.currentPos.toFixed(1)])),children:e.jsxs(Q,{children:[e.jsx(G,{children:e.jsxs(k,{children:[e.jsx(x,{children:"Keyword"}),e.jsx(x,{className:"text-right w-[80px]",children:"Clicks"}),e.jsx(x,{className:"text-right w-[80px]",children:"Prev"}),e.jsx(x,{className:"text-right w-[80px]",children:"Î"})]})}),e.jsx(B,{children:me.rising.slice(0,10).map(s=>e.jsxs(k,{children:[e.jsx(o,{className:"font-mono text-xs max-w-[260px] truncate",title:s.keyword,
7children:s.keyword}),e.jsx(o,{className:"text-right tabular-nums",children:s.clicks}),e.jsx(o,{className:"text-right tabular-nums text-muted-foreground",children:s.prevClicks}),e.jsxs(o,{className:"text-right tabular-nums text-green-600 dark:text-green-400 font-medium",children:["+",s.delta]})]},s.keyword))})]})}),e.jsx(J,{icon:e.jsx(Zs,{className:"h-4 w-4 text-red-600"}),title:"Declining keywords",caption:"Keywords losing the most clicks. Investigate before ranking drops snowball.",loading:R.isLoading||xe.isLoading,empty:me.declining.length===0,onExport:()=>Z("declining.csv",["Keyword","Clicks","Prev","Delta","Position"],me.declining.map(s=>[s.keyword,s.clicks,s.prevClicks,s.delta,s.currentPos.toFixed(1)])),children:e.jsxs(Q,{children:[e.jsx(G,{children:e.jsxs(k,{children:[e.jsx(x,{children:"Keyword"}),e.jsx(x,{className:"text-right w-[80px]",children:"Clicks"}),e.jsx(x,{className:"text-right w-[80px]",children:"Prev"}),e.jsx(x,{className:"text-right w-[80px]",children:"Î"})]})}),e.jsx(B,{children:me.declining.slice(0,10).map(s=>e.jsxs(k,{children:[e.jsx(o,{className:"font-mono text-xs max-w-[260px] truncate",title:s.keyword,children:s.keyword}),e.jsx(o,{className:"text-right tabular-nums",children:s.clicks}),e.jsx(o,{className:"text-right tabular-nums text-muted-foreground",children:s.prevClicks}),e.jsx(o,{className:"text-right tabular-nums text-red-600 dark:text-red-400 font-medium",children:s.delta})]},s.keyword))})]})}),e.jsx(J,{icon:e.jsx(ys,{className:"h-4 w-4"}),title:"Top landing pages",caption:"Pages driving the most organic clicks. Optimise these first - biggest impact per change.",loading:I.isLoading,empty:ze.length===0,onExport:()=>Z("top-pages.csv",["Page","Clicks","Impressions","CTR","Position"],ze.map(s=>[s.keys[0],s.clicks,s.impressions,(s.ctr*100).toFixed(2)+"%",s.position.toFixed(1)])),children:e.jsxs(Q,{children:[e.jsx(G,{children:e.jsxs(k,{children:[e.jsx(x,{children:"Page"}),e.jsx(x,{className:"text-right w-[80px]",children:"Clicks"}),e.jsx(x,{className:"text-right w-[80px]",children:"CTR"}),e.jsx(x,{className:"text-right w-[70px]",children:"Pos"})]})}),e.jsx(B,{children:ze.slice(0,10).map(s=>e.jsxs(k,{children:[e.jsx(o,{className:"font-mono text-xs max-w-[280px] truncate",title:s.keys[0],children:s.keys[0].replace(/^https?:\/\/[^/]+/,"")}),e.jsx(o,{className:"text-right tabular-nums",children:s.clicks.toLocaleString()}),e.jsxs(o,{className:"text-right tabular-nums",children:[(s.ctr*100).toFixed(1),"%"]}),e.jsx(o,{className:"text-right tabular-nums",children:s.position.toFixed(1)})]},s.keys[0]))})]})}),e.jsx(J,{icon:e.jsx(Js,{className:"h-4 w-4 text-amber-600"}),title:"Underperforming pages",caption:"High impressions, low CTR (< 1.5%). Snippet, schema, or title fixes unlock easy wins.",loading:I.isLoading,empty:Ve.length===0,onExport:()=>Z("underperforming-pages.csv",["Page","Impressions","Clicks","CTR","Position"],Ve.map(s=>[s.keys[0],s.impressions,s.clicks,(s.ctr*100).toFixed(2)+"%",s.position.toFixed(1)])),children:e.jsxs(Q,{children:[e.jsx(G,{children:e.jsxs(k,{children:[e.jsx(x,{children:"Page"}),e.jsx(x,{className:"text-right w-[90px]",children:"Impr."}),e.jsx(x,{className:"text-right w-[80px]",children:"CTR"}),e.jsx(x,{className:"text-right w-[70px]",children:"Pos"})]})}),e.jsx(B,{children:Ve.slice(0,10).map(s=>e.jsxs(k,{children:[e.jsx(o,{className:"font-mono text-xs max-w-[260px] truncate",title:s.keys[0],children:s.keys[0].replace(/^https?:\/\/[^/]+/,"")}),e.jsx(o,{className:"text-right tabular-nums",children:s.impressions.toLocaleString()}),e.jsxs(o,{className:"text-right tabular-nums text-amber-600 dark:text-amber-400",children:[(s.ctr*100).toFixed(2),"%"]}),e.jsx(o,{className:"text-right tabular-nums",children:s.position.toFixed(1)})]},s.keys[0]))})]})}),e.jsx(J,{icon:e.jsx(et,{className:"h-4 w-4"}),title:"Content-gap questions",caption:"Question-style searches you're already showing up for. Direct prompts for new FAQ or blog content.",loading:R.isLoading,empty:$e.length===0,onExport:()=>Z("question-keywords.csv",["Keyword","Impressions","Clicks","Position"],$e.map(s=>[s.keys[0],s.impressions,s.clicks,s.position.toFixed(1)])),children:e.jsxs(Q,{children:[e.jsx(G,{children:e.jsxs(k,{children:[e.jsx(x,{children:"Keyword"}),e.jsx(x,{className:"text-right w-[90px]",children:"Impr."}),e.jsx(x,{className:"text-right w-[80px]",children:"Clicks"}),e.jsx(x,{className:"text-right w-[70px]",children:"Pos"})]})}),e.jsx(B,{children:$e.slice(0,10).map(s=>e.jsxs(k,{children:[e.jsx(o,{className:"font-mono text-xs max-w-[260px] truncate",title:s.keys[0],children:s.keys[0]}),e.jsx(o,{className:"text-right tabular-nums",children:s.impressions.toLocaleStr
7ing()}),e.jsx(o,{className:"text-right tabular-nums",children:s.clicks}),e.jsx(o,{className:"text-right tabular-nums",children:s.position.toFixed(1)})]},s.keys[0]))})]})}),e.jsx(J,{icon:e.jsx(mt,{className:"h-4 w-4"}),title:"Keyword cannibalisation",caption:g?"Queries where multiple pages compete (brand included). Brand SERPs normally have many pages â usually safe to ignore.":"Non-brand queries where 2+ pages split impressions. Consolidate or internally link to the strongest page.",loading:ce.isLoading,empty:We.length===0,headerAction:e.jsx(Ge,{variant:"outline",size:"sm",className:"h-8 rounded-full text-xs",onClick:()=>f(s=>!s),children:g?"Hide brand":"Include brand"}),onExport:()=>Z("cannibalisation.csv",["Keyword","Pages","Impressions","Clicks","Top page share %","Top page"],We.map(s=>[s.keyword,s.pages,s.impressions,s.clicks,(s.topShare*100).toFixed(0),s.topPage])),children:e.jsxs(Q,{children:[e.jsx(G,{children:e.jsxs(k,{children:[e.jsx(x,{children:"Keyword"}),e.jsx(x,{className:"text-right w-[70px]",children:"Pages"}),e.jsx(x,{className:"text-right w-[90px]",children:"Impr."}),e.jsx(x,{className:"text-right w-[80px]",children:"Clicks"}),e.jsx(x,{className:"text-right w-[90px]",children:"Top %"})]})}),e.jsx(B,{children:We.slice(0,10).map(s=>{const r=c.has(s.keyword);return e.jsxs(st.Fragment,{children:[e.jsxs(k,{className:"cursor-pointer hover:bg-muted/40",onClick:()=>v(u=>{const C=new Set(u);return C.has(s.keyword)?C.delete(s.keyword):C.add(s.keyword),C}),children:[e.jsxs(o,{className:"font-mono text-xs max-w-[240px] truncate",title:s.keyword,children:[r?"â¾ ":"⸠",s.keyword]}),e.jsx(o,{className:"text-right tabular-nums",children:e.jsx(Je,{variant:"secondary",className:"text-xs",children:s.pages})}),e.jsx(o,{className:"text-right tabular-nums",children:s.impressions.toLocaleString()}),e.jsx(o,{className:"text-right tabular-nums",children:s.clicks}),e.jsxs(o,{className:"text-right tabular-nums",children:[(s.topShare*100).toFixed(0),"%"]})]}),r&&s.pageList.map(u=>e.jsxs(k,{className:"bg-muted/20",children:[e.jsx(o,{className:"pl-8 font-mono text-[11px] max-w-[260px] truncate text-muted-foreground",title:u.page,children:u.page.replace(/^https?:\/\/[^/]+/,"")}),e.jsx(o,{}),e.jsx(o,{className:"text-right tabular-nums text-xs",children:u.impressions.toLocaleString()}),e.jsx(o,{className:"text-right tabular-nums text-xs",children:u.clicks}),e.jsxs(o,{className:"text-right tabular-nums text-xs",children:["pos ",u.position.toFixed(1)]})]},s.keyword+"::"+u.page))]},s.keyword)})})]})}),e.jsx(J,{icon:e.jsx(fs,{className:"h-4 w-4"}),title:"Country breakdown",caption:"Where your organic traffic comes from. Spillover markets may be worth dedicated content.",loading:de.isLoading,empty:He.length===0,onExport:()=>Z("countries.csv",["Country","Clicks","Impressions","CTR","Position"],He.map(s=>[s.keys[0],s.clicks,s.impressions,(s.ctr*100).toFixed(2)+"%",s.position.toFixed(1)])),children:e.jsxs(Q,{children:[e.jsx(G,{children:e.jsxs(k,{children:[e.jsx(x,{children:"Country"}),e.jsx(x,{className:"text-right w-[80px]",children:"Clicks"}),e.jsx(x,{className:"text-right w-[100px]",children:"Impr."}),e.jsx(x,{className:"text-right w-[80px]",children:"CTR"})]})}),e.jsx(B,{children:He.map(s=>e.jsxs(k,{children:[e.jsx(o,{className:"font-mono uppercase text-xs",children:s.keys[0]}),e.jsx(o,{className:"text-right tabular-nums",children:s.clicks.toLocaleString()}),e.jsx(o,{className:"text-right tabular-nums",children:s.impressions.toLocaleString()}),e.jsxs(o,{className:"text-right tabular-nums",children:[(s.ctr*100).toFixed(1),"%"]})]},s.keys[0]))})]})}),e.jsx(J,{icon:e.jsx(bs,{className:"h-4 w-4"}),title:"Device & brand mix",caption:"Device split + brand vs non-brand. Non-brand growth is what scales SEO.",loading:F.isLoading||R.isLoading,empty:(F.data||[]).length===0,onExport:()=>{const s=[...(F.data||[]).map(r=>["device",r.keys[0],r.clicks,r.impressions,(r.ctr*100).toFixed(2)+"%",r.position.toFixed(1)]),["brand","brand",ie.brand.clicks,ie.brand.impressions,"",""],["brand","non-brand",ie.nonBrand.clicks,ie.nonBrand.impressions,"",""]];Z("device-brand.csv",["Type","Value","Clicks","Impressions","CTR","Position"],s)},children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground mb-2",children:"By device"}),e.jsxs(Q,{children:[e.jsx(G,{children:e.jsxs(k,{children:[e.jsx(x,{children:"Device"}),e.jsx(x,{className:"text-right w-[80px]",children:"Clicks"}),e.jsx(x,{className:"text-right w-[80px]",children:"CTR"}),e.jsx(x,{className:"text-right w-[70px]",children:"Pos"})]})}),e.jsx(B,{children:(F.data||[]).map(s=>e.jsxs(k,{children:[e.jsx(o,{className:"capitalize text-xs",children:s.keys[0].toLowerCase()}),e.jsx(o,{className:"text-right tabular-nums",children:s.clicks.toLocaleStr
7ing()}),e.jsxs(o,{className:"text-right tabular-nums",children:[(s.ctr*100).toFixed(1),"%"]}),e.jsx(o,{className:"text-right tabular-nums",children:s.position.toFixed(1)})]},s.keys[0]))})]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground mb-2",children:"Brand vs non-brand"}),e.jsxs(Q,{children:[e.jsx(G,{children:e.jsxs(k,{children:[e.jsx(x,{children:"Type"}),e.jsx(x,{className:"text-right w-[80px]",children:"Clicks"}),e.jsx(x,{className:"text-right w-[100px]",children:"Impr."}),e.jsx(x,{className:"text-right w-[80px]",children:"Share"})]})}),e.jsx(B,{children:(()=>{const s=ie.brand.clicks+ie.nonBrand.clicks;return[{label:"Brand (Simba)",d:ie.brand,color:"text-foreground"},{label:"Non-brand",d:ie.nonBrand,color:"text-primary"}].map(r=>e.jsxs(k,{children:[e.jsx(o,{className:`text-xs font-medium ${r.color}`,children:r.label}),e.jsx(o,{className:"text-right tabular-nums",children:r.d.clicks.toLocaleString()}),e.jsx(o,{className:"text-right tabular-nums",children:r.d.impressions.toLocaleString()}),e.jsxs(o,{className:"text-right tabular-nums",children:[s?(r.d.clicks/s*100).toFixed(0):0,"%"]})]},r.label))})()})]})]})]})})]})]})},Ae=({title:a,value:t,previous:i,icon:n,dateRange:m,format:h="number",invert:g=!1})=>{const f=q=>h==="percent"?`${q.toFixed(2)}%`:h==="position"?q.toFixed(1):q.toLocaleString(),c=i?(t-i)/i*100:0,v=!i||Math.abs(c)<1,D=c>0,T=g?!D:D;return e.jsxs("div",{className:"rounded-2xl border bg-card p-5 shadow-sm",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsx("span",{className:"inline-flex items-center justify-center w-9 h-9 rounded-full bg-primary/10 text-primary shrink-0",children:e.jsx(n,{className:"h-4 w-4"})}),!v&&e.jsxs("span",{className:`inline-flex items-center gap-0.5 px-2 py-0.5 rounded-full text-xs font-medium ${T?"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400":"bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400"}`,children:[D?e.jsx(ht,{className:"h-3 w-3"}):e.jsx(ut,{className:"h-3 w-3"}),Math.abs(c).toFixed(1),"%"]})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-3",children:a}),e.jsx("p",{className:"text-2xl font-bold mt-0.5",children:f(t)}),e.jsxs("p",{className:"text-[11px] text-muted-foreground mt-1",children:["vs previous ",m," days: ",f(i)]})]})},J=({icon:a,title:t,caption:i,loading:n,empty:m,onExport:h,headerAction:g,children:f})=>e.jsxs("div",{className:"rounded-2xl border bg-card shadow-sm overflow-hidden",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 p-5 pb-3",children:[e.jsxs("div",{className:"flex items-start gap-3 min-w-0",children:[e.jsx("span",{className:"inline-flex items-center justify-center w-8 h-8 rounded-full bg-primary/10 text-primary shrink-0",children:a}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"text-sm font-semibold leading-tight",children:t}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",dangerouslySetInnerHTML:{__html:i}})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[g,h&&!m&&!n&&e.jsx(Ge,{variant:"ghost",size:"sm",onClick:h,className:"h-8 w-8 p-0",title:"Export CSV",children:e.jsx(Ds,{className:"h-4 w-4"})})]})]}),e.jsx("div",{className:"px-2 pb-3",children:n?e.jsx("div",{className:"py-10 text-center",children:e.jsx(Te,{className:"h-5 w-5 animate-spin mx-auto text-muted-foreground"})}):m?e.jsx("div",{className:"py-10 text-center text-xs text-muted-foreground",children:"No data in this window."}):e.jsx("div",{className:"max-h-[420px] overflow-auto",children:f})})]}),Ps="sc-domain:simbacarhire.com.au";function Oe(a,t=[]){const i=[...t];return a.country&&i.push({dimension:"country",expression:a.country}),a.device&&i.push({dimension:"device",expression:a.device}),i.length?[{groupType:"and",filters:i}]:[]}async function kt(a){const{data:t,error:i}=await Be.functions.invoke("search-console",{body:{siteUrl:Ps,...a}});if(i)throw new Error(i.message);if(t!=null&&t.error)throw new Error(t.error);return{rows:(t==null?void 0:t.data)||[],totals:t==null?void 0:t.totals}}async function Qe(a){const{data:t,error:i}=await Be.functions.invoke("search-console",{body:{siteUrl:Ps,...a}});if(i)throw new Error(i.message);if(t!=null&&t.error)throw new Error(t.error);return(t==null?void 0:t.data)||[]}function Nt(a,t,i){const n=c=>{const v=String(c??"");return/[",\n]/.test(v)?`"${v.replace(/"/g,'""')}"`:v},m=[t.join(","),...i.map(c=>c.map(n).join(","))].join(` 8`),h=new Blob([m],{type:"text/csv;charset=utf-8;"}),g=URL.createObjectURL(h),f=document.createElement("a");f.href=g,f.download=a,f.click(),URL.revokeObjectURL(g)}
8function Ye({rows:a,keyLabel:t,loading:i}){const[n,m]=p.useState("clicks"),[h,g]=p.useState("desc"),[f,c]=p.useState(""),v=p.useMemo(()=>{const b=f.trim().toLowerCase();return[...b?a.filter(w=>(w.keys[0]||"").toLowerCase().includes(b)):a].sort((w,j)=>{const N=w[n],A=j[n];return h==="desc"?A-N:N-A})},[a,n,h,f]),D=b=>{b===n?g(y=>y==="desc"?"asc":"desc"):(m(b),g(b==="position"?"asc":"desc"))},T=({k:b,label:y,className:w})=>e.jsx(x,{className:w,children:e.jsxs("button",{onClick:()=>D(b),className:"inline-flex items-center gap-1 hover:text-foreground",children:[y," ",e.jsx(gt,{className:"h-3 w-3 opacity-50"})]})}),q=()=>{Nt(`gsc-${t.toLowerCase()}-${new Date().toISOString().split("T")[0]}.csv`,[t,"Clicks","Impressions","CTR","Position"],v.map(b=>[b.keys[0],b.clicks,b.impressions,(b.ctr*100).toFixed(2)+"%",b.position.toFixed(1)]))};return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 flex-wrap",children:[e.jsxs("div",{className:"relative flex-1 min-w-[240px] max-w-md",children:[e.jsx(it,{className:"absolute left-2 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(at,{placeholder:`Filter ${t.toLowerCase()}...`,value:f,onChange:b=>c(b.target.value),className:"pl-8 h-9"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(Je,{variant:"secondary",className:"text-xs",children:[v.length," rows"]}),e.jsxs(Ge,{size:"sm",variant:"outline",onClick:q,disabled:!v.length,children:[e.jsx(Ds,{className:"h-4 w-4 mr-1"})," CSV"]})]})]}),e.jsx("div",{className:"rounded-md border max-h-[560px] overflow-auto",children:e.jsxs(Q,{children:[e.jsx(G,{className:"sticky top-0 bg-background z-10",children:e.jsxs(k,{children:[e.jsx(x,{children:t}),e.jsx(T,{k:"clicks",label:"Clicks",className:"text-right w-[100px]"}),e.jsx(T,{k:"impressions",label:"Impressions",className:"text-right w-[120px]"}),e.jsx(T,{k:"ctr",label:"CTR",className:"text-right w-[90px]"}),e.jsx(T,{k:"position",label:"Position",className:"text-right w-[100px]"})]})}),e.jsxs(B,{children:[i&&e.jsx(k,{children:e.jsx(o,{colSpan:5,className:"text-center py-10",children:e.jsx(Te,{className:"h-5 w-5 animate-spin mx-auto text-muted-foreground"})})}),!i&&v.length===0&&e.jsx(k,{children:e.jsx(o,{colSpan:5,className:"text-center py-10 text-muted-foreground",children:"No data for this selection."})}),!i&&v.map((b,y)=>e.jsxs(k,{children:[e.jsx(o,{className:"font-mono text-xs max-w-[480px] truncate",title:b.keys[0],children:b.keys[0]}),e.jsx(o,{className:"text-right tabular-nums",children:b.clicks.toLocaleString()}),e.jsx(o,{className:"text-right tabular-nums",children:b.impressions.toLocaleString()}),e.jsxs(o,{className:"text-right tabular-nums",children:[(b.ctr*100).toFixed(2),"%"]}),e.jsx(o,{className:"text-right tabular-nums",children:b.position.toFixed(1)})]},y))]})]})})]})}const Ct=()=>{var ve,te;const[a,t]=p.useState(28),[i,n]=p.useState("all"),[m,h]=p.useState("all"),[g,f]=p.useState("by-page"),[c,v]=p.useState(""),[D,T]=p.useState(""),q=p.useMemo(()=>({days:a,country:i==="all"?void 0:i,device:m==="all"?void 0:m}),[a,i,m]),{window:b,maxAvailableDate:y,isLoading:w}=Fs(a),j=b??{startDate:"",endDate:"",prevStartDate:"",prevEndDate:"",maxAvailableDate:""},N=p.useMemo(()=>Oe(q),[q]),A=le({queryKey:["gsc-pages",j,N],enabled:!!b,queryFn:()=>kt({startDate:j.startDate,endDate:j.endDate,dimensions:["page"],rowLimit:5e3,dimensionFilterGroups:N}),staleTime:5*60*1e3}),re=((ve=A.data)==null?void 0:ve.rows)||[],R=((te=A.data)==null?void 0:te.totals)||null,I=le({queryKey:["gsc-queries",j,N],enabled:!!b,queryFn:()=>Qe({startDate:j.startDate,endDate:j.endDate,dimensions:["query"],rowLimit:5e3,dimensionFilterGroups:N}),staleTime:5*60*1e3});p.useEffect(()=>{!c&&re.length&&v(re[0].keys[0])},[A.data,c]),p.useEffect(()=>{var d;!D&&((d=I.data)!=null&&d.length)&&T(I.data[0].keys[0])},[I.data,D]);const ce=le({queryKey:["gsc-queries-for-page",c,j,N],enabled:g==="by-page"&&!!c,queryFn:()=>Qe({startDate:j.startDate,endDate:j.endDate,dimensions:["query"],rowLimit:5e3,dimensionFilterGroups:Oe(q,[{dimension:"page",expression:c}])}),staleTime:5*60*1e3}),de=le({queryKey:["gsc-pages-for-query",D,j,N],enabled:g==="by-keyword"&&!!D,queryFn:()=>
8Qe({startDate:j.startDate,endDate:j.endDate,dimensions:["page"],rowLimit:5e3,dimensionFilterGroups:Oe(q,[{dimension:"query",expression:D}])}),staleTime:5*60*1e3}),[F,xe]=p.useState("page"),we=p.useMemo(()=>{const d=[];return(F==="page"||F==="pair")&&c&&d.push({dimension:"page",expression:c}),(F==="keyword"||F==="pair")&&D&&d.push({dimension:"query",expression:D}),Oe(q,d)},[q,F,c,D]),ne=le({queryKey:["gsc-trend",F,c,D,j,N],enabled:g==="trend"&&(F==="page"&&!!c||F==="keyword"&&!!D||F==="pair"&&!!c&&!!D),queryFn:()=>Qe({startDate:j.startDate,endDate:j.endDate,dimensions:["date"],rowLimit:1e3,dimensionFilterGroups:we}),staleTime:5*60*1e3}),ee=p.useMemo(()=>(ne.data||[]).map(d=>({date:d.keys[0],dateLabel:Ls(d.keys[0],{month:"short",day:"numeric"}),clicks:d.clicks,impressions:d.impressions,ctr:d.ctr*100,position:d.position})).sort((d,Pe)=>new Date(d.date).getTime()-new Date(Pe.date).getTime()),[ne.data]);return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[e.jsxs(W,{value:String(a),onValueChange:d=>t(parseInt(d)),children:[e.jsx(H,{className:"w-[140px]",children:e.jsx(_,{})}),e.jsxs(X,{children:[e.jsx(l,{value:"7",children:"Last 7 days"}),e.jsx(l,{value:"28",children:"Last 28 days"}),e.jsx(l,{value:"90",children:"Last 90 days"}),e.jsx(l,{value:"180",children:"Last 180 days"}),e.jsx(l,{value:"365",children:"Last 12 months"})]})]}),e.jsxs(W,{value:i,onValueChange:n,children:[e.jsx(H,{className:"w-[140px]",children:e.jsx(_,{placeholder:"Country"})}),e.jsxs(X,{children:[e.jsx(l,{value:"all",children:"All countries"}),e.jsx(l,{value:"aus",children:"Australia"}),e.jsx(l,{value:"nzl",children:"New Zealand"}),e.jsx(l,{value:"usa",children:"United States"}),e.jsx(l,{value:"gbr",children:"United Kingdom"}),e.jsx(l,{value:"can",children:"Canada"}),e.jsx(l,{value:"ind",children:"India"}),e.jsx(l,{value:"sgp",children:"Singapore"}),e.jsx(l,{value:"deu",children:"Germany"}),e.jsx(l,{value:"fra",children:"France"}),e.jsx(l,{value:"idn",children:"Indonesia"}),e.jsx(l,{value:"phl",children:"Philippines"}),e.jsx(l,{value:"mys",children:"Malaysia"}),e.jsx(l,{value:"are",children:"United Arab Emirates"}),e.jsx(l,{value:"chn",children:"China"}),e.jsx(l,{value:"jpn",children:"Japan"})]})]}),e.jsxs(W,{value:m,onValueChange:h,children:[e.jsx(H,{className:"w-[140px]",children:e.jsx(_,{placeholder:"Device"})}),e.jsxs(X,{children:[e.jsx(l,{value:"all",children:"All devices"}),e.jsx(l,{value:"MOBILE",children:"Mobile"}),e.jsx(l,{value:"DESKTOP",children:"Desktop"}),e.jsx(l,{value:"TABLET",children:"Tablet"})]})]}),e.jsxs("div",{className:"flex items-center gap-1 text-xs text-muted-foreground",children:[e.jsx(pt,{className:"h-3 w-3"}),y?e.jsxs(e.Fragment,{children:["Window ends ",e.jsx("span",{className:"font-medium text-foreground",children:y})," (latest day GSC has data)."]}):w?"Resolving GSC windowâ¦":"GSC data delayed ~2 days."]})]}),e.jsxs(Ts,{value:g,onValueChange:d=>f(d),children:[e.jsxs(Rs,{children:[e.jsx(pe,{value:"by-page",children:"By page"}),e.jsx(pe,{value:"by-keyword",children:"By keyword"}),e.jsx(pe,{value:"totals",children:"Totals"}),e.jsx(pe,{value:"trend",children:"Trend"})]}),e.jsx(ge,{value:"by-page",className:"space-y-4 mt-4",children:e.jsxs(Ne,{children:[e.jsxs(Ce,{className:"pb-3",children:[e.jsx(Se,{className:"text-base",children:"Top keywords per page"}),e.jsx(Le,{children:"Pick a page to see which queries drive its impressions and clicks."})]}),e.jsxs(De,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Page:"}),e.jsxs(W,{value:c,onValueChange:v,children:[e.jsx(H,{className:"w-full max-w-2xl",children:e.jsx(_,{placeholder:A.isLoading?"Loading pages...":"Select a page"})}),e.jsx(X,{className:"max-h-[400px]",children:re.map(d=>e.jsxs(l,{value:d.keys[0],children:[e.jsx("span",{className:"font-mono text-xs",children:d.keys[0]}),e.jsxs("span",{className:"text-muted-foreground ml-2",children:["(",d.clicks.toLocaleString()," clicks)"]})]},d.keys[0]))})]})]}),e.jsx(Ye,{rows:ce.data||[],keyLabel:"Keyword",loading:ce.isLoading})]})]})}
8),e.jsx(ge,{value:"by-keyword",className:"space-y-4 mt-4",children:e.jsxs(Ne,{children:[e.jsxs(Ce,{className:"pb-3",children:[e.jsx(Se,{className:"text-base",children:"Top pages per keyword"}),e.jsx(Le,{children:"Pick a keyword to see which pages rank for it."})]}),e.jsxs(De,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Keyword:"}),e.jsxs(W,{value:D,onValueChange:T,children:[e.jsx(H,{className:"w-full max-w-2xl",children:e.jsx(_,{placeholder:I.isLoading?"Loading keywords...":"Select a keyword"})}),e.jsx(X,{className:"max-h-[400px]",children:(I.data||[]).map(d=>e.jsxs(l,{value:d.keys[0],children:[d.keys[0],e.jsxs("span",{className:"text-muted-foreground ml-2",children:["(",d.clicks.toLocaleString()," clicks)"]})]},d.keys[0]))})]})]}),e.jsx(Ye,{rows:de.data||[],keyLabel:"Page",loading:de.isLoading})]})]})}),e.jsx(ge,{value:"totals",className:"space-y-4 mt-4",children:e.jsxs(Ne,{children:[e.jsxs(Ce,{className:"pb-3",children:[e.jsx(Se,{className:"text-base",children:"Totals by keyword"}),e.jsx(Le,{children:"Site-wide totals per query â mirrors the numbers in GSC's Queries tab. No page filter applied."})]}),e.jsxs(De,{className:"space-y-4",children:[R&&e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[e.jsxs("div",{className:"rounded-lg border bg-muted/30 p-3",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"Clicks"}),e.jsx("div",{className:"text-xl font-semibold tabular-nums",children:R.clicks.toLocaleString()})]}),e.jsxs("div",{className:"rounded-lg border bg-muted/30 p-3",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"Impressions"}),e.jsx("div",{className:"text-xl font-semibold tabular-nums",children:R.impressions.toLocaleString()})]}),e.jsxs("div",{className:"rounded-lg border bg-muted/30 p-3",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"CTR"}),e.jsxs("div",{className:"text-xl font-semibold tabular-nums",children:[(R.ctr*100).toFixed(2),"%"]})]}),e.jsxs("div",{className:"rounded-lg border bg-muted/30 p-3",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:"Avg Position"}),e.jsx("div",{className:"text-xl font-semibold tabular-nums",children:R.position.toFixed(1)})]})]}),e.jsx(Ye,{rows:I.data||[],keyLabel:"Keyword",loading:I.isLoading})]})]})}),e.jsx(ge,{value:"trend",className:"space-y-4 mt-4",children:e.jsxs(Ne,{children:[e.jsxs(Ce,{className:"pb-3",children:[e.jsx(Se,{className:"text-base",children:"Trend"}),e.jsx(Le,{children:"Daily clicks, impressions, CTR and position over the selected period."})]}),e.jsxs(De,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs(W,{value:F,onValueChange:d=>xe(d),children:[e.jsx(H,{className:"w-[180px]",children:e.jsx(_,{})}),e.jsxs(X,{children:[e.jsx(l,{value:"page",children:"Selected page"}),e.jsx(l,{value:"keyword",children:"Selected keyword"}),e.jsx(l,{value:"pair",children:"Page + keyword"})]})]}),(F==="page"||F==="pair")&&e.jsxs(W,{value:c,onValueChange:v,children:[e.jsx(H,{className:"w-full max-w-md",children:e.jsx(_,{placeholder:"Select a page"})}),e.jsx(X,{className:"max-h-[400px]",children:re.map(d=>e.jsx(l,{value:d.keys[0],children:e.jsx("span",{className:"font-mono text-xs",children:d.keys[0]})},d.keys[0]))})]}),(F==="keyword"||F==="pair")&&e.jsxs(W,{value:D,onValueChange:T,children:[e.jsx(H,{className:"w-full max-w-md",children:e.jsx(_,{placeholder:"Select a keyword"})}),e.jsx(X,{className:"max-h-[400px]",children:(I.data||[]).map(d=>e.jsx(l,{value:d.keys[0],children:d.keys[0]},d.keys[0]))})]})]}),ne.isLoading&&e.jsx("div",{className:"py-16 text-center text-muted-foreground",children:e.jsx(Te,{className:"h-5 w-5 animate-spin mx-auto"})}),!ne.isLoading&&ee.length===0&&e.jsx("div",{className:"py-16 text-center text-muted-foreground text-sm",children:"No daily data for this selection."}),!ne.isLoading&&ee.length>0&&e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[e.jsx("div",{className:"h-[260px]",children:e.jsx(es,{width:"100%",height:"100%",children:e.jsxs(ws,{data:ee,children:[e.jsx(ss,{strokeDasharray:"3 3",className:"opacity-30"}),e.jsx(ts,{dataKey:"dateLabel",tick:{fontSize:10}}),e.jsx(je,{yAxisId:"left",tick:{fontSize:10}}),e.jsx(je,{yAxisId:"right",orientation:"right",tick:{fontSize:10}}),e.jsx(is,{contentStyle:{backgroundColor:"hsl(var(--card))",border:"1px solid hsl(var(--border))",borderRadius:8}}),e.jsx(as,{}),e.jsx(Me,{yAxisId:"left",type:"monotone",dataKey:"clicks",name:"Clicks",stroke:"hsl(var(--primary))",strokeWidth:2,dot:!1}),e.jsx(Me,{yAxisId:"right",type:"monotone",dataKey:"impressions",name:"Impressions",stroke:"hsl(var(--muted-foreground))",strokeWidth:2,dot:!1})]})})}),e.jsx("div",{className:"h-[260px]",children:e.jsx(es,{width:"100%",height:"100%",children:e.jsxs(ws,{data:ee,children:[e.jsx(ss,{strokeDasharray:"3 3",className:"opacity-30"}),e.jsx(ts,{dataKey:"dateLabel",tick:{fontSize:10}}),e.jsx(je,{yAxisId:"left",tick:{fontSize:10}
8,tickFormatter:d=>`${d}%`}),e.jsx(je,{yAxisId:"right",orientation:"right",reversed:!0,tick:{fontSize:10}}),e.jsx(is,{contentStyle:{backgroundColor:"hsl(var(--card))",border:"1px solid hsl(var(--border))",borderRadius:8}}),e.jsx(as,{}),e.jsx(Me,{yAxisId:"left",type:"monotone",dataKey:"ctr",name:"CTR %",stroke:"#22c55e",strokeWidth:2,dot:!1}),e.jsx(Me,{yAxisId:"right",type:"monotone",dataKey:"position",name:"Position",stroke:"#3b82f6",strokeWidth:2,dot:!1})]})})})]})]})]})})]})]})},yi=()=>{const a=rt(),[t,i]=p.useState("organic-performance"),n=m=>{m!=="organic-performance"&&a("/admin")};return e.jsx(nt,{activeTab:t,onTabChange:n,title:"Organic Performance",subtitle:"Track your Google Search Console metrics over time",children:e.jsxs(Ts,{defaultValue:"overview",className:"space-y-6",children:[e.jsxs(Rs,{children:[e.jsx(pe,{value:"overview",children:"Overview"}),e.jsx(pe,{value:"explorer",children:"Keyword à Page Explorer"})]}),e.jsx(ge,{value:"overview",className:"mt-0",children:e.jsx(vt,{})}),e.jsx(ge,{value:"explorer",className:"mt-0",children:e.jsx(Ct,{})})]})})};export{yi 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.