1import{r as h,H as F,j as e,aY as z,aZ as Y,a_ as U,a$ as T,b0 as W,b1 as B,ak as Z,B as J,G as K,p as X,a9 as ee,aA as q}from"./index-ByYYWl6V.js";import{u as te}from"./AioContext-tcHwp2Sp.js";import{u as se}from"./useAioQueryResults-BHlZz6X_.js";import{B as v}from"./badge-DuSeH5ON.js";import{E as ae}from"./external-link-CECnRthk.js";import{C as ie}from"./chevron-up-DJ99KL3C.js";import{D as ne}from"./download-BCb29Zdu.js";import{C as M,a as S,b as O,c as V}from"./card-CsB1Huog.js";import{T as re,a as oe,b as P,c as R}from"./tabs-DWXE4Edw.js";import{S as le,a as ce,b as de,c as me,d as k}from"./select-B7Jb7eSA.js";import{L as $}from"./label-Dast61oh.js";import{L as H}from"./link-2-C5arFvZC.js";import{Q as xe}from"./quote-CM8gKfZc.js";import"./useQuery-yGeh6Hp2.js";import"./index-CnBNeFET.js";function A(i){try{return new URL(i.startsWith("http")?i:`https://${i}`).hostname.replace(/^www\./,"")}catch{return i}}function pe(i,x,s,o){var u,p,n,g,b,N,w,L,E,D,y,_;const m=[],d=s.replace(/^www\./,"").toLowerCase(),f=o.toLowerCase();return(p=(u=i.chatgpt_response)==null?void 0:u.data)!=null&&p.annotations&&i.chatgpt_response.data.annotations.forEach(r=>{const c=r.url||r.text||"";if(!c)return;const t=A(c);m.push({url:c,domain:t,text:r.text||c,provider:"chatgpt",query:x,isBrandMention:t.includes(d)||(r.text||"").toLowerCase().includes(f),isDomainCitation:t.includes(d),timestamp:i.created_at})}),(((g=(n=i.chatgpt_response)==null?void 0:n.data)==null?void 0:g.content)||"").toLowerCase().includes(f)&&m.filter(r=>r.provider==="chatgpt").length===0&&m.push({url:"",domain:"",text:"Brand mentioned in response",provider:"chatgpt",query:x,isBrandMention:!0,isDomainCitation:!1,timestamp:i.created_at}),(N=(b=i.perplexity_response)==null?void 0:b.data)!=null&&N.citations&&i.perplexity_response.data.citations.forEach(r=>{const c=typeof r=="string"?r:r.url||"";if(!c)return;const t=A(c);m.push({url:c,domain:t,text:typeof r=="string"?c:r.text||c,provider:"perplexity",query:x,isBrandMention:t.includes(d),isDomainCitation:t.includes(d),timestamp:i.created_at})}),(L=(w=i.perplexity_response)==null?void 0:w.data)!=null&&L.structuredCitations&&i.perplexity_response.data.structuredCitations.forEach(r=>{if(!r||m.some(t=>t.url===r))return;const c=A(r);m.push({url:r,domain:c,text:r,provider:"perplexity",query:x,isBrandMention:c.includes(d),isDomainCitation:c.includes(d),timestamp:i.created_at})}),(D=(E=i.google_ai_response)==null?void 0:E.data)!=null&&D.aiOverviewReferences&&i.google_ai_response.data.aiOverviewReferences.forEach(r=>{const c=r.url||"",t=r.domain||A(c);m.push({url:c,domain:t,text:r.title||r.text||c,provider:"googleAI",query:x,isBrandMention:t.includes(d),isDomainCitation:t.includes(d),timestamp:i.created_at})}),(_=(y=i.google_ai_response)==null?void 0:y.data)!=null&&_.organicResults&&i.google_ai_response.data.organicResults.forEach(r=>{const c=r.url||"";if(!c||m.some(a=>a.url===c))return;const t=r.domain||A(c);m.push({url:c,domain:t,text:r.title||c,provider:"googleAI",query:x,isBrandMention:t.includes(d),isDomainCitation:t.includes(d),timestamp:i.created_at})}),m}function he(i,x,s){const{results:o,loading:m}=se(i);return{citations:h.useMemo(()=>{if(!o.length)return[];const f=[];return o.forEach(j=>{const u=pe(j,j.query,x||"",s||"");f.push(...u)}),f},[o,x,s]),loading:m}}const ue={chatgpt:"ChatGPT",perplexity:"Perplexity",googleAI:"Google AI"};function fe({citations:i,loading:x}){const{t:s}=F(),[o,m]=h.useState("timestamp"),[d,f]=h.useState("desc"),j=n=>{o===n?f(d==="asc"?"desc":"asc"):(m(n),f("asc"))},u=[...i].sort((n,g)=>{const b=d==="asc"?1:-1;if(o==="timestamp")return(new Date(n.timestamp).getTime()-new Date(g.timestamp).getTime())*b;const N=n[o]||"",w=g[o]||"";return N<w?-b:N>w?b:0}),p=({field:n})=>o===n?d==="asc"?e.jsx(ie,{className:"h-3 w-3 inline ml-1"}):e.jsx(Z,{className:"h-3 w-3 inline ml-1"}):null;return x?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-primary"})}):i.length===0?e.jsx("div",{className:"text-center py-12 text-muted-foreground",children:s("aio.citations.noCitationsFound")}):e.jsxs("div",{className:"rounded-md border overflow-x-auto",children:[e.jsxs(z,{children:[e.jsx(Y,{children:e.jsxs(U,{children:[e.jsxs(T,{className:"cursor-pointer hover:bg-accent",onClick:()=>j("domain"),children:[s("aio.citations.tableDomain")," ",e.jsx(p,{field:"domain"})]}),e.jsx(T,{children:s("aio.citations.tableUrl")}),e.jsxs(T,{className:"cursor-pointer hover:bg-accent",onClick:()=>j("provider"),children:[s("aio.citations.tableProvider")," ",e.jsx(p,{field:"provider"})]}),e.jsxs(T,{className:"cursor-pointer hover:bg-accent",onClick:()=>j("query"),children:[s("aio.citations.tableQuery")," ",e.jsx(p,{field:"query"})]}),e.jsx(T,{children:s("aio.citations.tableType")})]})}),e.jsx(W,{children:u.slice(0,100).map((n,g)=>e.jsxs(U,{children:[e.jsx(B,{className:"font-medium text-sm",children:n.domain||"â"}),e.jsx(B,{className:"max-w-[200px]",children:n.url?e.jsxs("a",{href:n.url,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-primary hover:underline truncate block",children:[n.url,e.jsx(ae,{className:"h-3 w-3 inline ml-1"})]}):e.jsx("span",{className:"text-xs text-muted-foreground",children:"â"})}),e.jsx(B,{children:e.jsx(v,{variant:"outline",className:"text-xs",children:ue[n.provider]||n.provider})}),e.jsx(B,{className:"max-w-[200px] text-xs text-muted-foreground truncate",children:n.query}),e.jsx(B,{children:e.jsxs("div",{className:"flex gap-1",children:[n.isBrandMention&&e.jsx(v,{variant:"default",className:"text-[10px] px-1.5",children:s("aio.citations.brandLabel")}),n.isDomainCitation&&e.jsx(v,{variant:"secondary",className:"text-[10px] px-1.5",children:s("aio.citations.domainLabel")})]})})]},g))})]}),u.length>100&&e.jsx("div",{className:"p-3 text-center text-xs text-muted-foreground border-t",children:s("aio.citations.showingFirst",{shown:100,total:u.length})})]})}function je({citations:i,brandName:x}){const{t:s}=F(),o=()=>
1{if(i.length===0)return;const m=["Domain","URL","Provider","Query","Brand Mention","Domain Citation","Timestamp"],d=i.map(n=>[n.domain,n.url,n.provider,`"${n.query.replace(/"/g,'""')}"`,n.isBrandMention?"Yes":"No",n.isDomainCitation?"Yes":"No",n.timestamp]),f=[m.join(","),...d.map(n=>n.join(","))].join(` 2`),j=new Blob([f],{type:"text/csv;charset=utf-8;"}),u=URL.createObjectURL(j),p=document.createElement("a");p.href=u,p.download=`${x.replace(/\s+/g,"-").toLowerCase()}-citations-${new Date().toISOString().split("T")[0]}.csv`,p.click(),URL.revokeObjectURL(u)};return e.jsxs(J,{variant:"outline",size:"sm",onClick:o,disabled:i.length===0,children:[e.jsx(ne,{className:"h-4 w-4 mr-2"}),s("aio.citations.exportCsv")]})}function Ee(){const{selectedBrand:i,brands:x}=te(),{t:s}=F(),{citations:o,loading:m}=he((i==null?void 0:i.id)||null,i==null?void 0:i.domain,i==null?void 0:i.company_name),[d,f]=h.useState(""),[j,u]=h.useState("all"),[p,n]=h.useState("all"),[g,b]=h.useState(!1),[N,w]=h.useState(!1),L=h.useMemo(()=>{let t=o;if(p!=="all"&&(t=t.filter(a=>a.provider===p)),g&&(t=t.filter(a=>a.isBrandMention)),N&&(t=t.filter(a=>a.isDomainCitation)),d.trim()){const a=d.toLowerCase();t=t.filter(l=>{var C,I,G,Q;return((C=l.url)==null?void 0:C.toLowerCase().includes(a))||((I=l.domain)==null?void 0:I.toLowerCase().includes(a))||((G=l.text)==null?void 0:G.toLowerCase().includes(a))||((Q=l.query)==null?void 0:Q.toLowerCase().includes(a))})}return t},[o,d,p,g,N]),E=h.useMemo(()=>{const t={chatgpt:0,googleAI:0,perplexity:0};return o.forEach(a=>{t[a.provider]=(t[a.provider]||0)+1}),t},[o]),D=h.useMemo(()=>{const t=new Set(o.map(C=>C.domain).filter(Boolean)),a=o.filter(C=>C.isBrandMention).length,l=o.filter(C=>C.isDomainCitation).length;return{total:o.length,uniqueDomains:t.size,brandMentions:a,domainCitations:l}},[o]),y=h.useMemo(()=>{const t=new Map;return o.forEach(a=>{if(!a.domain)return;const l=t.get(a.domain)||{count:0,brandMentions:0,providers:new Set};l.count++,a.isBrandMention&&l.brandMentions++,l.providers.add(a.provider),t.set(a.domain,l)}),Array.from(t.entries()).map(([a,l])=>({domain:a,...l,providers:Array.from(l.providers)})).sort((a,l)=>l.count-a.count)},[o]),_=h.useMemo(()=>y.slice(0,10),[y]),r=h.useMemo(()=>{const t=new Map;return o.forEach(a=>{if(!a.query)return;const l=t.get(a.query)||{count:0,providers:new Set,hasBrandMention:!1};l.count++,l.providers.add(a.provider),a.isBrandMention&&(l.hasBrandMention=!0),t.set(a.query,l)}),Array.from(t.entries()).map(([a,l])=>({query:a,...l,providers:Array.from(l.providers)})).sort((a,l)=>l.count-a.count)},[o]);if(!i||x.length===0)return e.jsx("div",{className:"flex items-center justify-center h-full text-muted-foreground",children:x.length===0?s("aio.citations.addBrandFirst"):s("aio.citations.selectBrandPrompt")});const c={chatgpt:"ChatGPT",perplexity:"Perplexity",googleAI:"Google AI"};return e.jsxs("div",{className:"p-4 md:p-6 space-y-6 max-w-7xl mx-auto",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold",children:s("aio.citations.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("aio.citations.subtitle",{brandName:i.company_name})})]}),e.jsx(je,{citations:L,brandName:i.company_name})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[e.jsx(M,{children:e.jsxs(S,{className:"p-4 flex items-center gap-3",children:[e.jsx(H,{className:"h-5 w-5 text-primary"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold",children:D.total}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("aio.citations.totalCitations")})]})]})}),e.jsx(M,{children:e.jsxs(S,{className:"p-4 flex items-center gap-3",children:[e.jsx(K,{className:"h-5 w-5 text-primary"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold",children:D.uniqueDomains}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("aio.citations.uniqueDomains")})]})]})}),e.jsx(M,{children:e.jsxs(S,{className:"p-4 flex items-center gap-3",children:[e.jsx(xe,{className:"h-5 w-5 text-primary"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold",children:D.brandMentions}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("aio.citations.brandMentions")})]})]})}),e.jsx(M,{children:e.jsxs(S,{className:"p-4 flex items-center gap-3",children:[e.jsx(H,{className:"h-5 w-5 text-primary"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold",children:D.domainCitations}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("aio.citations.domainCitations")})]})]})})]}),o.length>0&&e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[e.jsxs(M,{children:[e.jsx(O,{className:"pb-3",children:e.jsx(V,{className:"text-sm font-medium",children:s("aio.citations.platformDistribution")})}),e.jsx(S,{className:"space-y-2",children:[{key:"chatgpt",label:"ChatGPT",color:"bg-blue-500"},{key:"perplexity",label:"Perplexity",color:"bg-purple-500"},{key:"googleAI",label:"Google AI",color:"bg-green-500"}].map(({key:t,label:a,color:l})=>e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:`h-2.5 w-2.5 rounded-full ${l}`}),e.jsx("span",{className:"text-sm",children:a})]}),e.jsx("span",{className:"text-sm font-semibold",children:E[t]||0})]},t))})]}),e.jsxs(M,{children:[e.jsx(O,{className:"pb-3",children:e.jsx(V,{className:"text-sm font-medium",children:s("aio.citations.mostCitedDomains")})}),e.jsxs(S,{className:"space-y-2",children:[_.slice(0,8).map(t=>e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("img",{src:`https://www.google.com/s2/favicons?domain=${t.domain}
2&sz=16`,alt:"",className:"h-4 w-4 rounded-sm",onError:a=>{a.target.style.display="none"}}),e.jsx("span",{className:"text-sm truncate max-w-[180px]",children:t.domain})]}),e.jsx("span",{className:"text-xs text-muted-foreground",children:s("aio.citations.citationsCount",{count:t.count})})]},t.domain)),_.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground",children:s("aio.citations.noDomainData")})]})]})]}),e.jsxs(re,{value:j,onValueChange:u,children:[e.jsxs(oe,{children:[e.jsx(P,{value:"all",children:s("aio.citations.allCitations")}),e.jsxs(P,{value:"domains",children:[s("aio.citations.byDomain"),e.jsx(v,{variant:"secondary",className:"ml-1.5 text-[10px]",children:y.length})]}),e.jsxs(P,{value:"searches",children:[s("aio.citations.byQuery"),e.jsx(v,{variant:"secondary",className:"ml-1.5 text-[10px]",children:r.length})]})]}),e.jsxs(R,{value:"all",className:"space-y-4 mt-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-4",children:[e.jsxs("div",{className:"relative flex-1 min-w-[160px] sm:min-w-[200px]",children:[e.jsx(X,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(ee,{placeholder:s("aio.citations.searchCitations"),value:d,onChange:t=>f(t.target.value),className:"pl-10"})]}),e.jsxs(le,{value:p,onValueChange:n,children:[e.jsx(ce,{className:"w-full sm:w-[150px]",children:e.jsx(de,{placeholder:s("aio.citations.allPlatforms")})}),e.jsxs(me,{children:[e.jsx(k,{value:"all",children:s("aio.citations.allPlatforms")}),e.jsx(k,{value:"chatgpt",children:"ChatGPT"}),e.jsx(k,{value:"googleAI",children:"Google AI"}),e.jsx(k,{value:"perplexity",children:"Perplexity"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(q,{id:"brand-filter",checked:g,onCheckedChange:b}),e.jsx($,{htmlFor:"brand-filter",className:"text-xs cursor-pointer",children:s("aio.citations.brandMentionedFilter")})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(q,{id:"domain-filter",checked:N,onCheckedChange:w}),e.jsx($,{htmlFor:"domain-filter",className:"text-xs cursor-pointer",children:s("aio.citations.domainCitedFilter")})]})]}),e.jsx(fe,{citations:L,loading:m})]}),e.jsx(R,{value:"domains",className:"mt-4",children:e.jsx("div",{className:"rounded-md border overflow-x-auto",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b bg-muted/50",children:[e.jsx("th",{className:"py-3 px-4 text-left text-sm font-medium text-muted-foreground",children:s("aio.citations.tableDomain")}),e.jsx("th",{className:"py-3 px-4 text-right text-sm font-medium text-muted-foreground",children:s("aio.citations.tableCitations")}),e.jsx("th",{className:"py-3 px-4 text-right text-sm font-medium text-muted-foreground",children:s("aio.citations.tableBrandMentions")}),e.jsx("th",{className:"py-3 px-4 text-left text-sm font-medium text-muted-foreground",children:s("aio.citations.tableProviders")})]})}),e.jsxs("tbody",{children:[y.slice(0,50).map(t=>e.jsxs("tr",{className:"border-b last:border-0 hover:bg-muted/50",children:[e.jsx("td",{className:"py-3 px-4 font-medium text-sm",children:t.domain}),e.jsx("td",{className:"py-3 px-4 text-right",children:e.jsx(v,{variant:"secondary",children:t.count})}),e.jsx("td",{className:"py-3 px-4 text-right",children:t.brandMentions>0?e.jsx(v,{variant:"default",children:t.brandMentions}):e.jsx("span",{className:"text-muted-foreground text-sm",children:"0"})}),e.jsx("td",{className:"py-3 px-4",children:e.jsx("div",{className:"flex gap-1",children:t.providers.map(a=>e.jsx(v,{variant:"outline",className:"text-[10px]",children:c[a]||a},a))})})]},t.domain)),y.length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:4,className:"py-8 text-center text-muted-foreground text-sm",children:s("aio.citations.noDomainData")})})]})]})})}),e.jsx(R,{value:"searches",className:"mt-4",children:e.jsx("div",{className:"rounded-md border overflow-x-auto",children:e.jsxs("table",{className:"w-full",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b bg-muted/50",children:[e.jsx("th",{className:"py-3 px-4 text-left text-sm font-medium text-muted-foreground",children:s("aio.citations.tableQuery")}),e.jsx("th",{className:"py-3 px-4 text-right text-sm font-medium text-muted-foreground",children:s("aio.citations.tableCitations")}),e.jsx("th",{className:"py-3 px-4 text-center text-sm font-medium text-muted-foreground",children:s("aio.citations.tableBrandFound")}),e.jsx("th",{className:"py-3 px-4 text-left text-sm font-medium text-muted-foreground",children:s("aio.citations.tableProviders")})]})}),e.jsxs("tbody",{children:[r.slice(0,50).map(t=>e.jsxs("tr",{className:"border-b last:border-0 hover:bg-muted/50",children:[e.jsx("td",{className:"py-3 px-4 text-sm max-w-[400px] truncate",children:t.query}),e.jsx("td",{className:"py-3 px-4 text-right",children:e.jsx(v,{variant:"secondary",children:t.count})}),e.jsx("td",{className:"py-3 px-4 text-center",children:t.hasBrandMention?e.jsx(v,{variant:"default",className:"text-[10px]",children:s("common.yes")}):e.jsx("span",{className:"text-muted-foreground text-sm",children:s("common.no")})}),e.jsx("td",{className:"py-3 px-4",children:e.jsx("div",{className:"flex gap-1",children:t.providers.map(a=>e.jsx(v,{variant:"outline",className:"text-[10px]",children:c[a]||a},a))})})]},t.query)),r.length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:4,className:"py-8 text-center text-muted-foreground text-sm",children:s("aio.citations.noQueryData")})})]})]})})})]})]})}export{Ee 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.