1import{c as Je,u as je,h as Y,s as T,k as A,j as e,b as ke,r as m,i as Ze,B as S,X as es,a as ss}from"./index-DDM5dk0b.js";import{g as ts,D as is}from"./DashboardLayout-D4pFvceb.js";import{S as rs}from"./SEO-D6XjEQu2.js";import{C as Z,a as ee,b as as,c as ns,d as ls}from"./card-DEgzWvw5.js";import{B as H}from"./badge-BC_-ffdp.js";import{I as se}from"./input-CB0QRRvU.js";import{S as te,a as ie,b as re,c as ae,d as E}from"./select-B0YVmj_C.js";import{b as os}from"./useSelectedSite-DJBZVzUt.js";import{u as K}from"./useMutation-CtnWNKWa.js";import{O as cs}from"./onboarding-guide-BXPBbd49.js";import{T as ds,a as ms,b as be,c as W,d as us,e as O}from"./table-BMsFNn8Q.js";import{C as oe}from"./checkbox-SJL1LI2z.js";import{A as xs}from"./arrow-down-kPraj7sI.js";import{A as ps}from"./arrow-up-7JGzjiTE.js";import{A as hs}from"./arrow-up-down-BwqfsNdh.js";import{E as gs}from"./eye-Cs-gGMsx.js";import{P as fs}from"./pencil-Bb-RChdE.js";import{T as Be}from"./trash-2-DLYKeKyF.js";import{C as js}from"./chevron-left-HWpYslqI.js";import{C as ys}from"./chevron-right-BBZt2Fbq.js";import{S as Se}from"./sparkles-CpIfunfF.js";import{D as Ce}from"./download-B_uflK1r.js";import{S as _e,a as Pe,b as Te,c as Ee,d as qe}from"./sheet-BgKQopPJ.js";import{L as I}from"./loader-circle-D4BXDxKA.js";import{R as Ge}from"./refresh-cw-C6TP4FiG.js";import{C as Oe}from"./circle-check-BsWKPZtr.js";import{C as Ke}from"./circle-x-Dd7ohflJ.js";import{E as Qe}from"./external-link-Cn3bBx-h.js";import{f as ws}from"./formatDistanceToNow-CTraltex.js";import{P as Ae}from"./plus-iD05mNu5.js";import{T as vs,a as bs,b as $e,c as Fe}from"./tabs-qQTP-g4P.js";import{D as Ns}from"./database-DtgnIYRV.js";import{F as ks}from"./file-text-Btf8zv2A.js";import{S as Ue}from"./search-DdySdFDk.js";import{D as Ss,a as Cs,b as _s,c as Ps,e as Ts}from"./dialog-D1UXTEoE.js";import{L as J}from"./label-D_p07P0K.js";import{T as Es}from"./textarea-BpJ9CvPg.js";import{R as Ne}from"./radar-fhbntNP5.js";import{C as qs}from"./circle-alert-C-OLH9Mi.js";import{d as As,t as Vs}from"./csv-BiSujZuH.js";import{E as Ds}from"./earth-bHz_Wamc.js";import"./Logo-DaJ4nYOq.js";import"./useFeaturePreferences-SjnhQKB5.js";import"./infinity-DNWxkTuU.js";import"./heart-CHj1tVxM.js";import"./layout-dashboard-Bs40Jm_Q.js";import"./pen-tool-CD_8LZ1E.js";import"./wand-sparkles-CHCihP20.js";import"./bot-BOFGcXc2.js";import"./key-round-C3XttjTP.js";import"./share-2-BwrFOpeM.js";import"./calendar-days-xXAsp2YT.js";import"./globe-B8QcTDpd.js";import"./gift-CKgoruQl.js";import"./settings-r2YjUbHs.js";import"./dropdown-menu-BdS3K8Un.js";import"./index-QaJzJ_Zg.js";import"./Combination-Dkfmdx58.js";import"./index-C4oDHxzA.js";import"./check-D9A8J6nx.js";import"./avatar-p28dd_fK.js";import"./useAdminAnnouncements-WZi3_Iya.js";import"./en-US-DgaeWpfW.js";import"./constructFrom-rJN6zrQ_.js";import"./startOfWeek-CGNiWUve.js";import"./info-D77hYOXX.js";import"./circle-check-big-B9olxzQT.js";import"./triangle-alert-Bm8fQL2_.js";import"./megaphone-DO-qAaXU.js";import"./bell-CoNE08uI.js";import"./startOfMonth-BqpJtJQc.js";import"./crown-BeXfEaV_.js";import"./LanguageSwitcher-C3EeTro6.js";import"./useProfile-DLJIBHII.js";import"./menu-DxXqjd0J.js";import"./sun-Cvp432r0.js";import"./user-684CS7x0.js";import"./BottomNav-B1JpqRZZ.js";import"./index-BdQq_4o_.js";import"./usePersistentDismissal-DeSBlaY7.js";import"./index-BjPFedwd.js";import"./differenceInCalendarMonths-DdVU3xYm.js";import"./endOfDay-A-ioHiWL.js";import"./endOfMonth-CoG5-XNs.js";/** 2 * @license lucide-react v0.462.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const Re=Je("Power",[["path",{d:"M12 2v10",key:"mnfbl"}],["path",{d:"M18.4 6.6a9 9 0 1 1-12.77.04",key:"obofu9"}]]);function zs(t){return je({queryKey:["aiv-prompts",t],enabled:!!t,queryFn:async()=>{const{data:s,error:i}=await T.from("ai_visibility_prompts").select("*").eq("connection_id",t).order("created_at",{ascending:!1}).limit(500);if(i)throw i;return s??[]}})}function Ms(t){return je({queryKey:["aiv-runs",t],enabled:!!t,refetchInterval:s=>(s.state.data??[]).some(a=>a.status==="running"||a.status==="queued")?4e3:!1,queryFn:async()=>{const{data:s,error:i}=await T.from("ai_visibility_runs").select("*").eq("connection_id",t).order("started_at",{ascending:!1}).limit(10);if(i)throw i;return s??[]}})}function Ls(t){return je({queryKey:["aiv-snap",t],enabled:!!t,queryFn:async()=>{const{data:s,error:i}=await T.from("ai_visibility_snapshots").select("*").eq("connection_id",t).order("day",{ascending:!1}).limit(30);if(i)throw i;return s??[]}})}function $s(t){return je({queryKey:["aiv-results",t],enabled:!!t,queryFn:async()=>{const{data:s,error:i}=await T.from("ai_visibility_results").select("prompt_id, engine, cited, position, cited_domains, competitor_domains, answer_text, cited_urls, created_at").eq("connection_id",t).order("created_at",{ascending:!1}).limit(3e3);if(i)throw i;return s??[]}})}function Fs(){const t=Y();return K({mutationFn:async s=>{const{data:i,error:a}=await T.functions.invoke("ai-visibility-run",{body:{connection_id:s}});if(a)throw a;if((i==null?void 0:i.ok)===!1)throw new Error(i.error||"Run failed");return i},onSuccess:(s,i)=>{A.success("AI Visibility sweep started"),t.invalidateQueries({queryKey:["aiv-runs",i]})},onError:s=>A.error((s==null?void 0:s.message)||"Failed to start sweep")})}function Rs(){const t=Y();return K({mutationFn:async({connectionId:s,prompt:i,prompt_type:a,check_frequency:p})=>{const{data:h}=await T.auth.getUser();if(!h.user)throw new Error("Not signed in");const{data:u,error:f}=await T.from("ai_visibility_prompts").insert({connection_id:s,user_id:h.user.id,prompt:i,source:"manual",prompt_type:a??"organic",check_frequency:p??"daily"}).select("id").maybeSingle();if(f)throw f;const x=u==null?void 0:u.id;return x&&T.functions.invoke("ai-visibility-classify",{body:{connection_id:s,prompt_ids:[x]}}).then(()=>
6t.invalidateQueries({queryKey:["aiv-prompts",s]})).catch(()=>{}),u},onSuccess:(s,i)=>{t.invalidateQueries({queryKey:["aiv-prompts",i.connectionId]})},onError:s=>A.error((s==null?void 0:s.message)||"Failed to add prompt")})}function Bs(){const t=Y();return K({mutationFn:async({id:s,is_active:i})=>{const{error:a}=await T.from("ai_visibility_prompts").update({is_active:i}).eq("id",s);if(a)throw a},onSuccess:()=>{t.invalidateQueries({queryKey:["aiv-prompts"]})}})}function Gs(){const t=Y();return K({mutationFn:async s=>{const{error:i}=await T.from("ai_visibility_prompts").delete().eq("id",s);if(i)throw i},onSuccess:()=>{t.invalidateQueries({queryKey:["aiv-prompts"]})}})}function Os(){const t=Y();return K({mutationFn:async s=>{if(!s.length)return;const{error:i}=await T.from("ai_visibility_prompts").delete().in("id",s);if(i)throw i},onSuccess:(s,i)=>{A.success(`Deleted ${i.length} prompt${i.length===1?"":"s"}`),t.invalidateQueries({queryKey:["aiv-prompts"]})},onError:s=>A.error((s==null?void 0:s.message)||"Failed to delete")})}function Ks(){const t=Y();return K({mutationFn:async({ids:s,is_active:i})=>{if(!s.length)return;const{error:a}=await T.from("ai_visibility_prompts").update({is_active:i}).in("id",s);if(a)throw a},onSuccess:()=>{t.invalidateQueries({queryKey:["aiv-prompts"]})}})}function Qs(){const t=Y();return K({mutationFn:async({id:s,patch:i})=>{const{error:a}=await T.from("ai_visibility_prompts").update(i).eq("id",s);if(a)throw a},onSuccess:()=>{t.invalidateQueries({queryKey:["aiv-prompts"]})},onError:s=>A.error((s==null?void 0:s.message)||"Failed to update")})}function Us(){const t=Y();return K({mutationFn:async({connectionId:s,ids:i})=>{const{data:a,error:p}=await T.functions.invoke("ai-visibility-classify",{body:{connection_id:s,prompt_ids:i}});if(p)throw p;if((a==null?void 0:a.ok)===!1)throw new Error(a.error||"Classify failed");return a},onSuccess:(s,i)=>{A.success(`Reclassified ${(s==null?void 0:s.updated)??0} prompt${((s==null?void 0:s.updated)??0)===1?"":"s"}`),t.invalidateQueries({queryKey:["aiv-prompts",i.connectionId]})},onError:s=>A.error((s==null?void 0:s.message)||"Reclassify failed")})}function Ws(){return K({mutationFn:async t=>{const{data:s,error:i}=await T.functions.invoke("ai-visibility-suggest",{body:{connection_id:t}});if(i)throw i;if((s==null?void 0:s.ok)===!1)throw new Error(s.error||"Suggest failed");return s},onError:t=>A.error((t==null?void 0:t.message)||"Failed to fetch suggestions")})}function We(){const t=Y();return K({mutationFn:async({connectionId:s,items:i})=>{const{data:a}=await T.auth.getUser();if(!a.user)throw new Error("Not signed in");const p=i.map(x=>({connection_id:s,user_id:a.user.id,prompt:x.prompt,prompt_type:x.type,source:"explore",check_frequency:"daily"})),{data:h,error:u}=await T.from("ai_visibility_prompts").insert(p).select("id");if(u)throw u;const f=(h??[]).map(x=>x.id);return f.length&&T.functions.invoke("ai-visibility-classify",{body:{connection_id:s,prompt_ids:f}}).then(()=>t.invalidateQueries({queryKey:["aiv-prompts",s]})).catch(()=>{}),f.length},onSuccess:(s,i)=>{A.success(`Added ${s} prompt${s===1?"":"s"}`),t.invalidateQueries({queryKey:["aiv-prompts",i.connectionId]})},onError:s=>A.error((s==null?void 0:s.message)||"Failed to add prompts")})}const fe={organic:"bg-emerald-500",competitor:"bg-orange-500",brand:"bg-violet-500",category:"bg-sky-500",regional:"bg-amber-500"},ce={organic:"Organic",competitor:"Competitor",brand:"Brand",category:"Category",regional:"Regional"};function Hs({counts:t}){const s=["organic","competitor","brand","category","regional"],i=s.reduce((a,p)=>a+(t[p]??0),0);return e.jsx(Z,{children:e.jsxs(ee,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 flex-wrap",children:[e.jsx("div",{className:"text-[11px] font-medium uppercase tracking-wider text-muted-foreground",children:"Prompt types"}),e.jsx("div",{className:"flex items-center gap-3 text-xs flex-wrap",children:s.map(a=>e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:`h-2 w-2 rounded-full ${fe[a]}`}),e.jsx("span",{className:"text-muted-foreground",children:ce[a]}),e.jsx("span",{className:"font-medium",children:t[a]??0})]},a))})]}),e.jsx("div",{className:"mt-3 flex h-2 w-full overflow-hidden rounded-full bg-muted",children:i===0?e.jsx("div",{className:"h-full w-full bg-muted"}):s.map(a=>{const p=t[a]??0;if(!p)return null;const h=p/i*100;return e.jsx("div",{className:`h-full ${fe[a]}`,style:{width:`${h}%`}},a)})})]})})}const Ys=[{key:"chatgpt",label:"ChatGPT",short:"GPT",color:"bg-emerald-500",icon:"https://www.google.com/s2/favicons?domain=openai.com&sz=64"},{key:"gemini",label:"Gemini",short:"GEM",color:"bg-blue-500",icon:"https://www.google.com/s2/favicons?domain=gemini.google.com&sz=64"},{key:"deepseek",label:"DeepSeek",short:"DS",color:"bg-violet-500",icon:"https://www.google.com/s2/favicons?domain=deepseek.com&sz=64"},{key:"perplexity",label:"Perplexity",short:"PPX",color:"bg-cyan-500",icon:"https://www.google.com/s2/favicons?domain=perplexity.ai&sz=64"}];function Xs(t){return t==="daily"?"1d":t==="weekly"?"1w":"1m"}function Is({rows:t,selected:s,onSelectChange:i,onToggleActive:a,onDelete:p,onOpen:h,onEdit:u}){const{t:f}=ke(),[x,y]=m.useState(1),[w,C]=m.useState(25),[c,n]=m.useState("desc"),j=m.useMemo(()=>
6{if(c==="none")return t;const d=[...t];return d.sort((g,z)=>c==="desc"?(z.visibility??0)-(g.visibility??0):(g.visibility??0)-(z.visibility??0)),d},[t,c]),q=Math.max(1,Math.ceil(j.length/w));m.useEffect(()=>{x>q&&y(1)},[q,x]);const _=m.useMemo(()=>j.slice((x-1)*w,x*w),[j,x,w]),L=()=>{n(d=>d==="desc"?"asc":d==="asc"?"none":"desc"),y(1)},V=_.length>0&&_.every(d=>s.has(d.id)),X=()=>{const d=new Set(s);V?_.forEach(g=>d.delete(g.id)):_.forEach(g=>d.add(g.id)),i(d)},F=d=>{const g=new Set(s);g.has(d)?g.delete(d):g.add(d),i(g)};return e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"rounded-lg border overflow-hidden",children:e.jsxs(ds,{children:[e.jsx(ms,{children:e.jsxs(be,{children:[e.jsx(W,{className:"w-10",children:e.jsx(oe,{checked:V,onCheckedChange:X,"aria-label":"Select all"})}),e.jsx(W,{className:"min-w-[260px]",children:"@ Prompt"}),e.jsx(W,{className:"w-24 p-0",children:e.jsxs("button",{type:"button",onClick:L,"aria-label":"Sort by visibility",className:"flex h-full w-full items-center gap-1 px-4 py-2 text-left font-medium transition-colors hover:text-foreground",children:["Visibility",c==="desc"?e.jsx(xs,{className:"h-3.5 w-3.5 text-primary"}):c==="asc"?e.jsx(ps,{className:"h-3.5 w-3.5 text-primary"}):e.jsx(hs,{className:"h-3.5 w-3.5 opacity-40"})]})}),e.jsx(W,{className:"w-32",children:"Mentioned"}),e.jsx(W,{className:"w-[200px]",children:f("LLMs")}),e.jsx(W,{className:"w-20",children:"Mentions"}),e.jsx(W,{className:"w-20",children:"Check"}),e.jsx(W,{className:"w-16 text-right",children:"Active"}),e.jsx(W,{className:"w-28 text-right",children:"Actions"})]})}),e.jsx(us,{children:_.length===0?e.jsx(be,{children:e.jsx(O,{colSpan:9,className:"text-center text-sm text-muted-foreground py-12",children:"No prompts match your filters."})}):_.map(d=>e.jsxs(be,{className:"group",children:[e.jsx(O,{children:e.jsx(oe,{checked:s.has(d.id),onCheckedChange:()=>F(d.id)})}),e.jsx(O,{children:e.jsxs("button",{className:"flex items-start gap-2 text-left hover:underline",onClick:()=>h(d),children:[e.jsx("span",{className:`mt-1.5 h-2 w-2 shrink-0 rounded-full ${fe[d.prompt_type]??"bg-muted"}`}),e.jsxs("span",{className:"text-sm",children:[d.prompt,e.jsx(H,{variant:"outline",className:"ml-2 text-[9px] font-normal",children:ce[d.prompt_type]??d.prompt_type})]})]})}),e.jsx(O,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"relative h-6 w-6",children:e.jsxs("svg",{viewBox:"0 0 36 36",className:"h-6 w-6 -rotate-90",children:[e.jsx("circle",{cx:"18",cy:"18",r:"14",fill:"none",stroke:"hsl(var(--muted))",strokeWidth:"4"}),e.jsx("circle",{cx:"18",cy:"18",r:"14",fill:"none",stroke:"hsl(var(--primary))",strokeWidth:"4",strokeDasharray:`${d.visibility/100*87.96} 87.96`,strokeLinecap:"round"})]})}),e.jsxs("span",{className:"text-xs tabular-nums",children:[d.visibility,"%"]})]})}),e.jsx(O,{children:d.mentioned_domains.length===0?e.jsx("span",{className:"text-xs text-muted-foreground",children:"â"}):e.jsxs("div",{className:"flex items-center -space-x-1.5",children:[d.mentioned_domains.slice(0,4).map(g=>e.jsx("img",{src:`https://www.google.com/s2/favicons?domain=${g}&sz=32`,alt:g,title:g,className:"h-4 w-4 rounded-sm ring-1 ring-background",loading:"lazy"},g)),d.mentioned_domains.length>4&&e.jsxs("span",{className:"ml-2 text-[10px] text-muted-foreground",children:["+",d.mentioned_domains.length-4]})]})}),e.jsx(O,{children:e.jsx("div",{className:"flex flex-wrap items-center gap-1",children:Ys.map(g=>{var R;const z=!!((R=d.engines)!=null&&R[g.key]);return e.jsx("span",{title:`${g.label}: ${z?"Cited":"Not cited"}`,className:`inline-flex h-6 w-6 items-center justify-center rounded-md border transition ${z?"border-transparent ring-2 ring-offset-1 ring-offset-background "+g.color.replace("bg-","ring-")+" bg-background":"border-border bg-muted/40 grayscale opacity-50"}`,children:e.jsx("img",{src:g.icon,alt:g.label,className:"h-3.5 w-3.5",loading:"lazy"})},g.key)})})}),e.jsx(O,{className:"tabular-nums text-sm",children:d.mentions_count}),e.jsx(O,{children:e.jsx(H,{variant:"outline",className:"text-[10px]",children:Xs(d.check_frequency)})}),e.jsx(O,{className:"text-right",children:e.jsx(Ze,{checked:d.is_active,onCheckedChange:g=>a(d.id,g)})}),e.jsx(O,{className:"text-right",children:e.jsxs("div",{className:"inline-flex",children:[e.jsx(S,{size:"icon",variant:"ghost",className:"h-7 w-7",onClick:()=>h(d),title:"View",children:e.jsx(gs,{className:"h-3.5 w-3.5"})}),e.jsx(S,{size:"icon",variant:"ghost",className:"h-7 w-7",onClick:()=>u(d),title:"Edit",children:e.jsx(fs,{className:"h-3.5 w-3.5"})}),e.jsx(S,{size:"icon",variant:"ghost",className:"h-7 w-7",onClick:()=>p(d.id),title:"Delete",children:e.jsx(Be,{className:"h-3.5 w-3.5 text-destructive"})})]})})]},d.id))})]})}),e.jsxs("div",{className:"flex flex-col sm:flex-row items-center justify-between gap-3 px-1",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:j.length===0?"0 results":`Showing ${(x-1)*w+1}â${Math.min(x*w,j.length)} of ${j.length}`}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Rows"}),e.jsxs(te,{value:String(w),onValueChange:d=>{C(Number(d)),y(1)},children:[e.jsx(ie,{className:"h-8 w-[72px]",children:e.jsx(re,{})}),e.jsx(ae,{children:[10,25,50,100].map(d=>e.jsx(E,{value:String(d),children:d},d))})]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(S,{size:"icon",variant:"outline",className:"h-8 w-8",disabled:x<=1,onClick:()=>y(d=>Math.max(1,d-1)),children:e.jsx(js,{className:"h-4 w-4"})}),e.jsxs("span",{className:"text-xs tabular-nums px-2",children:["Page ",x," / ",q]}),e.jsx(S,{size:"icon",variant:"outline",className:"h-8 w-8",disabled:x>=q,onClick:()=>y(d=>Math.min(q,d+1)),children:e.jsx(ys,{className:"h-4 w-4"})})]})]})]})]})}function Js({count:t,onClear:s,onDelete:i,onToggleActive:a,onReclassify:p,onExport:h,busy:u}){return t===0?null:e.jsxs("div",{className:"sticky top-2 z-10 flex items-center justify-between gap-2 rounded-lg border bg-card px-3 py-2 shadow-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx(S,{size:"icon",variant:"ghost",className:"h-7 w-7",onClick:s,children:e.jsx(es,{className:"h-3.5 w-3.5"})}),e.jsx("span",{className:"font-medium",children:t}),e.jsx("span",{className:"text-muted-foreground",children:"selected"})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsxs(S,{size:"sm",variant:"outline",disabled:u,onClick:()=>a(!0),children:[e.jsx(Re,{className:"h-3.5 w-3.5 mr-1.5"})," Activate"]}),e.jsxs(S,{size:"sm",variant:"outline",disabled:u,onClick:()=>a(!1),children:[e.jsx(Re,{className:"h-3.5 w-3.5 mr-1.5"})," Pause"]}),e.jsxs(S,{size:"sm",variant:"outline",disabled:u,onClick:p,children:[e.jsx(Se,{className:"h-3.5 w-3.5 mr-1.5"})," Reclassify"]}),e.jsxs(S,{size:"sm",variant:"outline",disabled:u,onClick:h,children:[e.jsx(Ce,{className:"h-3.5 w-3.5 mr-1.5"})," Export"]}),e.jsxs(S,{size:"sm",variant:"destructive",disabled:u,onClick:i,children:[e.jsx(Be,{className:"h-3.5 w-3.5 mr-1.5"})," Delete"]})]})]})}const Zs={gemini:"Gemini",openai:"ChatGPT",deepseek:"DeepSeek",perplexity:"Perplexity"};function et({open:t,onOpenChange:s,prompt:i,results:a,onRun:p,running:h=!1}){const{t:u}=ke(),{locale:f}=ss(),x=ts(f),y=m.useMemo(()=>i?(a??[]).filter(C=>C.prompt_id===i.id):[],[a,i]),w=m.useMemo(()=>{const C=new Map;for(const c of y)C.has(c.engine)||C.set(c.engine,c);return C},[y]);return e.jsx(_e,{open:t,onOpenChange:s,children:e.jsx(Pe,{className:"sm:max-w-xl overflow-y-auto",children:i&&e.jsxs(e.Fragment,{children:[e.jsxs(Te,{children:[e.jsx(Ee,{className:"text-base leading-snug",children:i.prompt}),e.jsxs(qe,{className:"flex flex-wrap items-center gap-2 text-xs",children:[e.jsx(H,{variant:"outline",className:"text-[10px]",children:i.prompt_type}),i.last_run_at&&e.jsxs("span",{children:[u("Last probed")," ",ws(new Date(i.last_run_at),{addSuffix:!0,locale:x})]}),e.jsxs("span",{children:["· ",i.mentions_count," ",u("mentions")]})]})]}),e.jsx("div",{className:"mt-5 space-y-4",children:w.size===0?e.jsx(Z,{children:e.jsxs(ee,{className:"p-6 text-center text-sm text-muted-foreground space-y-4",children:[e.jsx("p",{children:u('No probe results yet. Click "Run now" below to start a sweep.')}),e.jsxs(S,{size:"sm",onClick:p,disabled:h,children:[h?e.jsx(I,{className:"h-4 w-4 animate-spin"}):e.jsx(Ge,{className:"h-4 w-4"}),u("Run now")]})]})}):Array.from(w.entries()).map(([C,c])=>e.jsx(Z,{children:e.jsxs(ee,{className:"p-4 space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"text-sm font-medium",children:Zs[C]??C}),e.jsx("div",{className:"flex items-center gap-1.5 text-xs",children:c.cited?e.jsxs(e.Fragment,{children:[e.jsx(Oe,{className:"h-3.5 w-3.5 text-emerald-500"}
6)," ",u("Cited"),c.position?` (#${c.position})`:""]}):e.jsxs(e.Fragment,{children:[e.jsx(Ke,{className:"h-3.5 w-3.5 text-muted-foreground"})," ",u("Not cited")]})})]}),c.answer_text&&e.jsx("p",{className:"text-xs text-muted-foreground line-clamp-6 whitespace-pre-wrap",children:c.answer_text}),Array.isArray(c.cited_urls)&&c.cited_urls.length>0&&e.jsxs("div",{className:"pt-2 border-t space-y-1",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wider text-muted-foreground",children:u("Sources cited")}),c.cited_urls.slice(0,10).map((n,j)=>{let q=n;try{q=new URL(n).hostname.replace(/^www\./,"")}catch{}return e.jsxs("a",{href:n,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-2 text-xs hover:underline",children:[e.jsx("img",{src:`https://www.google.com/s2/favicons?domain=${q}&sz=16`,alt:"",className:"h-3 w-3 rounded-sm",loading:"lazy"}),e.jsx("span",{className:"truncate flex-1",children:q}),e.jsx(Qe,{className:"h-3 w-3 text-muted-foreground"})]},j)})]})]})},C))})]})})})}function st({open:t,onOpenChange:s,connectionId:i}){const a=Ws(),p=We(),[h,u]=m.useState([]),[f,x]=m.useState(new Set);m.useEffect(()=>{t&&h.length===0&&!a.isPending&&a.mutate(i,{onSuccess:c=>{u(c.suggestions??[]),x(new Set((c.suggestions??[]).map(n=>n.prompt)))}}),t||(u([]),x(new Set))},[t]);const y=h.reduce((c,n)=>((c[n.type]=c[n.type]??[]).push(n),c),{}),w=c=>{const n=new Set(f);n.has(c)?n.delete(c):n.add(c),x(n)},C=()=>{const c=h.filter(n=>f.has(n.prompt));c.length&&p.mutate({connectionId:i,items:c},{onSuccess:()=>s(!1)})};return e.jsx(_e,{open:t,onOpenChange:s,children:e.jsxs(Pe,{className:"sm:max-w-lg overflow-y-auto",children:[e.jsxs(Te,{children:[e.jsxs(Ee,{className:"flex items-center gap-2",children:[e.jsx(Se,{className:"h-4 w-4"})," Explore prompt ideas"]}),e.jsx(qe,{children:"AI-generated prompts based on your site and top organic queries. Toggle and add the ones you want to track."})]}),a.isPending&&e.jsxs("div",{className:"flex items-center justify-center py-16 text-sm text-muted-foreground",children:[e.jsx(I,{className:"h-4 w-4 mr-2 animate-spin"})," Generating suggestionsâ¦"]}),!a.isPending&&h.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mt-4 space-y-5",children:["brand","competitor","category","regional","organic"].map(c=>{var n;return(n=y[c])!=null&&n.length?e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("span",{className:`h-2 w-2 rounded-full ${fe[c]}`}),e.jsx("span",{className:"text-xs font-semibold uppercase tracking-wider text-muted-foreground",children:ce[c]}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["(",y[c].length,")"]})]}),e.jsx("div",{className:"space-y-1",children:y[c].map(j=>e.jsxs("label",{className:"flex items-start gap-3 rounded-md border p-2.5 cursor-pointer hover:bg-accent",children:[e.jsx(oe,{checked:f.has(j.prompt),onCheckedChange:()=>w(j.prompt),className:"mt-0.5"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm",children:j.prompt}),j.rationale&&e.jsx("div",{className:"text-[11px] text-muted-foreground mt-0.5",children:j.rationale})]})]},j.prompt))})]},c):null})}),e.jsxs("div",{className:"sticky bottom-0 left-0 right-0 mt-6 bg-background border-t pt-3 flex items-center justify-between",children:[e.jsxs("div",{className:"text-xs text-muted-foreground",children:[f.size,"/",h.length," selected"]}),e.jsxs(S,{size:"sm",disabled:p.isPending||f.size===0,onClick:C,children:[p.isPending?e.jsx(I,{className:"h-3.5 w-3.5 mr-1.5 animate-spin"}):e.jsx(Ae,{className:"h-3.5 w-3.5 mr-1.5"}),"Add ",f.size," prompt",f.size===1?"":"s"]})]})]}),!a.isPending&&h.length===0&&!a.isError&&e.jsx("div",{className:"py-10 text-center text-sm text-muted-foreground",children:e.jsx(S,{size:"sm",variant:"outline",onClick:()=>a.mutate(i,{onSuccess:c=>{u(c.suggestions??[]),x(new Set((c.suggestions??[]).map(n=>n.prompt)))}}),children:"Generate suggestions"})})]})})}function tt({open:t,onOpenChange:s,connectionId:i}){const a=We(),[p,h]=m.useState(!1),[u,f]=m.useState([]),[x,y]=m.useState([]),[w,C]=m.useState("queries"),[c,n]=m.useState(""),[j,q]=m.useState("organic"),[_,L]=m.useState(new Set),[V,X]=m.useState(new Set),[F,d]=m.useState("what-is");m.useEffect(()=>{if(!t){f([]),y([]),L(new Set),X(new Set),n("");return}h(!0),T.functions.invoke("ai-visibility-import-sources",{body:{connection_id:i}}).then(({data:l,error:b})=>{if(b)throw b;if((l==null?void 0:l.ok)===!1)throw new Error(l.error||"Failed");f((l==null?void 0:l.queries)??[]),y((l==null?void 0:l.pages)??[])}).catch(l=>A.error((l==null?void 0:l.message)||"Failed to load GSC data")).finally(()=>h(!1))},[t,i]);const g=m.useMemo(()=>{const l=c.trim().toLowerCase();return l?u.filter(b=>b.query.toLowerCase().includes(l)):u},[u,c]),z=m.useMemo(()=>{const l=c.trim().toLowerCase();return l?x.filter(b=>b.title.toLowerCase().includes(l)||b.path.toLowerCase().includes(l)):x},[x,c]),R=(l,b)=>{l==="q"?L(b?new Set(g.map(P=>P.query)):new Set):X(b?new Set(z.map(P=>P.url)):new Set)},de=(l,b)=>{if(l==="q"){const P=new Set(_);P.has(b)?P.delete(b):P.add(b),L(P)}else{const P=new Set(V);P.has(b)?P.delete(b):P.add(b),X(P)}},B=l=>F==="what-is"?`What is ${l.title}?`:F==="how-to"?`How to ${l.title}`:l.title,ne=()=>{const l=[];
6if(w==="queries")for(const b of _)l.push({prompt:b,type:j,rationale:"From GSC query"});else for(const b of V){const P=x.find(me=>me.url===b);P&&l.push({prompt:B(P),type:j,rationale:`From page ${P.path}`})}if(!l.length){A.error("Select at least one item");return}a.mutate({connectionId:i,items:l},{onSuccess:()=>s(!1)})},le=w==="queries"?_.size:V.size;return e.jsx(_e,{open:t,onOpenChange:s,children:e.jsxs(Pe,{className:"sm:max-w-xl overflow-y-auto",children:[e.jsxs(Te,{children:[e.jsxs(Ee,{className:"flex items-center gap-2",children:[e.jsx(Ce,{className:"h-4 w-4"})," Import from your site"]}),e.jsx(qe,{children:"Pull real keywords from Search Console and your top pages, then track them as prompts."})]}),p?e.jsxs("div",{className:"flex items-center justify-center py-16 text-sm text-muted-foreground",children:[e.jsx(I,{className:"h-4 w-4 mr-2 animate-spin"})," Loading from GSCâ¦"]}):e.jsxs("div",{className:"mt-4 space-y-3",children:[e.jsxs(vs,{value:w,onValueChange:l=>C(l),children:[e.jsxs(bs,{className:"grid grid-cols-2 w-full",children:[e.jsxs($e,{value:"queries",children:[e.jsx(Ns,{className:"h-3.5 w-3.5 mr-1.5"})," GSC Keywords (",u.length,")"]}),e.jsxs($e,{value:"pages",children:[e.jsx(ks,{className:"h-3.5 w-3.5 mr-1.5"})," Site Pages (",x.length,")"]})]}),e.jsxs("div",{className:"flex items-center gap-2 mt-3",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(Ue,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),e.jsx(se,{className:"pl-8 h-9",placeholder:"Searchâ¦",value:c,onChange:l=>n(l.target.value)})]}),e.jsxs(te,{value:j,onValueChange:l=>q(l),children:[e.jsx(ie,{className:"h-9 w-[140px]",children:e.jsx(re,{})}),e.jsxs(ae,{children:[e.jsx(E,{value:"organic",children:"Organic"}),e.jsx(E,{value:"brand",children:"Brand"}),e.jsx(E,{value:"competitor",children:"Competitor"}),e.jsx(E,{value:"category",children:"Category"}),e.jsx(E,{value:"regional",children:"Regional"})]})]})]}),e.jsxs(Fe,{value:"queries",className:"mt-3",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2 text-xs text-muted-foreground",children:[e.jsx("button",{className:"underline",onClick:()=>R("q",_.size!==g.length),children:_.size===g.length&&g.length>0?"Clear":"Select all"}),e.jsxs("span",{children:[_.size," selected"]})]}),e.jsxs("div",{className:"space-y-1 max-h-[50vh] overflow-y-auto",children:[g.map(l=>e.jsxs("label",{className:"flex items-center gap-3 rounded-md border p-2.5 cursor-pointer hover:bg-accent",children:[e.jsx(oe,{checked:_.has(l.query),onCheckedChange:()=>de("q",l.query)}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-sm truncate",children:l.query}),e.jsxs("div",{className:"text-[11px] text-muted-foreground",children:[l.impressions.toLocaleString()," impr · ",l.clicks.toLocaleString()," clicks · pos ",l.position]})]})]},l.query)),!g.length&&e.jsx("div",{className:"text-xs text-muted-foreground text-center py-6",children:"No queries yet â run a GSC sync first."})]})]}),e.jsxs(Fe,{value:"pages",className:"mt-3",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Prompt template:"}),e.jsxs(te,{value:F,onValueChange:l=>d(l),children:[e.jsx(ie,{className:"h-8 w-[160px] text-xs",children:e.jsx(re,{})}),e.jsxs(ae,{children:[e.jsxs(E,{value:"what-is",children:['"What is ',"{title}",'?"']}),e.jsxs(E,{value:"how-to",children:['"How to ',"{title}",'"']}),e.jsx(E,{value:"as-title",children:"Use title as-is"})]})]})]}),e.jsxs("div",{className:"flex items-center justify-between mb-2 text-xs text-muted-foreground",children:[e.jsx("button",{className:"underline",onClick:()=>R("p",V.size!==z.length),children:V.size===z.length&&z.length>0?"Clear":"Select all"}),e.jsxs("span",{children:[V.size," selected"]})]}),e.jsxs("div",{className:"space-y-1 max-h-[50vh] overflow-y-auto",children:[z.map(l=>e.jsxs("label",{className:"flex items-center gap-3 rounded-md border p-2.5 cursor-pointer hover:bg-accent",children:[e.jsx(oe,{checked:V.has(l.url),onCheckedChange:()=>de("p",l.url)}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:"text-sm truncate",children:B(l)}),e.jsxs("div",{className:"text-[11px] text-muted-foreground truncate",children:[l.path," · ",l.clicks.toLocaleStr
6ing()," clicks"]})]})]},l.url)),!z.length&&e.jsx("div",{className:"text-xs text-muted-foreground text-center py-6",children:"No pages yet â run a GSC sync first."})]})]})]}),e.jsxs("div",{className:"flex items-center justify-between gap-2 pt-3 border-t",children:[e.jsxs("div",{className:"text-xs text-muted-foreground",children:[le," item",le===1?"":"s"," selected"]}),e.jsxs(S,{size:"sm",onClick:ne,disabled:!le||a.isPending,children:[a.isPending?e.jsx(I,{className:"h-3.5 w-3.5 mr-1.5 animate-spin"}):e.jsx(Ae,{className:"h-3.5 w-3.5 mr-1.5"}),"Import as prompts"]})]})]})]})})}function it({open:t,onOpenChange:s,prompt:i,onSave:a,busy:p}){const[h,u]=m.useState(""),[f,x]=m.useState("organic"),[y,w]=m.useState("daily");return m.useEffect(()=>{i&&(u(i.prompt),x(i.prompt_type),w(i.check_frequency))},[i]),e.jsx(Ss,{open:t,onOpenChange:s,children:e.jsxs(Cs,{className:"sm:max-w-md",children:[e.jsx(_s,{children:e.jsx(Ps,{children:"Edit prompt"})}),e.jsxs("div",{className:"space-y-3 pt-2",children:[e.jsxs("div",{children:[e.jsx(J,{className:"text-xs",children:"Prompt"}),e.jsx(se,{value:h,onChange:C=>u(C.target.value),className:"mt-1"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(J,{className:"text-xs",children:"Type"}),e.jsxs(te,{value:f,onValueChange:x,children:[e.jsx(ie,{className:"mt-1 h-9",children:e.jsx(re,{})}),e.jsxs(ae,{children:[e.jsx(E,{value:"organic",children:"Organic"}),e.jsx(E,{value:"competitor",children:"Competitor"}),e.jsx(E,{value:"brand",children:"Brand"}),e.jsx(E,{value:"category",children:"Category"}),e.jsx(E,{value:"regional",children:"Regional"})]})]})]}),e.jsxs("div",{children:[e.jsx(J,{className:"text-xs",children:"Check frequency"}),e.jsxs(te,{value:y,onValueChange:w,children:[e.jsx(ie,{className:"mt-1 h-9",children:e.jsx(re,{})}),e.jsxs(ae,{children:[e.jsx(E,{value:"daily",children:"Daily"}),e.jsx(E,{value:"weekly",children:"Weekly"}),e.jsx(E,{value:"monthly",children:"Monthly"})]})]})]})]})]}),e.jsxs(Ts,{children:[e.jsx(S,{variant:"outline",onClick:()=>s(!1),children:"Cancel"}),e.jsx(S,{disabled:p||!h.trim(),onClick:()=>a({prompt:h.trim(),prompt_type:f,check_frequency:y}),children:"Save"})]})]})})}const rt={gemini:"Gemini",openai:"ChatGPT",deepseek:"DeepSeek",perplexity:"Perplexity"};function at({defaultBrand:t="",defaultDomain:s=""}){const[i,a]=m.useState(t),[p,h]=m.useState(s),[u,f]=m.useState(""),[x,y]=m.useState(!1),[w,C]=m.useState([]),c=async()=>{if(!u.trim()){A.error("Enter a prompt to test");return}if(!i.trim()&&!p.trim()){A.error("Enter your brand name or domain");return}y(!0),C([]);try{const{data:n,error:j}=await T.functions.invoke("ai-brand-mention-check",{body:{prompt:u.trim(),brand:i.trim(),domain:p.trim()}});if(j)throw j;if((n==null?void 0:n.ok)===!1)throw new Error(n.error||"Check failed");C(n.results??[])}catch(n){A.error((n==null?void 0:n.message)||"Failed to run check")}finally{y(!1)}};return e.jsxs(Z,{children:[e.jsxs(as,{className:"pb-3",children:[e.jsxs(ns,{className:"flex items-center gap-2 text-base",children:[e.jsx(Ne,{className:"h-4 w-4"})," Brand Mention Check"]}),e.jsx(ls,{children:"Ask any question and see which AI engines mention your brand or cite your site â instantly across ChatGPT, Gemini, DeepSeek and Perplexity."})]}),e.jsxs(ee,{className:"space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(J,{className:"text-xs",children:"Your brand"}),e.jsx(se,{value:i,onChange:n=>a(n.target.value),placeholder:"e.g. Writer-GPT",className:"mt-1 h-9"})]}),e.jsxs("div",{children:[e.jsx(J,{className:"text-xs",children:"Your domain"}),e.jsx(se,{value:p,onChange:n=>h(n.target.value),placeholder:"e.g. writer-gpt.com",className:"mt-1 h-9"})]})]}),e.jsxs("div",{children:[e.jsx(J,{className:"text-xs",children:"Prompt to test"}),e.jsx(Es,{value:u,onChange:n=>f(n.target.value),placeholder:"e.g. What are the best AI SEO writing tools?",className:"mt-1 min-h-[80px]"})]}),e.jsx("div",{className:"flex justify-end",children:e.jsxs(S,{onClick:c,disabled:x,size:"sm",children:[x?e.jsx(I,{className:"h-3.5 w-3.5 mr-1.5 animate-spin"}):e.jsx(Ne,{className:"h-3.5 w-3.5 mr-1.5"}),"Check across engines"]})}),w.length>0&&e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3 pt-1",children:w.map(n=>{var j;return e.jsx(Z,{className:"border",children:e.jsxs(ee,{className:"p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"text-sm font-medium",children:rt[n.engine]??n.engine}),n.skipped?e.jsxs(H,{variant:"outline",className:"text-[10px]",children:[e.jsx(qs,{className:"h-3 w-3 mr-1"})," No API key"]}):n.error?e.jsx(H,{variant:"destructive",className:"text-[10px]",children:"Error"}
6):n.mentioned?e.jsxs(H,{className:"bg-emerald-500/15 text-emerald-600 hover:bg-emerald-500/15 text-[10px]",children:[e.jsx(Oe,{className:"h-3 w-3 mr-1"})," Mentioned",n.position?` · #${n.position}`:""]}):e.jsxs(H,{variant:"outline",className:"text-[10px]",children:[e.jsx(Ke,{className:"h-3 w-3 mr-1"})," Not mentioned"]})]}),n.error&&e.jsx("p",{className:"text-xs text-destructive",children:n.error}),!n.skipped&&!n.error&&n.answer_text&&e.jsx("p",{className:"text-xs text-muted-foreground line-clamp-5 whitespace-pre-wrap",children:n.answer_text}),!n.skipped&&!n.error&&(((j=n.cited_urls)==null?void 0:j.length)??0)>0&&e.jsxs("div",{className:"pt-2 border-t space-y-1",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-wider text-muted-foreground",children:"Sources"}),(n.cited_urls??[]).slice(0,6).map((q,_)=>{let L=q;try{L=new URL(q).hostname.replace(/^www\./,"")}catch{}return e.jsxs("a",{href:q,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-2 text-xs hover:underline",children:[e.jsx("img",{src:`https://www.google.com/s2/favicons?domain=${L}&sz=16`,alt:"",className:"h-3 w-3 rounded-sm",loading:"lazy"}),e.jsx("span",{className:"truncate flex-1",children:L}),e.jsx(Qe,{className:"h-3 w-3 text-muted-foreground"})]},_)})]})]})},n.engine)})})]})]})}const nt=[{key:"all",label:"All"},{key:"brand",label:"Brand"},{key:"competitor",label:"Competitor"},{key:"category",label:"Category"},{key:"regional",label:"Regional"},{key:"organic",label:"Organic"}],lt=[{key:"active",label:"Active"},{key:"dormant",label:"Dormant"},{key:"all",label:"All"}];function $i(){const{t}=ke(),{connection:s}=os(),i=(s==null?void 0:s.id)??null,a=(()=>{const r=(s==null?void 0:s.site_url)??"";return String(r).replace(/^sc-domain:/,"").replace(/^https?:\/\//,"").replace(/\/.*$/,"").replace(/^www\./,"")})(),{data:p=[]}=zs(i),{data:h=[]}=$s(i),{data:u=[]}=Ls(i),{data:f=[]}=Ms(i),x=Fs(),y=Rs(),w=Bs(),C=Gs(),c=Os(),n=Ks(),j=Us(),q=Qs(),[_,L]=m.useState(""),[V,X]=m.useState(""),[F,d]=m.useState("all"),[g,z]=m.useState("active"),[R,de]=m.useState("all"),[B,ne]=m.useState(new Set),[le,l]=m.useState(!1),[b,P]=m.useState(!1),[me,Ve]=m.useState(null),[ue,ye]=m.useState(null),xe=f.some(r=>r.status==="running"||r.status==="queued"),$=u==null?void 0:u[0],De=m.useMemo(()=>{const r=new Map;for(const N of p)r.set(N.id,{visibility:0,mentioned_domains:new Set,engines:{}});const o={};for(const N of h)(o[N.prompt_id]=o[N.prompt_id]??[]).push(N);for(const[N,M]of Object.entries(o)){const k=new Map;for(const U of M)k.has(U.engine)||k.set(U.engine,U);const v=Array.from(k.values()),D=v.filter(U=>U.cited).length,G=v.length?Math.round(D/v.length*100):0,he=new Set,ge={};for(const U of v){ge[U.engine]=!!U.cited;for(const Ie of U.cited_domains??[])he.add(Ie)}r.set(N,{visibility:G,mentioned_domains:he,engines:ge})}return r},[p,h]),Q=m.useMemo(()=>p.map(r=>{const o=De.get(r.id);return{...r,visibility:(o==null?void 0:o.visibility)??0,mentioned_domains:Array.from((o==null?void 0:o.mentioned_domains)??[]),engines:(o==null?void 0:o.engines)??{}}}),[p,De]),ze=m.useMemo(()=>{const r={};for(const o of p)r[o.prompt_type]=(r[o.prompt_type]??0)+1;return r},[p]),we=m.useMemo(()=>{let r=Q;if(F!=="all"&&(r=r.filter(o=>o.prompt_type===F)),R!=="all"&&(r=r.filter(o=>o.prompt_type===R)),g==="active"?r=r.filter(o=>o.is_active):g==="dormant"&&(r=r.filter(o=>!o.is_active)),V.trim()){const o=V.toLowerCase();r=r.filter(N=>N.prompt.toLowerCase().includes(o))}return r},[Q,F,g,V,R]),He=($==null?void 0:$.citation_rate)!=null?Math.round(Number($.citation_rate)*100):($==null?void 0:$.visibility)!=null?Math.round(Number($.visibility)):Q.length?Math.round(Q.reduce((r,o)=>r+o.visibility,0)/Q.length):0,Ye=p.filter(r=>r.is_active).length,Xe=m.useMemo(()=>Q.filter(r=>r.visibility>0).length,[Q]),pe=m.useMemo(()=>{const r={chatgpt:"ChatGPT",gemini:"Gemini",deepseek:"DeepSeek",perplexity:"Perplexity"},o=new Map,N=new Set;for(const k of h){const v=`${k.prompt_id}:${k.engine}`;if(N.has(v))continue;N.add(v);const D=o.get(k.engine)??{cited:0,total:0};D.total+=1,k.cited&&(D.cited+=1),o.set(k.engine,D)}return Array.from(o.entries()).filter(([,k])=>k.total>0).map(([k,v])=>({engine:k,label:r[k]??k,share:Math.round(v.cited/v.total*100)})).sort((k,v)=>v.share-k.share)[0]??null},[h]),ve=m.useMemo(()=>{const r=($==null?void 0:$.top_competitors)??null;if(r&&r.length){const v=r.reduce((he,ge)=>he+Number(ge.mentions||0),0),D=r[0],G=v>0?Math.round(Number(D.mentions)/v*100):0;return{domain:D.domain,share:G}}const o=new Map,N=a.toLowerCase();for(const v of h)for(const D of v.cited_domains??[]){if(!D)continue;const G=D.toLowerCase().replace(/^www\./,"");!G||G===N||G.endsWith(`.${N}`)||N.endsWith(`.${G}`)||o.set(G,(o.get(G)??0)+1)}const M=Array.from(o.entries()).sort((v,D)=>D[1]-v[1]);if(!M.length)return null;
6const k=M.reduce((v,[,D])=>v+D,0);return{domain:M[0][0],share:k>0?Math.round(M[0][1]/k*100):0}},[$,h,a]),Me=()=>{!_.trim()||!i||y.mutate({connectionId:i,prompt:_.trim()},{onSuccess:()=>L("")})},Le=()=>{const r=(B.size?Q.filter(o=>B.has(o.id)):we).map(o=>{var N,M,k,v;return{prompt:o.prompt,type:o.prompt_type,visibility_pct:o.visibility,mentions:o.mentions_count,chatgpt:(N=o.engines)!=null&&N.chatgpt?"yes":"no",gemini:(M=o.engines)!=null&&M.gemini?"yes":"no",deepseek:(k=o.engines)!=null&&k.deepseek?"yes":"no",perplexity:(v=o.engines)!=null&&v.perplexity?"yes":"no",check_frequency:o.check_frequency,active:o.is_active,mentioned_domains:o.mentioned_domains.join("|"),last_run_at:o.last_run_at??""}});As(`ai-visibility-prompts-${new Date().toISOString().slice(0,10)}.csv`,Vs(r))};return e.jsxs(is,{children:[e.jsx(rs,{title:t("aiVisibility.seoTitle"),description:t("aiVisibility.seoDescription")}),e.jsxs("div",{className:"container max-w-7xl space-y-5 px-0 py-0",children:[e.jsxs("section",{className:"brand-highlight relative overflow-hidden rounded-2xl border p-5 shadow-sm md:p-7",children:[e.jsx("div",{className:"pointer-events-none absolute -end-16 -top-16 h-44 w-44 rounded-full bg-primary/10 blur-3xl"}),e.jsxs("div",{className:"relative flex flex-col gap-5 lg:flex-row lg:items-center lg:justify-between",children:[e.jsxs("div",{className:"flex max-w-2xl items-start gap-3.5",children:[e.jsx("div",{className:"brand-gradient flex h-11 w-11 shrink-0 items-center justify-center rounded-2xl",children:e.jsx(Ne,{className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsxs("div",{className:"mb-2 flex flex-wrap items-center gap-2",children:[e.jsx(H,{variant:"secondary",className:"rounded-full",children:t("aiVisibility.intelligence")}),xe&&e.jsxs(H,{variant:"outline",children:[e.jsx("span",{className:"mr-1.5 h-1.5 w-1.5 animate-pulse rounded-full bg-emerald-500"}),t("aiVisibility.sweepRunning")]})]}),e.jsx("h1",{className:"text-2xl font-bold tracking-tight text-foreground md:text-3xl",children:t("aiVisibility.title")}),e.jsx("p",{className:"mt-2 text-sm leading-6 text-muted-foreground",children:t("aiVisibility.subtitle")}),a&&e.jsxs("p",{className:"mt-3 inline-flex items-center gap-1.5 text-xs text-muted-foreground",children:[e.jsx(Ds,{className:"h-3.5 w-3.5"})," ",t("aiVisibility.tracking",{domain:a})]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 sm:flex lg:max-w-md lg:flex-wrap lg:justify-end",children:[e.jsxs(S,{variant:"outline",className:"bg-background/70",onClick:()=>P(!0),disabled:!i,children:[e.jsx(Ce,{className:"mr-2 h-4 w-4"}),t("common.import")]}),e.jsxs(S,{variant:"outline",className:"bg-background/70",onClick:()=>l(!0),disabled:!i,children:[e.jsx(Se,{className:"mr-2 h-4 w-4"}),t("aiVisibility.explore")]}),e.jsxs(S,{className:"col-span-2",onClick:()=>i&&x.mutate(i),disabled:!i||xe||x.isPending,children:[xe||x.isPending?e.jsx(I,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(Ge,{className:"mr-2 h-4 w-4"}),t("aiVisibility.runSweep")]})]})]}),e.jsxs("div",{className:"relative mt-6 grid grid-cols-2 gap-2 border-t border-border/60 pt-5 md:grid-cols-3 lg:grid-cols-5",children:[e.jsxs("div",{className:"rounded-xl bg-background/60 p-3",children:[e.jsxs("p",{className:"text-xl font-bold tabular-nums md:text-2xl",children:[He,"%"]}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:t("aiVisibility.visibility")})]}),e.jsxs("div",{className:"rounded-xl bg-background/60 p-3",children:[e.jsx("p",{className:"text-xl font-bold tabular-nums md:text-2xl",children:Ye}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:t("aiVisibility.activePrompts")})]}),e.jsxs("div",{className:"rounded-xl bg-background/60 p-3",children:[e.jsxs("p",{className:"text-xl font-bold tabular-nums md:text-2xl",children:[Xe,e.jsxs("span",{className:"text-sm font-medium text-muted-foreground",children:["/",Q.length]})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:t("aiVisibility.mentionedPrompts",{defaultValue:"Prompts mentioning you"})})]}),e.jsxs("div",{className:"rounded-xl bg-background/60 p-3",children:[e.jsx("p",{className:"truncate text-xl font-bold md:text-2xl",children:pe?pe.label:"â"}),e.jsxs("p",{className:"text-[11px] text-muted-foreground",children:[t("aiVisibility.topEngine",{defaultValue:"Top AI engine"}),pe?` · ${pe.share}%`:""]})]}),e.jsxs("div",{className:"rounded-xl bg-background/60 p-3",children:[e.jsx("p",{className:"truncate text-xl font-bold md:text-2xl",children:(ve==null?void 0:ve.domain)||"â"}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:t("aiVisibility.topCompetitor")})]})]})]}),e.jsx(cs,{id:"ai-visibility",title:t("aiVisibility.guide.title"),intro:t("aiVisibility.guide.intro"),steps:[{title:t("aiVisibility.guide.addTitle"),description:t("aiVisibility.guide.addDescription")},{title:t("aiVisibility.guide.runTitle"),description:t("aiVisibility.guide.runDescription")},{title:t("aiVisibility.guide.reviewTitle"),description:t("aiVisibility.guide.reviewDescription")},{title:t("aiVisibility.guide.improveTitle"),description:t("aiVisibility.guide.improveDescription")}]}),i?e.jsxs(e.Fragment,{children:[e.jsx(Hs,{counts:ze}),e.jsx(at,{defaultDomain:a}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:nt.map(r=>{const o=r.key==="all"?p.length:ze[r.key]??0,N=F===r.key;return e.jsxs("button",{onClick:()=>d(r.key),className:`text-xs rounded-full border px-3 py-1.5 transition-all ${N?"brand-gradient":"hover:brand-gradient hover:text-white"}
6`,children:[t(`aiVisibility.types.${r.key}`)," ",e.jsx("span",{className:"opacity-60 ml-1",children:o})]},r.key)})}),e.jsx("div",{className:"flex items-center gap-1.5",children:lt.map(r=>{const o=r.key==="active"?p.filter(M=>M.is_active).length:r.key==="dormant"?p.filter(M=>!M.is_active).length:p.length,N=g===r.key;return e.jsxs("button",{onClick:()=>z(r.key),className:`text-xs rounded-md border px-3 py-1.5 transition-all ${N?"brand-gradient":"hover:brand-gradient hover:text-white"}`,children:[t(`aiVisibility.status.${r.key}`)," ",e.jsx("span",{className:"opacity-60 ml-1",children:o})]},r.key)})}),e.jsx(Js,{count:B.size,onClear:()=>ne(new Set),onDelete:()=>{c.mutate(Array.from(B)),ne(new Set)},onToggleActive:r=>n.mutate({ids:Array.from(B),is_active:r}),onReclassify:()=>j.mutate({connectionId:i,ids:Array.from(B)}),onExport:Le,busy:c.isPending||n.isPending||j.isPending}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("div",{className:"relative flex-1 min-w-[240px]",children:[e.jsx(Ue,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),e.jsx(se,{placeholder:t("aiVisibility.searchPlaceholder"),value:V,onChange:r=>X(r.target.value),className:"pl-8 h-9"})]}),e.jsxs(te,{value:R,onValueChange:de,children:[e.jsx(ie,{className:"h-9 w-[150px]",children:e.jsx(re,{})}),e.jsxs(ae,{children:[e.jsx(E,{value:"all",children:t("aiVisibility.allTypes")}),Object.keys(ce).map(r=>e.jsx(E,{value:r,children:ce[r]},r))]})]}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[we.length,"/",p.length]}),e.jsx(S,{size:"sm",variant:"outline",onClick:Le,children:t("aiVisibility.exportCsv")})]}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row",children:[e.jsx(se,{placeholder:t("aiVisibility.addPromptPlaceholder"),value:_,onChange:r=>L(r.target.value),onKeyDown:r=>r.key==="Enter"&&Me(),className:"h-9"}),e.jsxs(S,{className:"w-full sm:w-auto",size:"sm",onClick:Me,disabled:!_.trim()||y.isPending,children:[e.jsx(Ae,{className:"h-3.5 w-3.5 mr-1.5"})," ",t("common.add",{defaultValue:"Add"})]})]}),e.jsx(Is,{rows:we,selected:B,onSelectChange:ne,onToggleActive:(r,o)=>w.mutate({id:r,is_active:o}),onDelete:r=>C.mutate(r),onOpen:r=>Ve(r),onEdit:r=>ye(r)}),e.jsx(et,{open:!!me,onOpenChange:r=>!r&&Ve(null),prompt:me,results:h,onRun:()=>i&&x.mutate(i),running:xe||x.isPending}),e.jsx(tt,{open:b,onOpenChange:P,connectionId:i}),e.jsx(st,{open:le,onOpenChange:l,connectionId:i}),e.jsx(it,{open:!!ue,onOpenChange:r=>!r&&ye(null),prompt:ue,busy:q.isPending,onSave:r=>{ue&&q.mutate({id:ue.id,patch:r},{onSuccess:()=>ye(null)})}})]}):e.jsx(Z,{children:e.jsx(ee,{className:"p-8 text-sm text-muted-foreground text-center",children:t("aiVisibility.connectRequired")})})]})]})}export{$i 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.