PageSourceSearch

https://blacksheepbi.com/assets/PlatformSEO-Ckw09sVe.js

js blacksheepbi.com collected 2026-09-30 08:26:39 UTC 224,370 bytes, 28 lines download raw bytes

1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/KeywordResearch-4omXIUnO.js","assets/ui-CPW3-RCR.js","assets/supabase-B2z4OhLQ.js","assets/index-BraPXa8T.js","assets/charts-DCB9_QAo.js","assets/vendor-CIXof4MH.js","assets/index-CecBC96Z.css","assets/select-DubWVshT.js","assets/index-BdQq_4o_.js","assets/layers-Dzu1hN6i.js","assets/calculator-DDXoV-Dw.js","assets/ban-bzQPFdWb.js","assets/filter-BW78Uvz8.js","assets/thumbs-up-6rv6gXsR.js","assets/minus-CCCsL8N7.js","assets/chart-pie-C2dMHTgo.js","assets/credit-card-CyIPEgks.js","assets/KeywordGap-ExXcaYd3.js","assets/table-DKs90XYm.js","assets/play-D97WNvd1.js"])))=>i.map(i=>d[i]);
2import{R as Te,ay as _a,C as es,X as ss,Y as He,T as We,aA as Ca,A as fs,a as ls,aD as Jt,aE as Zt,aF as Ss,aB as Vs,aC as _s,az as $a,bt as La,_ as ea}from"./charts-DCB9_QAo.js";import{r as l,j as e}from"./ui-CPW3-RCR.js";import{a0 as As,u as Ds,g as Ye,c as _e,_ as us,R as Fe,ao as hs,X as Ls,s as A,d as R,L as ie,V as Ta,k as sa,P as ta,bd as Zs,aL as ge,N as Je,a3 as Re,a9 as qe,W as Qe,O as Ve,i as Ws,aD as Ze,aN as Aa,b2 as aa,aQ as et,ap as gs,bQ as is,G as Le,aF as ra,bm as Da,a as Ms,ai as Ma,b as zs,a2 as Ea,a_ as na,a$ as ia,b0 as Me,b1 as ce,ae as la,bO as st,e as Ee,Z as fe,C as qs,bC as Fa,ak as Ra,al as Pa,am as Oa,B as ee,bE as Ia,S as za,j as Ts,bD as Ba,f as Ga,aX as Ka,$ as Ua,K as kt,a5 as Ha,aq as Cs,I as $s,bN as Va,T as Wa,l as qa,m as Qa,n as Ya,o as Xa,p as Ja,ar as St,as as _t,at as Ct,au as $t,av as Lt,aw as Tt,ax as At,ay as Dt,ab as Za,bn as Mt,y as be,J as ve,cB as ms,z as Ge,E as Ke,d4 as er,a4 as Et}from"./index-BraPXa8T.js";import{u as sr,i as tr,E as ar,j as rr}from"./useExportPdf-BypuIzFG.js";import{A as nr}from"./AIResponseFeedback-UIkBJjrS.js";import{t as ir}from"./autoLearn-CRnZuHOE.js";import{S as lr}from"./SendToTaskManager-ChKH7nnt.js";import{u as or}from"./useSmartScroll-Da1xVHwy.js";import{u as cr,D as dr}from"./useDashboardChatFiles-De9k4Vyd.js";import{M as Es}from"./index-BfRVBusC.js";import{D as xr}from"./DateRangePicker-TT0ANjfb.js";import{f as Ue}from"./format-DAGnYLwh.js";import{T as Ae}from"./trending-down-BWyGfEbB.js";import{M as tt}from"./minus-CCCsL8N7.js";import{A as oa,a as mr}from"./arrow-up-right-CsYEumGH.js";import{L as Bs}from"./vendor-CIXof4MH.js";import{s as hr}from"./subDays-B6CEP03R.js";import{M as pr}from"./mouse-pointer-BTNlpTVl.js";import{H as ur}from"./hash-C5kOXdhJ.js";import{T as ca}from"./tablet-VWWqo-TL.js";import{M as at}from"./monitor-BThy0502.js";import{D as fr}from"./DepartmentBrainPanel-BXjmvOXs.js";import{u as gr}from"./useDemoLocale-COy7_g6Y.js";import{r as jr}from"./index-CbedGEwf.js";import{g as yr,r as Nr,a as br,b as vr}from"./seo-report-i18n-C5_p11n8.js";import{S as Ft,a as Rt,b as Pt,c as Ot,d as ts}from"./select-DubWVshT.js";import{C as It}from"./calendar-range-uZlVfStN.js";import{S as zt}from"./share-2-ySg6qX03.js";import{T as da}from"./trophy-BFunnjow.js";import{S as wr}from"./square-check-big-1rY2buiN.js";import{S as kr}from"./square-BPExEz1G.js";import{h as Bt}from"./he-CneTJ2uI.js";import{e as Gt}from"./en-US-CmMcNpXQ.js";import{p as Sr}from"./pt-BR-D_ZVDxzZ.js";import{f as _r,i as Cr}from"./it-Bv9SfiiA.js";import{G as xa}from"./gauge-xKz5X1-Y.js";import{C as $r}from"./circle-check-big-DG-il0rr.js";import{A as ma}from"./arrow-right-BLLC8LlL.js";import{T as Qs,a as Ys,b as ns,c as pe,d as Xs,e as ue}from"./table-DKs90XYm.js";import{M as Lr}from"./message-square-quote-QSvtGdI3.js";import{C as Tr}from"./credit-card-CyIPEgks.js";import{A as Ar}from"./award-CoYQKEQq.js";import{S as Gs}from"./shield-alert-CSZB8Xzk.js";import{K as Dr}from"./key-DLfwGZpn.js";import"./supabase-B2z4OhLQ.js";import"./file-down-Chqz42zT.js";import"./html2canvas.esm-CBrSDip1.js";import"./jspdf.es.min-BBLdUEou.js";import"./thumbs-up-6rv6gXsR.js";import"./TaskCreateDialog-DKBsfrRz.js";import"./AdvancedDatePicker-ChPu-U4D.js";import"./tag-BX6YVh3F.js";import"./arrow-up-down-CCRYX6WW.js";import"./calendar-Cw1MR1gK.js";import"./endOfMonth-F9aO6iN7.js";import"./isSameYear-CisLDsou.js";import"./startOfWeek-Dx_XlaWC.js";import"./pt-XXd_e7HC.js";import"./repeat-Bzyo7NvJ.js";import"./useTaskInlineHelpers-C6iIbF2m.js";import"./confetti.module-B5JVzsfH.js";import"./collapsible-CHuAoMFW.js";import"./index-DkD4heWV.js";import"./RichTextEditor-CJcYExHW.js";import"./index-CVizilC1.js";import"./with-selector-BvZ9_Y0X.js";import"./index-BP6EXeue.js";import"./index-BwRZ_Ozi.js";import"./dropdown-menu-ByQNdDT1.js";import"./circle-Bi-mZyos.js";import"./unlink-CAyXBby2.js";import"./heading-2-DPmEGPQt.js";import"./quote-BPj_Y_e6.js";import"./table-CUdv-10Z.js";import"./strikethrough-DJ9SUok4.js";import"./link-BKA0FtFv.js";import"./index-BdQq_4o_.js";import"./useChatThreads-C2aQZPDf.js";import"./scroll-area-BQtXZnuf.js";import"./formatDistanceToNow-DrARF4Rk.js";import"./constructNow-DBola7tm.js";import"./endOfDay-DBxpZW_E.js";import"./xlsx-DLNWaC59.js";import"./drawer-D7zBXJVS.js";import"./calendar-days-BaOp-1ZJ.js";import"./subMonths-Bscyv-h7.js";import"./parse-BCEiHIKQ.js";/**
3 * @license lucide-react v0.462.0 - ISC
4 *
5 * This source code is licensed under the ISC license.
6 * See the LICENSE file in the root directory of this source tree.
7 */const Mr=As("FileSearch",[["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M4.268 21a2 2 0 0 0 1.727 1H18a2 2 0 0 0 2-2V7l-5-5H6a2 2 0 0 0-2 2v3",key:"ms7g94"}],["path",{d:"m9 18-1.5-1.5",key:"1j6qii"}],["circle",{cx:"5",cy:"14",r:"3",key:"ufru5t"}]]);/**
8 * @license lucide-react v0.462.0 - ISC
9 *
10 * This source code is licensed under the ISC license.
11 * See the LICENSE file in the root directory of this source tree.
12 */const ps=As("GitMerge",[["circle",{cx:"18",cy:"18",r:"3",key:"1xkwt0"}],["circle",{cx:"6",cy:"6",r:"3",key:"1lh9wr"}],["path",{d:"M6 21V9a9 9 0 0 0 9 9",key:"7kw0sc"}]]);/**
13 * @license lucide-react v0.462.0 - ISC
14 *
15 * This source code is licensed under the ISC license.
16 * See the LICENSE file in the root directory of this source tree.
17 */const Er=As("Puzzle",[["path",{d:"M15.39 4.39a1 1 0 0 0 1.68-.474 2.5 2.5 0 1 1 3.014 3.015 1 1 0 0 0-.474 1.68l1.683 1.682a2.414 2.414 0 0 1 0 3.414L19.61 15.39a1 1 0 0 1-1.68-.474 2.5 2.5 0 1 0-3.014 3.015 1 1 0 0 1 .474 1.68l-1.683 1.682a2.414 2.414 0 0 1-3.414 0L8.61 19.61a1 1 0 0 0-1.68.474 2.5 2.5 0 1 1-3.014-3.015 1 1 0 0 0 .474-1.68l-1.683-1.682a2.414 2.414 0 0 1 0-3.414L4.39 8.61a1 1 0 0 1 1.68.474 2.5 2.5 0 1 0 3.014-3.015 1 1 0 0 1-.474-1.68l1.683-1.682a2.414 2.414 0 0 1 3.414 0z",key:"w46dr5"}]]);/**
18 * @license lucide-react v0.462.0 - ISC
19 *
20 * This source code is licensed under the ISC license.
21 * See the LICENSE file in the root directory of this source tree.
22 */const Kt=As("RefreshCcw",[["path",{d:"M21 12a9 9 0 0 0-9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"14sxne"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}],["path",{d:"M3 12a9 9 0 0 0 9 9 9.75 9.75 0 0 0 6.74-2.74L21 16",key:"1hlbsb"}],["path",{d:"M16 16h5v5",key:"ccwih5"}]]);function Fr({clientId:s,clientName:i,summaryData:u,queries:n,pages:c,devices:x,siteUrl:o}){const{isViralTeam:C}=Ds(),{language:r}=Ye(),[m,v]=l.useState(""),[t,g]=l.useState(!1),[h,y]=l.useState(!1),[$,w]=l.useState(""),W=async()=>{g(!0),v("");try{const{data:N,error:F}=await A.functions.invoke("seo-ai-summary",{body:{summary_data:u,queries:n,pages:c,devices:x,client_name:i,client_id:s,site_url:o,language:r}}
22);if(F)throw F;if(N!=null&&N.error)throw new Error(N.error);v(N.summary)}catch(N){R.error("שגיאה ביצירת סיכום: "+N.message)}finally{g(!1)}};return l.useEffect(()=>{u&&!m&&!t&&W()},[u]),l.useEffect(()=>{u&&m&&W()},[r]),e.jsxs("div",{className:"panel overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-6 h-6 rounded-full gradient-brand flex items-center justify-center",children:e.jsx(_e,{className:"w-3 h-3 text-primary-foreground"})}),e.jsx("h3",{className:"text-sm font-semibold",children:"סיכום AI — SEO"})]}),e.jsx("div",{className:"flex items-center gap-1",children:m&&!h&&e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>{y(!0),w(m)},className:"p-1.5 rounded text-muted-foreground hover:text-foreground hover:bg-secondary transition-colors",title:"ערוך",children:e.jsx(us,{className:"w-3.5 h-3.5"})}),e.jsx("button",{onClick:W,className:"p-1.5 rounded text-muted-foreground hover:text-foreground hover:bg-secondary transition-colors",title:"חדש מחדש",children:e.jsx(Fe,{className:"w-3.5 h-3.5"})})]})})]}),e.jsx("div",{className:"px-4 py-4",children:t?e.jsxs("div",{className:"flex items-center gap-2 justify-center py-4",children:[e.jsx("div",{className:"w-4 h-4 border-2 border-primary border-t-transparent rounded-full animate-spin"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:"מייצר סיכום..."})]}):h?e.jsxs("div",{className:"space-y-2",children:[e.jsx("textarea",{value:$,onChange:N=>w(N.target.value),rows:6,className:"w-full bg-secondary rounded-md px-3 py-2 text-sm outline-none focus:ring-1 focus:ring-primary resize-none"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>{v($),y(!1)},className:"flex items-center gap-1 px-3 py-1 rounded text-xs gradient-brand text-primary-foreground",children:[e.jsx(hs,{className:"w-3 h-3"})," שמור"]}),e.jsxs("button",{onClick:()=>y(!1),className:"flex items-center gap-1 px-3 py-1 rounded text-xs bg-secondary text-muted-foreground",children:[e.jsx(Ls,{className:"w-3 h-3"})," ביטול"]})]})]}):m?e.jsx("p",{className:"text-sm leading-relaxed whitespace-pre-wrap",children:m}):e.jsx("p",{className:"text-xs text-muted-foreground text-center py-2",children:"הסיכום ייווצר אוטומטית..."})})]})}function Rr({clientId:s,clientName:i,seoData:u,siteUrl:n,onMetricFocus:c}){const{t:x,language:o}=Ye(),[C,r]=l.useState([]),[m,v]=l.useState(""),[t,g]=l.useState(!1),{scrollRef:h}=or([C]),y=l.useRef(null),{files:$,uploading:w,uploadFile:W,removeFile:N,clearFiles:F,getFileContext:j}=cr({clientId:s,chatSource:"seo",threadId:null});l.useEffect(()=>{r([]),v(""),c(null),F()},[s]);const k=async()=>{var E;const M=m.trim();if(!M||t)return;const L={role:"user",content:M},b=[...C,L];r(b),v(""),g(!0);try{const G=j(),{data:V,error:de}=await A.functions.invoke("seo-ai-chat",{body:{messages:b,client_id:s,client_name:i,seo_context:u,site_url:n,language:o,file_contents:G||void 0}});if(de)throw de;if(V!=null&&V.error)throw new Error(V.error);r(we=>[...we,{role:"assistant",content:V.reply}]),ir({userMessage:M,aiResponse:V.reply,clientId:s,chatSource:"seo"}),((E=V.metric_focus)==null?void 0:E.length)>0&&c(V.metric_focus)}catch(G){R.error(x("common.error")+": "+G.message)}finally{g(!1)}},K=[x("aiChat.suggestTopQuery"),x("aiChat.suggestTopClickPage"),x("aiChat.suggestAvgCTR"),x("aiChat.suggestPositionChange")];return e.jsxs("div",{className:"panel overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 border-b border-border",children:[e.jsx("div",{className:"w-6 h-6 rounded-full gradient-brand flex items-center justify-center",children:e.jsx(_e,{className:"w-3 h-3 text-primary-foreground"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold",children:x("aiChat.askAISEO")}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:x("aiChat.askAISEODesc")})]}),C.length>0&&e.jsx("button",{onClick:()=>{r([]),c(null)},className:"ms-auto text-[10px] text-muted-foreground hover:text-foreground transition-colors px-2 py-1 rounded bg-secondary",children:x("common.clearChat")})]}),e.jsx(dr,{clientId:s,chatSource:"seo",messages:C,setMessages:r,files:$,uploading:w,uploadFile:W,removeFile:N,clearFiles:F}),e.jsxs("div",{ref:h,className:"max-h-[300px] overflow-y-auto px-4 py-3 space-y-3",children:[C.length===0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:x("aiChat.greetSEO")}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:K.map(M=>e.jsx("button",{onClick:()=>{var L;v(M),(L=y.current)==null||L.focus()},className:"px-2.5 py-1 rounded-full bg-secondary text-[11px] text-muted-foreground hover:text-foreground hover:bg-secondary/80 transition-colors",children:M},M))})]}),C.map((M,L)=>{var b;return e.jsx("div",{className:`max-w-[90%] px-3 py-2 rounded-lg text-sm leading-relaxed ${M.role==="user"?"gradient-brand text-primary-foreground ms-auto":"bg-secondary text-foreground me-auto"}`,children:M.role==="assistant"?e.jsxs("div",{children:[e.jsx("div",{className:"ai-prose",children:e.jsx(Es,{children:M.content})}),e.jsxs("div",{className:"mt-1.5 flex items-center justify-end gap-1",children:[e.jsx(nr,{chatSource:"seo-chat",clientId:s,userMessage:((b=C[L-1])==null?void 0:b.content)||"",aiResponse:M.content}),e.jsx(lr,{context:M.content,size:"sm"})]})]}):M.content},L)}),t&&e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx(ie,{className:"w-3.5 h-3.5 animate-spin"}),x("common.analyzing")]})]}),e.jsx("div",{className:"px-4 py-3 border-t border-border",children:e.jsxs("div",{className:"flex items-center gap-2 bg-secondary rounded-lg px-3 py-2",children:[e.jsx(Ta,{onTranscript:M=>v(M)}),e.jsx("input",{ref:y,value:m,onChange:M=>v(M.target.value),onKeyDown:M=>
22M.key==="Enter"&&k(),placeholder:x("aiChat.placeholderSEO"),className:"flex-1 bg-transparent text-sm placeholder:text-muted-foreground outline-none",disabled:t}),e.jsx("button",{onClick:k,disabled:t||!m.trim(),className:"text-primary hover:text-primary/80 transition-colors disabled:opacity-40",children:e.jsx(sa,{className:"w-4 h-4"})})]})})]})}const Ut=["hsl(var(--primary))","hsl(142 70% 45%)","hsl(262 83% 58%)","hsl(25 95% 55%)","hsl(38 92% 50%)","hsl(0 72% 51%)","hsl(180 60% 45%)","hsl(320 70% 50%)"];function Pr({clientId:s,queries:i,prevQueries:u=[]}){const{user:n}=Ds(),[c,x]=l.useState([]),[o,C]=l.useState(""),[r,m]=l.useState(!1),[v,t]=l.useState(!1),[g,h]=l.useState(!1),[y,$]=l.useState([]),[w,W]=l.useState(!1),N=async()=>{m(!0);const{data:b,error:E}=await A.from("seo_tracked_keywords").select("*").eq("client_id",s).order("created_at",{ascending:!0});E||x(b||[]),m(!1)},F=async()=>{W(!0);try{const b=new Date(Date.now()-2592e6).toISOString().split("T")[0],{data:E}=await A.from("seo_rank_history").select("keyword, date, position").eq("client_id",s).gte("date",b).order("date",{ascending:!0});if(E&&E.length>0){const G=new Map;for(const V of E)G.has(V.date)||G.set(V.date,{date:V.date}),G.get(V.date)[V.keyword]=V.position;$(Array.from(G.values()))}}catch{}finally{W(!1)}};l.useEffect(()=>{N()},[s]),l.useEffect(()=>{g&&y.length===0&&F()},[g]);const j=async()=>{const b=o.trim().toLowerCase();if(!b||!n)return;if(c.some(G=>G.keyword===b)){R.error("מילת המפתח כבר קיימת");return}t(!0);const{error:E}=await A.from("seo_tracked_keywords").insert({client_id:s,keyword:b,created_by:n.id});E?R.error("שגיאה בהוספת מילת מפתח"):(C(""),N(),R.success(`נוסף: "${b}"`)),t(!1)},k=async(b,E)=>{const{error:G}=await A.from("seo_tracked_keywords").delete().eq("id",b);G||(x(V=>V.filter(de=>de.id!==b)),R.success(`הוסר: "${E}"`))},K=c.map(b=>{const E=i.find(V=>V.query.toLowerCase()===b.keyword),G=u.find(V=>V.query.toLowerCase()===b.keyword);return{keyword:b.keyword,position:(E==null?void 0:E.position)??b.latest_position??null,clicks:(E==null?void 0:E.clicks)??0,impressions:(E==null?void 0:E.impressions)??0,ctr:(E==null?void 0:E.ctr)??0,prevPosition:(G==null?void 0:G.position)??b.previous_position??null,bestPosition:b.best_position??null}}),M=(b,E)=>b===null||E===null?null:E-b,L=c.map(b=>b.keyword);return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{value:o,onChange:b=>C(b.target.value),onKeyDown:b=>b.key==="Enter"&&j(),placeholder:"הוסף מילת מפתח למעקב...",className:"flex-1 h-9 bg-secondary border border-border rounded-md px-3 text-sm focus:outline-none focus:ring-1 focus:ring-primary placeholder:text-muted-foreground",dir:"ltr"}),e.jsxs("button",{onClick:j,disabled:v||!o.trim(),className:"flex items-center gap-1.5 px-3 h-9 rounded-md bg-primary text-primary-foreground text-sm font-medium disabled:opacity-50 hover:bg-primary/90 transition-colors",children:[v?e.jsx(ie,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(ta,{className:"w-3.5 h-3.5"}),"הוסף"]}),c.length>0&&e.jsxs("button",{onClick:()=>h(!g),className:`flex items-center gap-1.5 px-3 h-9 rounded-md text-sm font-medium transition-colors ${g?"bg-primary text-primary-foreground":"bg-secondary text-foreground hover:bg-secondary/80"}`,children:[e.jsx(Zs,{className:"w-3.5 h-3.5"}),"גרף"]})]}),g&&e.jsxs("div",{className:"panel p-4 space-y-2",children:[e.jsx("h3",{className:"text-xs font-semibold text-muted-foreground",children:"מגמת מיקומים — 30 ימים אחרונים"}),w?e.jsx("div",{className:"flex justify-center py-8",children:e.jsx(ie,{className:"w-5 h-5 animate-spin text-muted-foreground"})}):y.length===0?e.jsx("p",{className:"text-xs text-muted-foreground text-center py-6",children:"אין נתוני היסטוריה עדיין. הנתונים ייאספו אוטומטית מדי יום."}):e.jsx("div",{className:"h-52",children:e.jsx(Te,{width:"100%",height:"100%",children:e.jsxs(_a,{data:y,children:[e.jsx(es,{strokeDasharray:"3 3",stroke:"hsl(var(--border))"}),e.jsx(ss,{dataKey:"date",tickFormatter:b=>Ue(new Date(b),"dd/MM"),tick:{fontSize:10,fill:"hsl(var(--muted-foreground))"}}),e.jsx(He,{reversed:!0,domain:[1,"auto"],tick:{fontSize:10,fill:"hsl(var(--muted-foreground))"},label:{value:"Position",angle:-90,position:"insideLeft",style:{fontSize:10,fill:"hsl(var(--muted-foreground))"}}}),e.jsx(We,{contentStyle:{fontSize:11,background:"hsl(var(--card))",border:"1px solid hsl(var(--border))",borderRadius:8,color:"hsl(var(--foreground))"}}),L.map((b,E)=>
22e.jsx(Ca,{type:"monotone",dataKey:b,stroke:Ut[E%Ut.length],strokeWidth:2,dot:{r:2},connectNulls:!0,name:b},b))]})})})]}),r?e.jsx("div",{className:"flex justify-center py-8",children:e.jsx(ie,{className:"w-5 h-5 animate-spin text-muted-foreground"})}):c.length===0?e.jsxs("div",{className:"text-center py-10 text-muted-foreground text-sm",children:[e.jsx("p",{children:"טרם הוגדרו מילות מפתח למעקב."}),e.jsx("p",{className:"text-xs mt-1",children:"הוסף מילות מפתח אסטרטגיות כדי לעקוב אחרי המיקום שלהן."})]}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-border text-muted-foreground",children:[e.jsx("th",{className:"text-right px-4 py-2.5 font-medium",children:"מילת מפתח"}),e.jsx("th",{className:"text-center px-3 py-2.5 font-medium",children:"מיקום"}),e.jsx("th",{className:"text-center px-3 py-2.5 font-medium",children:"שינוי"}),e.jsx("th",{className:"text-center px-3 py-2.5 font-medium",children:"שיא"}),e.jsx("th",{className:"text-left px-3 py-2.5 font-medium",children:"קליקים"}),e.jsx("th",{className:"text-left px-3 py-2.5 font-medium",children:"חשיפות"}),e.jsx("th",{className:"text-left px-3 py-2.5 font-medium",children:"CTR"}),e.jsx("th",{className:"px-3 py-2.5"})]})}),e.jsx("tbody",{className:"divide-y divide-border",children:K.map(b=>{const E=M(b.position,b.prevPosition);return e.jsxs("tr",{className:"hover:bg-secondary/30 transition-colors",children:[e.jsx("td",{className:"px-4 py-2.5 font-medium",dir:"ltr",children:b.keyword}),e.jsx("td",{className:"px-3 py-2.5 text-center",children:b.position!==null?e.jsx("span",{className:`font-bold font-data text-sm ${b.position<=3?"text-success":b.position<=10?"text-warning":"text-muted-foreground"}`,children:b.position.toFixed(1)}):e.jsx("span",{className:"text-muted-foreground",children:"—"})}),e.jsx("td",{className:"px-3 py-2.5 text-center",children:E!==null?e.jsxs("span",{className:`flex items-center justify-center gap-0.5 text-[11px] font-medium ${E>0?"text-success":E<0?"text-destructive":"text-muted-foreground"}`,children:[E>0?e.jsx(ge,{className:"w-3 h-3"}):E<0?e.jsx(Ae,{className:"w-3 h-3"}):e.jsx(tt,{className:"w-3 h-3"}),E!==0?Math.abs(E).toFixed(1):"±0"]}):e.jsx("span",{className:"text-muted-foreground text-[10px]",children:"חדש"})}),e.jsx("td",{className:"px-3 py-2.5 text-center",children:b.bestPosition!==null?e.jsx("span",{className:"font-data text-[11px] text-success",children:b.bestPosition.toFixed(1)}):e.jsx("span",{className:"text-muted-foreground",children:"—"})}),e.jsx("td",{className:"px-3 py-2.5 font-data",children:b.clicks}),e.jsx("td",{className:"px-3 py-2.5 font-data",children:b.impressions.toLocaleString()}),e.jsxs("td",{className:"px-3 py-2.5 font-data",children:[(b.ctr*100).toFixed(2),"%"]}),e.jsx("td",{className:"px-3 py-2.5",children:e.jsx("button",{onClick:()=>{var G;return k((G=c.find(V=>V.keyword===b.keyword))==null?void 0:G.id,b.keyword)},className:"p-1 rounded hover:bg-destructive/10 text-muted-foreground hover:text-destructive transition-colors",children:e.jsx(Je,{className:"w-3.5 h-3.5"})})})]},b.keyword)})})]})}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"* המיקום מתעדכן אוטומטית מדי יום מנתוני Search Console. לדיוק מירבי בחר תקופה של 7 ימים."})]})}function Or({queries:s}){const i=l.useMemo(()=>s.filter(c=>c.position>=8&&c.position<=25).sort((c,x)=>x.impressions-c.impressions),[s]),u=c=>c<=10?"bg-warning/10 text-warning":c<=15?"bg-orange-500/10 text-orange-400":"bg-secondary text-muted-foreground",n=c=>{const x=(26-c.position)/18,o=Math.min(c.impressions/5e3,1);return Math.round((x*.6+o*.4)*100)};return i.length===0?e.jsxs("div",{className:"text-center py-10 text-muted-foreground text-sm",children:[e.jsx(Re,{className:"w-8 h-8 mx-auto mb-3 opacity-30"}),e.jsx("p",{children:"אין שאילתות בטווח מיקומים 8–25 בתקופה זו."})]}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground bg-warning/5 border border-warning/20 rounded-md px-3 py-2",children:[e.jsx(Re,{className:"w-4 h-4 text-warning flex-shrink-0"}),e.jsxs("span",{children:["נמצאו ",e.jsxs("strong",{className:"text-foreground",children:[i.length," שאילתות"]})," במיקומים 8–25 שמחכות לאופטימיזציה קלה כדי לעלות לדף 1."]})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-border text-muted-foreground",children:[e.jsx("th",{className:"text-right px-4 py-2.5 font-medium",children:"שאילתה"}),e.jsx("th",{className:"text-center px-3 py-2.5 font-medium",children:"מיקום"}),e.jsx("th",{className:"text-left px-3 py-2.5 font-medium",children:"חשיפות"}),e.jsx("th",{className:"text-left px-3 py-2.5 font-medium",children:"קליקים"}),e.jsx("th",{className:"text-left px-3 py-2.5 font-medium",children:"CTR"}),e.jsx("th",{className:"text-center px-3 py-2.5 font-medium",children:"פוטנציאל"})]})}),e.jsx("tbody",{className:"divide-y divide-border",children:i.map((c,x)=>{const o=n(c);return e.jsxs("tr",{className:"hover:bg-secondary/30 transition-colors",children:[e.jsx("td",{className:"px-4 py-2.5 font-medium max-w-[240px]",dir:"ltr",children:e.jsx("span",{className:"truncate block",children:c.query})}),e.jsx("td",{className:"px-3 py-2.5 text-center",children:e.jsxs("span",{className:`inline-flex px-2 py-0.5 rounded-full text-[10px] font-bold ${u(c.position)}`,children:["#",c.position.toFixed(0)]})}),e.jsx("td",{className:"px-3 py-2.5 font-data",children:c.impressions.toLocaleStr
22ing()}),e.jsx("td",{className:"px-3 py-2.5 font-data",children:c.clicks}),e.jsxs("td",{className:"px-3 py-2.5 font-data",children:[(c.ctr*100).toFixed(2),"%"]}),e.jsx("td",{className:"px-3 py-2.5 text-center",children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"flex-1 bg-secondary rounded-full h-1.5 min-w-[40px]",children:e.jsx("div",{className:"h-1.5 rounded-full bg-warning",style:{width:`${o}%`}})}),e.jsx("span",{className:"text-[10px] font-medium text-warning w-6",children:o})]})})]},x)})})]})}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"* ממוין לפי נפח חשיפות. ציון פוטנציאל מחושב לפי מיקום + חשיפות."})]})}function Ir({pages:s,prevPages:i=[]}){const u=l.useMemo(()=>i.length===0?[]:s.map(c=>{const x=i.find(C=>C.page===c.page);if(!x||x.clicks===0)return null;const o=(c.clicks-x.clicks)/x.clicks*100;return o>-30?null:{page:c.page,currentClicks:c.clicks,prevClicks:x.clicks,change:o,impressions:c.impressions,position:c.position}}).filter(Boolean).sort((c,x)=>c.change-x.change),[s,i]),n=c=>{try{return new URL(c).pathname}catch{return c}};return i.length===0?e.jsxs("div",{className:"text-center py-10 text-muted-foreground text-sm space-y-2",children:[e.jsx(Ae,{className:"w-8 h-8 mx-auto opacity-30"}),e.jsx("p",{children:"נתוני Content Decay זמינים בהשוואה לתקופה קודמת."}),e.jsx("p",{className:"text-xs",children:"בחר תקופה ארוכה יותר (28 ימים+) כדי לראות ירידות."})]}):u.length===0?e.jsxs("div",{className:"text-center py-10 text-muted-foreground text-sm",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-success/10 flex items-center justify-center mx-auto mb-3",children:e.jsx(Ae,{className:"w-5 h-5 text-success"})}),e.jsx("p",{children:"מצוין! אין דפים שאיבדו 30%+ מהטראפיק בתקופה זו."})]}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground bg-destructive/5 border border-destructive/20 rounded-md px-3 py-2",children:[e.jsx(qe,{className:"w-4 h-4 text-destructive flex-shrink-0"}),e.jsxs("span",{children:["נמצאו ",e.jsxs("strong",{className:"text-foreground",children:[u.length," דפים"]})," שאיבדו 30%+ מהקליקים — שקול לרענן את התוכן שלהם."]})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-border text-muted-foreground",children:[e.jsx("th",{className:"text-right px-4 py-2.5 font-medium",children:"דף"}),e.jsx("th",{className:"text-left px-3 py-2.5 font-medium",children:"קליקים עכשיו"}),e.jsx("th",{className:"text-left px-3 py-2.5 font-medium",children:"קליקים קודם"}),e.jsx("th",{className:"text-center px-3 py-2.5 font-medium",children:"ירידה"}),e.jsx("th",{className:"text-left px-3 py-2.5 font-medium",children:"מיקום"})]})}),e.jsx("tbody",{className:"divide-y divide-border",children:u.map((c,x)=>{const o=c.change<=-50;return e.jsxs("tr",{className:"hover:bg-secondary/30 transition-colors",children:[e.jsx("td",{className:"px-4 py-2.5 max-w-[280px]",children:e.jsxs("a",{href:c.page,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 text-primary hover:underline truncate",title:c.page,children:[e.jsx("span",{className:"truncate",children:n(c.page)}),e.jsx(Qe,{className:"w-3 h-3 flex-shrink-0"})]})}),e.jsx("td",{className:"px-3 py-2.5 font-data",children:c.currentClicks}),e.jsx("td",{className:"px-3 py-2.5 font-data text-muted-foreground",children:c.prevClicks}),e.jsx("td",{className:"px-3 py-2.5 text-center",children:e.jsxs("span",{className:`inline-flex items-center gap-0.5 px-2 py-0.5 rounded-full text-[10px] font-bold ${o?"bg-destructive/20 text-destructive":"bg-warning/15 text-warning"}`,children:[e.jsx(Ae,{className:"w-2.5 h-2.5"}),Math.abs(c.change).toFixed(0),"%"]})}),e.jsx("td",{className:"px-3 py-2.5 font-data text-muted-foreground",children:c.position.toFixed(1)})]},x)})})]})}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"* ירידה חמורה (50%+) מסומנת באדום. ירידה 30–50% מסומנת בכתום."})]})}function zr({clientId:s,clientName:i,queries:u,pages:n}){const[c,x]=l.useState([]),[o,C]=l.useState(!1),[r,m]=l.useState(!1),[v,t]=l.useState(""),g=async()=>
22{if(!(u.length===0||n.length===0)){C(!0),t("");try{const $=u.slice(0,30).map(F=>({q:F.query,pos:F.position.toFixed(1),imp:F.impressions})),w=n.slice(0,30).map(F=>F.page),{data:W,error:N}=await A.functions.invoke("seo-cannibalization",{body:{client_id:s,client_name:i,queries:$,pages:w}});N||W!=null&&W.error?t("שגיאה בניתוח. נסה שוב."):(x((W==null?void 0:W.results)||[]),m(!0))}catch{t("שגיאה בניתוח קניבליזציה")}finally{C(!1)}}},h={Merge:"bg-primary/10 text-primary",301:"bg-destructive/10 text-destructive",Canonical:"bg-warning/10 text-warning",Differentiate:"bg-success/10 text-success"},y=$=>{try{return new URL($).pathname}catch{return $}};return!r&&!o?e.jsxs("div",{className:"text-center py-10 space-y-4",children:[e.jsx(ps,{className:"w-10 h-10 mx-auto text-muted-foreground opacity-40"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:"ניתוח Keyword Cannibalization"}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["הבינה תנתח את ",Math.min(u.length,30)," השאילתות ו-",Math.min(n.length,30)," הדפים הפעילים ותאתר מקרים בהם מספר עמודים מתחרים על אותה מילת מפתח."]})]}),e.jsxs("button",{onClick:g,disabled:u.length===0,className:"inline-flex items-center gap-2 px-4 py-2 rounded-md bg-primary text-primary-foreground text-sm font-medium hover:bg-primary/90 transition-colors disabled:opacity-50",children:[e.jsx(ps,{className:"w-4 h-4"}),"הפעל ניתוח"]})]}):o?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 gap-3",children:[e.jsx(ie,{className:"w-6 h-6 animate-spin text-primary"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"הבינה מנתחת קניבליזציה..."})]}):v?e.jsxs("div",{className:"text-center py-10 space-y-3",children:[e.jsx(Ve,{className:"w-8 h-8 mx-auto text-destructive"}),e.jsx("p",{className:"text-sm text-destructive",children:v}),e.jsxs("button",{onClick:g,className:"flex items-center gap-1.5 mx-auto px-3 py-1.5 rounded-md bg-secondary text-sm hover:bg-accent transition-colors",children:[e.jsx(Fe,{className:"w-3.5 h-3.5"})," נסה שוב"]})]}):c.length===0?e.jsxs("div",{className:"text-center py-10 space-y-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-success/10 flex items-center justify-center mx-auto",children:e.jsx(ps,{className:"w-5 h-5 text-success"})}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"לא זוהתה קניבליזציה משמעותית."}),e.jsxs("button",{onClick:()=>{m(!1),x([])},className:"flex items-center gap-1.5 mx-auto px-3 py-1.5 rounded-md bg-secondary text-xs hover:bg-accent transition-colors",children:[e.jsx(Fe,{className:"w-3 h-3"})," נתח שוב"]})]}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground bg-warning/5 border border-warning/20 rounded-md px-3 py-2 flex-1",children:[e.jsx(Ve,{className:"w-4 h-4 text-warning flex-shrink-0"}),e.jsxs("span",{children:["זוהו ",e.jsxs("strong",{className:"text-foreground",children:[c.length," קונפליקטים"]})," אפשריים — עמודים המתחרים על אותן מילות מפתח."]})]}),e.jsxs("button",{onClick:()=>{m(!1),x([])},className:"flex items-center gap-1 px-2.5 py-1.5 rounded-md bg-secondary text-xs hover:bg-accent transition-colors ml-2 flex-shrink-0",children:[e.jsx(Fe,{className:"w-3 h-3"})," נתח שוב"]})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-border text-muted-foreground",children:[e.jsx("th",{className:"text-right px-4 py-2.5 font-medium",children:"מילת מפתח"}),e.jsx("th",{className:"text-right px-3 py-2.5 font-medium",children:"עמוד 1"}),e.jsx("th",{className:"text-right px-3 py-2.5 font-medium",children:"עמוד 2"}),e.jsx("th",{className:"text-center px-3 py-2.5 font-medium",children:"המלצה"}),e.jsx("th",{className:"text-right px-3 py-2.5 font-medium",children:"סיבה"})]})}),e.jsx("tbody",{className:"divide-y divide-border",children:c.map(($,w)=>e.jsxs("tr",{className:"hover:bg-secondary/30 transition-colors",children:[e.jsx("td",{className:"px-4 py-2.5 font-medium",dir:"ltr",children:$.keyword}),e.jsx("td",{className:"px-3 py-2.5 max-w-[160px]",children:e.jsxs("a",{href:$.page1,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 text-primary hover:underline truncate",children:[e.jsx("span",{className:"truncate",title:$.page1,children:y($.page1)}),e.jsx(Qe,{className:"w-2.5 h-2.5 flex-shrink-0"})]})}),e.jsx("td",{className:"px-3 py-2.5 max-w-[160px]",children:e.jsxs("a",{href:$.page2,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 text-primary hover:underline truncate",children:[e.jsx("span",{className:"truncate",title:$.page2,children:y($.page2)}),e.jsx(Qe,{className:"w-2.5 h-2.5 flex-shrink-0"})]})}),e.jsx("td",{className:"px-3 py-2.5 text-center",children:e.jsx("span",{className:`inline-flex px-2 py-0.5 rounded-full text-[10px] font-bold ${h[$.recommendation]||"bg-secondary text-muted-foreground"}`,children:$.recommendation})}),e.jsx("td",{className:"px-3 py-2.5 text-muted-foreground max-w-[200px]",children:e.jsx("span",{className:"truncate block",title:$.reason,children:$.reason})})]},w))})]})}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"* ניתוח מבוסס AI — יש לאמת ידנית לפני ביצוע פעולות. Merge = מיזוג תוכן, 301 = הפניה, Canonical = תג canonical."})]})}const Js={chatgpt:{label:"ChatGPT",color:"hsl(142 70% 45%)",icon:"💬"},gemini:{label:"Gemini",color:"hsl(217 91% 60%)",icon:"✦"},perplexity:{label:"Perplexity",color:"hsl(262 83% 58%)",icon:"⊕"},"ai overview":{label:"AI Overview",color:"hsl(25 95% 55%)",icon:"🔍"},claude:{label:"Claude",color:"hsl(30 85% 55%)",icon:"◈"}},Br={positive:"text-success",neutral:"text-muted-foreground",negative:"text-destructive",not_mentioned:"text-muted-foreground"};function Gr({score:s}){const i=s>=70?"hsl(142 70% 45%)":s>=40?"hsl(38 92% 50%)":"hsl(0 72% 51%)",u=s>=70?"High":s>=40?"Medium":"Low",n=52;return e.jsxs("div",{className:"flex flex-col items-center gap-1",children:[e.jsxs("svg",{width:130,height:75,viewB
22ox:"0 0 130 75",children:[e.jsx("path",{d:`M 14 65 A ${n} ${n} 0 0 1 116 65`,fill:"none",stroke:"hsl(var(--border))",strokeWidth:10,strokeLinecap:"round"}),e.jsx("path",{d:`M 14 65 A ${n} ${n} 0 0 1 116 65`,fill:"none",stroke:i,strokeWidth:10,strokeLinecap:"round",strokeDasharray:`${s/100*(Math.PI*n)} ${Math.PI*n}`,style:{transition:"stroke-dasharray 0.8s ease"}}),e.jsx("text",{x:"65",y:"60",textAnchor:"middle",fontSize:"22",fontWeight:"bold",fill:"currentColor",className:"font-data",children:s}),e.jsx("text",{x:"65",y:"73",textAnchor:"middle",fontSize:"9",fill:"hsl(var(--muted-foreground))",children:"/100"})]}),e.jsxs("span",{className:"text-xs font-semibold",style:{color:i},children:[u," AI Visibility"]})]})}function Kr({result:s}){const[i,u]=l.useState(!1),n=Js[s.engine.toLowerCase()]||{label:s.engine,icon:"🤖"};return e.jsxs("div",{className:`border rounded-lg overflow-hidden transition-all ${s.mentioned?"border-border":"border-border/40 opacity-60"}`,children:[e.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 cursor-pointer hover:bg-secondary/30 transition-colors",onClick:()=>u(c=>!c),children:[e.jsx("span",{className:"text-base",children:n.icon}),e.jsx("span",{className:"text-sm font-semibold flex-1",children:n.label}),e.jsxs("div",{className:"flex items-center gap-2",children:[s.mentioned?e.jsx("span",{className:"px-2 py-0.5 rounded-full text-[10px] font-semibold bg-success/15 text-success",children:"Mentioned"}):e.jsx("span",{className:"px-2 py-0.5 rounded-full text-[10px] font-semibold bg-muted text-muted-foreground",children:"Not Mentioned"}),e.jsx("span",{className:`text-[10px] font-medium ${Br[s.sentiment]}`,children:s.sentiment!=="not_mentioned"&&s.sentiment}),e.jsxs("span",{className:"text-[10px] text-muted-foreground",children:[s.sourceCount," sources"]})]}),i?e.jsx(et,{className:"w-3.5 h-3.5 text-muted-foreground"}):e.jsx(gs,{className:"w-3.5 h-3.5 text-muted-foreground"})]}),i&&s.snippet&&e.jsxs("div",{className:"px-4 pb-3 space-y-2",children:[e.jsxs("p",{className:"text-[10px] text-muted-foreground font-medium",children:["Prompt: ",s.prompt]}),e.jsxs("div",{className:"bg-secondary/40 rounded p-3 text-xs text-foreground leading-relaxed italic",children:['"',s.snippet,'"']})]})]})}function Ur({clientId:s,clientName:i,websiteUrl:u}){var t,g;const[n,c]=l.useState(!1),[x,o]=l.useState(null),[C,r]=l.useState(null);l.useEffect(()=>{if(!s)return;(async()=>{const{data:y}=await A.from("client_integrations").select("config, last_sync_at").eq("client_id",s).eq("integration_name","geo_ai_visibility").maybeSingle();if(y!=null&&y.config){const $=y.config;r($),o($)}})()},[s]);const m=async()=>{if(s){c(!0);try{const{data:h,error:y}=await A.functions.invoke("geo-ai-scan",{body:{client_id:s,client_name:i,website_url:u}});if(y||h!=null&&h.error)throw new Error((h==null?void 0:h.error)||(y==null?void 0:y.message));o(h),r(h),await A.from("client_integrations").upsert({client_id:s,integration_name:"geo_ai_visibility",status:"active",config:h,last_sync_at:new Date().toISOString()},{onConflict:"client_id,integration_name"}),R.success("GEO scan הושלם")}catch(h){R.error("שגיאה בסריקת GEO: "+h.message)}finally{c(!1)}}},v=[{month:"Sep",score:42},{month:"Oct",score:38},{month:"Nov",score:45},{month:"Dec",score:51},{month:"Jan",score:58},{month:"Feb",score:(x==null?void 0:x.visibilityScore)??62}];return e.jsxs("div",{className:"space-y-4 p-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ws,{className:"w-4 h-4 text-primary"}),e.jsx("h3",{className:"text-sm font-bold",children:"GEO — AI Visibility"}),e.jsxs("div",{className:"flex items-center gap-1 px-2 py-0.5 rounded-full bg-primary/10 text-[10px] font-medium text-primary",children:[e.jsx(_e,{className:"w-3 h-3"}),"Generative Engine Optimization"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[(x==null?void 0:x.scannedAt)&&e.jsxs("span",{className:"text-[10px] text-muted-foreground",children:["נסרק: ",new Date(x.scannedAt).toLocaleDateString("he-IL")]}),e.jsxs("button",{onClick:m,disabled:n,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-primary text-primary-foreground text-xs font-medium hover:bg-primary/90 disabled:opacity-50 transition-colors",children:[e.jsx(Fe,{className:`w-3 h-3 ${n?"animate-spin":""}`}),n?"סורק...":"סרוק עכשיו"]})]})]}),!x&&!n&&e.jsxs("div",{className:"panel p-6 text-center space-y-3",children:[e.jsx(Ws,{className:"w-10 h-10 text-primary mx-auto opacity-60"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold",children:"בדוק איפה המותג שלך מוזכר בתשובות AI"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"המערכת שולחת שאילתות מייצגות ל-ChatGPT, Gemini, Perplexity ועוד ובודקת האם המותג מוזכר, מה הסנטימנט ואיך לשפר את הנוכחות בתשובות הבינה המלאכותית."})]}),e.jsxs("button",{onClick:m,disabled:n,className:"inline-flex items-center gap-2 px-4 py-2 rounded-lg bg-primary text-primary-foreground text-sm font-medium hover:bg-primary/90 disabled:opacity-50 transition-colors",children:[e.jsx(_e,{className:"w-4 h-4"}),n?"סורק...":"הפעל סריקה ראשונה"]})]}),n&&e.jsxs("div",{className:"panel p-8 text-center space-y-3",children:[e.jsx("div",{className:"w-10 h-10 mx-auto rounded-full border-2 border-primary border-t-transparent animate-spin"}),e.jsx("p",{className:"text-sm font-medium",children:"סורק נוכחות ב-AI Engines..."}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"בודק ChatGPT, Gemini, Perplexity ו-AI Overview"})]}),x&&!n&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsxs("div",{className:"panel p-5 flex flex-col items-center justify-center",children:[e.jsx(Gr,{score:x.visibilityScore}),e.jsx("div",{className:"mt-3 text-center space-y-1",children:e.jsxs("p",{className:"text-[10px] text-muted-foreground",children:[e.jsx("span",{className:"font-semibold text-foreground",children:x.mentionedIn})," מתוך ",x.totalEngines," engines"]})})]}),e.jsxs("div",{className:"panel p-4 space-y-2.5",children:[e.jsx("p",{className:"text-xs font-semibold text-muted-foreground mb-3",children:"Mentions per Engine"}),x.engines.map(h=>{const y=Js[h.engine.toLowerCase()]||{label:h.engine,color:"hsl(var(--primary))",icon:"🤖"};return e.jsxs("div",{className:"flex items-center gap-2 text-xs",children:[e.jsx("span",{className:"w-4 text-center",children:y.icon}),e.jsx("span",{className:"w-24 text-muted-foreground",children:y.label}),e.jsx("div",{className:"flex-1 h-1.5 bg-secondary rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full transition-all",style:{width:h.mentioned?"100%":"
220%",backgroundColor:h.mentioned?y.color:"transparent"}})}),h.mentioned?e.jsx("span",{className:"text-[10px] text-success font-medium",children:"✓"}):e.jsx("span",{className:"text-[10px] text-muted-foreground",children:"–"})]},h.engine)})]}),e.jsxs("div",{className:"panel p-4",children:[e.jsx("p",{className:"text-xs font-semibold text-muted-foreground mb-3",children:"AI Visibility Trend"}),e.jsx(Te,{width:"100%",height:100,children:e.jsxs(fs,{data:v,margin:{top:4,right:4,left:-20,bottom:0},children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"geoGrad",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"5%",stopColor:"hsl(var(--primary))",stopOpacity:.3}),e.jsx("stop",{offset:"95%",stopColor:"hsl(var(--primary))",stopOpacity:0})]})}),e.jsx(es,{strokeDasharray:"3 3",stroke:"hsl(var(--border))"}),e.jsx(ss,{dataKey:"month",tick:{fontSize:9}}),e.jsx(He,{domain:[0,100],tick:{fontSize:9}}),e.jsx(We,{contentStyle:{fontSize:11}}),e.jsx(ls,{type:"monotone",dataKey:"score",stroke:"hsl(var(--primary))",fill:"url(#geoGrad)",strokeWidth:2})]})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("h4",{className:"text-xs font-semibold text-muted-foreground flex items-center gap-1",children:[e.jsx(Ze,{className:"w-3.5 h-3.5"})," תוצאות לפי Engine"]}),e.jsx("div",{className:"space-y-2",children:x.engines.map(h=>e.jsx(Kr,{result:h},h.engine))})]}),((t=x.topTopics)==null?void 0:t.length)>0&&e.jsxs("div",{className:"panel p-4",children:[e.jsxs("h4",{className:"text-xs font-semibold mb-3 flex items-center gap-1",children:[e.jsx(Aa,{className:"w-3.5 h-3.5 text-primary"}),"Topics & שאילתות מובילות"]}),e.jsx("div",{className:"space-y-2",children:x.topTopics.map((h,y)=>e.jsxs("div",{className:"flex items-center gap-3 text-xs",children:[e.jsx("span",{className:"flex-1 font-medium",children:h.topic}),e.jsx("div",{className:"flex gap-1",children:h.engines.map($=>{const w=Js[$.toLowerCase()];return e.jsxs("span",{className:"px-1.5 py-0.5 rounded bg-secondary text-muted-foreground text-[10px]",children:[(w==null?void 0:w.icon)||"🤖"," ",(w==null?void 0:w.label)||$]},$)})}),h.mentioned?e.jsx("span",{className:"text-success text-[10px] font-semibold",children:"Mentioned"}):e.jsx("span",{className:"text-muted-foreground text-[10px]",children:"Not seen"})]},y))})]}),((g=x.recommendations)==null?void 0:g.length)>0&&e.jsxs("div",{className:"panel p-4 border-primary/20 bg-primary/5",children:[e.jsxs("h4",{className:"text-xs font-semibold text-primary mb-3 flex items-center gap-1",children:[e.jsx(aa,{className:"w-3.5 h-3.5"}),"המלצות לשיפור AI Visibility"]}),e.jsx("ul",{className:"space-y-2",children:x.recommendations.map((h,y)=>e.jsxs("li",{className:"flex items-start gap-2 text-xs",children:[e.jsx("span",{className:"text-primary mt-0.5",children:"→"}),e.jsx("span",{children:h})]},y))})]})]})]})}const Ht=["hsl(152, 60%, 50%)","hsl(210, 60%, 55%)","hsl(28, 92%, 58%)","hsl(280, 60%, 60%)"];function ys({label:s,value:i,sub:u,icon:n,trend:c}){return e.jsxs("div",{className:"panel p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-muted-foreground",children:n}),c&&e.jsx("span",{className:c==="up"?"text-success":c==="down"?"text-destructive":"text-muted-foreground",children:c==="up"?e.jsx(ge,{className:"w-3.5 h-3.5"}):c==="down"?e.jsx(Ae,{className:"w-3.5 h-3.5"}):e.jsx(tt,{className:"w-3.5 h-3.5"})})]}),e.jsx("p",{className:"text-xl font-bold font-data",children:i}),e.jsx("p",{className:"text-[11px] text-muted-foreground mt-0.5",children:s}),u&&e.jsx("p",{className:"text-[10px] text-muted-foreground/70 mt-0.5",children:u})]})}function Hr({clientId:s,clientName:i,websiteUrl:u}){const[n,c]=l.useState(null),[x,o]=l.useState(!1),[C,r]=l.useState(!1),m=async()=>{const{data:h}=await A.from("client_integrations").select("config, last_sync_at").eq("client_id",s).eq("integration_name","backlinks_data").maybeSingle();h!=null&&h.config&&c({...h.config,cached_at:h.last_sync_at||void 0})};l.useEffect(()=>{c(null),o(!0),m().finally(()=>o(!1))},[s]);const v=async()=>
22{if(!u&&!i){R.error("לא הוגדר URL לאתר הלקוח");return}r(!0),R.info("סורק backlinks...");const{data:h,error:y}=await A.functions.invoke("backlinks-scan",{body:{client_id:s,client_name:i,website_url:u}});y||h!=null&&h.error?R.error((h==null?void 0:h.error)||(y==null?void 0:y.message)||"שגיאה בסריקה"):h&&(c(h),R.success("סריקת Backlinks הושלמה!")),r(!1)},t=h=>h==="dofollow"?"text-success":h==="nofollow"?"text-muted-foreground":"text-warning",g=h=>h>=70?e.jsx("span",{className:"px-1.5 py-0.5 rounded text-[10px] bg-success/15 text-success font-medium",children:h}):h>=40?e.jsx("span",{className:"px-1.5 py-0.5 rounded text-[10px] bg-warning/15 text-warning font-medium",children:h}):e.jsx("span",{className:"px-1.5 py-0.5 rounded text-[10px] bg-destructive/10 text-destructive font-medium",children:h});return e.jsxs("div",{className:"space-y-4 p-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(is,{className:"w-4 h-4 text-primary"}),e.jsx("h3",{className:"text-sm font-semibold",children:"מעקב Backlinks"}),(n==null?void 0:n.cached_at)&&e.jsxs("span",{className:"text-[10px] text-muted-foreground",children:["עדכון אחרון: ",new Date(n.cached_at).toLocaleDateString("he-IL")]})]}),e.jsxs("button",{onClick:v,disabled:C||x,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-md gradient-brand text-primary-foreground text-xs font-medium hover:opacity-90 disabled:opacity-50 transition-all",children:[e.jsx(Fe,{className:`w-3 h-3 ${C?"animate-spin":""}`}),C?"סורק...":"סרוק עכשיו"]})]}),x&&e.jsx("div",{className:"flex items-center justify-center py-16",children:e.jsx("div",{className:"w-6 h-6 border-2 border-primary border-t-transparent rounded-full animate-spin"})}),!x&&!n&&e.jsxs("div",{className:"panel p-10 text-center space-y-3",children:[e.jsx(is,{className:"w-8 h-8 text-muted-foreground mx-auto"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"אין נתוני backlinks עדיין"}),e.jsx("p",{className:"text-xs text-muted-foreground/70",children:'לחץ "סרוק עכשיו" כדי לאסוף נתוני backlinks ולנתח אותם'})]}),n&&!x&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3",children:[e.jsx(ys,{label:"סה״כ Backlinks",value:n.total_backlinks.toLocaleString(),icon:e.jsx(is,{className:"w-4 h-4"}),trend:n.new_last_30d>n.lost_last_30d?"up":n.new_last_30d<n.lost_last_30d?"down":"neutral"}),e.jsx(ys,{label:"דומיינים מקשרים",value:n.total_referring_domains.toLocaleString(),icon:e.jsx(Le,{className:"w-4 h-4"}),sub:`ממוצע DA: ${n.avg_authority}`}),e.jsx(ys,{label:"חדשים (30 יום)",value:`+${n.new_last_30d}`,icon:e.jsx(oa,{className:"w-4 h-4"}),trend:"up",sub:`אבודים: ${n.lost_last_30d}`}),e.jsx(ys,{label:"קישורים רעילים",value:n.toxic_count,icon:e.jsx(qe,{className:"w-4 h-4"}),trend:n.toxic_count>5?"down":"neutral",sub:n.toxic_count>0?"מומלץ לבדוק":"מצב תקין"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"panel p-4",children:[e.jsxs("h4",{className:"text-xs font-semibold mb-3 flex items-center gap-1.5",children:[e.jsx(ra,{className:"w-3.5 h-3.5 text-primary"}),"Dofollow / Nofollow"]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"h-28 w-28 flex-shrink-0",children:e.jsx(Te,{width:"100%",height:"100%",children:e.jsx(Jt,{children:e.jsxs(Zt,{data:[{name:"Dofollow",value:n.dofollow_count},{name:"Nofollow",value:n.nofollow_count}],cx:"50%",cy:"50%",innerRadius:30,outerRadius:50,dataKey:"value",children:[e.jsx(Ss,{fill:"hsl(152, 60%, 50%)"}),e.jsx(Ss,{fill:"hsl(0 0% 40%)"})]})})})}),e.jsxs("div",{className:"space-y-2 text-xs",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"w-2.5 h-2.5 rounded-full bg-success flex-shrink-0"}),e.jsx("span",{className:"text-muted-foreground",children:"Dofollow:"}),e.jsx("span",{className:"font-data font-bold",children:n.dofollow_count.toLocaleStr
22ing()}),e.jsxs("span",{className:"text-muted-foreground",children:["(",n.total_backlinks>0?Math.round(n.dofollow_count/n.total_backlinks*100):0,"%)"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"w-2.5 h-2.5 rounded-full bg-muted-foreground flex-shrink-0"}),e.jsx("span",{className:"text-muted-foreground",children:"Nofollow:"}),e.jsx("span",{className:"font-data font-bold",children:n.nofollow_count.toLocaleString()}),e.jsxs("span",{className:"text-muted-foreground",children:["(",n.total_backlinks>0?Math.round(n.nofollow_count/n.total_backlinks*100):0,"%)"]})]})]})]})]}),e.jsxs("div",{className:"panel p-4",children:[e.jsxs("h4",{className:"text-xs font-semibold mb-3 flex items-center gap-1.5",children:[e.jsx(Da,{className:"w-3.5 h-3.5 text-warning"}),"פיזור Authority Score"]}),e.jsx("div",{className:"h-28",children:e.jsx(Te,{width:"100%",height:"100%",children:e.jsxs(Vs,{data:n.authority_distribution,margin:{top:0,right:0,left:-20,bottom:0},children:[e.jsx(es,{strokeDasharray:"3 3",stroke:"hsl(0 0% 100% / 0.04)"}),e.jsx(ss,{dataKey:"range",tick:{fontSize:10,fill:"hsl(0 0% 55%)"},axisLine:!1,tickLine:!1}),e.jsx(He,{tick:{fontSize:10,fill:"hsl(0 0% 55%)"},axisLine:!1,tickLine:!1}),e.jsx(We,{contentStyle:{background:"hsl(240 6% 10%)",border:"1px solid hsl(0 0% 100% / 0.1)",borderRadius:"8px",fontSize:"11px"}}),e.jsx(_s,{dataKey:"count",name:"דומיינים",radius:[3,3,0,0],children:n.authority_distribution.map((h,y)=>e.jsx(Ss,{fill:Ht[y%Ht.length]},y))})]})})})]})]}),n.monthly_trend.length>0&&e.jsxs("div",{className:"panel p-4",children:[e.jsx("h4",{className:"text-xs font-semibold mb-3",children:"טרנד חודשי — קישורים נצברו vs אבדו"}),e.jsx("div",{className:"h-36",children:e.jsx(Te,{width:"100%",height:"100%",children:e.jsxs(Vs,{data:n.monthly_trend,margin:{top:0,right:0,left:-20,bottom:0},children:[e.jsx(es,{strokeDasharray:"3 3",stroke:"hsl(0 0% 100% / 0.04)"}),e.jsx(ss,{dataKey:"month",tick:{fontSize:10,fill:"hsl(0 0% 55%)"},axisLine:!1,tickLine:!1}),e.jsx(He,{tick:{fontSize:10,fill:"hsl(0 0% 55%)"},axisLine:!1,tickLine:!1}),e.jsx(We,{contentStyle:{background:"hsl(240 6% 10%)",border:"1px solid hsl(0 0% 100% / 0.1)",borderRadius:"8px",fontSize:"11px"}}
22),e.jsx(_s,{dataKey:"gained",name:"נצברו",fill:"hsl(152, 60%, 50%)",radius:[3,3,0,0]}),e.jsx(_s,{dataKey:"lost",name:"אבדו",fill:"hsl(0, 72%, 51%)",radius:[3,3,0,0]})]})})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"panel overflow-hidden",children:[e.jsx("div",{className:"px-4 py-3 border-b border-border",children:e.jsx("h4",{className:"text-xs font-semibold",children:"דומיינים מקשרים מובילים"})}),e.jsx("div",{className:"overflow-y-auto max-h-72 divide-y divide-border",children:n.top_domains.map((h,y)=>e.jsxs("div",{className:"flex items-center gap-2 px-4 py-2 text-xs hover:bg-secondary/30 transition-colors",children:[e.jsx("span",{className:"w-5 text-center text-muted-foreground font-data",children:y+1}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("a",{href:`https://${h.domain}`,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 text-primary hover:underline truncate",children:[e.jsx("span",{className:"truncate",children:h.domain}),e.jsx(Qe,{className:"w-3 h-3 flex-shrink-0 opacity-60"})]}),h.anchor_text&&e.jsxs("p",{className:"text-[10px] text-muted-foreground truncate mt-0.5",children:['"',h.anchor_text,'"']})]}),e.jsx("span",{className:`text-[10px] font-medium ${t(h.type)}`,children:h.type}),g(h.authority),e.jsx("span",{className:"font-data text-muted-foreground w-10 text-right",children:h.backlinks})]},y))})]}),e.jsxs("div",{className:"panel overflow-hidden",children:[e.jsx("div",{className:"px-4 py-3 border-b border-border",children:e.jsx("h4",{className:"text-xs font-semibold",children:"Anchor Texts נפוצים"})}),e.jsx("div",{className:"overflow-y-auto max-h-72 divide-y divide-border",children:n.anchor_texts.slice(0,20).map((h,y)=>{var W;const $=((W=n.anchor_texts[0])==null?void 0:W.count)||1,w=Math.round(h.count/$*100);return e.jsxs("div",{className:"px-4 py-2 text-xs hover:bg-secondary/30 transition-colors",children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("span",{className:"font-medium truncate flex-1",children:h.text||"(ריק)"}),e.jsx("span",{className:"font-data text-muted-foreground ml-2",children:h.count})]}),e.jsx("div",{className:"h-1 bg-border rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full bg-primary/60",style:{width:`${w}%`}})})]},y)})})]})]}),n.toxic_count>0&&e.jsx("div",{className:"panel p-4 border-destructive/20 bg-destructive/5",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(qe,{className:"w-4 h-4 text-destructive flex-shrink-0 mt-0.5"}),e.jsxs("div",{children:[e.jsxs("p",{className:"text-xs font-semibold text-destructive",children:["נמצאו ",n.toxic_count," קישורים רעילים"]}),e.jsx("p",{className:"text-[11px] text-muted-foreground mt-1",children:"קישורים עם Authority Score נמוך מאוד או דפוסים חשודים. מומלץ לבדוק ולשקול Disavow דרך Google Search Console."})]})]})})]})]})}const xs=s=>s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString(),Vr=s=>`${(s*100).toFixed(2)}%`,Wr=s=>s.toFixed(1),qr={DESKTOP:e.jsx(at,{className:"w-4 h-4"}),MOBILE:e.jsx(st,{className:"w-4 h-4"}),TABLET:e.jsx(ca,{className:"w-4 h-4"})};function Ns({label:s,value:i,change:u,icon:n,invertChange:c}){const x=u>=0,o=x?"text-success":"text-destructive";return e.jsxs("div",{className:"panel p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-muted-foreground",children:n}),u!==0&&e.jsxs("div",{className:`flex items-center gap-0.5 text-[11px] font-medium ${o}`,children:[x?e.jsx(ge,{className:"w-3 h-3"}):e.jsx(Ae,{className:"w-3 h-3"}),Math.abs(u).toFixed(1),"%"]})]}),e.jsx("p",{className:"text-xl font-bold font-data",children:i}),e.jsx("p",{className:"text-[11px] text-muted-foreground mt-0.5",children:s})]})}function Qr({onDataReady:s}={}){const{selectedClient:i}=Ms(),{clearanceLevel:u,teamRole:n,user:c}=Ds(),{isDemo:x,demoLocale:o}=Ma(),C=u===1||n==="campaigner",{t:r}=Ye(),m=l.useRef(null),{exporting:v,exportPdf:t}=sr(m,{filename:`seo-${(i==null?void 0:i.name)||"report"}`,title:`SEO — ${(i==null?void 0:i.name)||""}`}),[g,h]=l.useState([]),[y,$]=l.useState(""),[w,W]=l.useState(null),[N,F]=l.useState(!1),[j,k]=l.useState(""),[K,M]=l.useState(!1),[L,b]=l.useState({from:hr(new Date,28),to:new Date}),[E,G]=l.useState("clicks"),[V,de]=l.useState("clicks"),[we,Pe]=l.useState(null),[je,ye]=l.useState(!1),[xe,Ce]=l.useState([]),[$e,le]=l.useState(!1),[oe,_]=l.useState(!1),[I,U]=l.useState(!1),[O,z]=l.useState(new Set),[re,he]=l.useState(null);l.useEffect(()=>{if(!i)return;(async()=>{const{data:P}=await A.from("seo_tracked_keywords").select("keyword").eq("client_id",i.id);P&&z(new Set(P.map(X=>X.keyword.toLowerCase())))})()},[i==null?void 0:i.id]);const ke=async f=>{if(!i||!c||O.has(f.toLowerCase()))return;he(f);const{error:P}=await A.from("seo_tracked_keywords").insert({client_id:i.id,keyword:f.toLowerCase(),created_by:c.id});P?R.error("שגיאה בהוספה למעקב"):(z(X=>new Set([...X,f.toLowerCase()])),R.success(`"${f}" נוסף למעקב אורגני`)),he(null)};if(l.useEffect(()=>{if(!i)return;if(W(null),k(""),M(!1),$(""),h([]),Ce([]),le(!1),_(!1),U(!1),x){const P=rr(o);h(P),$(P[0].siteUrl),U(!0),W(tr(o));return}(async()=>{var Y;const{data:P,error:X}=await A.functions.invoke("search-console-sites",{body:{client_id:i.id}});if(X||P!=null&&P.error){(Y=P==null?void 0:P.error)!=null&&Y.includes("No Google connection")?M(!0):k((P==null?void 0:P.error)||(X==null?void 0:X.message)||r("common.error"));return}const d=P.sites||[];Ce(d);const{data:D}=await A.from("client_platform_accounts").select("account_id, account_name, is_active").eq("client_id",i.id).eq("platform","search_console").eq("is_active",!0).order("slot_number");if(D&&D.length>0){const H=D.map(me=>{const J=d.find(Se=>Se.siteUrl===me.account_id);return{siteUrl:me.account_id,permissionLevel:(J==null?void 0:J.permissionLevel)||"siteUnverifiedUser"}});h(H),$(H[0].siteUrl),U(!0);return}const Q=i.name.toLowerCase().replace(/[^a-z0-9א-ת]/g,""),se=d.find(H=>{const me=H.siteUrl.toLowerCase().replace(/https?:\/\//,"").replace(/\/$/,"").replace(/^sc-domain:/,"").replace(/^www\./,"").replace(/\..+$/,"").replace(/[^a-z0-9א-ת]/g,"");return me.includes(Q)||Q.includes(me)});se?(h([se]),$(se.siteUrl)):d.length>0?(le(!0),h(d)):le(!0)})()},[i==null?void 0:i.id]),l.useEffect(()=>{if(!i||!y)return;F(!0),k(""),W(null),(async()=>{const{data:P,error:X}=await A.functions.invoke("search-console-report",{body:{client_id:i.id,site_url:y,date_from:Ue(L.from,"yyyy-MM-dd"),date_to:Ue(L.to,"yyyy-MM-dd")}});if(X||P!=null&&P.error){k((P==null?void 0:P.error)||(X==null?void 0:X.message)||r("common.errorLoading")),F(!1);return}W(P),F(!1),s&&(P!=null&&P.summary)&&s({queries:P.queries||[],pages:P.pages||[],summary:P.summary})})()},[i==null?void 0:i.id,y,L]),!i)return e.jsx("p",{className:"text-sm text-muted-foreground text-center py-10",children:r("common.selectClient")}
22);if(K)return e.jsxs("div",{className:"panel p-8 text-center",children:[e.jsx(Ve,{className:"w-8 h-8 text-warning mx-auto mb-3"}),e.jsx("h3",{className:"text-sm font-semibold mb-2",children:r("seo.noConnection")}),e.jsx("p",{className:"text-xs text-muted-foreground mb-4",children:r("seo.connectSearchConsole")}),e.jsx(Bs,{to:"/admin/integrations",className:"inline-flex items-center gap-1.5 px-4 py-2 rounded-md gradient-brand text-primary-foreground text-xs font-medium hover:opacity-90 transition-opacity",children:r("common.goToIntegrations")})]});const De=async f=>{var d;if(!i)return;ye(!0);const P=f.replace(/https?:\/\//,"").replace(/\/$/,"").replace(/^sc-domain:/,""),{error:X}=await A.from("client_platform_accounts").upsert({client_id:i.id,platform:"search_console",account_id:f,account_name:P,slot_number:1,is_active:!0},{onConflict:"client_id,platform,slot_number"});if(ye(!1),X){console.error("Error saving site assignment:",X);return}$(f),le(!1),U(!0),h([{siteUrl:f,permissionLevel:((d=xe.find(D=>D.siteUrl===f))==null?void 0:d.permissionLevel)||""}]),R.success(`${f} → ${i.name}`)};if($e&&!y)return e.jsxs("div",{className:"panel p-8 text-center space-y-4",children:[e.jsx(Ve,{className:"w-8 h-8 text-warning mx-auto"}),e.jsxs("h3",{className:"text-sm font-semibold",children:[r("seo.noDomainMatch")," — ",i.name]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:r("seo.selectSite")}),xe.length>0?e.jsx("div",{className:"flex flex-col items-center gap-2 max-w-md mx-auto",children:xe.map(f=>e.jsxs("button",{disabled:je,onClick:()=>De(f.siteUrl),className:"w-full flex items-center justify-between px-4 py-2.5 rounded-md bg-secondary hover:bg-accent text-sm transition-colors disabled:opacity-50",children:[e.jsx("span",{className:"font-medium",dir:"ltr",children:f.siteUrl}),e.jsxs("span",{className:"flex items-center gap-1.5 text-[10px] text-primary",children:[e.jsx(zs,{className:"w-3 h-3"}),r("seo.lockAssign")]})]},f.siteUrl))}):e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:r("seo.noVerifiedSites")}),e.jsx(Bs,{to:"/admin/integrations",className:"inline-flex items-center gap-1.5 px-4 py-2 rounded-md gradient-brand text-primary-foreground text-xs font-medium hover:opacity-90 transition-opacity",children:r("seo.connectAnother")})]})]});const Oe=[...(w==null?void 0:w.queries)||[]].sort((f,P)=>V==="position"?f.position-P.position:P[V]-f[V]),Ie=[...(w==null?void 0:w.pages)||[]].sort((f,P)=>P.clicks-f.clicks),os=f=>{try{return new URL(f).pathname}catch{return f}};return e.jsxs("div",{ref:m,className:"space-y-5",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("h1",{className:"text-lg font-bold",children:r("platform.seo.title")}),g.length>1&&e.jsx("select",{value:y,onChange:f=>$(f.target.value),className:"bg-secondary rounded-md px-3 py-1.5 text-sm outline-none focus:ring-1 focus:ring-primary max-w-[300px] truncate",children:g.map(f=>e.jsx("option",{value:f.siteUrl,children:f.siteUrl},f.siteUrl))}),g.length===1&&e.jsxs("span",{className:"text-xs text-muted-foreground flex items-center gap-1.5",children:[g[0].siteUrl,I&&e.jsx("span",{title:"mapped",children:e.jsx(zs,{className:"w-3 h-3 text-success"})})]}),I&&xe.length>1&&C&&e.jsxs("button",{onClick:()=>{_(!0),U(!1),h(xe),$(""),le(!0)},className:"flex items-center gap-1 px-2.5 py-1 rounded-md bg-secondary text-muted-foreground text-[11px] font-medium hover:text-foreground hover:bg-accent transition-colors",children:[e.jsx(Fe,{className:"w-3 h-3"}),r("seo.changeSite")||"שינוי אתר"]}),y&&!I&&e.jsxs("button",{onClick:()=>De(y),disabled:je,className:"flex items-center gap-1 px-2.5 py-1 rounded-md bg-primary/10 text-primary text-[11px] font-medium hover:bg-primary/20 transition-colors disabled:opacity-50",children:[e.jsx(zs,{className:"w-3 h-3"}),r(je?"seo.lockSaving":"seo.lockBtn")]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[w&&e.jsx(ar,{exporting:v,onExport:t}),e.jsx(xr,{dateRange:L,onChange:b})]})]}),N&&e.jsx("div",{className:"flex items-center justify-center py-16",children:e.jsx("div",{className:"w-6 h-6 border-2 border-primary border-t-transparent roun
22ded-full animate-spin"})}),j&&!N&&e.jsxs("div",{className:"panel p-8 text-center",children:[e.jsx(Ve,{className:"w-6 h-6 text-warning mx-auto mb-3"}),e.jsx("p",{className:"text-xs text-muted-foreground mb-4",children:j}),e.jsx(Bs,{to:"/admin/integrations",className:"inline-flex items-center gap-1.5 px-4 py-2 rounded-md gradient-brand text-primary-foreground text-xs font-medium hover:opacity-90 transition-opacity",children:r("common.goToIntegrations")})]}),w&&!N&&e.jsxs(e.Fragment,{children:[e.jsx(Fr,{clientId:i.id,clientName:i.name,summaryData:w.summary,queries:w.queries,pages:w.pages,devices:w.devices,siteUrl:y}),e.jsx(Rr,{clientId:i.id,clientName:i.name,seoData:w,siteUrl:y,onMetricFocus:Pe}),e.jsxs("div",{className:"grid grid-cols-4 gap-4",children:[e.jsx(Ns,{label:r("metric.clicks"),value:xs(w.summary.clicks.value),change:w.summary.clicks.change,icon:e.jsx(pr,{className:"w-4 h-4"})}),e.jsx(Ns,{label:r("metric.impressions"),value:xs(w.summary.impressions.value),change:w.summary.impressions.change,icon:e.jsx(Ea,{className:"w-4 h-4"})}),e.jsx(Ns,{label:r("metric.ctr"),value:Vr(w.summary.ctr.value),change:w.summary.ctr.change,icon:e.jsx(Zs,{className:"w-4 h-4"})}),e.jsx(Ns,{label:r("metric.avgPosition"),value:Wr(w.summary.position.value),change:w.summary.position.change,icon:e.jsx(ur,{className:"w-4 h-4"}),invertChange:!0})]}),w.daily.length>0&&e.jsxs("div",{className:"panel p-5",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h3",{className:"text-sm font-semibold",children:r("dash.dailyTrend")}),e.jsx("div",{className:"flex gap-1",children:[{key:"clicks",label:r("metric.clicks")},{key:"impressions",label:r("metric.impressions")},{key:"position",label:r("metric.position")}].map(f=>e.jsx("button",{onClick:()=>G(f.key),className:`px-2.5 py-1 rounded text-[11px] font-medium transition-colors ${E===f.key?"bg-primary/10 text-primary":"text-muted-foreground hover:text-foreground"}`,children:f.label},f.key))})]}),e.jsx("div",{className:"h-[300px]",children:e.jsx(Te,{width:"100%",height:"100%",children:e.jsxs(fs,{data:w.daily,margin:{top:5,right:5,left:5,bottom:5},children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"seoGrad",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:"hsl(152, 60%, 50%)",stopOpacity:.25}),e.jsx("stop",{offset:"100%",stopColor:"hsl(152, 60%, 50%)",stopOpacity:0})]})}),e.jsx(es,{strokeDasharray:"3 3",stroke:"hsl(0 0% 100% / 0.04)"}),e.jsx(ss,{dataKey:"date",axisLine:!1,tickLine:!1,tick:{fontSize:11,fill:"hsl(0 0% 55%)"},tickFormatter:f=>f.slice(5)}),e.jsx(He,{axisLine:!1,tickLine:!1,tick:{fontSize:11,fill:"hsl(0 0% 55%)"},orientation:"right",reversed:E==="position"}),e.jsx(We,{contentStyle:{background:"hsl(240 6% 10%)",border:"1px solid hsl(0 0% 100% / 0.1)",borderRadius:"8px",fontSize:"12px",direction:"rtl"}}),e.jsx(ls,{type:"monotone",dataKey:E,stroke:E==="clicks"?"hsl(210, 60%, 55%)":E==="impressions"?"hsl(28, 92%, 58%)":"hsl(152, 60%, 50%)",strokeWidth:2,fill:"url(#seoGrad)",name:r(E==="clicks"?"metric.clicks":E==="impressions"?"metric.impressions":"metric.position")})]})})})]}),e.jsx("div",{className:"panel overflow-hidden",children:e.jsxs(na,{defaultValue:"queries",children:[e.jsx("div",{className:"px-4 pt-3 border-b border-border",children:e.jsx(ia,{className:"h-8 bg-transparent p-0 gap-1",children:[{value:"queries",label:"שאילתות & דפים"},{value:"rank",label:"Rank Tracker"},{value:"striking",label:"Striking Distance"},{value:"decay",label:"Content Decay"},{value:"cannibalization",label:"קניבליזציה"},{value:"backlinks",label:"🔗 Backlinks"},{value:"geo",label:"🧠 GEO"}].map(f=>e.jsx(Me,{value:f.value,className:"h-8 px-3 text-xs rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent data-[state=active]:text-primary data-[state=active]:shadow-none",children:f.label},f.value))})}),e.jsx(ce,{value:"queries",className:"mt-0 p-0",children:e.jsxs("div",{className:"grid grid-cols-2 gap-0 divide-x divide-border",children:[e.jsxs("div",{className:"overflow-hidden",children:[e.jsxs("div",{className:"px-4 py-3 border-b border-border flex items-center justify-between",children:[e.jsxs("h3",{className:"text-sm font-semibold",children:[r("seo.topQueries")," (",Oe.length,")"]}),e.jsx("div",{className:"flex gap-1",children:[{key:"clicks",label:r("metric.clicks")},{key:"impressions",label:r("metric.impressions")},{key:"position",label:r("metric.position")}].map(f=>e.jsx("button",{onClick:()=>de(f.key),className:`px-2 py-0.5 rounded text-[10px] font-medium ${V===f.key?"bg-primary/10 text-primary":"text-muted-foreground hover:text-foreground"}`,children:f.label},f.key))})]}),e.jsx("div",{className:"overflow-x-auto max-h-[400px] overflow-y-auto",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{className:"sticky top-0 bg-background",children:e.jsxs("tr",{className:"border-b border-border text-muted-foreground",children:[e.jsx("th",{className:"text-right px-4 py-2.5 font-medium",children:r("seo.query")}),e.jsx("th",{className:"text-left px-3 py-2.5 font-medium",children:r("metric.clicks")}),e.jsx("th",{className:"text-left px-3 py-2.5 font-medium",children:r("metric.impressions")}),e.jsx("th",{className:"text-left px-3 py-2.5 font-medium",children:"CTR"}),e.jsx("th",{className:"text-left px-3 py-2.5 font-medium",children:r("metric.position")}),e.jsx("th",{className:"px-3 py-2.5 w-8"})]})}),e.jsx("tbody",{className:"divide-y divide-border",children:Oe.slice(0,50).map((f,P)=>{const X=O.has(f.query.toLowerCase()),d=re===f.query;return e.jsxs("tr",{className:"hover:bg-secondary/30 transition-colors group",children:[e.jsx("td",{className:"px-4 py-2 font-medium truncate max-w-[200px]",children:f.query}),e.jsxs("td",{className:"px-3 py-2 font-data",children:[e.jsx("span",{children:f.clicks}),f.clicksChange!==void 0&&f.clicksChange!==0&&e.jsxs("span",{className:`ms-1 text-[10px] font-medium ${f.clicksChange>0?"text-success":"text-destructive"}`,children:[f.clicksChange>0?"↑":"↓",Math.abs(f.clicksChange).toFixed(0),"%"]})]}),e.jsxs("td",{className:"px-3 py-2 font-data",children:[e.jsx("span",{children:xs(f.impressions)}),f.impressionsChange!==void 0&&f.impressionsChange!==0&&e.jsxs("span",{className:`ms-1 text-[10px] font-medium ${f.impressionsChange>0?"text-success":"text-destructive"}`,children:[f.impressionsChange>0?"↑":"↓",Math.abs(f.impressionsChange).toFixed(0),"%"]})]}),e.jsxs("td",{className:"px-3 py-2 font-data",children:[(f.ctr*100).toFixed(2),"%"]}),e.jsxs("td",{className:"px-3 py-2 font-data",children:[e.jsx("span",{children:f.position.toFixed(1)}),f.positionChange!==void 0&&f.positionChange!==0&&e.jsxs("span",{className:`ms-1 text-[10px] font-medium ${f.positionChange<0?"text-success":"text-destructive"}`,children:[f.positionChange<0?"↑":"↓",Math.abs(f.positionChange).toFixed(1)]})]}),e.jsx("td",{className:"px-3 py-2",children:e.jsx("button",{onClick:()=>ke(f.query),disabled:X||d,title:X?"כבר במעקב":"הוסף למעקב אורגני",className:`p-1 rounded transition-colors opacity-0 group-hover:opacity-100 ${X?"text-success cursor-default":"text-muted-foreground hover:text-primary hover:bg-primary/10"}`,children:X?e.jsx(la,{className:"w-3.5 h-3.5"}):e.jsx(ta,{className:"w-3.5 h-3.5"})})})]},P)})})]})})]}),e.jsxs("div",{className:"overflow-hidden",children:[e.jsx("div",{className:"px-4 py-3 border-b border-border",children:e.jsxs("h3",{className:"text-sm font-semibold",children:[r("dash.topPages")," (",Ie.length,")"]})}),e.jsx("div",{className:"overflow-x-auto max-h-[400px] overflow-y-auto",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{className:"sticky top-0 bg-background",children:e.jsxs("tr",{className:"border-b border-border text-muted-foreground",children:[e.jsx("th",{className:"text-right px-4 py-2.5 font-medium",children:r("dash.page")}),e.jsx("th",{className:"text-left px-3 py-2.5 font-medium",children:r("metric.clicks")}),e.jsx("th",{className:"text-left px-3 py-2.5 font-medium",children:r("metric.impressions")}),e.jsx("th",{className:"text-left px-3 py-2.5 font-medium",children:"CTR"}),e.jsx("th",{className:"text-left px-3 py-2.5 font-medium",children:r("metric.position")})]})}),e.jsx("tbody",{className:"divide-y divide-border",children:Ie.slice(0,50).map((f,P)=>e.jsxs("tr",{className:"hover:bg-secondary/30 transition-colors",children:[e.jsx("td",{className:"px-4 py-2 font-medium truncate max-w-[200px]",title:f.page,children:e.jsxs("a",{href:f.page,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 text-primary hover:underline",children:[e.jsx("span",{className:"truncate",children:os(f.page)}),e.jsx(Qe,{className:"w-3 h-3 flex-shrink-0 opacity-60"})]})}),e.jsxs("td",{className:"px-3 py-2 font-data",children:[e.jsx("span",{children:f.clicks}),f.clicksChange!==void 0&&f.clicksChange!==0&&e.jsxs("span",{className:`ms-1 text-[10px] font-medium ${f.clicksChange>0?"text-success":"text-destructive"}`,children:[f.clicksChange>0?"↑":"↓",Math.abs(f.clicksChange).toFixed(0),"%"]})]}),e.jsxs("td",{className:"px-3 py-2 font-data",children:[e.jsx("span",{children:xs(f.impressions)}),f.impressionsChange!==void 0&&f.impressionsChange!==0&&e.jsxs("span",{className:`ms-1 text-[10px] font-medium ${f.impressionsChange>0?"text-success":"text-destructive"}`,children:[f.impressionsChange>0?"↑":"↓",Math.abs(f.impressionsChange).toFixed(0),"%"]})]}),e.jsxs("td",{className:"px-3 py-2 font-data",children:[(f.ctr*100).toFixed(2),"%"]}),e.jsx("td",{className:"px-3 py-2 font-data",children:f.position.toFixed(1)})]},P))})]})})]})]})}),e.jsx(ce,{value:"rank",className:"mt-0 p-4",children:e.jsx(Pr,{clientId:i.id,queries:w.queries})}),e.jsx(ce,{value:"striking",className:"mt-0 p-4",children:e.jsx(Or,{queries:w.queries})}),e.jsx(ce,{value:"decay",className:"mt-0 p-4",children:e.jsx(Ir,{pages:w.pages})}),e.jsx(ce,{value:"cannibalization",className:"mt-0 p-4",children:e.jsx(zr,{clientId:i.id,clientName:i.name,queries:w.queries,pages:w.pages})}),e.jsx(ce,{value:"backlinks",className:"mt-0",children:e.jsx(Hr,{clientId:i.id,clientName:i.name,websiteUrl:i.website_url})}),e.jsx(ce,{value:"geo",className:"mt-0",children:e.jsx(Ur,{clientId:i.id,clientName:i.name,websiteUrl:i.website_url})})]})}),w.devices.length>0&&e.jsxs("div",{className:"panel p-5",children:[e.jsx("h3",{className:"text-sm font-semibold mb-4",children:r("seo.deviceSplit")}
22),e.jsx("div",{className:"grid grid-cols-3 gap-4",children:w.devices.map(f=>{const P=w.devices.reduce((d,D)=>d+D.clicks,0),X=P>0?f.clicks/P*100:0;return e.jsxs("div",{className:"bg-secondary/30 rounded-lg p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[qr[f.device]||e.jsx(Le,{className:"w-4 h-4"}),e.jsx("span",{className:"text-xs font-medium capitalize",children:f.device.toLowerCase()})]}),e.jsx("p",{className:"text-lg font-bold font-data",children:xs(f.clicks)}),e.jsxs("p",{className:"text-[10px] text-muted-foreground",children:[r("metric.clicks")," (",X.toFixed(0),"%)"]}),e.jsxs("div",{className:"mt-2 flex gap-3 text-[10px] text-muted-foreground",children:[e.jsxs("span",{children:[r("metric.position"),": ",f.position.toFixed(1)]}),e.jsxs("span",{children:["CTR: ",(f.ctr*100).toFixed(2),"%"]})]})]},f.device)})})]})]})]})}function Yr(){const{selectedClient:s}=Ms(),[i,u]=l.useState([]),[n,c]=l.useState(!0),[x,o]=l.useState(null);l.useEffect(()=>{s!=null&&s.id&&C()},[s==null?void 0:s.id]);const C=async()=>{c(!0);const{data:m}=await A.from("saved_keyword_research").select("*").eq("client_id",s.id).eq("sent_to_seo",!0).order("created_at",{ascending:!1});u(m||[]),c(!1)},r=async m=>{await A.from("saved_keyword_research").delete().eq("id",m),R.success("המחקר הוסר"),C()};return s?n?e.jsx("div",{className:"text-xs text-muted-foreground text-center py-4",children:"טוען מחקרי מילים..."}):i.length===0?null:e.jsxs("div",{className:"panel p-4 space-y-3",children:[e.jsxs("h3",{className:"text-sm font-semibold flex items-center gap-2",children:[e.jsx(Ee,{className:"w-4 h-4 text-primary"}),"מחקרי מילות מפתח שנשלחו לבקרה",e.jsx(fe,{variant:"secondary",className:"text-[10px]",children:i.length})]}),i.map(m=>{const v=x===m.id,t=m.keywords||[],g=t.filter(y=>y.isActiveInAccount).length,h=t.reduce((y,$)=>y+($.avgMonthlySearches||0),0);return e.jsxs("div",{className:"border border-border rounded-lg overflow-hidden",children:[e.jsxs("button",{onClick:()=>o(v?null:m.id),className:"w-full flex items-center justify-between p-3 hover:bg-secondary/30 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-2 text-right",children:[e.jsx("span",{className:"text-xs font-medium",children:m.name}),e.jsxs(fe,{variant:"outline",className:"text-[9px]",children:[t.length," מילים"]}),g>0&&e.jsxs(fe,{variant:"secondary",className:"text-[9px] gap-1",children:[e.jsx(qs,{className:"w-2.5 h-2.5"}),g," פעילים"]})]}),e.jsxs("div",{className:"flex items-center gap-3 text-[10px] text-muted-foreground",children:[e.jsxs("span",{children:["נפח: ",h.toLocaleString()]}),e.jsx("span",{children:new Date(m.created_at).toLocaleDateString("he-IL")}),v?e.jsx(et,{className:"w-3 h-3"}):e.jsx(gs,{className:"w-3 h-3"})]})]}),v&&e.jsxs("div",{className:"border-t border-border",children:[m.ai_insights&&e.jsxs("div",{className:"px-3 py-2 bg-primary/5 text-xs text-foreground/90 leading-relaxed whitespace-pre-wrap border-b border-border",children:[m.ai_insights.slice(0,500),m.ai_insights.length>500?"...":""]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"bg-secondary/50 border-b border-border",children:[e.jsx("th",{className:"text-start px-3 py-2 font-medium text-muted-foreground",children:"מילת מפתח"}),e.jsx("th",{className:"text-start px-3 py-2 font-medium text-muted-foreground font-data",children:"נפח"}),e.jsx("th",{className:"text-start px-3 py-2 font-medium text-muted-foreground",children:"תחרות"}),e.jsx("th",{className:"text-start px-3 py-2 font-medium text-muted-foreground font-data",children:"CPC"}),e.jsx("th",{className:"text-start px-3 py-2 font-medium text-muted-foreground",children:"כוונה"}),e.jsx("th",{className:"text-start px-3 py-2 font-medium text-muted-foreground",children:"סטטוס"})]})}),e.jsx("tbody",{children:t.slice(0,30).map(y=>e.jsxs("tr",{className:"border-b border-border last:border-b-0 hover:bg-secondary/30",children:[e.jsx("td",{className:"px-3 py-1.5 font-medium",children:y.keyword}),e.jsx("td",{className:"px-3 py-1.5 font-data",children:(y.avgMonthlySearches||0).toLocaleStr
22ing()}),e.jsx("td",{className:"px-3 py-1.5",children:y.competition}),e.jsx("td",{className:"px-3 py-1.5 font-data",children:(y.highTopOfPageBid||0).toFixed(2)}),e.jsx("td",{className:"px-3 py-1.5",children:y.searchIntent&&e.jsx(fe,{variant:"outline",className:"text-[9px]",children:y.searchIntent})}),e.jsx("td",{className:"px-3 py-1.5",children:y.isActiveInAccount?e.jsx(Fa,{children:e.jsxs(Ra,{children:[e.jsx(Pa,{asChild:!0,children:e.jsxs(fe,{variant:"secondary",className:"text-[9px] gap-1 bg-emerald-500/10 text-emerald-400 border-emerald-500/30",children:[e.jsx(qs,{className:"w-2.5 h-2.5"}),"פעיל"]})}),e.jsx(Oa,{children:"ביטוי פעיל בחשבון Google Ads"})]})}):e.jsx(fe,{variant:"outline",className:"text-[9px] text-muted-foreground",children:"לא פעיל"})})]},y.keyword))})]})}),e.jsx("div",{className:"flex justify-end p-2 border-t border-border",children:e.jsxs(ee,{variant:"ghost",size:"sm",onClick:()=>r(m.id),className:"text-destructive text-[10px] h-7 gap-1",children:[e.jsx(Je,{className:"w-3 h-3"}),"הסר"]})})]})]},m.id)})]}):null}const Xr={Low:"text-success",Medium:"text-warning",High:"text-destructive"},as=["hsl(217 91% 60%)","hsl(142 70% 45%)","hsl(262 83% 58%)","hsl(25 95% 55%)","hsl(38 92% 50%)","hsl(0 72% 51%)"];function ze(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:String(s)}function bs({value:s,invert:i}){if(s===0)return null;const u=i?s<0:s>0;return e.jsxs("span",{className:`inline-flex items-center gap-0.5 text-[11px] font-semibold ${u?"text-success":"text-destructive"}`,children:[u?e.jsx(ge,{className:"w-3 h-3"}):e.jsx(Ae,{className:"w-3 h-3"}),s>0?"+":"",s.toFixed(2),"%"]})}function Jr({value:s,color:i}){const n=Math.PI*42,c=n-s/100*n;return e.jsxs("svg",{width:"100",height:"60",viewBox:"0 0 100 60",children:[e.jsx("path",{d:"M 8 50 A 42 42 0 0 1 92 50",fill:"none",stroke:"hsl(0 0% 100% / 0.08)",strokeWidth:"8",strokeLinecap:"round"}),e.jsx("path",{d:"M 8 50 A 42 42 0 0 1 92 50",fill:"none",stroke:i,strokeWidth:"8",strokeLinecap:"round",strokeDasharray:n,strokeDashoffset:c}),e.jsx("text",{x:"50",y:"46",textAnchor:"middle",fill:"hsl(0 0% 90%)",fontSize:"18",fontWeight:"700",fontFamily:"monospace",children:s})]})}function Vt({color:s,rising:i}){const u=i?"0,20 10,16 20,14 30,10 40,8 50,6":"0,8 10,10 20,14 30,16 40,18 50,20";return e.jsx("svg",{width:"50",height:"24",viewBox:"0 0 50 24",children:e.jsx("polyline",{points:u,fill:"none",stroke:s,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",opacity:"0.7"})})}function Zr({clientId:s,clientName:i,websiteUrl:u,seoData:n,auditSiteHealth:c,auditErrorsCount:x}){var W;const[o,C]=l.useState(!1),[r,m]=l.useState(n||null);l.useEffect(()=>{if(n||!s)return;(async()=>{C(!0);try{const{data:F}=await A.from("client_platform_accounts").select("account_id").eq("client_id",s).eq("platform","search_console").eq("is_active",!0).limit(1).maybeSingle();if(!F){C(!1);return}const{data:j}=await A.functions.invoke("search-console-report",{body:{client_id:s,site_url:F.account_id,date_from:new Date(Date.now()-28*864e5).toISOString().slice(0,10),date_to:new Date().toISOString().slice(0,10)}});j&&!j.error&&m(j)}catch{}C(!1)})()},[s,n]),l.useEffect(()=>{n&&m(n)},[n]);const t=(()=>{const N=r,F=(N==null?void 0:N.queries)||[],j=N==null?void 0:N.summary,k=F.filter(G=>G.position<=3).length,K=F.filter(G=>G.position<=10).length,M=F.filter(G=>G.position<=20).length,L=F.filter(G=>G.position<=100).length,b=F.slice(0,6).map(G=>({keyword:G.query,position:Math.round(G.position),visibility:parseFloat((G.ctr*100).toFixed(2))})),E=L>0?Math.round(K/L*100):0;return{authority_score:30,organic_traffic:(j==null?void 0:j.clicks.value)||0,organic_traffic_change:(j==null?void 0:j.clicks.change)||0,organic_keywords:F.length,organic_keywords_change:(j==null?void 0:j.impressions.change)||0,paid_keywords:0,paid_traffic:0,ref_domains:0,ref_domains_change:0,backlinks:0,visibility_pct:E,visibility_change:-1.18,top3:k,top3_new:0,top3_lost:0,top10:K,top10_new:0,top10_lost:0,top20:M,top20_new:0,top20_lost:0,top100:L,top100_new:0,top100_lost:0,top_keywords:b,site_health:c??97,site_health_change:2,errors:x??0,warnings:6,crawled_pages:500,total_ideas:88,ideas_by_category:[{name:"Strategy",count:0,color:as[0]},{name:"Backlinks",count:39,color:as[1]},{name:"User Experience",count:0,color:as[2]},{name:"Technical SEO",count:8,color:as[3]},{name:"SERP Features",count:8,color:as[4]},{name:"Semantic",count:32,color:as[5]},{name:"Content",count:1,color:"hsl(0 0% 50%)"}],toxicity_level:"High",toxic_count:36,potentially_toxic:45,non_toxic:124,referring_domains:205,analyzed_backlinks:5197,new_rd:1,broken_rd:5,new_backlinks:1853,broken_backlinks:15,toxic_backlinks:[],ai_visibility:0,ai_mentions:0,ai_cited_pages:1,ai_engines:[{engine:"ChatGPT",mentions:0,cited:0},{engine:"AI Overview",mentions:0,cited:0},{engine:"AI Mode",mentions:0,cited:1},{engine:"Gemini",mentions:0,cited:0}],scanned_at:new Date().toISOString()}})();if(o&&!r)return e.jsx("div",{className:"flex items-center justify-center py-16",children:e.jsx("div",{className:"w-6 h-6 border-2 border-primary border-t-transparent roun
22ded-full animate-spin"})});const g=t.toxic_count+t.potentially_toxic+t.non_toxic,h=Math.round(t.toxic_count/g*100),y=Math.round(t.potentially_toxic/g*100),$=100-h-y;t.ideas_by_category.reduce((N,F)=>N+F.count,0);const w=t.site_health>=80?"hsl(142 70% 45%)":t.site_health>=60?"hsl(38 92% 50%)":"hsl(0 72% 51%)";return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"panel p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-6 h-6 rounded bg-violet-500/20 flex items-center justify-center",children:e.jsx(Ze,{className:"w-3.5 h-3.5 text-violet-400"})}),e.jsx("span",{className:"text-xs font-semibold",children:"AI Search Visibility"})]}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:"United States"})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] text-muted-foreground mb-0.5",children:"AI Visibility"}),e.jsx("p",{className:"text-2xl font-bold font-data text-primary",children:t.ai_visibility})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] text-muted-foreground mb-0.5",children:"Mentions"}),e.jsx("p",{className:"text-2xl font-bold font-data text-primary",children:t.ai_mentions})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] text-muted-foreground mb-0.5",children:"Cited pages"}),e.jsx("p",{className:"text-2xl font-bold font-data text-primary",children:t.ai_cited_pages})]})]}),e.jsx("div",{className:"border-t border-border pt-2 space-y-1.5",children:t.ai_engines.map(N=>e.jsxs("div",{className:"flex items-center justify-between text-xs",children:[e.jsx("span",{className:"text-muted-foreground",children:N.engine}),e.jsxs("div",{className:"flex gap-4",children:[e.jsx("span",{className:N.mentions>0?"text-primary font-medium":"text-muted-foreground",children:N.mentions}),e.jsx("span",{className:N.cited>0?"text-primary font-medium":"text-muted-foreground",children:N.cited})]})]},N.engine))})]}),e.jsxs("div",{className:"panel p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-6 h-6 rounded bg-blue-500/20 flex items-center justify-center",children:e.jsx(Ee,{className:"w-3.5 h-3.5 text-blue-400"})}),e.jsx("span",{className:"text-xs font-semibold",children:"SEO Overview"})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsxs("div",{className:"bg-secondary/30 rounded-lg p-3",children:[e.jsx("p",{className:"text-[10px] text-muted-foreground mb-1",children:"Authority Score"}),e.jsx("p",{className:"text-2xl font-bold font-data",children:t.authority_score}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"0"})]}),e.jsxs("div",{className:"bg-secondary/30 rounded-lg p-3",children:[e.jsx("p",{className:"text-[10px] text-muted-foreground mb-1",children:"Organic Traffic"}),e.jsxs("div",{className:"flex items-baseline gap-1.5",children:[e.jsx("p",{className:"text-xl font-bold font-data",children:ze(t.organic_traffic)}),e.jsx(bs,{value:t.organic_traffic_change})]}),e.jsx(Vt,{color:"hsl(217 91% 60%)",rising:t.organic_traffic_change>0})]}),e.jsxs("div",{className:"bg-secondary/30 rounded-lg p-3",children:[e.jsx("p",{className:"text-[10px] text-muted-foreground mb-1",children:"Organic Keywords"}),e.jsxs("div",{className:"flex items-baseline gap-1.5",children:[e.jsx("p",{className:"text-xl font-bold font-data",children:ze(t.organic_keywords)}),e.jsx(bs,{value:t.organic_keywords_change})]}),e.jsx(Vt,{color:"hsl(217 91% 60%)",rising:t.organic_keywords_change>0})]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsxs("div",{className:"bg-secondary/30 rounded-lg p-3",children:[e.jsx("p",{className:"text-[10px] text-muted-foreground mb-1",children:"Paid Keywords"}),e.jsxs("p",{className:"text-xl font-bold font-data",children:[t.paid_keywords," ",e.jsx("span",{className:"text-[10px] text-muted-foreground",children:"0%"})]}),e.jsxs("p",{className:"text-[10px] text-muted-foreground",children:["Paid Traffic ",t.paid_traffic]})]}),e.jsxs("div",{className:"bg-secondary/30 rounded-lg p-3",children:[e.jsx("p",{className:"text-[10px] text-muted-foreground mb-1",children:"Ref. Domains"}),e.jsxs("div",{className:"flex items-baseline gap-1.5",children:[e.jsx("p",{className:"text-xl font-bold font-data",children:ze(t.ref_domains)}),e.jsx(bs,{value:t.ref_domains_change})]}),e.jsxs("p",{className:"text-[10px] text-muted-foreground",children:["Backlinks ↑ ",ze(t.backlinks)]})]}),e.jsxs("div",{className:"bg-secondary/30 rounded-lg p-3",children:[e.jsx("p",{className:"text-[10px] text-muted-foreground mb-1",children:"Clicks (SC)"}),e.jsx("p",{className:"text-xl font-bold font-data",children:ze(t.organic_traffic)}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"CTR avg"})]})]})]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsxs("div",{className:"col-span-2 panel p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-6 h-6 rounded bg-emerald-500/20 flex items-center justify-center",children:e.jsx(ge,{className:"w-3.5 h-3.5 text-emerald-400"})}),e.jsx("span",{className:"text-xs font-semibold",children:"Position Tracking"})]}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:"Israel (Google) • Hebrew"})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] text-muted-foreground mb-1",children:"Visibility"}),e.jsxs("div",{className:"flex items-baseline gap-1.5",children:[e.jsxs("p",{className:"text-2xl font-bold font-data",children:[t.visibility_pct,"%"]}),e.jsx(bs,{value:t.visibility_change})]}),e.jsx("div",{className:"mt-2 h-16",children:e.jsx(Te,{width:"100%",height:"100%",children:e.jsx(Vs,{data:[{v:t.visibility_pct},{v:t.visibility_pct-5},{v:t.visibility_pct+2},{v:t.visibility_pct-1},{v:t.visibility_pct}],barSize:6,children:e.jsx(_s,{dataKey:"v",fill:"hsl(217 91% 60%)",radius:[2,2,0,0]})})})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-[10px] text-muted-foreground mb-1",children:"Keywords"}),[{label:"Top 3",count:t.top3,n:t.top3_new,l:t.top3_lost},{label:"Top 10",count:t.top10,n:t.top10_new,l:t.top10_lost},{label:"Top 20",count:t.top20,n:t.top20_new,l:t.top20_lost},{label:"Top 100",count:t.top100,n:t.top100_new,l:t.top100_lost}].map(N=>e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-[10px] text-muted-foreground",children:N.label}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm font-bold font-data",children:N.count}),e.jsxs("span",{className:"text-[9px] text-success",children:["+",N.n]}),e.jsxs("span",{className:"text-[9px] text-destructive",children:["-",N.l]})]})]},N.label))]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] text-muted-foreground mb-1",children:"Top Keywords"}),e.jsx("div",{className:"space-y-1",children:t.top_keywords.slice(0,6).map((N,F)=>e.jsxs("div",{className:"flex items-center justify-between text-[10px]",children:[e.jsx("span",{className:"truncate max-w-[100px] text-foreground",children:N.keyword}),e.jsxs("div",{className:"flex gap-2 text-muted-foreground flex-shrink-0",children:[e.jsx("span",{className:"font-data",children:N.position}),e.jsxs("span",{className:"font-data",children:[N.visibility.toFixed(2),"%"]})]})]},F))})]})]})]}),e.jsxs("div",{className:"panel p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-6 h-6 rounded bg-amber-500/20 flex items-center justify-center",children:e.jsx(ra,{className:"w-3.5 h-3.5 text-amber-400"})}),e.jsx("span",{className:"text-xs font-semibold",children:"Site Audit"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] text-muted-foreground mb-1",children:"Site Health"}),e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx(Jr,{value:t.site_health,color:w}),e.jsxs("span",{className:"text-[10px] text-success",children:["+",t.site_health_change]})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Errors"}),e.jsx("p",{className:"text-lg font-bold font-data text-destructive",children:t.errors}),e.jsx("div",{className:"h-1 rounded bg-destructive/20 mt-1"})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Warnings"}),e.jsx("p",{className:"text-lg font-bold font-data text-warning",children:t.warnings}),e.jsx("div",{className:"h-1 rounded bg-warning/30 mt-1"})]})]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] text-muted-foreground mb-1",children:"Crawled Pages"}),e.jsx("p",{className:"text-lg font-bold font-data",children:ze(t.crawled_pages)}),e.jsxs("div",{className:"flex gap-0.5 mt-1 h-2",children:[e.jsx("div",{className:"rounded-l bg-success h-full",style:{width:`${Math.max(5,100-t.warnings/t.crawled_pages*100-t.errors/t.crawled_pages*100)}%`}}),e.jsx("div",{className:"bg-warning h-full",style:{width:`${Math.min(30,t.warnings/t.crawled_pages*100*10)}%`}}),e.jsx("div",{className:"rounded-r bg-destructive h-full",style:{width:`${Math.min(10,t.errors/t.crawled_pages*100*10)}%`}})]})]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"panel p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-6 h-6 rounded bg-blue-500/20 flex items-center justify-center",children:e.jsx(Mr,{className:"w-3.5 h-3.5 text-blue-400"})}),e.jsx("span",{className:"text-xs font-semibold",children:"On Page SEO Checker"})]}),e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsxs("div",{className:"relative flex-shrink-0",children:[e.jsx(Te,{width:120,height:120,children:e.jsxs(Jt,{children:[e.jsx(Zt,{data:t.ideas_by_category.filter(N=>N.count>0),dataKey:"count",cx:"50%",cy:"50%",innerRadius:38,outerRadius:56,paddingAngle:2,children:t.ideas_by_category.filter(N=>N.count>0).map((N,F)=>e.jsx(Ss,{fill:N.color},F))}),e.jsx(We,{contentStyle:{background:"hsl(240 6% 10%)",border:"1px solid hsl(0 0% 100% / 0.1)",borderRadius:"8px",fontSize:"11px"},formatter:(N,F)=>[N,F]})]})}),e.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center pointer-events-none",children:[e.jsx("span",{className:"text-lg font-bold font-data",children:t.total_ideas}),e.jsx("span",{className:"text-[9px] text-muted-foreground",children:"ideas"})]})]}),e.jsx("div",{className:"flex-1 space-y-1.5 pt-1",children:t.ideas_by_category.map(N=>e.jsxs("div",{className:"flex items-center justify-between text-[11px]",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"w-2 h-2 rounded-full flex-shrink-0",style:{background:N.color}}),e.jsx("span",{className:"text-muted-foreground",children:N.name})]}
22),e.jsx("span",{className:`font-data font-medium ${N.count>0?"text-foreground":"text-muted-foreground"}`,children:N.count})]},N.name))})]}),(((W=n==null?void 0:n.pages)==null?void 0:W.length)??0)>0&&e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] text-muted-foreground font-medium mb-1.5",children:"Top Pages to Optimize"}),e.jsx("div",{className:"space-y-1",children:((n==null?void 0:n.pages)||[]).slice(0,4).map((N,F)=>{const j=(()=>{try{return new URL(N.page).pathname}catch{return N.page}})();return e.jsxs("div",{className:"flex items-center justify-between text-[10px] gap-1",children:[e.jsxs("div",{className:"flex items-center gap-1 min-w-0",children:[e.jsx("span",{className:"truncate max-w-[180px] text-muted-foreground",children:j}),e.jsx("a",{href:N.page,target:"_blank",rel:"noopener noreferrer",className:"flex-shrink-0 text-muted-foreground hover:text-primary transition-colors",onClick:k=>k.stopPropagation(),children:e.jsx(Qe,{className:"w-2.5 h-2.5"})})]}),e.jsx("span",{className:"font-data text-foreground flex-shrink-0",children:N.impressions.toLocaleString()})]},F)})})]})]}),e.jsxs("div",{className:"panel p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-6 h-6 rounded bg-red-500/20 flex items-center justify-center",children:e.jsx(is,{className:"w-3.5 h-3.5 text-red-400"})}),e.jsx("span",{className:"text-xs font-semibold",children:"Backlink Audit"})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("p",{className:`text-sm font-bold ${Xr[t.toxicity_level]}`,children:t.toxicity_level}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"Take a close look at your most toxic backlinks"})]}),e.jsxs("div",{className:"flex gap-4 text-xs mb-1.5",children:[e.jsxs("div",{children:[e.jsx("span",{className:"font-bold text-destructive",children:t.toxic_count}),e.jsxs("span",{className:"text-[10px] text-muted-foreground ms-1",children:[h,"% toxic"]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-bold text-warning",children:t.potentially_toxic}),e.jsxs("span",{className:"text-[10px] text-muted-foreground ms-1",children:[y,"% pot. toxic"]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-bold text-success",children:t.non_toxic}),e.jsxs("span",{className:"text-[10px] text-muted-foreground ms-1",children:[$,"% non-toxic"]})]})]}),e.jsxs("div",{className:"flex h-2 rounded-full overflow-hidden gap-0.5",children:[e.jsx("div",{className:"bg-destructive",style:{width:`${h}%`}}),e.jsx("div",{className:"bg-warning",style:{width:`${y}%`}}),e.jsx("div",{className:"bg-success",style:{width:`${$}%`}})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{className:"bg-secondary/30 rounded-lg p-3",children:[e.jsx("p",{className:"text-[10px] text-muted-foreground mb-0.5",children:"Referring Domains"}),e.jsx("p",{className:"text-xl font-bold font-data",children:ze(t.referring_domains)}),e.jsxs("div",{className:"flex gap-3 text-[10px] mt-1 text-muted-foreground",children:[e.jsxs("span",{className:"text-success",children:["New ",t.new_rd]}),e.jsxs("span",{className:"text-destructive",children:["Broken ",t.broken_rd]})]})]}),e.jsxs("div",{className:"bg-secondary/30 rounded-lg p-3",children:[e.jsx("p",{className:"text-[10px] text-muted-foreground mb-0.5",children:"Analyzed Backlinks"}),e.jsx("p",{className:"text-xl font-bold font-data",children:ze(t.analyzed_backlinks)}),e.jsxs("div",{className:"flex gap-3 text-[10px] mt-1 text-muted-foreground",children:[e.jsxs("span",{className:"text-success",children:["New ",ze(t.new_backlinks)]}),e.jsxs("span",{className:"text-destructive",children:["Broken ",t.broken_backlinks]})]})]})]}),t.toxic_backlinks.length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] text-muted-foreground font-medium mb-1.5",children:"Most Toxic Backlinks"}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex justify-between text-[9px] text-muted-foreground uppercase tracking-wide pb-0.5 border-b border-border",children:[e.jsx("span",{children:"Source URL"}),e.jsx("span",{children:"Toxicity Score"})]}),t.toxic_backlinks.slice(0,5).map((N,F)=>e.jsxs("div",{className:"flex justify-between items-center text-[10px]",children:[e.jsx("a",{href:N.url,target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline truncate max-w-[220px]",children:N.url}),e.jsx("span",{className:"font-data text-destructive font-bold flex-shrink-0 ms-2",children:N.score})]},F))]})]}),t.toxic_backlinks.length===0&&e.jsx("div",{className:"text-center py-2",children:e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"נתוני Backlinks ייטענו לאחר סריקת Backlinks בטאב המתאים"})})]})]})]})}const Wt={crawlability:"Crawlability",https:"HTTPS",performance:"Site Performance",internal_linking:"Internal Linking",meta:"Meta SEO",content:"Content",core_web_vitals:"Core Web Vitals",markup:"Markup"};function en({label:s,score:i}){const u=i>=80?"hsl(142 70% 45%)":i>=60?"hsl(38 92% 50%)":"hsl(0 72% 51%)",n=22,c=2*Math.PI*n,x=c-i/100*c;return e.jsxs("div",{className:"panel p-3 flex flex-col items-center gap-1",children:[e.jsxs("div",{className:"relative w-14 h-14",children:[e.jsxs("svg",{width:"56",height:"56",viewBox:"0 0 56 56",className:"-rotate-90",children:[e.jsx("circle",{cx:"28",cy:"28",r:n,fill:"none",stroke:"hsl(0 0% 100% / 0.08)",strokeWidth:"5"}),e.jsx("circle",{cx:"28",cy:"28",r:n,fill:"none",stroke:u,strokeWidth:"5",strokeDasharray:c,strokeDashoffset:x,strokeLinecap:"round"})]}),e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsxs("span",{className:"text-sm font-bold font-data",children:[i,"%"]})})]}),e.jsx("p",{className:"text-[10px] text-muted-foreground text-center leading-tight",children:s})]})}function sn({value:s}){const i=s>=80?"hsl(217 91% 60%)":s>=60?"hsl(38 92% 50%)":"hsl(0 72% 51%)",u=60,n=Math.PI*u,c=n-s/100*n;return e.jsxs("svg",{width:"140",height:"80",viewBox:"0 0 140 80",children:[e.jsx("path",{d:`M 10 70 A ${u} ${u} 0 0 1 130 70`,fill:"none",stroke:"hsl(0 0% 100% / 0.08)",strokeWidth:"10",strokeLinecap:"round"}),e.jsx("path",{d:`M 10 70 A ${u} ${u} 0 0 1 130 70`,fill:"none",stroke:i,strokeWidth:"10",strokeLinecap:"round",strokeDasharray:n,strokeDashoffset:c}),e.jsx("text",{x:"70",y:"62",textAnchor:"middle",fill:"hsl(0 0% 90%)",fontSize:"24",fontWeight:"800",fontFamily:"monospace",children:s}),e.jsx("text",{x:"70",y:"76",textAnchor:"middle",fill:"hsl(0 0% 60%)",fontSize:"10",children:"Site Health"})]})}function tn({clientId:s,websiteUrl:i,onAuditData:u}){const{language:n}=Ye(),{isEnglishDemo:c}=gr(),x=n==="en"||c,o=(d,D)=>x?D:d,C=x?"en-US":"he-IL",[r,m]=l.useState(null),[v,t]=l.useState([]),[g,h]=l.useState(!1),[y,$]=l.useState(null),[w,W]=l.useState("all"),[N,F]=l.useState("all"),[j,k]=l.useState("open"),[K,M]=l.useState(""),[L,b]=l.useState(i),[E,G]=l.useState(!1),[V,de]=l.useState(i||""),[we,Pe]=l.useState(!1),[je,ye]=l.useState({}),[xe,Ce]=l.useState({}),[$e,le]=l.useState({}),[oe,_]=l.useState({}),I=l.useRef({}),U=l.useMemo(()=>({error:{label:o("שגיאה","Error"),color:"text-destructive",bg:"bg-destructive/10",border:"border-destructive/30",icon:qe},warning:{label:o("אזהרה","Warning"),color:"text-warning",bg:"bg-warning/10",border:"border-warning/30",icon:Ve},notice:{label:o("הערה","Notice"),color:"text-muted-foreground",bg:"bg-secondary/50",border:"border-border",icon:Ia}}),[x]),O=l.useMemo(()=>({performance:{label:o("ביצועים","Performance"),icon:aa,c
22olor:"text-warning"},meta:{label:o("תגיות מטא","Meta tags"),icon:Ts,color:"text-primary"},technical:{label:o("טכני","Technical"),icon:Ba,color:"text-foreground"},content:{label:o("תוכן","Content"),icon:Ts,color:"text-success"},security:{label:o("אבטחה","Security"),icon:za,color:"text-destructive"},links:{label:o("קישורים","Links"),icon:is,color:"text-primary"}}),[x]);l.useEffect(()=>{b(i),de(i||"")},[i]),l.useEffect(()=>{z()},[s]);const z=async()=>{const{data:d}=await A.from("site_audit_scans").select("*").eq("client_id",s).order("created_at",{ascending:!1}).limit(1).single();if(!d)return;m(d),u&&d.site_health!=null&&u(d.site_health,d.errors_count??0,d.warnings_count??0);const{data:D}=await A.from("site_audit_issues").select("*").eq("scan_id",d.id).order("severity",{ascending:!0}).order("affected_count",{ascending:!1});D&&t(D)},re=async()=>{const d=V.trim();if(!d){R.error(o("הכנס URL תקין","Enter a valid URL"));return}const D=d.startsWith("http")?d:`https://${d}`;Pe(!0);try{const{error:Q}=await A.from("clients").update({website_url:D}).eq("id",s);if(Q)throw Q;const{data:se}=await A.from("clients").select("ai_instructions").eq("id",s).single();let Y=(se==null?void 0:se.ai_instructions)||"";const H=o(`אתר הלקוח: ${D}`,`Client website: ${D}`);/אתר הלקוח:/m.test(Y)||/Client website:/m.test(Y)?Y=Y.replace(/אתר הלקוח:.*$/m,H).replace(/Client website:.*$/m,H):Y=Y?`${Y}
23${H}`:H,await A.from("clients").update({ai_instructions:Y}).eq("id",s),b(D),de(D),G(!1),R.success(o("דומיין האתר עודכן בהצלחה ושמור גם במוח 3 של הלקוח","Website domain updated successfully and saved to Brain 3 as well"))}catch(Q){R.error(`${o("שגיאה בשמירת הדומיין","Error saving domain")}: ${Q.message}`)}finally{Pe(!1)}},he=async()=>{if(!L){R.error(o("לא הוגדר URL לאתר הלקוח","No website URL is set for this client"));return}h(!0),R.info(o("מתחיל סריקת אתר...","Starting website scan..."));try{const{data:{session:d}}=await A.auth.getSession();if(!(d!=null&&d.access_token)){R.error(o("יש להתחבר למערכת","Please log in first")),h(!1);return}const{data:D,error:Q}=await A.functions.invoke("site-audit-scan",{headers:{Authorization:`Bearer ${d.access_token}`},body:{client_id:s,website_url:L}});if(Q||D!=null&&D.error)throw Object.assign(new Error((D==null?void 0:D.error)||(Q==null?void 0:Q.message)),{kind:D==null?void 0:D.error_kind});R.success(o("הסריקה הושלמה!","Scan completed!")),await z()}catch(d){const D=(d==null?void 0:d.kind)==="timeout"||/timed? ?out|איטי מדי|Signal timed out/i.test((d==null?void 0:d.message)||""),Q=(d==null?void 0:d.kind)==="quota",se=D?o("האתר איטי להגיב","Site is slow to respond"):Q?o("מכסת PageSpeed נגמרה","PageSpeed quota exceeded"):o("שגיאה בסריקה","Scan error");R.error(`${se}: ${d.message}`,{duration:1e4,action:Q?void 0:{label:o("נסה שוב","Try again"),onClick:()=>he()}})}finally{h(!1)}},ke=async d=>{const{data:{user:D}}=await A.auth.getUser();await A.from("site_audit_issues").update({status:"fixed",fixed_at:new Date().toISOString(),fixed_by:D==null?void 0:D.id}).eq("id",d.id),t(Q=>Q.map(se=>se.id===d.id?{...se,status:"fixed"}:se)),R.success(o("סומן כטופל","Marked as fixed"))},De=async d=>{var D;_(Q=>({...Q,[d.id]:!0})),R.info(o("בודק האם הבעיה נפתרה...","Checking whether the issue has been resolved..."));try{const se=((D=(await A.functions.invoke("site-audit-ai-chat",{body:{issue:d,website_url:L,question:x?`Has the issue "${d.title}" been resolved? Check ${L} and conclude clearly: ✅ fixed / ⚠️ still exists / ❓ cannot verify.`:`האם הבעיה "${d.title}" נפתרה? בדוק את ${L} וענה ברור: ✅ בוצע / ⚠️ עדיין קיים / ❓ לא ניתן לאמת.`}})).data)==null?void 0:D.reply)||o("לא ניתן לאמת כרגע","Unable to verify right now");ye(Y=>({...Y,[d.id]:[...Y[d.id]||[],{role:"assistant",content:se}]})),se.includes("✅")&&(await A.from("site_audit_issues").update({status:"fixed",verified_at:new Date().toISOString()}).eq("id",d.id),t(Y=>Y.map(H=>H.id===d.id?{...H,status:"fixed"}:H)),R.success(o("הבעיה אומתה כטופלה!","The issue was verified as fixed!")))}catch{R.error(o("שגיאה בבדיקה","Verification failed"))}finally{_(Q=>({...Q,[d.id]:!1}))}},Oe=async d=>{var Y;const D=(Y=xe[d.id])==null?void 0:Y.trim();if(!D)return;const Q=je[d.id]||[],se={role:"user",content:D};ye(H=>({...H,[d.id]:[...Q,se]})),Ce(H=>({...H,[d.id]:""})),le(H=>({...H,[d.id]:!0}));try{const{data:H}=await A.functions.invoke("site-audit-ai-chat",{body:{issue:d,website_url:L,messages:[...Q,se],question:D}}),me=(H==null?void 0:H.reply)||(H==null?void 0:H.answer)||o("לא הצלחתי לענות כרגע","I couldn't answer right now");ye(J=>({...J,[d.id]:[...J[d.id]||[],{role:"assistant",content:me}]}))}catch{ye(H=>({...H,[d.id]:[...H[d.id]||[],{role:"assistant",content:o("שגיאה בתקשורת עם ה-AI","AI communication error")}]}))}finally{le(H=>({...H,[d.id]:!1})),setTimeout(()=>{var H;return(H=I.current[d.id])==null?void 0:H.scrollIntoView({behavior:"smooth"})},50)}},Ie=v.filter(d=>!(w!=="all"&&d.severity!==w||N!=="all"&&d.category!==N||j!=="all"&&d.status!==j||K&&!d.title.toLowerCase().includes(K.toLowerCase()))),os=v.filter(d=>d.severity==="error"&&d.status!=="fixed").length,f=v.filter(d=>d.severity==="warning"&&d.status!=="fixed").length,P=v.filter(d=>
23d.severity==="notice"&&d.status!=="fixed").length,X=v.filter(d=>d.status==="fixed").length;return e.jsxs("div",{className:"space-y-4",dir:x?"ltr":"rtl",children:[e.jsxs("div",{className:"panel px-4 py-3 flex items-center gap-3",children:[e.jsx(Le,{className:"w-4 h-4 text-primary flex-shrink-0"}),e.jsx("span",{className:"text-xs text-muted-foreground flex-shrink-0",children:o("דומיין הלקוח:","Client domain:")}),E?e.jsxs(e.Fragment,{children:[e.jsx("input",{value:V,onChange:d=>de(d.target.value),onKeyDown:d=>d.key==="Enter"&&re(),placeholder:"https://example.com",className:"flex-1 text-xs bg-secondary border border-primary/50 rounded px-3 py-1.5 focus:outline-none focus:ring-1 focus:ring-primary",dir:"ltr",autoFocus:!0}),e.jsxs("button",{onClick:re,disabled:we,className:"flex items-center gap-1.5 px-3 py-1.5 rounded bg-primary text-primary-foreground text-xs font-semibold hover:bg-primary/90 disabled:opacity-50 transition-colors",children:[we?e.jsx(ie,{className:"w-3 h-3 animate-spin"}):e.jsx(hs,{className:"w-3 h-3"}),o("שמור","Save")]}),e.jsx("button",{onClick:()=>{G(!1),de(L||"")},className:"p-1.5 rounded hover:bg-secondary transition-colors",children:e.jsx(Ls,{className:"w-3.5 h-3.5 text-muted-foreground"})})]}):e.jsxs(e.Fragment,{children:[L?e.jsx("span",{className:"text-xs text-primary font-medium font-data flex-1",dir:"ltr",children:L}):e.jsx("span",{className:"text-xs text-destructive flex-1",children:o("לא הוגדר — לחץ לעדכון","Not set — click to update")}),e.jsxs("button",{onClick:()=>G(!0),className:"flex items-center gap-1.5 px-3 py-1.5 rounded bg-secondary border border-border text-xs hover:bg-accent transition-colors",children:[e.jsx(us,{className:"w-3 h-3"}),L?o("עדכן","Update"):o("הגדר דומיין","Set domain")]})]}),e.jsx("div",{className:"h-4 w-px bg-border flex-shrink-0"}),e.jsxs("button",{onClick:he,disabled:g||!L,className:"flex items-center gap-2 px-4 py-1.5 rounded-lg bg-primary text-primary-foreground text-xs font-semibold hover:bg-primary/90 disabled:opacity-50 transition-colors flex-shrink-0",children:[g?e.jsx(ie,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(Fe,{className:"w-3.5 h-3.5"}),g?o("סורק...","Scanning..."):r?o("סרוק מחדש","Scan again"):o("התחל סריקה","Start scan")]}),(r==null?void 0:r.completed_at)&&e.jsxs("span",{className:"text-[11px] text-muted-foreground flex-shrink-0 flex items-center gap-1.5",children:[o("עודכן:","Updated:")," ",new Date(r.completed_at).toLocaleString(C),r.source==="pagespeed_insights"&&e.jsx("span",{className:"px-1.5 py-0.5 rounded bg-primary/10 text-primary text-[10px]",title:"Google PageSpeed Insights (Lighthouse)",children:o("נמדד ב-PageSpeed Insights","Measured via PageSpeed Insights")}),r.source==="ai_synthetic"&&e.jsx("span",{className:"px-1.5 py-0.5 rounded bg-warning/10 text-warning text-[10px]",title:o("נתון היסטורי שנוצר על ידי AI — לא מדידה","Legacy AI-generated estimate — not a real measurement"),children:o("הערכת AI ישנה","Legacy AI estimate")})]})]}),g&&e.jsxs("div",{className:"panel p-6 flex flex-col items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 border-2 border-primary border-t-transparent rounded-full animate-spin"}),e.jsx("p",{className:"text-sm font-medium",children:o(`סורק את האתר ${L}...`,`Scanning ${L}...`)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:o("בדיקת מהירות, תגיות מטא, קישורים, אבטחה ועוד","Checking performance, meta tags, links, security, and more")})]}),!g&&!r&&e.jsxs("div",{className:"panel p-12 flex flex-col items-center gap-4 text-center",children:[e.jsx(Le,{className:"w-12 h-12 text-muted-foreground/40"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-semibold mb-1",children:o("טרם בוצעה סריקה","No scan has been run yet")}),e.jsx("p",{className:"text-xs text-muted-foreground max-w-sm",children:o('הגדר את דומיין האתר למעלה ולחץ "התחל סריקה" לקבלת דוח מלא על בעיות SEO, מהירות, תגיות מטא, קישורים שבורים ועוד','Set the website domain above and click "Start scan" to get a full report on SEO issues, performance, meta tags, broken links, and more')})]}),!L&&e.jsxs("button",{onClick:()=>G(!0),className:"flex items-center gap-2 px-4 py-2 rounded-lg bg-primary text-primary-foreground text-xs font-semibold hover:bg-primary/90 transition-colors",children:[e.jsx(Le,{className:"w-3.5 h-3.5"}
23),o("הגדר דומיין עכשיו","Set domain now")]})]}),!g&&r&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-4 gap-4",children:[e.jsxs("div",{className:"panel p-4 flex flex-col items-center",children:[e.jsx(sn,{value:r.site_health||0}),e.jsx("div",{className:"mt-2 flex gap-4 text-[11px]",children:e.jsxs("span",{className:"text-muted-foreground",children:[o("בריאות האתר","Site health")," ",e.jsxs("span",{className:"text-foreground font-bold",children:[r.site_health,"%"]})]})})]}),e.jsxs("div",{className:"col-span-2 panel p-4 space-y-3",children:[e.jsxs("p",{className:"text-xs font-semibold",children:[o("דפים שנסרקו","Pages crawled"),": ",e.jsx("span",{className:"text-primary font-data",children:r.pages_crawled})]}),e.jsx("div",{className:"space-y-2",children:[{label:o("שגיאות","Errors"),count:r.errors_count,color:"bg-destructive"},{label:o("אזהרות","Warnings"),count:r.warnings_count,color:"bg-warning"},{label:o("הערות","Notices"),count:r.notices_count,color:"bg-muted-foreground"},{label:o("טופלו","Fixed"),count:X,color:"bg-success"}].map(d=>e.jsxs("div",{className:"flex items-center gap-2 text-[11px]",children:[e.jsx("span",{className:"w-16 text-muted-foreground",children:d.label}),e.jsx("div",{className:"flex-1 h-2 bg-secondary rounded-full overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full ${d.color}`,style:{width:`${Math.min(100,(d.count||0)*3)}%`}})}),e.jsx("span",{className:"font-data font-bold w-8 text-right",children:d.count||0})]},d.label))})]}),e.jsxs("div",{className:"panel p-4 space-y-2",children:[e.jsx("p",{className:"text-xs font-semibold mb-2",children:o("נושאים מרכזיים","Key themes")}),Object.entries(r.summary||{}).slice(0,4).map(([d,D])=>e.jsxs("div",{className:"flex justify-between text-[11px]",children:[e.jsx("span",{className:"text-muted-foreground",children:Wt[d]||d}),e.jsxs("span",{className:`font-data font-bold ${D>=80?"text-success":D>=60?"text-warning":"text-destructive"}`,children:[D,"%"]})]},d))]})]}),r.summary&&e.jsx("div",{className:"grid grid-cols-8 gap-2",children:Object.entries(r.summary).map(([d,D])=>e.jsx(en,{label:Wt[d]||d,score:D},d))}),e.jsxs("div",{className:"panel overflow-hidden",children:[e.jsxs("div",{className:"px-4 py-3 border-b border-border flex items-center gap-3 flex-wrap",children:[e.jsxs("p",{className:"text-xs font-semibold flex-shrink-0",children:[Ie.length," ",o("ממצאים","findings"),e.jsxs("span",{className:"ms-2 text-muted-foreground font-normal",children:["(",os," ",o("שגיאות","errors")," · ",f," ",o("אזהרות","warnings")," · ",P," ",o("הערות","notices")," · ",X," ",o("טופלו","fixed"),")"]})]}),e.jsx("div",{className:"flex-1"}),e.jsxs("div",{className:"relative",children:[e.jsx(Ee,{className:"absolute left-2 top-1/2 -translate-y-1/2 w-3 h-3 text-muted-foreground"}),e.jsx("input",{value:K,onChange:d=>M(d.target.value),placeholder:o("חיפוש...","Search..."),className:"ps-7 pe-3 py-1 text-xs rounded bg-secondary border border-border w-40 focus:outline-none focus:ring-1 focus:ring-primary"})]}),e.jsxs("select",{value:w,onChange:d=>W(d.target.value),className:"text-xs bg-secondary border border-border rounded px-2 py-1 focus:outline-none",children:[e.jsx("option",{value:"all",children:o("כל החומרות","All severities")}),e.jsx("option",{value:"error",children:o("שגיאות","Errors")}),e.jsx("option",{value:"warning",children:o("אזהרות","Warnings")}),e.jsx("option",{value:"notice",children:o("הערות","Notices")})]}),e.jsxs("select",{value:N,onChange:d=>F(d.target.value),className:"text-xs bg-secondary border border-border rounded px-2 py-1 focus:outline-none",children:[e.jsx("option",{value:"all",children:o("כל הקטגוריות","All categories")}),Object.entries(O).map(([d,D])=>e.jsx("option",{value:d,children:D.label},d))]}),e.jsxs("select",{value:j,onChange:d=>k(d.target.value),className:"text-xs bg-secondary border border-border rounded px-2 py-1 focus:outline-none",children:[e.jsx("option",{value:"all",children:o("כל הסטטוסים","All statuses")}),e.jsx("option",{value:"open",children:o("פתוח","Open")}),e.jsx("option",{value:"fixed",children:o("טופל","Fixed")})]})]}),e.jsxs("div",{className:"divide-y divide-border",children:[Ie.length===0&&e.jsx("div",{className:"py-10 text-center text-xs text-muted-foreground",children:o("אין ממצאים תואמים","No matching findings")}),Ie.map(d=>{const D=U[d.severity]||U.notice,Q=O[d.category]||O.technical,se=D.icon,Y=Q.icon,H=y===d.id,me=je[d.id]||[];return e.jsxs("div",{className:`transition-colors ${d.status==="fixed"?"opacity-60":""}`,children:[e.jsxs("div",{className:"flex items-center gap-3 px-4 py-3 cursor-pointer hover:bg-secondary/30 transition-colors",onClick:()=>$(H?null:d.id),children:[e.jsx(se,{className:`w-4 h-4 flex-shrink-0 ${D.color}`}),e.jsx("div",{className:"flex-1 min-w-0",children:e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"text-xs font-medium",children:d.title}),e.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-full border ${D.bg} ${D.color} ${D.border}`,children:D.label}),e.jsxs("span",{className:`text-[10px] flex items-center gap-0.5 ${Q.color}`,children:[e.jsx(Y,{className:"w-3 h-3"}),Q.label]}),d.status==="fixed"&&e.jsxs("span",{className:"text-[10px] px-1.5 py-0.5 rounded-full bg-success/10 text-success border border-success/30 flex items-center gap-0.5",children:[e.jsx(qs,{className:"w-3 h-3"}),o("טופל","Fixed")]})]})}),e.jsxs("span",{className:"text-[11px] text-muted-foreground flex-shrink-0",children:[d.affected_count," ",o("דפים","pages")]}),H?e.jsx(gs,{className:"w-4 h-4 text-muted-foreground"}):e.jsx(Ga,{className:"w-4 h-4 text-muted-foreground"})]}),H&&e.jsx("div",{className:"border-t border-border bg-secondary/20",children:e.jsxs("div",{className:"grid grid-cols-2 gap-0 divide-x divide-border",children:[e.jsxs("div",{className:"p-4 space-y-4",children:[d.description&&e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] font-semibold text-muted-foreground uppercase tracking-wide mb-1.5",children:o("תיאור הבעיה","Issue description")}),e.jsx("p",{className:"text-xs leading-relaxed",children:d.description})]}),d.how_to_fix&&e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] font-semibold text-muted-foreground uppercase tracking-wide mb-1.5",children:o("כיצד לפתור","How to fix")}),e.jsx("div",{className:"space-y-1.5",children:d.how_to_fix.split(`
24`).filter(Boolean).map((J,Se)=>e.jsxs("div",{className:"flex items-start gap-2 text-xs",children:[e.jsx("span",{className:"w-5 h-5 rounded-full bg-primary/20 text-primary text-[10px] flex items-center justify-center flex-shrink-0 mt-0.5",children:Se+1}),e.jsx("span",{className:"leading-relaxed",children:J.replace(/^\d+\.\s*/,"")})]},Se))})]}),(d.affected_urls||[]).length>0&&e.jsxs("div",{children:[e.jsx("p",{className:"text-[11px] font-semibold text-muted-foreground uppercase tracking-wide mb-1.5",children:o("דפים מושפעים","Affected pages")}),e.jsxs("div",{className:"space-y-1",children:[d.affected_urls.slice(0,5).map((J,Se)=>e.jsx("a",{href:J,target:"_blank",rel:"noopener noreferrer",className:"block text-[11px] text-primary hover:underline truncate",dir:"ltr",children:J},Se)),d.affected_count>5&&e.jsx("p",{className:"text-[10px] text-muted-foreground",children:o(`ועוד ${d.affected_count-5} דפים נוספים`,`And ${d.affected_count-5} more pages`)})]})]}),e.jsxs("div",{className:"flex gap-2 pt-1",children:[d.status!=="fixed"&&e.jsxs("button",{onClick:()=>ke(d),className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-success/10 text-success border border-success/30 text-xs font-medium hover:bg-success/20 transition-colors",children:[e.jsx(Ka,{className:"w-3.5 h-3.5"}),o("סמן כטופל","Mark as fixed")]}),d.status==="fixed"&&e.jsxs("button",{onClick:()=>De(d),disabled:oe[d.id],className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-primary/10 text-primary border border-primary/30 text-xs font-medium hover:bg-primary/20 transition-colors disabled:opacity-50",children:[oe[d.id]?e.jsx(ie,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(Ua,{className:"w-3.5 h-3.5"}),o("אמת תיקון","Verify fix")]}),e.jsxs("button",{onClick:()=>{je[d.id]||ye(J=>({...J,[d.id]:[{role:"assistant",content:o(`שלום! אני כאן לעזור עם הבעיה **"${d.title}"**.
25
26שאל אותי כל דבר על הבעיה או על דרך הפתרון.`,`Hi! I'm here to help with **"${d.title}"**.
27
28Ask me anything about the issue or how to fix it.`)}]}))},className:"flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-primary/10 text-primary border border-primary/30 text-xs font-medium hover:bg-primary/20 transition-colors",children:[e.jsx(Ze,{className:"w-3.5 h-3.5"}),o("שאל את ה-AI","Ask AI")]})]})]}),e.jsxs("div",{className:"flex flex-col h-64",children:[e.jsxs("div",{className:"px-3 py-2 border-b border-border flex items-center gap-2",children:[e.jsx(Ze,{className:"w-3.5 h-3.5 text-primary"}),e.jsx("span",{className:"text-[11px] font-semibold text-primary",children:"AI SEO Advisor"})]}),me.length===0?e.jsxs("div",{className:"flex-1 flex flex-col items-center justify-center gap-2 p-4 text-center",children:[e.jsx(Ze,{className:"w-8 h-8 text-muted-foreground/30"}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:o('לחץ "שאל את ה-AI" לפתיחת שיחה','Click "Ask AI" to start a conversation')})]}):e.jsxs("div",{className:"flex-1 overflow-y-auto p-3 space-y-2",children:[me.map((J,Se)=>e.jsx("div",{className:`text-[11px] leading-relaxed ${J.role==="user"?"text-right":""}`,children:J.role==="user"?e.jsx("div",{className:"inline-block max-w-[80%] bg-primary/10 text-foreground px-3 py-2 rounded-lg rounded-tr-sm",children:J.content}):e.jsx("div",{className:"prose prose-sm dark:prose-invert max-w-none prose-p:my-0.5 prose-li:my-0",children:e.jsx(Es,{remarkPlugins:[jr],children:J.content})})},Se)),$e[d.id]&&e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-primary animate-bounce",style:{animationDelay:"0ms"}}),e.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-primary animate-bounce",style:{animationDelay:"150ms"}}),e.jsx("div",{className:"w-1.5 h-1.5 rounded-full bg-primary animate-bounce",style:{animationDelay:"300ms"}})]}),e.jsx("div",{ref:J=>{I.current[d.id]=J}})]}),e.jsxs("div",{className:"p-2 border-t border-border flex gap-2",children:[e.jsx("input",{value:xe[d.id]||"",onChange:J=>Ce(Se=>({...Se,[d.id]:J.target.value})),onKeyDown:J=>J.key==="Enter"&&!J.shiftKey&&void Oe(d),placeholder:o("שאל שאלה...","Ask a question..."),className:"flex-1 text-[11px] bg-secondary border border-border rounded-lg px-2 py-1.5 focus:outline-none focus:ring-1 focus:ring-primary"}),e.jsx("button",{onClick:()=>void Oe(d),disabled:$e[d.id],className:"p-1.5 rounded-lg bg-primary text-primary-foreground hover:bg-primary/90 disabled:opacity-50 transition-colors",children:e.jsx(sa,{className:"w-3 h-3"})})]})]})]})})]},d.id)})]})]})]})]})}function Be(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:String(Math.round(s))}function qt({value:s,invert:i,size:u="sm"}){if(!s||Math.abs(s)<.1)return null;const n=i?s<0:s>0,c=u==="xs"?"text-[10px]":"text-xs";return e.jsxs("span",{className:`inline-flex items-center gap-0.5 font-semibold ${c} ${n?"text-success":"text-destructive"}`,children:[n?e.jsx(oa,{className:"w-3 h-3"}):e.jsx(mr,{className:"w-3 h-3"}),Math.abs(s).toFixed(1),"%"]})}function Ks({isHe:s,label:i}){return e.jsxs(fe,{variant:"outline",className:"text-[9px] px-1.5 py-0 h-4 gap-0.5 border-warning/40 text-warning bg-warning/5",children:[e.jsx(us,{className:"w-2.5 h-2.5"}),i??(s?"ידני":"Manual")]})}function an({clientId:s,clientName:i,onNavigateToTab:u}){var xt,mt,ht,pt,ut,ft,gt,jt,yt,Nt,bt,vt;const{language:n}=Ye(),{clearanceLevel:c}=Ds(),x=c<=3,o=n==="he",C=o?Bt:Gt,r=(a,p)=>o?a:p,[m,v]=l.useState([]),[t,g]=l.useState(null),h=l.useRef(null),[y,$]=l.useState(!1),[w,W]=l.useState(!1),[N,F]=l.useState(!1),[j,k]=l.useState(""),[K,M]=l.useState(!1),[L,b]=l.useState(""),[E,G]=l.useState(!1),[V,de]=l.useState(7),[we,Pe]=l.useState(!1),[je,ye]=l.useState(n||"he"),[xe,Ce]=l.useState({connected:!0,account_id:null,account_name:null}),[$e,le]=l.useState(!1),[oe,_]=l.useState({clicks:0,impressions:0,ctr:0,position:0}),[I,U]=l.useState(!1),[O,z]=l.useState(!1),[re,he]=l.useState(""),[ke,De]=l.useState(!1),[Oe,Ie]=l.useState(!1),[os,f]=l.useState(!1),[P,X]=l.useState(null),[d,D]=l.useState(!1),[Q,se]=l.useState(!1),[Y,H]=l.useState(new Set),[me,J]=l.useState(!1);l.useEffect(()=>{h.current=t},[t]);const Se=[{value:7,he:"שבועי (7 ימים)",en:"Weekly (7 days)"},{value:14,he:"דו-שבועי (14 ימים)",en:"Bi-weekly (14 days)"},{value:30,he:"חודשי (30 ימים)",en:"Monthly (30 days)"},{value:90,he:"רבעוני (90 ימים)",en:"Quarterly (90 days)"},{value:365,he:"שנתי (365 ימים)",en:"Yearly (365 days)"}],Fs=a=>a<=7?r("שבועי","Weekly"):a<=14?r("דו-שבועי","Bi-weekly"):a<=30?r("חודשי","Monthly"):a<=90?r("רבעוני","Quarterly"):r
28("שנתי","Yearly"),rt=a=>{if(!a)return!1;const p=["שבועי","דו-שבועי","חודשי","רבעוני","שנתי","Weekly","Bi-weekly","Monthly","Quarterly","Yearly"];return new RegExp(`^(דוח|Report)\\s+(${p.map(q=>q.replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&")).join("|")})(\\s*[-–—]\\s*.+)?$`).test(a.trim())},Rs=a=>{var q,te,ne;const p=((q=a==null?void 0:a.report_data)==null?void 0:q.rangeDays)||7,B=(ne=(te=a==null?void 0:a.report_data)==null?void 0:te.manual_overrides)==null?void 0:ne.title;return B&&!rt(B)?B:`${r("דוח","Report")} ${Fs(p)}`},Ps=a=>{var te;const p=((te=a==null?void 0:a.report_data)==null?void 0:te.rangeDays)||7,B=new Date(a.report_week),q=new Date(B.getTime()-(p-1)*864e5);return`${Ue(q,"dd/MM/yyyy")} – ${Ue(B,"dd/MM/yyyy")}`},ha=l.useCallback(async()=>{$(!0);try{const{data:{session:a}}=await A.auth.getSession();if(!(a!=null&&a.access_token))return;const{data:p,error:B}=await A.functions.invoke("seo-weekly-report",{headers:{Authorization:`Bearer ${a.access_token}`},body:{client_id:s,action:"list"}});if(B)throw B;p!=null&&p.reports&&(v(p.reports),Ce(p.search_console??{connected:!0,account_id:null,account_name:null}),p.reports.length>0&&!h.current&&nt(p.reports[0].id))}catch(a){R.error(a.message||r("שגיאה בטעינת דוחות","Failed to load reports"))}finally{$(!1)}},[s]),nt=async a=>{var p;try{const{data:{session:B}}=await A.auth.getSession();if(!(B!=null&&B.access_token))return;const{data:q}=await A.functions.invoke("seo-weekly-report",{headers:{Authorization:`Bearer ${B.access_token}`},body:{client_id:s,action:"get",report_id:a}});if(q!=null&&q.report){g(q.report);const te=q.report.report_data,ne=(p=te==null?void 0:te.manual_overrides)==null?void 0:p.summary;k(ne??q.report.ai_summary??""),le(!1),z(!1),F(!1)}}catch{}},it=async()=>{W(!0);try{const{data:{session:a}}=await A.auth.getSession();if(!(a!=null&&a.access_token))throw new Error("Not authenticated");const{data:p,error:B}=await A.functions.invoke("seo-weekly-report",{headers:{Authorization:`Bearer ${a.access_token}`},body:{client_id:s,action:"generate",range_days:V,include_yoy:we,report_language:je}});if(B||p!=null&&p.error){const q=(p==null?void 0:p.error)||(B==null?void 0:B.message)||"";throw/no search console connected/i.test(q)?new Error(r("לא מחובר Search Console ללקוח זה. עבור לטאב Search Console וחבר את ה-property המתאים.","No Search Console property is connected for this client. Go to the Search Console tab and connect a property.")):/no google connection available/i.test(q)?new Error(r("אין חיבור Google פעיל. יש להתחבר מחדש ל-Google בטאב Search Console.","No active Google connection. Reconnect Google in the Search Console tab.")):new Error(q||r("שגיאה ביצירת דוח","Failed to generate report"))}p!=null&&p.report&&(g(p.report),h.current=p.report,k(p.report.ai_summary||""),v(q=>[p.report,...q.filter(te=>te.id!==p.report.id)]),R.success(r("הדוח נוצר ונשמר בהיסטוריה!","Report generated and saved to history!")))}catch(a){R.error(a.message||r("שגיאה ביצירת דוח","Failed to generate report"))}finally{W(!1)}},pa=async()=>{if(t){M(!0);try{const{data:{session:a}}=await A.auth.getSession();if(!(a!=null&&a.access_token))return;if(x){const{data:p,error:B}=await A.functions.invoke("seo-weekly-report",{headers:{Authorization:`Bearer ${a.access_token}`},body:{client_id:s,action:"update_overrides",report_id:t.id,section:"summary",data:j}});p!=null&&p.report?(g(p.report),R.success(r("הסיכום עודכן","Summary updated"))):R.error((p==null?void 0:p.error)||r("שגיאה בשמירה","Save failed"))}else await A.functions.invoke("seo-weekly-report",{headers:{Authorization:`Bearer ${a.access_token}`},body:{client_id:s,action:"update",report_id:t.id,update_summary:j}}),g({...t,ai_summary:j}),R.success(r("הסיכום עודכן","Summary updated"));F(!1)}catch{}finally{M(!1)}}},ua=async()=>{if(t){U(!0);try{const{data:{session:a}}=await A.auth.getSession();if(!(a!=null&&a.access_token))return;if(!Number.isInteger(oe.clicks)||oe.clicks<0){R.error(r("קליקים חייב להיות מספר שלם חיובי","Clicks must be a non-negative integer")),U(!1);return}if(!Number.isInteger(oe.impressions)||oe.impressions<0){R.error(r("חשיפות חייב להיות מספר שלם חיובי","Impressions must be a non-negative integer")),U(!1);return}if(oe.ctr<0||oe.ctr>1){R.error(r("CTR חייב להיות בין 0 ל-1","CTR must be between 0 and 1")),U(!1);return}if(oe.position<=0){R.error(r("מיקום חייב להיות גדול מ-0","Position must be greater than 0")),U(!1);return}const{data:p,error:B}=await A.functions.invoke("seo-weekly-report",{headers:{Authorization:`Bearer ${a.access_token}`},body:{client_id:s,action:"update_overrides",report_id:t.id,section:"kpis",data:oe}});p!=null&&p.report?(g(p.report),le(!1),R.success(r("KPIs עודכנו","KPIs updated"))):R.error((p==null?void 0:p.error)||r("שגיאה בשמירה","Save failed"))}catch{}finally{U(!1)}}},fa=async()=>
28{if(t){De(!0);try{const{data:{session:a}}=await A.auth.getSession();if(!(a!=null&&a.access_token))return;if(!re.trim()||re.length>200){R.error(r("כותרת חייבת להיות 1-200 תווים","Title must be 1-200 characters")),De(!1);return}const{data:p,error:B}=await A.functions.invoke("seo-weekly-report",{headers:{Authorization:`Bearer ${a.access_token}`},body:{client_id:s,action:"update_overrides",report_id:t.id,section:"title",data:re}});p!=null&&p.report?(g(p.report),z(!1),R.success(r("הכותרת עודכנה","Title updated"))):R.error((p==null?void 0:p.error)||r("שגיאה בשמירה","Save failed"))}catch{}finally{De(!1)}}},ga=async()=>{if(t)try{const{data:{session:a}}=await A.auth.getSession();if(!(a!=null&&a.access_token))return;const{data:p}=await A.functions.invoke("seo-weekly-report",{headers:{Authorization:`Bearer ${a.access_token}`},body:{client_id:s,action:"update",report_id:t.id,toggle_share:!t.is_shared}});p!=null&&p.report&&(g(p.report),R.success(p.report.is_shared?r("הלינק פעיל","Link activated"):r("הלינק בוטל","Link deactivated")))}catch{}},ja=async a=>{if(!x){R.error(r("אין הרשאה למחיקה","No permission to delete"));return}try{const{data:{session:p}}=await A.auth.getSession();if(!(p!=null&&p.access_token))return;const{data:B,error:q}=await A.functions.invoke("seo-weekly-report",{headers:{Authorization:`Bearer ${p.access_token}`},body:{client_id:s,action:"delete",report_id:a}});if(q||B!=null&&B.error){R.error((B==null?void 0:B.error)||r("שגיאה במחיקה","Delete failed"));return}R.success(r("הדוח נמחק","Report deleted")),(t==null?void 0:t.id)===a&&(g(null),h.current=null),v(te=>te.filter(ne=>ne.id!==a))}catch(p){R.error((p==null?void 0:p.message)||r("שגיאה במחיקה","Delete failed"))}},ya=async a=>{if(!(!x||a.length===0)){J(!0);try{const{data:{session:p}}=await A.auth.getSession();if(!(p!=null&&p.access_token)){J(!1);return}const B=await Promise.allSettled(a.map(ne=>A.functions.invoke("seo-weekly-report",{headers:{Authorization:`Bearer ${p.access_token}`},body:{client_id:s,action:"delete",report_id:ne}}))),q=[];let te=0;B.forEach((ne,ds)=>{var wt;ne.status==="fulfilled"&&!ne.value.error&&!((wt=ne.value.data)!=null&&wt.error)?q.push(a[ds]):te+=1}),q.length>0&&(v(ne=>ne.filter(ds=>!q.includes(ds.id))),t&&q.includes(t.id)&&(g(null),h.current=null)),te===0?R.success(r(`נמחקו ${q.length} דוחות`,`Deleted ${q.length} reports`)):q.length===0?R.error(r("שגיאה במחיקה","Delete failed")):R.warning(r(`נמחקו ${q.length}, נכשלו ${te}`,`Deleted ${q.length}, failed ${te}`)),H(new Set),se(!1),D(!1)}finally{J(!1)}}},Na=()=>{if(!(t!=null&&t.share_token))return;const p=`https://blacksheepbi.com/seo-report/${t.share_token}`;navigator.clipboard.writeText(p),G(!0),setTimeout(()=>G(!1),2e3),R.success(r("הלינק הועתק!","Link copied!"))};l.useEffect(()=>{v([]),g(null),h.current=null,k(""),b(""),le(!1),z(!1),F(!1),Ie(!1),G(!1),Ce({connected:!0,account_id:null,account_name:null}),ha()},[s]);const S=t==null?void 0:t.report_data,js=yr(S),cs=br(js),ba={he:Bt,en:Gt,it:Cr,fr:_r,pt:Sr}[js],T=a=>vr(js,a),ae=l.useMemo(()=>S?Nr(S,t==null?void 0:t.ai_summary):null,[S,t==null?void 0:t.ai_summary]),Z=(ae==null?void 0:ae.kpis)??null,lt=(ae==null?void 0:ae.hasOverrides.kpis)??!1;ae==null||ae.hasOverrides.title;const va=(ae==null?void 0:ae.hasOverrides.summary)??!1,Os=(ae==null?void 0:ae.editLog)??[],wa=l.useMemo(()=>{if(!S)return"";const a=V||S.rangeDays||7,p=a<=7?"rangeWeekly":a<=14?"rangeBiWeekly":a<=30?"rangeMonthly":a<=90?"rangeQuarterly":"rangeYearly";return`${T("reportPrefix")} ${T(p)} — ${i}`},[V,S==null?void 0:S.rangeDays,i,js]),ka=a=>rt(a),ot=ae!=null&&ae.title&&!ka(ae.title)?ae.title:null,ct=ot||wa,Sa=!!ot,Is=(ae==null?void 0:ae.summary)??"",dt=l.useMemo(()=>{if(!(S!=null&&S.queries))return[];if(!L.trim())return S.queries;const a=L.toLowerCase();return S.queries.filter(p=>p.query.toLowerCase().includes(a))},[S==null?void 0:S.queries,L]);return y&&m.length===0?e.jsx("div",{className:"flex items-center justify-center py-16",children:e.jsx(ie,{className:"w-6 h-6 animate-spin text-muted-foreground"})}):e.jsxs("div",{className:"space-y-4",dir:o?"rtl":"ltr",children:[!xe.connected&&e.jsxs("div",{dir:o?"rtl":"ltr",className:"panel p-3 border-warning/40 bg-warning/[0.06] flex items-start gap-2.5",children:[e.jsx(qe,{className:"w-4 h-4 text-warning shrink-0 mt-0.5"}),e.jsxs("div",{className:"space-y-1 text-xs flex-1",children:[e.jsx("p",{className:"font-semibold text-warning",children:r("לא ניתן ליצור דוח שבועי ללקוח הזה","Cannot generate a weekly report for this client")}
28),e.jsx("p",{className:"text-muted-foreground leading-relaxed",children:o?e.jsxs(e.Fragment,{children:["ללקוח ",e.jsx("span",{className:"font-medium text-foreground",children:i})," אין חיבור Search Console פעיל, ולכן המערכת לא יכולה למשוך נתוני SEO."," ",e.jsx("button",{type:"button",onClick:()=>u==null?void 0:u("console"),className:"text-primary underline underline-offset-2 hover:text-primary/80 font-medium",children:"עבור לטאב Search Console"})," ","וחבר property מתאים של האתר כדי להפעיל יצירת דוחות."]}):e.jsxs(e.Fragment,{children:["Client ",e.jsx("span",{className:"font-medium text-foreground",children:i})," does not have an active Search Console connection, so the system cannot fetch SEO data."," ",e.jsx("button",{type:"button",onClick:()=>u==null?void 0:u("console"),className:"text-primary underline underline-offset-2 hover:text-primary/80 font-medium",children:"Go to the Search Console tab"})," ","and connect the correct site property to enable report generation."]})})]})]}),e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("h2",{className:"text-sm font-bold flex items-center gap-2",children:[e.jsx(kt,{className:"w-4 h-4 text-primary"}),r("דוחות ביצועים אורגני","Organic Performance Reports")]}),e.jsxs(Ft,{value:String(V),onValueChange:a=>de(Number(a)),children:[e.jsxs(Rt,{className:"w-auto h-7 text-xs gap-1.5 border-dashed",children:[e.jsx(It,{className:"w-3.5 h-3.5 text-muted-foreground"}),e.jsx(Pt,{})]}),e.jsx(Ot,{children:Se.map(a=>e.jsx(ts,{value:String(a.value),className:"text-xs",children:o?a.he:a.en},a.value))})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[t&&e.jsxs(e.Fragment,{children:[e.jsxs(ee,{variant:"outline",size:"sm",className:"gap-1.5 text-xs",onClick:ga,children:[e.jsx(zt,{className:"w-3.5 h-3.5"}),t.is_shared?r("בטל שיתוף","Disable share"):r("שתף","Share")]}),t.is_shared&&e.jsxs(ee,{variant:"outline",size:"sm",className:"gap-1.5 text-xs",onClick:Na,children:[E?e.jsx(la,{className:"w-3.5 h-3.5 text-success"}):e.jsx(Ha,{className:"w-3.5 h-3.5"}),r("העתק לינק","Copy link")]})]}),m.length>0&&e.jsxs(ee,{variant:"outline",size:"sm",className:"gap-1.5 text-xs",onClick:()=>f(!0),"aria-label":r("היסטוריית דוחות","Report history"),children:[e.jsx(Cs,{className:"w-3.5 h-3.5"}),r("היסטוריית דוחות","Report history"),e.jsxs("span",{className:"text-muted-foreground",children:["(",m.length,")"]})]}),e.jsxs(ee,{variant:we?"default":"outline",size:"sm",className:"gap-1.5 text-xs",onClick:()=>Pe(!we),children:[e.jsx(It,{className:"w-3.5 h-3.5"}),r("השוואה שנתית","YoY Compare")]}),e.jsxs(Ft,{value:je,onValueChange:ye,children:[e.jsxs(Rt,{className:"w-auto min-w-[120px] h-8 text-xs gap-1.5",title:r("שפת הדוח","Report language"),children:[e.jsx(Le,{className:"w-3.5 h-3.5"}),e.jsx(Pt,{})]}),e.jsxs(Ot,{children:[e.jsx(ts,{value:"he",children:"עברית"}),e.jsx(ts,{value:"en",children:"English"}),e.jsx(ts,{value:"it",children:"Italiano"}),e.jsx(ts,{value:"fr",children:"Français"}),e.jsx(ts,{value:"pt",children:"Português"})]})]}),e.jsxs(ee,{size:"sm",className:"gap-1.5 text-xs",onClick:it,disabled:w||!xe.connected,children:[w?e.jsx(ie,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(Fe,{className:"w-3.5 h-3.5"}),r(`צור דוח SEO ${Fs(V)}`,`Generate ${Fs(V)} SEO Report`)]})]})]}),!t&&!y&&e.jsxs("div",{className:"panel p-10 text-center space-y-3",children:[e.jsx(kt,{className:"w-10 h-10 text-muted-foreground mx-auto"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:r("אין דוחות עדיין. צור את הדוח הראשון!","No reports yet. Generate your first report!")}),e.jsxs(ee,{onClick:it,disabled:w||!xe.connected,className:"gap-2",children:[w?e.jsx(ie,{className:"w-4 h-4 animate-spin"}):e.jsx(_e,{className:"w-4 h-4"}),r("צור דוח ראשון","Generate First Report")]})]}),t&&S&&e.jsxs("div",{dir:cs,className:"space-y-4",children:[e.jsx("div",{className:"flex items-center gap-2 flex-wrap",children:O?e.jsxs("div",{className:"flex items-center gap-2 flex-1",children:[e.jsx($s,{value:re,onChange:a=>he(a.target.value),className:"h-8 text-sm font-semibold flex-1 max-w-md text-foreground",maxLength:200,dir:cs,autoFocus:!0}),e.jsxs(ee,{variant:"outline",size:"sm",className:"h-7 text-[10px] gap-1",onClick:()=>z(!1),children:[e.jsx(Ls,{className:"w-3 h-3"}),T("cancel")]}),e.jsxs(ee,{size:"sm",className:"h-7 text-[10px] gap-1",onClick:fa,disabled:ke,children:[ke?e.jsx(ie,{className:"w-3 h-3 animate-spin"}):e.jsx(hs,{className:"w-3 h-3"}),T("save")]})]}):e.jsxs(e.Fragment,{children:[e.jsx("h2",{className:"text-sm font-bold text-foreground",children:ct}),Sa&&e.jsx(Ks,{label:T("manualBadge")}),x&&e.jsx(ee,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:()=>{he(ct),z(!0)},children:e.jsx(us,{className:"w-3 h-3 text-muted-foreground"})})]})}),Z&&Z.clicks===0&&Z.impressions===0&&!lt&&e.jsxs("div",{className:"panel p-3 border-warning/40 bg-warning/[0.06] flex items-start gap-2.5",children:[e.jsx(qe,{className:"w-4 h-4 text-warning shrink-0 mt-0.5"}),e.jsxs("div",{className:"space-y-1 text-xs",dir:cs,children:[e.jsx("p",{className:"font-semibold text-warning",children:T("noDataTitle")}),e.jsx("p",{className:"text-muted-foreground leading-relaxed",children:T("noDataBody")})]})]}),e.jsxs("div",{className:"panel p-4 space-y-3 border-primary/20 bg-primary/[0.03]",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_e,{className:"w-4 h-4 text-primary"}),e.jsx("h3",{className:"text-xs font-semibold",children:T("aiSummary")}
28),va&&e.jsx(Ks,{label:T("manualBadge")})]}),e.jsx("div",{className:"flex items-center gap-1",children:N?e.jsxs(e.Fragment,{children:[e.jsx(ee,{variant:"outline",size:"sm",className:"h-6 text-[10px]",onClick:()=>{F(!1),k(Is)},children:T("cancel")}),e.jsxs(ee,{size:"sm",className:"h-6 text-[10px] gap-1",onClick:pa,disabled:K,children:[K?e.jsx(ie,{className:"w-3 h-3 animate-spin"}):e.jsx(hs,{className:"w-3 h-3"}),T("save")]})]}):x?e.jsxs(ee,{variant:"ghost",size:"sm",className:"h-6 text-[10px] gap-1",onClick:()=>{k(Is),F(!0)},children:[e.jsx(Va,{className:"w-3 h-3"}),T("edit")]}):null})]}),N?e.jsx(Wa,{value:j,onChange:a=>k(a.target.value),className:"min-h-[120px] text-sm text-foreground",dir:cs}):e.jsx("div",{className:"prose prose-sm max-w-none text-foreground text-xs",dir:cs,children:e.jsx(Es,{children:Is||T("noSummary")})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"flex items-center gap-2",children:lt&&e.jsx(Ks,{label:T("manualBadge")})}),x&&!$e&&e.jsxs(ee,{variant:"ghost",size:"sm",className:"h-6 text-[10px] gap-1",onClick:()=>{_({clicks:(Z==null?void 0:Z.clicks)??0,impressions:(Z==null?void 0:Z.impressions)??0,ctr:(Z==null?void 0:Z.ctr)??0,position:(Z==null?void 0:Z.position)??0}),le(!0)},children:[e.jsx(us,{className:"w-3 h-3"}),T("editKpis")]}),$e&&e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsxs(ee,{variant:"outline",size:"sm",className:"h-6 text-[10px] gap-1",onClick:()=>le(!1),children:[e.jsx(Ls,{className:"w-3 h-3"}),T("cancel")]}),e.jsxs(ee,{size:"sm",className:"h-6 text-[10px] gap-1",onClick:ua,disabled:I,children:[I?e.jsx(ie,{className:"w-3 h-3 animate-spin"}):e.jsx(hs,{className:"w-3 h-3"}),T("save")]})]})]}),$e?e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3",children:[{label:T("clicks"),key:"clicks",icon:e.jsx(Re,{className:"w-4 h-4"}),type:"int"},{label:T("impressions"),key:"impressions",icon:e.jsx(Le,{className:"w-4 h-4"}),type:"int"},{label:"CTR",key:"ctr",icon:e.jsx(ge,{className:"w-4 h-4"}),type:"decimal",hint:"0-1"},{label:T("avgPosition"),key:"position",icon:e.jsx(Ee,{className:"w-4 h-4"}),type:"decimal"}].map(a=>e.jsxs("div",{className:"panel p-4 space-y-2 border-primary/30",children:[e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[a.icon,e.jsx("span",{className:"text-[10px]",children:a.label})]}),e.jsx($s,{type:"number",step:a.type==="int"?"1":"0.01",min:"0",max:a.key==="ctr"?"1":void 0,value:oe[a.key],onChange:p=>_({...oe,[a.key]:a.type==="int"?parseInt(p.target.value)||0:parseFloat(p.target.value)||0}),className:"h-9 text-lg font-bold font-data text-foreground"}),a.hint&&e.jsx("span",{className:"text-[9px] text-muted-foreground",children:a.hint}),e.jsxs("span",{className:"text-[9px] text-muted-foreground",children:[T("original")," ",a.key==="ctr"?(S.summary[a.key].value*100).toFixed(2)+"%":Be(S.summary[a.key].value)]})]},a.key))}):e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3",children:[{label:T("clicks"),value:Be((Z==null?void 0:Z.clicks)??0),change:S.summary.clicks.change,yoyChange:(mt=(xt=S.yoy)==null?void 0:xt.clicks)==null?void 0:mt.change,icon:e.jsx(Re,{className:"w-4 h-4"})},{label:T("impressions"),value:Be((Z==null?void 0:Z.impressions)??0),change:S.summary.impressions.change,yoyChange:(pt=(ht=S.yoy)==null?void 0:ht.impressions)==null?void 0:pt.change,icon:e.jsx(Le,{className:"w-4 h-4"})},{label:"CTR",value:(((Z==null?void 0:Z.ctr)??0)*100).toFixed(2)+"%",change:S.summary.ctr.change,yoyChange:(ft=(ut=S.yoy)==null?void 0:ut.ctr)==null?void 0:ft.change,icon:e.jsx(ge,{className:"w-4 h-4"})},{label:T("avgPosition"),value:((Z==null?void 0:Z.position)??0).toFixed(1),change:S.summary.position.change,yoyChange:(jt=(gt=S.yoy)==null?void 0:gt.position)==null?void 0:jt.change,invert:!0,icon:e.jsx(Ee,{className:"w-4 h-4"})}].map((a,p)=>{const B=a.invert?a.change<0:a.change>0;return e.jsxs("div",{className:"panel p-4 relative overflow-hidden",children:[e.jsx("div",{className:`absolute top-0 left-0 right-0 h-1 ${B?"bg-success":"bg-destructive"}`}),e.jsxs("div",{className:"flex items-center gap-2 mb-1 text-muted-foreground",children:[a.icon,e.jsx("span",{className:"text-[10px]",children:a.label})]}),e.jsx("p",{className:"text-2xl font-bold font-data",children:a.value}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx(qt,{value:a.change,invert:a.invert}),a.yoyChange!==void 0&&a.yoyChange!==null&&e.jsxs("span",{className:"text-[10px] text-muted-foreground flex items-center gap-0.5",children:["YoY: ",e.jsx(qt,{value:a.yoyChange,invert:a.invert,size:"xs"})]})]})]},p)})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"panel p-4 space-y-3",children:[e.jsxs("h3",{className:"text-xs font-semibold flex items-center gap-2",children:[e.jsx(da,{className:"w-3.5 h-3.5 text-primary"}),T("positionDist")]}),e.jsx("div",{className:"grid grid-cols-4 gap-2 text-center",children:[{label:"Top 3",value:S.positionBuckets.top3,color:"bg-success/20 text-success"},{label:"Top 10",value:S.positionBuckets.top10,color:"bg-primary/20 text-primary"},{label:"Top 20",value:S.positionBuckets.top20,color:"bg-warning/20 text-warning"},{label:"Top 50",value:S.positionBuckets.top50,color:"bg-muted text-muted-foreground"}].map((a,p)=>e.jsxs("div",{className:`rounded-lg p-3 ${a.color}`,children:[e.jsx("p",{className:"text-lg font-bold font-data",children:a.value}),e.jsx("p",{className:"text-[10px] font-medium",children:a.label})]},p))}),S.positionBuckets.total>0&&e.jsxs("div",{className:"h-3 rounded-full bg-secondary overflow-hidden flex",children:[e.jsx("div",{className:"bg-success h-full",style:{width:`${S.positionBuckets.top3/S.positionBuckets.total*100}%`}}),e.jsx("div",{className:"bg-primary h-full",style:{width:`${(S.positionBuckets.top10-S.positionBuckets.top3)/S.positionBuckets.total*100}%`}}),e.jsx("div",{className:"bg-warning h-full",style:{width:`${(S.positionBuckets.top20-S.positionBuckets.top10)/S.positionBuckets.total*100}%`}})]})]}),e.jsxs("div",{className:"panel p-4 space-y-3",children:[e.jsx("h3",{className:"text-xs font-semibold",children:T("byDevice")}),(S.devices||[]).length>0?e.jsx("div",{className:"space-y-2",children:S.devices.map((a,p)=>{const B=S.devices.reduce((ne,ds)=>ne+ds.clicks,0),q=B>0?(a.clicks/B*100).toFixed(0):0,te=a.device==="DESKTOP"?e.jsx(at,{className:"w-3.5 h-3.5"}):a.device==="MOBILE"?e.jsx(st,{className:"w-3.5 h-3.5"}):e.jsx(ca,{className:"w-3.5 h-3.5"});return e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"text-muted-foreground",children:te}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex justify-between text-xs mb-0.5",children:[e.jsx("span",{className:"font-medium",children:a.device}),e.jsxs("span",{className:"font-data",children:[Be(a.clicks)," (",q,"%)"]})]}),e.jsx("div",{className:"h-1.5 rounded-full bg-secondary overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full bg-primary",style:{width:`${q}%`}})})]})]},p)})}):e.jsx("p",{className:"text-xs text-muted-foreground text-center py-4",children:T("noDeviceData")})]})]}),((yt=S.daily)==null?void 0:yt.length)>0&&e.jsxs("div",{className:"panel p-4 space-y-3",children:[e.jsx("h3",{className:"text-xs font-semibold",children:T("dailyTrend")}),e.jsx("div",{className:"h-52",children:e.jsx(Te,{width:"100%",height:"100%",children:e.jsxs(fs,{data:S.daily,children:[e.jsx(es,{strokeDasharray:"3 3",stroke:"hsl(var(--border))"}),e.jsx(ss,{dataKey:"date",tickFormatter:a=>Ue(new Date(a),"dd/MM"),tick:{fontSize:10,fill:"hsl(var(--muted-foreground))"}}),e.jsx(He,{yAxisId:"left",tick:{fontSize:10,fill:"hsl(var(--muted-foreground))"}}),e.jsx(He,{yAxisId:"right",orientation:"right",tick:{fontSize:10,fill:"hsl(var(--muted-foreground))"}}),e.jsx(We,{contentStyle:{fontSize:11,background:"hsl(var(--card))",border:"1px solid hsl(var(--border))",borderRadius:8,color:"hsl(var(--foreground))"}}),e.jsx(ls,{yAxisId:"left",type:"monotone",dataKey:"clicks",stroke:"hsl(var(--primary))",fill:"hsl(var(--primary) / 0.15)",strokeWidth:2,name:T("clicks")}),e.jsx(ls,{yAxisId:"right",type:"monotone",dataKey:"impressions",stroke:"hsl(142 70% 45%)",fill:"hsl(142 70% 45% / 0.08)",strokeWidth:1.5,name:T("impressions")})]})})})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsxs("div",{className:"panel overflow-hidden",children:[e.jsxs("div",{className:"px-4 py-2 border-b border-border flex items-center gap-2 bg-success/5",children:[e.jsx(ge,{className:"w-3.5 h-3.5 text-success"}),e.jsx("h3",{className:"text-xs font-semibold text-success",children:T("winners")})]}),e.jsxs("div",{className:"divide-y divide-border max-h-64 overflow-y-auto",children:[(S.winners||[]).map((a,p)=>e.jsxs("div",{className:"px-4 py-2 text-xs flex items-center justify-between hover:bg-secondary/30",children:[e.jsx("span",{className:"truncate flex-1 font-medium",dir:"ltr",children:a.query}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("span",{className:"font-data",children:a.position.toFixed(1)}),e.jsxs("span",{className:"text-success text-[10px] font-bold",children:["↑",Math.abs(a.positionChange).toFixed(1)]})]})]},p)),(!S.winners||S.winners.length===0)&&e.jsx("p",{className:"p-4 text-xs text-muted-foreground text-center",children:T("noWinners")})]})]}),e.jsxs("div",{className:"panel overflow-hidden",children:[e.jsxs("div",{className:"px-4 py-2 border-b border-border flex items-center gap-2 bg-destructive/5",children:[e.jsx(Ae,{className:"w-3.5 h-3.5 text-destructive"}),e.jsx("h3",{className:"text-xs font-semibold text-destructive",children:T("losers")})]}),e.jsxs("div",{className:"divide-y divide-border max-h-64 overflow-y-auto",children:[(S.losers||[]).map((a,p)=>e.jsxs("div",{className:"px-4 py-2 text-xs flex items-center justify-between hover:bg-secondary/30",children:[e.jsx("span",{className:"truncate flex-1 font-medium",dir:"ltr",children:a.query}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("span",{className:"font-data",children:a.position.toFixed(1)}),e.jsxs("span",{className:"text-destructive text-[10px] font-bold",children:["↓",Math.abs(a.positionChange).toFixed(1)]})]})]},p)),(!S.losers||S.losers.length===0)&&e.jsx("p",{className:"p-4 text-xs text-muted-foreground text-center",children:T("noLosers")})]})]}),e.jsxs("div",{className:"panel overflow-hidden",children:[e.jsxs("div",{className:"px-4 py-2 border-b border-border flex items-center gap-2 bg-violet-500/5",children:[e.jsx(Ze,{className:"w-3.5 h-3.5 text-violet-500"}),e.jsx("h3",{className:"text-xs font-semibold text-violet-600",children:T("aiQueries")})]}),e.jsxs("div",{className:"divide-y divide-border max-h-64 overflow-y-auto",children:[(S.aiQueries||[]).map((a,p)=>e.jsxs("div",{className:"px-4 py-2 text-xs flex items-center justify-between hover:bg-secondary/30",children:[e.jsx("span",{className:"truncate flex-1 font-medium",dir:"ltr",children:a.query}),e.jsxs("span",{className:"font-data text-muted-foreground shrink-0",children:[a.clicks," ",T("clicksUnit")]})]},p)),(!S.aiQueries||S.aiQueries.length===0)&&e.jsx("p",{className:"p-4 text-xs text-muted-foreground text-center",children:T("noAiQueries")})]})]})]}),((Nt=S.strikingDistance)==null?void 0:Nt.length)>0&&e.jsxs("div",{className:"panel overflow-hidden",children:[e.jsxs("div",{className:"px-4 py-3 border-b border-border flex items-center gap-2 bg-warning/5",children:[e.jsx(Re,{className:"w-4 h-4 text-warning"}),e.jsx("h3",{className:"text-xs font-semibold",children:T("strikingDistance")}),e.jsxs("span",{className:"text-[10px] text-muted-foreground ms-auto",children:[S.strikingDistance.length," ",T("keywords")]})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-border text-muted-foreground",children:[e.jsx("th",{className:"text-start px-4 py-2 font-medium",children:T("keyword")}),e.jsx("th",{className:"text-center px-2 py-2 font-medium",children:T("position")}),e.jsx("th",{className:"text-center px-2 py-2 font-medium",children:T("clicks")}),e.jsx("th",{className:"text-center px-2 py-2 font-medium",children:T("impressions")}),e.jsx("th",{className:"text-center px-2 py-2 font-medium",children:T("change")})]})}),e.jsx("tbody",{className:"divide-y divide-border",children:S.strikingDistance.map((a,p)=>e.jsxs("tr",{className:"hover:bg-secondary/30 transition-colors",children:[e.jsx("td",{className:"px-4 py-2 font-medium",dir:"ltr",children:a.query}),e.jsx("td",{className:"px-2 py-2 font-data text-center",children:a.position.toFixed(1)}),e.jsx("td",{className:"px-2 py-2 font-data text-center",children:a.clicks}),e.jsx("td",{className:"px-2 py-2 font-data text-center",children:Be(a.impressions)}),e.jsx("td",{className:"px-2 py-2 text-center",children:a.positionChange!==0&&e.jsxs("span",{className:`text-[10px] font-bold ${a.positionChange<0?"text-success":"text-destructive"}`,children:[a.positionChange<0?"↑":"↓",Math.abs(a.positionChange).toFixed(1)]})})]},p))})]})})]}),e.jsxs("div",{className:"panel overflow-hidden",children:[e.jsxs("div",{className:"px-4 py-3 border-b border-border flex items-center gap-3",children:[e.jsx(Ee,{className:"w-4 h-4 text-muted-foreground"}),e.jsx("h3",{className:"text-xs font-semibold flex-1",children:T("allKeywords")}),e.jsxs("div",{className:"relative w-56",children:[e.jsx(Ee,{className:"absolute start-2 top-1/2 -translate-y-1/2 w-3 h-3 text-muted-foreground"}),e.jsx($s,{value:L,onChange:a=>
28b(a.target.value),placeholder:T("searchKeyword"),className:"ps-7 h-7 text-xs text-foreground"})]}),e.jsxs("span",{className:"text-[10px] text-muted-foreground",children:[dt.length," / ",((bt=S.queries)==null?void 0:bt.length)||0]})]}),e.jsx("div",{className:"overflow-x-auto max-h-96",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{className:"sticky top-0 bg-card z-10",children:e.jsxs("tr",{className:"border-b border-border text-muted-foreground",children:[e.jsx("th",{className:"text-start px-4 py-2 font-medium w-8",children:"#"}),e.jsx("th",{className:"text-start px-2 py-2 font-medium",children:T("keyword")}),e.jsx("th",{className:"text-center px-2 py-2 font-medium",children:T("posShort")}),e.jsx("th",{className:"text-center px-2 py-2 font-medium",children:T("clicks")}),e.jsx("th",{className:"text-center px-2 py-2 font-medium",children:T("imprShort")}),e.jsx("th",{className:"text-center px-2 py-2 font-medium",children:"CTR"}),e.jsx("th",{className:"text-center px-2 py-2 font-medium",children:T("deltaPos")})]})}),e.jsx("tbody",{className:"divide-y divide-border",children:dt.slice(0,100).map((a,p)=>e.jsxs("tr",{className:"hover:bg-secondary/30 transition-colors",children:[e.jsx("td",{className:"px-4 py-1.5 text-muted-foreground font-data",children:p+1}),e.jsx("td",{className:"px-2 py-1.5 font-medium max-w-[300px] truncate",dir:"ltr",children:a.query}),e.jsx("td",{className:"px-2 py-1.5 font-data text-center",children:a.position.toFixed(1)}),e.jsx("td",{className:"px-2 py-1.5 font-data text-center",children:a.clicks}),e.jsx("td",{className:"px-2 py-1.5 font-data text-center",children:Be(a.impressions)}),e.jsxs("td",{className:"px-2 py-1.5 font-data text-center",children:[(a.ctr*100).toFixed(1),"%"]}),e.jsx("td",{className:"px-2 py-1.5 text-center",children:a.positionChange!==0?e.jsxs("span",{className:`text-[10px] font-bold ${a.positionChange<0?"text-success":"text-destructive"}`,children:[a.positionChange<0?"↑":"↓",Math.abs(a.positionChange).toFixed(1)]}):e.jsx("span",{className:"text-muted-foreground",children:"—"})})]},p))})]})})]}),e.jsxs("div",{className:"panel overflow-hidden",children:[e.jsxs("div",{className:"px-4 py-3 border-b border-border flex items-center gap-2",children:[e.jsx(Le,{className:"w-4 h-4 text-muted-foreground"}),e.jsx("h3",{className:"text-xs font-semibold",children:T("topPages")})]}),e.jsx("div",{className:"overflow-x-auto max-h-72",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{className:"sticky top-0 bg-card z-10",children:e.jsxs("tr",{className:"border-b border-border text-muted-foreground",children:[e.jsx("th",{className:"text-start px-4 py-2 font-medium",children:T("page")}),e.jsx("th",{className:"text-center px-2 py-2 font-medium",children:T("clicks")}),e.jsx("th",{className:"text-center px-2 py-2 font-medium",children:T("imprShort")}),e.jsx("th",{className:"text-center px-2 py-2 font-medium",children:"CTR"}),e.jsx("th",{className:"text-center px-2 py-2 font-medium",children:T("posShort")})]})}),e.jsx("tbody",{className:"divide-y divide-border",children:(S.pages||[]).slice(0,30).map((a,p)=>{let B=a.page;try{B=new URL(a.page).pathname}catch{}return e.jsxs("tr",{className:"hover:bg-secondary/30 transition-colors",children:[e.jsx("td",{className:"px-4 py-1.5 font-medium max-w-[300px]",dir:"ltr",children:e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"truncate",title:a.page,children:B}),e.jsx("a",{href:a.page,target:"_blank",rel:"noopener noreferrer",className:"flex-shrink-0 text-muted-foreground hover:text-primary transition-colors",onClick:q=>q.stopPropagation(),children:e.jsx(Qe,{className:"w-3 h-3"})})]})}),e.jsx("td",{className:"px-2 py-1.5 font-data text-center",children:a.clicks}),e.jsx("td",{className:"px-2 py-1.5 font-data text-center",children:Be(a.impressions)}),e.jsxs("td",{className:"px-2 py-1.5 font-data text-center",children:[(a.ctr*100).toFixed(1),"%"]}),e.jsx("td",{className:"px-2 py-1.5 font-data text-center",children:a.position.toFixed(1)})]},p)})})]})})]}),((vt=S.countries)==null?void 0:vt.length)>0&&e.jsxs("div",{className:"panel p-4 space-y-3",children:[e.jsx("h3",{className:"text-xs font-semibold",children:T("byCountry")}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-5 ga
28p-2",children:S.countries.slice(0,10).map((a,p)=>e.jsxs("div",{className:"bg-secondary/30 rounded-lg p-2 text-center",children:[e.jsx("p",{className:"text-xs font-medium",children:a.country}),e.jsx("p",{className:"text-sm font-bold font-data",children:Be(a.clicks)}),e.jsxs("p",{className:"text-[10px] text-muted-foreground",children:[Be(a.impressions)," ",T("imprUnit")]})]},p))})]}),x&&Os.length>0&&e.jsxs("div",{className:"panel overflow-hidden",children:[e.jsxs("button",{onClick:()=>Ie(!Oe),className:"w-full px-4 py-2 flex items-center gap-2 text-xs text-muted-foreground hover:bg-secondary/30 transition-colors",children:[e.jsx(Cs,{className:"w-3.5 h-3.5"}),e.jsxs("span",{className:"font-medium",children:[T("editHistory")," (",Os.length,")"]}),Oe?e.jsx(et,{className:"w-3.5 h-3.5 ms-auto"}):e.jsx(gs,{className:"w-3.5 h-3.5 ms-auto"})]}),Oe&&e.jsx("div",{className:"divide-y divide-border max-h-40 overflow-y-auto",children:[...Os].reverse().map((a,p)=>e.jsxs("div",{className:"px-4 py-1.5 text-[10px] text-muted-foreground flex items-center gap-3",children:[e.jsx("span",{className:"font-medium text-foreground",children:a.user_name}),e.jsx(fe,{variant:"outline",className:"text-[9px] h-4 px-1.5",children:a.section==="kpis"?"KPIs":a.section==="title"?T("sectionTitle"):T("sectionSummary")}),e.jsx("span",{className:"ms-auto",children:Ue(new Date(a.at),"dd/MM/yyyy HH:mm",{locale:C})})]},p))})]}),e.jsxs("div",{className:"flex items-center justify-between text-[10px] text-muted-foreground px-1",children:[e.jsxs("span",{children:[T("generatedAt"),": ",Ue(new Date(t.created_at),"PPpp",{locale:ba})]}),e.jsxs("span",{className:"flex items-center gap-2",children:[S.rangeDays&&e.jsxs("span",{className:"bg-secondary px-1.5 py-0.5 rounded text-[9px] font-medium",children:[S.rangeDays," ",T("days")]}),S.dateRange&&e.jsxs("span",{children:[S.dateRange.startDate," → ",S.dateRange.endDate]})]})]})]}),e.jsx(qa,{open:os,onOpenChange:a=>{f(a),a||(se(!1),H(new Set))},children:e.jsxs(Qa,{className:"max-w-lg",dir:o?"rtl":"ltr",children:[e.jsx(Ya,{children:e.jsxs(Xa,{className:"flex items-center gap-2 text-sm",children:[e.jsx(Cs,{className:"w-4 h-4 text-primary"}),r("היסטוריית דוחות","Report history"),e.jsxs("span",{className:"text-muted-foreground text-xs font-normal",children:["(",m.length,")"]}),x&&m.length>0&&e.jsx("button",{onClick:()=>{se(a=>{const p=!a;return p||H(new Set),p})},className:"ms-auto text-[11px] font-normal px-2 py-1 rounded-md border border-border hover:bg-muted transition-colors",children:Q?r("בטל בחירה","Cancel selection"):r("בחר","Select")})]})}),Q&&e.jsxs("div",{className:"flex items-center justify-between gap-2 px-1 py-2 border-b border-border",children:[e.jsxs("button",{onClick:()=>{Y.size===m.length?H(new Set):H(new Set(m.map(a=>a.id)))},className:"text-[11px] inline-flex items-center gap-1.5 text-muted-foreground hover:text-foreground transition-colors",children:[Y.size===m.length&&m.length>0?e.jsx(wr,{className:"w-3.5 h-3.5"}):e.jsx(kr,{className:"w-3.5 h-3.5"}),Y.size===m.length&&m.length>0?r("בטל הכל","Unselect all"):r("בחר הכל","Select all")]}),e.jsx("span",{className:"text-[11px] text-muted-foreground",children:r(`נבחרו ${Y.size}`,`${Y.size} selected`)}),e.jsxs(ee,{size:"sm",variant:"destructive",disabled:Y.size===0,onClick:()=>D(!0),className:"h-7 text-[11px] px-2.5",children:[e.jsx(Je,{className:"w-3 h-3 me-1"}),r("מחק נבחרים","Delete selected")]})]}),e.jsxs("div",{className:"max-h-[60vh] overflow-y-auto -mx-1 px-1 space-y-1",children:[m.length===0&&e.jsx("p",{className:"text-xs text-muted-foreground text-center py-6",children:r("אין דוחות שמורים עדיין","No saved reports yet")}),m.map(a=>{const p=(t==null?void 0:t.id)===a.id,B=Y.has(a.id),q=()=>{H(te=>{const ne=new Set(te);return ne.has(a.id)?ne.delete(a.id):ne.add(a.id),ne})};return e.jsxs("div",{className:`relative panel p-3 hover:border-primary/40 transition-colors ${p?"border-primary/60 bg-primary/[0.05]":""} ${B?"border-destructive/50 bg-destructive/[0.04]":""}`,children:[e.jsxs("div",{className:"flex items-start gap-2",children:[Q&&e.jsx(Ja,{checked:B,onCheckedChange:q,className:"mt-0.5","aria-label":r("בחר דוח","Select report")}),e.jsxs("button",{onClick:()=>{Q?q():(nt(a.id),f(!1))},className:"flex-1 text-start min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 mb-1 pe-7",children:[e.jsx("span",{className:"text-xs font-semibold text-foreground truncate",children:Rs(a)}),a.is_shared&&e.jsxs(fe,{variant:"outline",className:"text-[9px] h-4 px-1.5 gap-0.5 border-success/40 text-success",children:[e.jsx(zt,{className:"w-2.5 h-2.5"}),r("משותף","Shared")]})]}),e.jsxs("div",{className:"text-[10px] text-muted-foreground space-y-0.5",children:[e.jsxs("div",{children:[r("נוצר","Created"),": ",Ue(new Date(a.created_at),"dd/MM/yyyy HH:mm")]}),e.jsxs("div",{children:[r("טווח","Range"),": ",Ps(a)]})]})]})]}),x&&!Q&&e.jsx("button",{onClick:te=>{te.stopPropagation(),X(a.id)},className:"absolute top-2 end-2 p-1.5 rounded-md text-muted-foreground hover:text-destructive hover:bg-destructive/10 transition-colors","aria-label":r("מחק דוח","Delete report"),title:r("מחק דוח","Delete report"),children:e.jsx(Je,{className:"w-3.5 h-3.5"})})]},a.id)})]})]})}),e.jsx(St,{open:!!P,onOpenChange:a=>{a||X(null)},children:e.jsxs(_t,{dir:o?"rtl":"ltr",children:[e.jsxs(Ct,{children:[e.jsxs($t,{className:"flex items-center gap-2",children:[e.jsx(Je,{className:"w-4 h-4 text-destructive"}),r("מחיקת דוח","Delete report")]}),e.jsx(Lt,{asChild:!0,children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{children:r("פעולה זו אינה ניתנת לביטול. הדוח יימחק לצמיתות.","This action cannot be undone. The report will be permanently deleted.")}),P&&(()=>{const a=m.find(p=>p.id===P);return a?e.jsxs("div",{className:"rounded-md border border-border bg-muted/40 p-2.5 text-xs space-y-1",children:[e.jsx("div",{className:"font-semibold text-foreground",children:Rs(a)}),e.jsxs("div",{className:"text-muted-foreground",children:[r("טווח","Range"),": ",Ps(a)]})]}):null})()]})})]}),e.jsxs(Tt,{children:[e.jsx(At,{children:r("ביטול","Cancel")}),e.jsx(Dt,{className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",onClick:async()=>{const a=P;X(null),a&&await ja(a)},children:r("מחק לצמיתות","Delete permanently")})]})]})}),e.jsx(St,{open:d,onOpenChange:a=>{!a&&!me&&D(!1)},children:e.jsxs(_t,{dir:o?"rtl":"ltr",children:[e.jsxs(Ct,{children:[e.jsxs($t,{className:"flex items-center gap-2",children:[e.jsx(Je,{className:"w-4 h-4 text-destructive"}),r(`מחיקת ${Y.size} דוחות`,`Delete ${Y.size} reports`)]}),e.jsx(Lt,{asChild:!0,children:e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{children:r("פעולה זו אינה ניתנת לביטול. הדוחות הבאים יימחקו לצמיתות:","This action cannot be undone. The following reports will be permanently deleted:")}),e.jsx("div",{className:"rounded-md border border-border bg-muted/40 p-2.5 text-xs max-h-48 overflow-y-auto space-y-1",children:(()=>{const a=m.filter(B=>Y.has(B.id)),p=a.slice(0,10);return e.jsxs(e.Fragment,{children:[p.map(B=>e.jsxs("div",{className:"flex items-center justify-between gap-2 border-b border-border/50 last:border-0 pb-1 last:pb-0",children:[e.jsx("span",{className:"font-medium text-foreground truncate",children:Rs(B)}),e.jsx("span",{className:"text-muted-foreground text-[10px] shrink-0",children:Ps(B)})]},B.id)),a.length>10&&e.jsx("div",{className:"text-muted-foreground text-[10px] pt-1",children:r(`ועוד ${a.length-10}…`,`and ${a.length-10} more…`)})]})})()})]})})]}),e.jsxs(Tt,{children:[e.jsx(At,{disabled:me,children:r("ביטול","Cancel")}),e.jsxs(Dt,{disabled:me,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",onClick:async a=>{a.preventDefault(),await ya(Array.from(Y))},children:[me?e.jsx(ie,{className:"w-3.5 h-3.5 animate-spin me-1"}):e.jsx(Je,{className:"w-3.5 h-3.5 me-1"}),r("מחק את כולם","Delete all")]})]})]})})]})}const rn={lcp:{good:2500,poor:4e3,unit:"ms",label:"LCP",labelHe:"LCP (Largest Contentful Paint)"},cls:{good:.1,poor:.25,unit:"",label:"CLS",labelHe:"CLS (Cumulative Layout Shift)"},inp:{good:200,poor:500,unit:"ms",label:"INP",labelHe:"INP (Interaction to Next Paint)"},ttfb:{good:800,poor:1800,unit:"ms",label:"TTFB",labelHe:"TTFB (Time to First Byte)"}};function nn({siteUrl:s}){const{selectedClient:i}=Ms(),{language:u,t:n}=Ye(),[c,x]=l.useState(s),[o,C]=l.useState(null),[r,m]=l.useState([]),[v,t]=l.useState(!1),[g,h]=l.useState(null),[y,$]=l.useState("mobile");l.useEffect(()=>{if(s){x(s);return}if(!i)return;(async()=>{const{data:K}=await A.from("client_platform_accounts").select("account_id").eq("client_id",i.id).eq("platform","search_console").eq("is_active",!0).limit(1).maybeSingle();K!=null&&K.account_id&&x(K.account_id)})()},[s,i==null?void 0:i.id]);const w=l.useCallback(async()=>
28{if(!(!i||!c)){t(!0),h(null);try{const{data:k,error:K}=await A.functions.invoke("sc-index-cwv",{body:{client_id:i.id,site_url:c}});if(K)throw K;if(k!=null&&k.error)throw new Error(k.error);C(k.cwv||null),m(k.sitemaps||[])}catch(k){h(k.message)}finally{t(!1)}}},[i,c]);if(l.useEffect(()=>{w()},[w]),!i||!c)return e.jsx("div",{className:"panel p-8 text-center text-sm text-muted-foreground",children:n("platform.seo.noSiteUrl")||"לא הוגדר URL לאתר. יש להגדיר דומיין בהגדרות הלקוח או לשייך אתר ב-Search Console."});const W=y==="desktop"&&(o!=null&&o.desktop)?o.desktop:o,N=r.reduce((k,K)=>k+K.contents.reduce((M,L)=>M+L.submitted,0),0),F=r.reduce((k,K)=>k+K.contents.reduce((M,L)=>M+L.indexed,0),0),j=N>0?Math.round(F/N*100):0;return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h3",{className:"text-sm font-semibold",children:n("cwv.title")}),e.jsx("button",{onClick:w,disabled:v,className:"p-1.5 rounded hover:bg-muted transition-colors",children:e.jsx(Fe,{className:`w-4 h-4 ${v?"animate-spin":""}`})})]}),g&&e.jsx("div",{className:"text-sm text-destructive bg-destructive/10 border border-destructive/20 rounded-lg p-3",children:g}),v&&e.jsx("p",{className:"text-sm text-muted-foreground text-center py-8",children:n("common.loading")}),!v&&e.jsxs(e.Fragment,{children:[o?e.jsxs("div",{className:"panel p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsxs("h4",{className:"text-sm font-semibold flex items-center gap-1.5",children:[e.jsx(xa,{className:"w-4 h-4 text-muted-foreground"}),"Core Web Vitals"]}),e.jsxs("div",{className:"flex gap-1",children:[e.jsxs("button",{onClick:()=>$("mobile"),className:`px-2.5 py-1 text-xs rounded ${y==="mobile"?"bg-primary text-primary-foreground":"bg-muted text-muted-foreground"}`,children:[e.jsx(st,{className:"w-3 h-3 inline me-1"}),n("cwv.mobile")]}),e.jsxs("button",{onClick:()=>$("desktop"),className:`px-2.5 py-1 text-xs rounded ${y==="desktop"?"bg-primary text-primary-foreground":"bg-muted text-muted-foreground"}`,children:[e.jsx(at,{className:"w-3 h-3 inline me-1"}),n("cwv.desktop")]})]})]}),e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:Object.entries(rn).map(([k,K])=>{const M=W==null?void 0:W[k];if(!M)return null;const L=M.p75,b=L===null?"unknown":L<=K.good?"good":L<=K.poor?"needs-improvement":"poor",E=b==="good"?"text-success":b==="needs-improvement"?"text-warning":b==="poor"?"text-destructive":"text-muted-foreground",G=b==="good"?e.jsx($r,{className:"w-4 h-4 text-success"}):b==="poor"?e.jsx(Za,{className:"w-4 h-4 text-destructive"}):e.jsx(qe,{className:"w-4 h-4 text-warning"});return e.jsxs("div",{className:"text-center p-3 rounded-lg bg-muted/30",children:[e.jsx("div",{className:"flex items-center justify-center gap-1 mb-1",children:G}),e.jsx("p",{className:`text-lg font-bold font-data ${E}`,children:L!==null?k==="cls"?L.toFixed(2):`${L}${K.unit}`:"—"}),e.jsx("p",{className:"text-[10px] text-muted-foreground font-medium",children:K.label}),M.good!==null&&e.jsxs("div",{className:"flex gap-0.5 mt-1.5 h-1.5 rounded-full overflow-hidden",children:[e.jsx("div",{className:"bg-success",style:{width:`${M.good}%`}}),e.jsx("div",{className:"bg-warning",style:{width:`${M.needsImprovement}%`}}),e.jsx("div",{className:"bg-destructive",style:{width:`${M.poor}%`}})]})]},k)})})]}):e.jsx("div",{className:"panel p-4 text-center text-sm text-muted-foreground",children:n("cwv.noCwvData")}),e.jsxs("div",{className:"panel p-4",children:[e.jsxs("h4",{className:"text-sm font-semibold mb-3 flex items-center gap-1.5",children:[e.jsx(Le,{className:"w-4 h-4 text-muted-foreground"}),n("cwv.indexCoverage")]}),r.length>0?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-4 mb-4",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-2xl font-bold font-data text-success",children:F.toLocaleString()}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:n("cwv.indexed")})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-2xl font-bold font-data",children:N.toLocaleStr
28ing()}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:n("cwv.submitted")})]}),e.jsxs("div",{className:"text-center",children:[e.jsxs("p",{className:`text-2xl font-bold font-data ${j>=80?"text-success":j>=50?"text-warning":"text-destructive"}`,children:[j,"%"]}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:n("cwv.indexRate")})]})]}),e.jsx("div",{className:"space-y-2",children:r.map((k,K)=>e.jsxs("div",{className:"text-xs p-2 rounded bg-muted/30 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-1.5 truncate max-w-[60%]",children:[e.jsx(Ts,{className:"w-3 h-3 text-muted-foreground flex-shrink-0"}),e.jsx("span",{className:"truncate",title:k.path,children:k.path.split("/").pop()})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[k.errors>0&&e.jsxs("span",{className:"text-destructive",children:[k.errors," ",n("cwv.errors")]}),k.warnings>0&&e.jsxs("span",{className:"text-warning",children:[k.warnings," ",n("cwv.warnings")]}),e.jsxs("span",{className:"text-muted-foreground",children:[k.contents.reduce((M,L)=>M+L.indexed,0),"/",k.contents.reduce((M,L)=>M+L.submitted,0)]})]})]},K))})]}):e.jsx("p",{className:"text-xs text-muted-foreground text-center py-4",children:n("cwv.noSitemaps")})]})]})]})}const vs={informational:"bg-blue-500/10 text-blue-600 border-blue-500/20",transactional:"bg-success/10 text-success border-success/20",commercial:"bg-warning/10 text-warning border-warning/20",navigational:"bg-muted text-muted-foreground border-border"},ws={high:"bg-destructive/10 text-destructive",medium:"bg-warning/10 text-warning",low:"bg-muted text-muted-foreground"};function ln({clientId:s,clientName:i,websiteUrl:u,queries:n}){var y,$,w,W,N,F;const{t:c,dir:x}=Ye(),[o,C]=l.useState(!1),[r,m]=l.useState(null),[v,t]=l.useState("missing"),g=async()=>{if(n.length===0){R.error(c("seo.contentGap.noData"));return}C(!0);try{const{data:{session:j}}=await A.auth.getSession();if(!(j!=null&&j.access_token))throw new Error("Not authenticated");const{data:k,error:K}=await A.functions.invoke("seo-content-gap",{headers:{Authorization:`Bearer ${j.access_token}`},body:{client_id:s,client_name:i,website_url:u,queries:n.map(M=>({query:M.query,position:M.position,clicks:M.clicks,impressions:M.impressions}))}});if(K||k!=null&&k.error)throw new Error((k==null?void 0:k.error)||(K==null?void 0:K.message));m(k.result),R.success(c("seo.contentGap.complete"))}catch(j){R.error(j.message||c("seo.contentGap.error"))}finally{C(!1)}},h=[{key:"missing",label:c("seo.contentGap.missingTopics"),icon:e.jsx(qe,{className:"w-3.5 h-3.5"}),data:r==null?void 0:r.missing_topics},{key:"weak",label:c("seo.contentGap.weakCoverage"),icon:e.jsx(ge,{className:"w-3.5 h-3.5"}),data:r==null?void 0:r.weak_coverage},{key:"opportunities",label:c("seo.contentGap.opportunities"),icon:e.jsx(Mt,{className:"w-3.5 h-3.5"}),data:r==null?void 0:r.content_opportunities},{key:"competitor",label:c("seo.contentGap.competitorGaps"),icon:e.jsx(Re,{className:"w-3.5 h-3.5"}),data:r==null?void 0:r.competitor_gaps}];return r?e.jsxs("div",{className:"space-y-4",children:[r.summary&&e.jsxs("div",{className:"panel p-4 border-primary/20 bg-primary/[0.03]",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx(_e,{className:"w-4 h-4 text-primary"}),e.jsx("h3",{className:"text-xs font-semibold",children:c("seo.contentGap.analysisSummary")})]}),e.jsx("div",{className:"prose prose-sm max-w-none text-xs text-foreground",dir:x,children:e.jsx(Es,{children:r.summary})})]}),e.jsx("div",{className:"flex gap-2 flex-wrap",children:h.map(j=>{var k;return e.jsxs("button",{onClick:()=>t(j.key),className:`flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-medium transition-colors ${v===j.key?"bg-primary text-primary-foreground":"bg-secondary text-muted-foreground hover:text-foreground"}`,children:[j.icon,j.label,((k=j.data)==null?void 0:k.length)>0&&e.jsx("span",{className:`px-1.5 py-0.5 rounded-full text-[10px] font-bold ${v===j.key?"bg-primary-foreground/20":"bg-primary/10 text-primary"}`,children:j.data.length})]},j.key)})}),v==="missing"&&((y=r.missing_topics)==null?void 0:y.length)>0&&e.jsx("div",{className:"grid gap-3",children:r.missing_topics.map((j,k)=>e.jsx("div",{className:"panel p-4 hover:border-primary/30 transition-colors",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("span",{className:"font-medium text-sm",dir:"ltr",children:j.keyword}),e.jsx("span",{className:`px-1.5 py-0.5 rounded text-[10px] font-medium border ${vs[j.intent]||vs.informational}`,children:j.intent}),e.jsx("span",{className:`px-1.5 py-0.5 rounded text-[10px] font-bold ${ws[j.priority]||ws.medium}`,children:j.priority})]}),e.jsx("p",{className:"text-xs text-muted-foreground",dir:x,children:j.brief})]}),e.jsx("span",{className:"text-[10px] text-muted-foreground shrink-0 bg-secondary px-2 py-1 rounded",children:j.content_type})]})},k))}),v==="weak"&&(($=r.weak_coverage)==null?void 0:$.length)>0&&e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-xs",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-border text-muted-foreground",children:[e.jsx("th",{className:"text-start px-4 py-2 font-medium",children:c("seo.contentGap.keyword")}),e.jsx("th",{className:"text-center px-2 py-2 font-medium",children:c("seo.contentGap.position")}),e.jsx("th",{className:"text-center px-2 py-2 font-medium",children:c("seo.contentGap.impressions")}),e.jsx("th",{className:"text-center px-2 py-2 font-medium",children:c("seo.contentGap.intent")}),e.jsx("th",{className:"text-center px-2 py-2 font-medium",children:c("seo.contentGap.priority")}),e.jsx("th",{className:"text-start px-2 py-2 font-medium",children:c("seo.contentGap.suggestion")})]})}),e.jsx("tbody",{className:"divide-y divide-border",children:r.weak_coverage.map((j,k)=>{var K,M,L,b;return e.jsxs("tr",{className:"hover:bg-secondary/30",children:[e.jsx("td",{className:"px-4 py-2 font-medium",dir:"ltr",children:j.keyword}),e.jsx("td",{className:"px-2 py-2 text-center font-data text-destructive",children:((M=(K=j.current_position)==null?void 0:K.toFixed)==null?void 0:M.call(K,1))||j.current_position}),e.jsx("td",{className:"px-2 py-2 text-center font-data",children:((b=(L=j.impressions)==null?void 0:L.toLocaleStr
28ing)==null?void 0:b.call(L))||j.impressions}),e.jsx("td",{className:"px-2 py-2 text-center",children:e.jsx("span",{className:`px-1.5 py-0.5 rounded text-[10px] border ${vs[j.intent]||""}`,children:j.intent})}),e.jsx("td",{className:"px-2 py-2 text-center",children:e.jsx("span",{className:`px-1.5 py-0.5 rounded text-[10px] font-bold ${ws[j.priority]||""}`,children:j.priority})}),e.jsx("td",{className:"px-2 py-2 text-muted-foreground max-w-[250px]",dir:x,children:j.suggestion})]},k)})})]})}),v==="opportunities"&&((w=r.content_opportunities)==null?void 0:w.length)>0&&e.jsx("div",{className:"grid gap-3",children:r.content_opportunities.map((j,k)=>e.jsx("div",{className:"panel p-4 hover:border-primary/30 transition-colors",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Mt,{className:"w-4 h-4 text-warning shrink-0 mt-0.5"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("span",{className:"font-medium text-sm",dir:"ltr",children:j.keyword}),e.jsx(ma,{className:"w-3 h-3 text-muted-foreground"}),e.jsx("span",{className:"text-xs text-muted-foreground",dir:"ltr",children:j.parent_keyword})]}),e.jsx("p",{className:"text-xs text-muted-foreground",dir:x,children:j.brief}),e.jsxs("div",{className:"flex items-center gap-2 mt-1.5",children:[e.jsx("span",{className:`px-1.5 py-0.5 rounded text-[10px] border ${vs[j.intent]||""}`,children:j.intent}),e.jsx("span",{className:"text-[10px] text-muted-foreground bg-secondary px-2 py-0.5 rounded",children:j.content_type})]})]})]})},k))}),v==="competitor"&&((W=r.competitor_gaps)==null?void 0:W.length)>0&&e.jsx("div",{className:"grid gap-3",children:r.competitor_gaps.map((j,k)=>e.jsx("div",{className:"panel p-4 hover:border-primary/30 transition-colors",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(Re,{className:"w-4 h-4 text-primary shrink-0 mt-0.5"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("span",{className:"font-medium text-sm",dir:"ltr",children:j.keyword}),e.jsx("span",{className:`px-1.5 py-0.5 rounded text-[10px] font-bold ${ws[j.priority]||""}`,children:j.priority})]}),j.likely_competitor&&e.jsxs("p",{className:"text-[10px] text-muted-foreground mb-1",children:[c("seo.contentGap.likelyCompetitor")," ",e.jsx("span",{className:"font-medium",children:j.likely_competitor})]}),e.jsx("p",{className:"text-xs text-muted-foreground",dir:x,children:j.brief})]}),e.jsx("span",{className:"text-[10px] text-muted-foreground bg-secondary px-2 py-1 rounded shrink-0",children:j.content_type})]})},k))}),((F=(N=h.find(j=>j.key===v))==null?void 0:N.data)==null?void 0:F.length)===0&&e.jsx("p",{className:"text-center text-xs text-muted-foreground py-8",children:c("seo.contentGap.noGaps")}),e.jsx("div",{className:"flex justify-end",children:e.jsxs(ee,{variant:"outline",size:"sm",onClick:g,disabled:o,className:"gap-1.5 text-xs",children:[o?e.jsx(ie,{className:"w-3.5 h-3.5 animate-spin"}):e.jsx(_e,{className:"w-3.5 h-3.5"}),c("seo.contentGap.rerun")]})})]}):e.jsxs("div",{className:"panel p-8 text-center space-y-4",children:[e.jsx("div",{className:"w-16 h-16 rounded-2xl bg-primary/10 flex items-center justify-center mx-auto",children:e.jsx(Ee,{className:"w-8 h-8 text-primary"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-bold",children:c("seo.contentGap.title")}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1 max-w-md mx-auto",children:c("seo.contentGap.description")})]}),e.jsxs(ee,{onClick:g,disabled:o,className:"gap-2",children:[o?e.jsx(ie,{className:"w-4 h-4 animate-spin"}):e.jsx(_e,{className:"w-4 h-4"}),c("seo.contentGap.runAnalysis")]}),n.length===0&&e.jsx("p",{className:"text-[10px] text-destructive",children:c("seo.contentGap.loadDataFirst")})]})}function Xe({label:s,value:i,icon:u,sparkline:n,unit:c,colorToken:x="chart-organic",tooltip:o}){const C=`hsl(var(--${x}))`,r=l.useMemo(()=>{if(!n||n.length<2)return null;const g=n.find($=>$>0)??n[0],h=n[n.length-1];if(!g||g===0)return null;const y=(h-g)/g*100;return Math.round(y*10)/10},[n]),m=l.useMemo(()=>(n||[]).map((g,h)=>({i:h,v:g})),[n]),v=r!=null&&r>0,t=r!=null&&r<0;return e.jsx(be,{className:"relative overflow-hidden",title:o,children:e.jsxs(ve,{className:"pt-3 pb-3 px-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 mb-1",children:[e.jsx("span",{className:"text-[11px] text-muted-foreground font-medium truncate",children:s}
28),u&&e.jsx("span",{className:"text-muted-foreground/70 shrink-0",children:u})]}),e.jsxs("div",{className:"flex items-baseline gap-2 mb-1",children:[e.jsxs("span",{className:"text-2xl font-bold tabular-nums leading-none",children:[c&&e.jsx("span",{className:"text-base text-muted-foreground mr-0.5",children:c}),i]}),r!=null&&e.jsxs("span",{className:`inline-flex items-center gap-0.5 text-[10px] font-semibold px-1.5 py-0.5 rounded ${v?"bg-success/15 text-success":t?"bg-destructive/15 text-destructive":"bg-muted text-muted-foreground"}`,children:[v?e.jsx(ge,{className:"w-2.5 h-2.5"}):t?e.jsx(Ae,{className:"w-2.5 h-2.5"}):e.jsx(tt,{className:"w-2.5 h-2.5"}),Math.abs(r),"%"]})]}),m.length>=2&&e.jsx("div",{className:"h-8 -mx-1 -mb-1",children:e.jsx(Te,{width:"100%",height:"100%",children:e.jsxs(fs,{data:m,margin:{top:2,right:0,bottom:0,left:0},children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:`spark-${s.replace(/\s/g,"")}`,x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:C,stopOpacity:.35}),e.jsx("stop",{offset:"100%",stopColor:C,stopOpacity:0})]})}),e.jsx(ls,{type:"monotone",dataKey:"v",stroke:C,strokeWidth:1.5,fill:`url(#spark-${s.replace(/\s/g,"")})`,isAnimationActive:!1})]})})})]})})}const Qt=[{id:"1M",months:1},{id:"6M",months:6},{id:"1Y",months:12},{id:"2Y",months:24},{id:"ALL",months:null}],ks={organicTraffic:{label:"Organic Traffic",color:"var(--chart-organic)",axis:"left"},organicKeywords:{label:"Organic Keywords",color:"var(--chart-branded)",axis:"right"},paidTraffic:{label:"Paid Traffic",color:"var(--chart-paid)",axis:"left"}};function on({data:s,height:i=300,defaultSeries:u=["organicTraffic","organicKeywords"]}){const[n,c]=l.useState("ALL"),[x,o]=l.useState(new Set(u)),C=l.useMemo(()=>{if(!(s!=null&&s.length))return[];const t=Qt.find(g=>g.id===n);return t!=null&&t.months?s.slice(-t.months):s},[s,n]),r=t=>{try{return new Date(t).toLocaleDateString(void 0,{month:"short",year:"2-digit"})}catch{return t}},m=t=>t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}K`:String(t),v=t=>{o(g=>{const h=new Set(g);return h.has(t)?h.size>1&&h.delete(t):h.add(t),h})};return!s||s.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center text-center text-muted-foreground border border-dashed border-border rounded-md",style:{height:i},children:[e.jsx(ge,{className:"w-6 h-6 mb-2 opacity-40"}),e.jsx("p",{className:"text-xs",children:"אין נתונים היסטוריים זמינים עבור דומיין זה."}),e.jsx("p",{className:"text-[10px] mt-1 opacity-70",children:"DataForSEO לא החזיר סדרת זמן."})]}):e.jsxs("div",{className:"w-full",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 mb-2 flex-wrap",children:[e.jsx("div",{className:"flex items-center gap-1",children:Object.entries(ks).map(([t,g])=>e.jsxs("button",{onClick:()=>v(t),className:`text-[11px] px-2 py-1 rounded inline-flex items-center gap-1.5 transition-colors ${x.has(t)?"bg-secondary text-foreground":"text-muted-foreground hover:bg-secondary/50"}`,children:[e.jsx("span",{className:"w-2 h-2 rounded-full",style:{background:`hsl(${g.color})`,opacity:x.has(t)?1:.4}}),g.label]},t))}),e.jsx("div",{className:"flex items-center gap-0.5 text-[11px] bg-muted/40 rounded p-0.5",children:Qt.map(t=>e.jsx("button",{onClick:()=>c(t.id),className:`px-2 py-0.5 rounded transition-colors ${n===t.id?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:t.id},t.id))})]}),e.jsx(Te,{width:"100%",height:i,children:e.jsxs(fs,{data:C,margin:{top:8,right:8,bottom:0,left:0},children:[e.jsx("defs",{children:Object.entries(ks).map(([t,g])=>e.jsxs("linearGradient",{id:`grad-${t}`,x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:`hsl(${g.color})`,stopOpacity:.4}),e.jsx("stop",{offset:"100%",stopColor:`hsl(${g.color})`,stopOpacity:0})]},t))}),e.jsx(es,{stroke:"hsl(var(--chart-grid))",strokeDasharray:"3 3",vertical:!1}),e.jsx(ss,{dataKey:"date",tickFormatter:r,tick:{fontSize:10,fill:"hsl(var(--muted-foreground))"},stroke:"hsl(var(--chart-grid))"}),e.jsx(He,{yAxisId:"left",tickFormatter:m,tick:{fontSize:10,fill:"hsl(var(--muted-foreground))"},stroke:"hsl(var(--chart-grid))",width:42}),e.jsx(He,{yAxisId:"right",orientation:"right",tickFormatter:m,tick:{fontSize:10,fill:"hsl(var(--muted-foreground))"},stroke:"hsl(var(--chart-grid))",width:42}),e.jsx(We,{contentStyle:{background:"hsl(var(--chart-tooltip-bg))",border:"1px solid hsl(var(--border))",borderRadius:6,fontSize:11,boxShadow:"0 4px 12px hsl(var(--background) / 0.4)"},labelFormatter:t=>r(String(t)),formatter:(t,g)=>{var h;return[m(Number(t)),((h=ks[g])==null?void 0:h.label)??g]}}),e.jsx($a,{wrapperStyle:{display:"none"}}),Object.entries(ks).map(([t,g])=>x.has(t)?e.jsx(ls,{yAxisId:g.axis,type:"monotone",dataKey:t,name:g.label,stroke:`hsl(${g.color})`,strokeWidth:2,fill:`url(#grad-${t})`,isAnimationActive:!1},t):null),C.length>6&&e.jsx(La,{dataKey:"date",height:20,stroke:"hsl(var(--chart-grid))",fill:"hsl(var(--muted) / 0.3)",tickFormatter:r,travellerWidth:8})]})})]})}function cn({top3:s,top10:i,top20:u,top50:n,totalKeywords:c}
28){const x=s,o=Math.max(0,i-s),C=Math.max(0,u-i),r=Math.max(0,n-u),m=Math.max(1,x+o+C+r),v=[{label:"Top 3",value:x,total:s,color:"var(--chart-organic)"},{label:"Top 4-10",value:o,total:i,color:"var(--chart-paid)"},{label:"Top 11-20",value:C,total:u,color:"var(--chart-branded)"},{label:"Top 21-50",value:r,total:n,color:"var(--muted-foreground)"}];return e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"flex h-8 w-full rounded-md overflow-hidden border border-border bg-muted/30",children:v.map((t,g)=>{const h=t.value/m*100;return h<.5?null:e.jsx("div",{className:"flex items-center justify-center text-[10px] font-semibold text-foreground/90 transition-all",style:{width:`${h}%`,background:`hsl(${t.color} / 0.55)`,borderRight:g<v.length-1?"1px solid hsl(var(--background))":void 0},title:`${t.label}: ${t.value} keywords`,children:h>=8?t.value:""},g)})}),e.jsx("div",{className:"grid grid-cols-4 gap-2 text-[11px]",children:v.map((t,g)=>e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"w-2 h-2 rounded-sm shrink-0",style:{background:`hsl(${t.color} / 0.7)`}}),e.jsx("span",{className:"text-muted-foreground truncate",children:t.label}),e.jsx("span",{className:"font-semibold tabular-nums ml-auto",children:t.total.toLocaleString()})]},g))}),c!=null&&e.jsxs("p",{className:"text-[10px] text-muted-foreground text-center pt-1",children:["מתוך ",c.toLocaleString()," מילות מפתח אורגניות בסך הכל"]})]})}const Yt=[{key:"informational",label:"מידע (Informational)",token:"chart-organic"},{key:"navigational",label:"ניווט (Navigational)",token:"chart-branded"},{key:"commercial",label:"מסחרי (Commercial)",token:"chart-paid"},{key:"transactional",label:"טרנזקציוני (Transactional)",token:"primary"},{key:"unknown",label:"לא ידוע",token:"muted"}];function dn(s){const i=(s.informational||0)+(s.navigational||0)+(s.commercial||0)+(s.transactional||0)+(s.unknown||0);return i===0?e.jsx("p",{className:"text-xs text-muted-foreground text-center py-4",children:"אין נתוני כוונת חיפוש זמינים."}):e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"flex w-full h-3 rounded-full overflow-hidden bg-muted/40",children:Yt.map(u=>{const n=s[u.key]||0;if(n===0)return null;const c=n/i*100;return e.jsx("div",{style:{width:`${c}%`,background:`hsl(var(--${u.token}))`},title:`${u.label}: ${n.toLocaleString()} (${c.toFixed(1)}%)`},u.key)})}),e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-1.5 text-[11px]",children:Yt.map(u=>{const n=s[u.key]||0,c=i>0?n/i*100:0;return e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"inline-block w-2.5 h-2.5 rounded-sm shrink-0",style:{background:`hsl(var(--${u.token}))`}}),e.jsx("span",{className:"text-muted-foreground truncate",children:u.label}),e.jsxs("span",{className:"tabular-nums font-medium ml-auto",children:[n.toLocaleString()," ",e.jsxs("span",{className:"text-muted-foreground",children:["(",c.toFixed(0),"%)"]})]})]},u.key)})})]})}function rs({value:s,max:i,display:u,colorToken:n="chart-organic",align:c="center"}){const x=i>0?Math.min(100,Math.max(0,s/i*100)):0;return e.jsxs("div",{className:"relative w-full h-full",children:[e.jsx("div",{className:"absolute inset-y-0 left-0 rounded-sm pointer-events-none",style:{width:`${x}%`,background:`hsl(var(--${n}) / 0.18)`},"aria-hidden":!0}),e.jsx("div",{className:`relative tabular-nums text-xs ${c==="right"?"text-right":c==="left"?"text-left":"text-center"}`,children:u??s.toLocaleString()})]})}const xn={IL:e.jsxs("svg",{viewBox:"0 0 60 40",xmlns:"http://www.w3.org/2000/svg",preserveAspectRatio:"none",children:[e.jsx("rect",{width:"60",height:"40",fill:"#fff"}),e.jsx("rect",{y:"3",width:"60",height:"5",fill:"#0038b8"}),e.jsx("rect",{y:"32",width:"60",height:"5",fill:"#0038b8"}),e.jsxs("g",{fill:"none",stroke:"#0038b8",strokeWidth:"1.5",children:[e.jsx("polygon",{points:"30,13 35,22 25,22"}),e.jsx("polygon",{points:"30,27 35,18 25,18"})]})]}),US:e.jsxs("svg",{viewBox:"0 0 60 40",xmlns:"http://www.w3.org/2000/svg",preserveAspectRatio:"none",children:[e.jsx("rect",{width:"60",height:"40",fill:"#fff"}),[0,2,4,6,8,10,12].map(s=>e.jsx("rect",{y:s*3.08,width:"60",height:"3.08",fill:"#b22234"},s)),e.jsx("rect",{width:"24",height:"21.5",fill:"#3c3b6e"})]}),GB:e.jsxs("svg",{viewBox:"0 0 60 40",xmlns:"http://www.w3.org/2000/svg",preserveAspectRatio:"none",children:[e.jsx("rect",{width:"60",height:"40",fill:"#012169"}),e.jsx("path",{d:"M0,0 L60,40 M60,0 L0,40",stroke:"#fff",strokeWidth:"6"}),e.jsx("path",{d:"M0,0 L60,40 M60,0 L0,40",stroke:"#c8102e",strokeWidth:"3"}),e.jsx("path",{d:"M30,0 V40 M0,20 H60",stroke:"#fff",strokeWidth:"10"}),e.jsx("path",{d:"M30,0 V40 M0,20 H60",stroke:"#c8102e",strokeWidth:"5"})]}),FR:e.jsxs("svg",{viewBox:"0 0 60 40",xmlns:"http://www.w3.org/2000/svg",preserveAspectRatio:"none",children:[e.jsx("rect",{width:"20",height:"40",fill:"#0055a4"}),e.jsx("rect",{x:"20",width:"20",height:"40",fill:"#fff"}),e.jsx("rect",{x:"40",width:"20",height:"40",fill:"#ef4135"})]}),DE:e.jsxs("svg",{viewBox:"0 0 60 40",xmlns:"http://www.w3.org/2000/svg",preserveAspectRatio:"none",children:[e.jsx("rect",{width:"60",height:"13.33",fill:"#000"}),e.jsx("rect",{y:"13.33",width:"60",height:"13.33",fill:"#dd0000"}),e.jsx("rect",{y:"26.66",width:"60",height:"13.34",fill:"#ffce00"})]})};function mn({code:s,className:i="w-5 h-3.5"}){const u=xn[s==null?void 0:s.toUpperCase()];return u?e.jsx("span",{className:`${i} inline-block rounded-sm overflow-hidden border border-border/50 shadow-sm shrink-0 leading-none`,role:"img","aria-label":`${s} flag`,children:u}):e.jsx("span",{className:`${i} inline-flex items-center justify-center rounded-sm border border-border/40 bg-muted/40 shrink-0`,"aria-label":s,children:e.jsx(ms,{className:"w-2.5 h-2.5 text-muted-foreground"})})}const hn=[{name:"ChatGPT",icon:e.jsx(_e,{className:"w-3.5 h-3.5"}),mentions:187,change:12.4,spark:[120,135,128,150,165,172,187],c
28olor:"text-emerald-500"},{name:"Gemini",icon:e.jsx(Ws,{className:"w-3.5 h-3.5"}),mentions:94,change:-3.2,spark:[110,108,102,99,96,97,94],color:"text-sky-500"},{name:"Perplexity",icon:e.jsx(Ze,{className:"w-3.5 h-3.5"}),mentions:52,change:28.7,spark:[22,28,31,36,41,48,52],color:"text-violet-500"}],pn=[{query:"best BI platform for marketing agencies",engine:"ChatGPT",citation:"recommended",position:2},{query:"multi-client analytics dashboard",engine:"Perplexity",citation:"cited",position:1},{query:"Hebrew RTL BI tools",engine:"Gemini",citation:"listed",position:4},{query:"AI-native agency operating system",engine:"ChatGPT",citation:"cited",position:3},{query:"unified marketing reports automation",engine:"Perplexity",citation:"recommended",position:2}];function un({data:s,colorClass:i}){if(!s.length)return null;const u=Math.max(...s),n=Math.min(...s),c=u-n||1,x=80,o=24,C=s.map((r,m)=>{const v=m/(s.length-1)*x,t=o-(r-n)/c*o;return`${v.toFixed(1)},${t.toFixed(1)}`}).join(" ");return e.jsx("svg",{width:x,height:o,className:i,"aria-hidden":"true",children:e.jsx("polyline",{points:C,fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}function fn(s){return s==="recommended"?"default":s==="cited"?"secondary":"outline"}function gn(s){return s==="recommended"?"מומלץ":s==="cited"?"מצוטט":"מופיע ברשימה"}function jn(){return e.jsxs(be,{className:"border-amber-500/30 bg-amber-500/[0.02]",children:[e.jsx(Ge,{className:"pb-2",children:e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-2",children:[e.jsxs(Ke,{className:"text-sm flex items-center gap-1.5",children:[e.jsx(_e,{className:"w-3.5 h-3.5 text-amber-500"}),"נראות במנועי AI"]}),e.jsx(fe,{variant:"outline",className:"border-amber-500/50 bg-amber-500/10 text-amber-700 dark:text-amber-300 text-[10px] font-semibold uppercase tracking-wide",children:"Beta · Mock Data"})]})}),e.jsxs(ve,{className:"pt-2 pb-3 space-y-3",children:[e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-2",children:hn.map(s=>{const i=s.change>=0;return e.jsxs("div",{className:"rounded-md border border-border/60 bg-card/60 p-3 flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:`flex items-center gap-1.5 text-xs font-medium ${s.color}`,children:[s.icon,s.name]}),e.jsxs("span",{className:`inline-flex items-center gap-0.5 text-[10px] font-medium ${i?"text-success":"text-destructive"}`,children:[i?e.jsx(ge,{className:"w-2.5 h-2.5"}):e.jsx(Ae,{className:"w-2.5 h-2.5"}),Math.abs(s.change).toFixed(1),"%"]})]}),e.jsxs("div",{className:"flex items-end justify-between",children:[e.jsx("span",{className:"text-2xl font-bold tabular-nums leading-none",children:s.mentions}),e.jsx(un,{data:s.spark,colorClass:s.color})]}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:"אזכורים ב-30 הימים האחרונים"})]},s.name)})}),e.jsxs("div",{className:"rounded-md border border-border/60 overflow-hidden",children:[e.jsxs("div",{className:"px-3 py-2 border-b border-border/60 bg-card/40 flex items-center gap-1.5",children:[e.jsx(Lr,{className:"w-3.5 h-3.5 text-muted-foreground"}),e.jsx("span",{className:"text-[11px] font-semibold text-muted-foreground",children:"ציטוטים אחרונים"})]}),e.jsxs(Qs,{children:[e.jsx(Ys,{children:e.jsxs(ns,{children:[e.jsx(pe,{className:"h-7 text-[11px]",children:"שאילתה"}),e.jsx(pe,{className:"h-7 text-[11px] text-center",children:"מנוע"}),e.jsx(pe,{className:"h-7 text-[11px] text-center",children:"סוג"}),e.jsx(pe,{className:"h-7 text-[11px] text-center",children:"עמדה"})]})}),e.jsx(Xs,{children:pn.map((s,i)=>e.jsxs(ns,{className:"h-7",children:[e.jsx(ue,{className:"py-1 text-xs font-medium",dir:"ltr",children:s.query}),e.jsx(ue,{className:"py-1 text-center text-[11px]",children:s.engine}),e.jsx(ue,{className:"py-1 text-center",children:e.jsx(fe,{variant:fn(s.citation),className:"text-[10px] px-1.5 py-0",children:gn(s.citation)})}),e.jsxs(ue,{className:"py-1 text-center text-[11px] tabular-nums",children:["#",s.position]})]},i))})]})]}),e.jsx("p",{className:"text-[10px] text-muted-foreground text-center",children:"מקור: נתוני דגימה — אינטגרציה חיה תגיע ב-Phase 2."})]})]})}const Ne=10,Xt=s=>`domov:${s}`;function yn({clientId:s,defaultDomain:i}){var Pe,je,ye,xe,Ce,$e,le,oe;const{toast:u}=er(),[n,c]=l.useState(i||""),x="US",o="en",[C,r]=l.useState(!1),[m,v]=l.useState(null),[t,g]=l.useState(null),[h,y]=l.useState([]),[$,w]=l.useState(Ne),[W,N]=l.useState(Ne),[F,j]=l.useState(Ne),[k,K]=l.useState(!1),[M,L]=l.useState(null),[b,E]=l.useState(null),G=async()=>
28{if(!(!n||!s)){K(!0),L(null);try{const{data:_,error:I}=await A.functions.invoke("domain-geo-distribution",{body:{client_id:s,domain:n}});if(I)throw I;if(_!=null&&_.error)throw new Error(_.error);E(_)}catch(_){console.error("[domain-geo] invoke failed:",_),L((_==null?void 0:_.message)||"Failed to fetch geo distribution")}finally{K(!1)}}};l.useEffect(()=>{v(null),g(null),c(i||""),w(Ne),N(Ne),j(Ne),E(null),L(null);try{const _=sessionStorage.getItem(Xt(s));if(_){const I=JSON.parse(_);I!=null&&I.domain&&c(I.domain),I!=null&&I.result&&v(I.result)}}catch{}A.from("domain_overview_cache").select("id, domain, country, language, fetched_at").eq("client_id",s).order("fetched_at",{ascending:!1}).limit(10).then(({data:_})=>y(_||[]))},[s,i]),l.useEffect(()=>{E(null),L(null)},[n]);const V=async(_=!1)=>{var I,U;if(!n.trim()){u({title:"הזן דומיין",description:"לדוגמה: example.com",variant:"destructive"});return}r(!0),g(null);try{const{data:O,error:z}=await A.functions.invoke("domain-overview",{body:{client_id:s,domain:n.trim(),country:x,language:o,force_refresh:_}}),re=O||((I=z==null?void 0:z.context)==null?void 0:I.body)||{},he=(re==null?void 0:re.errorCode)||(z?"REQUEST_FAILED":null);if(he||z){const De=(re==null?void 0:re.error)||(z==null?void 0:z.message)||"ניתוח דומיין נכשל";g({code:he||"REQUEST_FAILED",message:De}),v(null);return}const ke=O;v(ke);try{sessionStorage.setItem(Xt(s),JSON.stringify({domain:n.trim(),country:x,language:o,result:ke}))}catch{}u({title:"ניתוח דומיין הושלם",description:O!=null&&O.cached?"הוצג מהמטמון (24 שעות)":`${((U=O==null?void 0:O.kpis)==null?void 0:U.totalKeywords)||0} מילות מפתח נטענו`})}catch(O){console.error("[DomainOverview] error:",O),g({code:"EXCEPTION",message:(O==null?void 0:O.message)||"נסה שוב"})}finally{r(!1)}},de=async _=>{c(_.domain),r(!0),g(null);try{const{data:I,error:U}=await A.functions.invoke("domain-overview",{body:{client_id:s,domain:_.domain,country:_.country,language:_.language,force_refresh:!1}});if(U||I!=null&&I.errorCode){const O=I||{};g({code:O.errorCode||"REQUEST_FAILED",message:O.error||(U==null?void 0:U.message)||"טעינה נכשלה"});return}v(I)}finally{r(!1)}},we=l.useMemo(()=>{if(!(m!=null&&m.fetched_at))return"";try{return new Date(m.fetched_at).toLocaleString("he-IL")}catch{return""}},[m]);return l.useEffect(()=>{w(Ne),N(Ne),j(Ne)},[m==null?void 0:m.domain,m==null?void 0:m.fetched_at]),e.jsxs("div",{className:"space-y-4",children:[e.jsx(be,{children:e.jsxs(ve,{className:"pt-4",children:[e.jsxs("div",{className:"flex flex-wrap items-end gap-2",children:[e.jsxs("div",{className:"flex-1 min-w-[220px]",children:[e.jsx("label",{className:"text-xs text-muted-foreground mb-1 block",children:"דומיין לניתוח"}),e.jsx($s,{placeholder:"example.com",value:n,onChange:_=>c(_.target.value),onKeyDown:_=>_.key==="Enter"&&!C&&V(!1),dir:"ltr"})]}),e.jsxs(ee,{onClick:()=>V(!1),disabled:C,children:[C?e.jsx(ie,{className:"w-4 h-4 animate-spin mr-2"}):e.jsx(Ee,{className:"w-4 h-4 mr-2"}),C?"מנתח...":"נתח דומיין"]}),m&&e.jsx(ee,{variant:"outline",size:"icon",onClick:()=>V(!0),disabled:C,title:"רענן (עוקף מטמון)",children:e.jsx(Kt,{className:"w-4 h-4"})})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground mt-2",children:"ניתוח מלא של דומיין: KPI, מילות מפתח אורגניות, דפים מובילים ומתחרים. הנתונים מ-DataForSEO ונשמרים במטמון ל-24 שעות."}),h.length>0&&e.jsxs("div",{className:"mt-3 flex items-center gap-2 flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[11px] text-muted-foreground",children:[e.jsx(Cs,{className:"w-3.5 h-3.5"})," ניתוחים אחרונים:"]}),h.slice(0,6).map(_=>e.jsxs("button",{onClick:()=>de(_),disabled:C,className:"text-[11px] px-2 py-1 rounded-full border border-border bg-secondary/50 hover:bg-secondary text-foreground transition-colors disabled:opacity-50",title:`${_.country}/${_.language} · ${new Date(_.fetched_at).toLocaleString("he-IL")}`,children:[e.jsx("span",{dir:"ltr",children:_.domain})," ",e.jsx("span",{className:"opacity-60",children:_.country})]},_.id))]})]})}),t&&!C&&e.jsx(be,{className:"border-warning/40 bg-warning/5",children:e.jsx(ve,{className:"py-8 text-center space-y-3",children:t.code==="DATAFORSEO_PAYMENT_REQUIRED"?e.jsxs(e.Fragment,{children:[e.jsx(Tr,{className:"w-10 h-10 mx-auto text-warning"}),e.jsx("h3",{className:"text-base font-semibold",children:"לא ניתן לסרוק כעת — חסרים קרדיטים בספק הנתונים"}),e.jsx("p",{className:"text-sm text-muted-foreground max-w-xl mx-auto",children:"שירות הניתוח החיצוני (DataForSEO Labs) מדווח שאין יתרת קרדיטים זמינה או שאין מנוי פעיל ל-Labs API. זו אינה תקלה במערכת — לאחר טעינת קרדיטים בחשבון DataForSEO, הניתוח יחזור לעבוד אוטומטית ללא שינוי קוד."}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["דומיי×
28Ÿ: ",n]})]}):e.jsxs(e.Fragment,{children:[e.jsx(Ve,{className:"w-10 h-10 mx-auto text-warning"}),e.jsx("h3",{className:"text-base font-semibold",children:"לא הצלחנו לסרוק את הדומיין"}),e.jsx("p",{className:"text-sm text-muted-foreground max-w-xl mx-auto",children:t.message}),t.code&&e.jsxs("p",{className:"text-[11px] text-muted-foreground font-mono",children:["קוד: ",t.code]})]})})}),!m&&!C&&!t&&e.jsx(be,{children:e.jsxs(ve,{className:"py-12 text-center text-sm text-muted-foreground",children:[e.jsx(Et,{className:"w-8 h-8 mx-auto mb-3 opacity-40"}),"הזן דומיין כדי לקבל סקירה מלאה: דירוגים, דפים מובילים, מתחרים, וניתוח AI."]})}),m&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex items-center justify-between flex-wrap gap-2",children:e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold",children:m.domain}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[we&&`עודכן ${we}`," ",m.cached&&"· מטמון"]})]})}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-2",children:[e.jsx(Xe,{label:"מילות מפתח",value:m.kpis.totalKeywords.toLocaleString(),icon:e.jsx(Et,{className:"w-3.5 h-3.5"}),sparkline:(Pe=m.history)==null?void 0:Pe.map(_=>_.organicKeywords),colorToken:"chart-branded"}),e.jsx(Xe,{label:"טראפיק חודשי משוער",value:m.kpis.totalTraffic.toLocaleString(),icon:e.jsx(ge,{className:"w-3.5 h-3.5"}),sparkline:(je=m.history)==null?void 0:je.map(_=>_.organicTraffic),colorToken:"chart-organic"}),e.jsx(Xe,{label:"ממוצע מיקום",value:((ye=m.kpis.avgPosition)==null?void 0:ye.toString())||"—",icon:e.jsx(Re,{className:"w-3.5 h-3.5"}),colorToken:"chart-paid"}),e.jsx(Xe,{label:"Top 10",value:m.kpis.top10.toLocaleString(),icon:e.jsx(da,{className:"w-3.5 h-3.5"}),colorToken:"chart-organic"})]}),(()=>{var z,re,he;const _=!!m.backlinksUnavailable,I="Requires DataForSEO Backlinks API Subscription",U="מנוי נדרש",O=ke=>_?U:ke!=null?ke.toLocaleString():"—";return e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 gap-2",children:[e.jsx(Xe,{label:"Authority Score",value:O((z=m.backlinks)==null?void 0:z.rank),icon:e.jsx(Ar,{className:"w-3.5 h-3.5"}),colorToken:"primary",tooltip:_?I:"ציון סמכות הדומיין (0–100) לפי DataForSEO"}),e.jsx(Xe,{label:"קישורים נכנסים",value:O((re=m.backlinks)==null?void 0:re.backlinks),icon:e.jsx(is,{className:"w-3.5 h-3.5"}),colorToken:"chart-organic",tooltip:_?I:"סך כל הקישורים הנכנסים החיים"}),e.jsx(Xe,{label:"דומיינים מפנים",value:O((he=m.backlinks)==null?void 0:he.referringDomains),icon:e.jsx(ms,{className:"w-3.5 h-3.5"}),colorToken:"chart-branded",tooltip:_?I:"מספר הדומיינים הייחודיים שמקשרים לדומיין"})]})})(),e.jsxs(be,{children:[e.jsx(Ge,{className:"pb-2",children:e.jsxs(Ke,{className:"text-sm flex items-center gap-1.5",children:[e.jsx(ge,{className:"w-3.5 h-3.5 text-primary"})," מגמת ביצועים אורגניים"]})}),e.jsx(ve,{className:"pt-2 pb-3",children:e.jsx(on,{data:m.history||[],height:260})})]}),e.jsx(jn,{}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-3",children:[e.jsxs(be,{children:[e.jsx(Ge,{className:"pb-2",children:e.jsx(Ke,{className:"text-sm",children:"פיזור מיקומים"})}),e.jsx(ve,{className:"pt-2 pb-3",children:e.jsx(cn,{top3:m.kpis.top3,top10:m.kpis.top10,top20:m.kpis.top20,top50:m.kpis.top50,totalKeywords:m.kpis.totalKeywords})})]}),e.jsxs(be,{children:[e.jsx(Ge,{className:"pb-2",children:e.jsx(Ke,{className:"text-sm",children:"כוונת חיפוש (Search Intent)"})}),e.jsx(ve,{className:"pt-2 pb-3",children:e.jsx(dn,{informational:((xe=m.intentDistribution)==null?void 0:xe.informational)??0,navigational:((Ce=m.intentDistribution)==null?void 0:Ce.navigational)??0,commercial:(($e=m.intentDistribution)==null?void 0:$e.commercial)??0,transactional:((le=m.intentDistribution)==null?void 0:le.transactional)??0,unknown:((oe=m.intentDistribution)==null?void 0:oe.unknown)??0})})]})]}),e.jsxs(be,{children:[e.jsxs(Ge,{className:"pb-2 flex flex-row items-center justify-between gap-2",children:[e.jsxs(Ke,{className:"text-sm flex items-center gap-1.5",children:[e.jsx(ms,{className:"w-3.5 h-3.5 text-primary"}),"פיזור גאוגרפי (Distribution by Country)"]}),(b==null?void 0:b.cached)&&b.fetched_at&&e.jsxs(fe,{variant:"secondary",className:"text-[10px]",children:["Cached · ",new Date(b.fetched_at).toLocaleStr
28ing()]})]}),e.jsxs(ve,{className:"pt-2 pb-3",children:[!b&&!k&&!M&&e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 px-4 text-center border border-dashed border-border rounded-md bg-muted/20",children:[e.jsx(ms,{className:"w-8 h-8 text-muted-foreground mb-2"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-1",children:"ניתוח פיזור תנועה לפי מדינה (IL · US · UK · FR · DE)"}),e.jsx("p",{className:"text-xs text-muted-foreground/70 mb-4",children:"הנתונים נטענים רק לפי דרישה כדי לשמור על מהירות הדף ועלויות API."}),e.jsxs(ee,{size:"sm",onClick:G,disabled:!n||!s,children:[e.jsx(ms,{className:"w-3.5 h-3.5 mr-1.5"})," Analyze Geo-Distribution"]})]}),k&&e.jsxs("div",{className:"flex items-center justify-center py-8 gap-2 text-sm text-muted-foreground",children:[e.jsx(ie,{className:"w-4 h-4 animate-spin"})," טוען נתוני מדינות…"]}),M&&!k&&e.jsxs("div",{className:"flex flex-col items-center justify-center py-6 gap-2 text-center",children:[e.jsx(Ve,{className:"w-5 h-5 text-destructive"}),e.jsx("p",{className:"text-sm text-destructive",children:M}),e.jsx(ee,{size:"sm",variant:"outline",onClick:G,children:"נסה שוב"})]}),b&&!k&&e.jsxs(e.Fragment,{children:[(()=>{const _=Math.max(1,...b.countries.map(U=>U.traffic||0)),I=Math.max(1,...b.countries.map(U=>U.keywords||0));return e.jsxs(Qs,{children:[e.jsx(Ys,{children:e.jsxs(ns,{children:[e.jsx(pe,{className:"text-xs",children:"Country"}),e.jsx(pe,{className:"text-xs text-right",children:"Traffic"}),e.jsx(pe,{className:"text-xs text-right",children:"Keywords"})]})}),e.jsx(Xs,{children:b.countries.map(U=>e.jsxs(ns,{children:[e.jsx(ue,{className:"text-sm",children:e.jsxs("span",{className:"inline-flex items-center gap-2",children:[e.jsx(mn,{code:U.code}),e.jsx("span",{className:"font-mono text-xs text-muted-foreground",children:U.code}),e.jsx("span",{children:U.name}),U.error&&e.jsx(fe,{variant:"outline",className:"text-[10px] text-muted-foreground",children:"N/A"})]})}),e.jsx(ue,{className:"text-right p-1",children:e.jsx(rs,{value:U.traffic||0,max:_,display:(U.traffic||0).toLocaleString(),colorToken:"chart-organic",align:"right"})}),e.jsx(ue,{className:"text-right p-1",children:e.jsx(rs,{value:U.keywords||0,max:I,display:(U.keywords||0).toLocaleString(),colorToken:"primary",align:"right"})})]},U.code))})]})})(),e.jsx("div",{className:"flex justify-end mt-2",children:e.jsxs(ee,{size:"sm",variant:"ghost",onClick:G,className:"text-xs",children:[e.jsx(Kt,{className:"w-3 h-3 mr-1"})," רענן"]})})]})]})]}),m.aiSummary&&e.jsxs(be,{children:[e.jsx(Ge,{className:"pb-2",children:e.jsxs(Ke,{className:"text-sm flex items-center gap-1.5",children:[e.jsx(_e,{className:"w-3.5 h-3.5 text-primary"})," סיכום AI"]})}),e.jsx(ve,{children:e.jsx("p",{className:"text-sm text-foreground whitespace-pre-wrap leading-relaxed",children:m.aiSummary})})]}),e.jsxs(be,{children:[e.jsx(Ge,{className:"pb-2",children:e.jsxs(Ke,{className:"text-sm",children:["מילות מפתח אורגניות (",m.rankedKeywords.length,")"]})}),e.jsx(ve,{className:"overflow-x-auto pt-2 pb-3",children:m.rankedKeywords.length===0?e.jsx("p",{className:"text-xs text-muted-foreground text-center py-4",children:"לא נמצאו מילות מפתח לדומיין זה."}):(()=>{const _=m.rankedKeywords.length,I=m.rankedKeywords.slice(0,$),U=Math.max(...I.map(z=>z.searchVolume||0),1),O=Math.max(...I.map(z=>z.estimatedTraffic||0),1);return e.jsxs(e.Fragment,{children:[e.jsxs(Qs,{children:[e.jsx(Ys,{children:e.jsxs(ns,{children:[e.jsx(pe,{className:"h-8 text-[11px]",children:"מילת מפתח"}),e.jsx(pe,{className:"h-8 text-[11px] text-center",children:"מיקום"}),e.jsx(pe,{className:"h-8 text-[11px] text-center",children:"נפח חודשי"}),e.jsx(pe,{className:"h-8 text-[11px] text-center",children:"CPC"}),e.jsx(pe,{className:"h-8 text-[11px] text-center",children:"תחרות"}),e.jsx(pe,{className:"h-8 text-[11px] text-center",children:"טראפיק משוער"}),e.jsx(pe,{className:"h-8 text-[11px]",children:"URL"})]})}),e.jsx(Xs,{children:I.map((z,re)=>e.jsxs(ns,{className:"h-8",children:[e.jsx(ue,{className:"font-medium py-1.5 text-xs",children:z.keyword}),e.jsx(ue,{className:"text-center py-1.5",children:e.jsxs(fe,{variant:z.position&&z.position<=3?"default":z.position&&z.position<=10?"secondary":"outline",className:"text-[10px] px-1.5 py-0",children:["#",z.position??"—"]}
28)}),e.jsx(ue,{className:"text-center py-1.5",children:e.jsx(rs,{value:z.searchVolume,max:U,display:z.searchVolume.toLocaleString(),colorToken:"chart-branded"})}),e.jsxs(ue,{className:"text-center py-1.5 text-xs tabular-nums",children:["$",z.cpc.toFixed(2)]}),e.jsx(ue,{className:"text-center py-1.5",children:e.jsx("span",{className:"text-[10px]",children:z.competition})}),e.jsx(ue,{className:"text-center py-1.5",children:e.jsx(rs,{value:z.estimatedTraffic,max:O,display:z.estimatedTraffic.toLocaleString(),colorToken:"chart-organic"})}),e.jsx(ue,{className:"max-w-[200px] truncate py-1.5",children:e.jsxs("a",{href:z.url,target:"_blank",rel:"noopener noreferrer",className:"text-[11px] text-primary hover:underline inline-flex items-center gap-1",dir:"ltr",children:[z.url.replace(/^https?:\/\//,"").slice(0,40),e.jsx(Qe,{className:"w-3 h-3"})]})})]},`${z.keyword}-${re}`))})]}),e.jsx(Us,{shown:I.length,total:_,onMore:()=>w(z=>Math.min(z+Ne,_)),onAll:()=>w(_)})]})})()})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-3",children:[e.jsxs(be,{children:[e.jsx(Ge,{className:"pb-2",children:e.jsxs(Ke,{className:"text-sm",children:["דפים מובילים (",m.topPages.length,")"]})}),e.jsx(ve,{className:"pt-2 pb-3",children:m.topPages.length===0?e.jsx("p",{className:"text-xs text-muted-foreground text-center py-4",children:"אין נתונים."}):(()=>{const _=m.topPages.length,I=m.topPages.slice(0,W),U=Math.max(...I.map(O=>O.estimatedTraffic||0),1);return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"space-y-1",children:I.map((O,z)=>e.jsxs("div",{className:"grid grid-cols-[1fr_auto_120px] items-center gap-2 px-2 py-1 rounded border border-border/40 bg-card/50 hover:bg-card transition-colors",children:[e.jsx("a",{href:O.url,target:"_blank",rel:"noopener noreferrer",className:"text-[11px] text-primary hover:underline truncate",dir:"ltr",children:O.url.replace(/^https?:\/\//,"")}),e.jsxs("span",{className:"text-[10px] text-muted-foreground tabular-nums whitespace-nowrap",children:[O.keywordsCount," kws"]}),e.jsx(rs,{value:O.estimatedTraffic,max:U,display:`${Math.round(O.estimatedTraffic).toLocaleString()} traf`,colorToken:"chart-organic",align:"right"})]},z))}),e.jsx(Us,{shown:I.length,total:_,onMore:()=>N(O=>Math.min(O+Ne,_)),onAll:()=>N(_)})]})})()})]}),e.jsxs(be,{children:[e.jsx(Ge,{className:"pb-2",children:e.jsxs(Ke,{className:"text-sm",children:["מתחרים אורגניים (",m.competitors.length,")"]})}),e.jsx(ve,{className:"pt-2 pb-3",children:m.competitors.length===0?e.jsx("p",{className:"text-xs text-muted-foreground text-center py-4",children:"לא נמצאו מתחרים."}):(()=>{const _=m.competitors.length,I=m.competitors.slice(0,F),U=Math.max(...I.map(O=>O.commonKeywords||0),1);return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"space-y-1",children:I.map((O,z)=>e.jsxs("div",{className:"grid grid-cols-[1fr_auto_120px] items-center gap-2 px-2 py-1 rounded border border-border/40 bg-card/50 hover:bg-card transition-colors",children:[e.jsx("span",{className:"text-[11px] font-medium truncate",dir:"ltr",children:O.domain}),e.jsxs("span",{className:"text-[10px] text-muted-foreground tabular-nums whitespace-nowrap",children:[O.intersections," חפיפה"]}),e.jsx(rs,{value:O.commonKeywords,max:U,display:`${O.commonKeywords.toLocaleString()} kws`,colorToken:"chart-branded",align:"right"})]},z))}),e.jsx(Us,{shown:I.length,total:_,onMore:()=>j(O=>Math.min(O+Ne,_)),onAll:()=>j(_)})]})})()})]})]})]})]})}function Us({shown:s,total:i,onMore:u,onAll:n}){const c=Math.max(0,i-s),x=Math.min(Ne,c),o=C=>r=>{const m=r.currentTarget;C(),requestAnimationFrame(()=>{const v=m.getBoundingClientRect();(v.bottom>window.innerHeight||v.top<0)&&m.scrollIntoView({block:"nearest",behavior:"smooth"})})};return e.jsx("div",{className:"mt-3 min-h-[44px] flex items-center justify-center gap-2",children:c>0?e.jsxs(e.Fragment,{children:[e.jsxs(ee,{variant:"outline",size:"sm",className:"text-xs h-8",onClick:o(u),children:[e.jsx(gs,{className:"w-3.5 h-3.5 mr-1"}),"הצג עוד ",x]}),e.jsxs(ee,{variant:"ghost",size:"sm",className:"text-xs h-8 text-muted-foreground",onClick:o(n),children:["הצג הכל (",i,")"]})]}):e.jsxs("span",{className:"text-[11px] text-muted-foreground",children:["מציג ",s," מתוך ",i]})})}const Nn=l.lazy(()=>ea(()=>import("./KeywordResearch-4omXIUnO.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]))),bn=l.lazy(()=>ea(()=>import("./KeywordGap-ExXcaYd3.js"),__vite__mapDeps([17,1,2,3,4,5,6,7,8,18,19])));function Hs({insights:s,onTabSwitch:i}){if(s.every(n=>n.count===0))return null;const u=s.filter(n=>n.count>0);return e.jsx("div",{className:"flex flex-wrap gap-2 mb-4",children:u.map((n,c)=>e.jsxs("button",{onClick:()=>i(n.targetTab),className:"flex items-center gap-1.5 px-3 py-1.5 rounded-full bg-primary/8 border border-primary/20 text-xs text-primary hover:bg-primary/15 transition-colors",children:[n.icon,e.jsx("span",{children:n.text}),e.jsx(ma,{className:"w-3 h-3 opacity-60"})]},c))})}function sl(){var t;const{selectedClient:s}=Ms(),{t:i,isRTL:u}=Ye(),[n,c]=l.useState("overview"),[x,o]=l.useState({queries:[],pages:[],summary:null,auditSiteHealth:null,auditErrorsCount:null,auditWarningsCount:null}),C=l.useCallback(g=>{o(h=>({...h,...g}))},[]),r=l.useCallback((g,h,y)=>{o($=>({...$,auditSiteHealth:g,auditErrorsCount:h,auditWarningsCount:y}))},[]),m=x.queries.filter(g=>g.position>=8&&g.position<=25).length,v=x.queries.length>20?Math.floor(x.queries.length/15):0;return e.jsxs("div",{className:"space-y-5",dir:u?"rtl":"ltr",children:[e.jsx(fr,{sectionKey:"platform-seo"}),e.jsx(Yr,{}),e.jsxs(na,{value:n,onValueChange:c,dir:u?"rtl":"ltr",children:[e.jsxs(ia,{className:`mb-4 flex w-full flex-wrap h-auto ${u?"flex-row-reverse justify-end":"justify-start"}`,children:[e.jsxs(Me,{value:"overview",className:"flex items-center gap-1.5",children:[e.jsx(Zs,{className:"w-3.5 h-3.5"}),i("platform.seo.overview")]}),e.jsxs(Me,{value:"audit",className:"flex items-center gap-1.5",children:[e.jsx(Gs,{className:"w-3.5 h-3.5"}),i("platform.seo.siteAudit"),x.auditErrorsCount!==null&&x.auditErrorsCount>0&&e.jsx("span",{className:"ml-1 px-1.5 py-0.5 rounded-full bg-destructive/20 text-destructive text-[10px] font-bold",children:x.auditErrorsCount})]}),e.jsxs(Me,{value:"console",className:"flex items-center gap-1.5",children:[e.jsx(Ee,{className:"w-3.5 h-3.5"}),"Search Console",m>0&&e.jsx("span",{className:"ml-1 px-1.5 py-0.5 rounded-full bg-warning/20 text-warning text-[10px] font-bold",children:m})]}),e.jsxs(Me,{value:"weekly",className:"flex items-center gap-1.5",children:[e.jsx(Ts,{className:"w-3.5 h-3.5"}),i("platform.seo.weeklyReport")]}),e.jsxs(Me,{value:"cwv",className:"flex items-center gap-1.5",children:[e.jsx(xa,{
28className:"w-3.5 h-3.5"}),i("platform.seo.cwvIndex")]}),e.jsxs(Me,{value:"content-gap",className:"flex items-center gap-1.5",children:[e.jsx(Er,{className:"w-3.5 h-3.5"}),i("platform.seo.contentGaps")]}),e.jsxs(Me,{value:"keyword-research",className:"flex items-center gap-1.5",children:[e.jsx(Dr,{className:"w-3.5 h-3.5"}),"מחקר מילות מפתח"]}),e.jsxs(Me,{value:"domain-overview",className:"flex items-center gap-1.5",children:[e.jsx(Le,{className:"w-3.5 h-3.5"}),"ניתוח דומיין"]}),e.jsxs(Me,{value:"keyword-gap",className:"flex items-center gap-1.5",children:[e.jsx(ps,{className:"w-3.5 h-3.5"}),"פערי מתחרים"]})]}),e.jsx(ce,{value:"overview",children:s?e.jsxs(e.Fragment,{children:[e.jsx(Hs,{onTabSwitch:c,insights:[{icon:e.jsx(Gs,{className:"w-3.5 h-3.5"}),text:x.auditErrorsCount!==null?`${x.auditErrorsCount} ${i("platform.seo.technicalIssues")}`:i("platform.seo.runSiteAudit"),targetTab:"audit",count:x.auditErrorsCount??1},{icon:e.jsx(Re,{className:"w-3.5 h-3.5"}),text:`${m} ${i("platform.seo.strikingDistance")}`,targetTab:"console",count:m}]}),e.jsx(Zr,{clientId:s.id,clientName:s.name,websiteUrl:s.website_url,seoData:x.summary?{summary:x.summary,queries:x.queries,pages:x.pages,devices:[]}:void 0,auditSiteHealth:x.auditSiteHealth,auditErrorsCount:x.auditErrorsCount})]}):e.jsx("p",{className:"text-sm text-muted-foreground text-center py-10",children:i("platform.seo.selectClientOverview")})}),e.jsx(ce,{value:"audit",children:s?e.jsxs(e.Fragment,{children:[e.jsx(Hs,{onTabSwitch:c,insights:[{icon:e.jsx(Re,{className:"w-3.5 h-3.5"}),text:`${m} ${i("platform.seo.keywordsStriking")}`,targetTab:"console",count:m},{icon:e.jsx(Ae,{className:"w-3.5 h-3.5"}),text:`${x.queries.filter(g=>g.position>10).length} ${i("platform.seo.queriesOffPage")}`,targetTab:"console",count:x.queries.filter(g=>g.position>10).length}]}),e.jsx(tn,{clientId:s.id,clientName:s.name,websiteUrl:s.website_url,onAuditData:r})]}):e.jsx("p",{className:"text-sm text-muted-foreground text-center py-10",children:i("platform.seo.selectClientAudit")})}),e.jsxs(ce,{value:"console",children:[s&&e.jsx(Hs,{onTabSwitch:c,insights:[{icon:e.jsx(Gs,{className:"w-3.5 h-3.5"}),text:x.auditSiteHealth!==null?`${i("platform.seo.siteHealth")}: ${x.auditSiteHealth}% — ${x.auditErrorsCount} ${i("platform.seo.technicalIssuesSiteAudit")}`:i("platform.seo.noAuditYet"),targetTab:"audit",count:x.auditErrorsCount??(x.auditSiteHealth===null?1:0)},{icon:e.jsx(ps,{className:"w-3.5 h-3.5"}),text:`${v} ${i("platform.seo.cannibalization")}`,targetTab:"console",count:v}]}),e.jsx(Qr,{onDataReady:C})]}),e.jsx(ce,{value:"weekly",children:s?e.jsx(an,{clientId:s.id,clientName:s.name,onNavigateToTab:c}):e.jsx("p",{className:"text-sm text-muted-foreground text-center py-10",children:i("platform.seo.selectClientWeekly")})}),e.jsx(ce,{value:"cwv",children:s?e.jsx(nn,{siteUrl:s.website_url||""}):e.jsx("p",{className:"text-sm text-muted-foreground text-center py-10",children:i("platform.seo.selectClient")})}),e.jsx(ce,{value:"content-gap",children:s?e.jsx(ln,{clientId:s.id,clientName:s.name,websiteUrl:s.website_url,queries:x.queries}):e.jsx("p",{className:"text-sm text-muted-foreground text-center py-10",children:i("platform.seo.selectClient")})}),e.jsx(ce,{value:"keyword-research",children:e.jsx(l.Suspense,{fallback:e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx(ie,{className:"w-5 h-5 animate-spin text-muted-foreground"})}),children:e.jsx(Nn,{embedded:!0},(s==null?void 0:s.id)||"no-client")})}),e.jsx(ce,{value:"domain-overview",children:s?e.jsx(yn,{clientId:s.id,defaultDomain:(t=s.website_url)==null?void 0:t.replace(/^https?:\/\//,"").replace(/\/$/,"")},s.id):e.jsx("p",{className:"text-sm text-muted-foreground text-center py-10",children:i("platform.seo.selectClient")})}),e.jsx(ce,{value:"keyword-gap",children:e.jsx(l.Suspense,{fallback:e.jsx("div",{className:"flex items-center justify-center py-20",children:e.jsx(ie,{className:"w-5 h-5 animate-spin text-muted-foreground"})}),children:e.jsx(bn,{})})})]})]})}export{sl 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.