1import{R as p,r as x,j as e}from"./vendor-react-Dw2zQmPu.js";import{S as De}from"./SkeletonBlocks-D-0xzD__.js";import{S as Be}from"./skeleton-BJiIkxs-.js";import{B as j}from"./badge-CeMSLKTm.js";import{B as se}from"./button-CFi0D1K4.js";import{C as f,e as b}from"./card-B8ye2dFa.js";import{n as $e,A as Fe}from"./DiscoveryRoute-DrlLeagW.js";import{t as ze}from"./externalUrl-DG9qKTjM.js";import{I as R}from"./InfoTooltip-DW-Y0IWR.js";import{aO as ae,u as qe,W as Ge,aY as Ke,az as S,a7 as E,aK as ie,O as We,dH as He,h as K,S as Ae,dV as Ve,a9 as Re,U as Qe,aX as Ye,A as Xe,aW as Ze,bU as Se,V as Je,bH as ke,ae as et,af as Te,a4 as tt,be as st,cE as rt,dW as nt,cy as ot,k as at,l as it,p as V,ab as ct}from"./vendor-ui-mAy9LocR.js";import{c as w}from"./app-cn-C2LL9ulS.js";import{I as lt}from"./input-D2ulylI3.js";import{D as dt,a as mt,d as ut,b as pt}from"./dialog-BvmB9skF.js";import{P as xt}from"./progress-Bo241eve.js";import{N as ht,o as gt,b as ft}from"./app-core-DTTgVEgu.js";import{u as bt,b as Q,a as ge}from"./vendor-tanstack-Dk5vt_tN.js";import{b as vt}from"./vendor-router-CtopkIuN.js";import{i as wt}from"./vendor-utils-CQ_dDVxl.js";import{aH as M,fJ as jt,fK as Nt,fL as yt,fM as Ct}from"./app-shared-QFLrTdTF.js";import{R as At,g as Rt}from"./reviewsApi-D3Xxc9Z7.js";import"./commonjs-helpers-C05_-Ghz.js";import"./skeletonRows-bFntY3QY.js";import"./vendor-radix-guzGw5-0.js";import"./useBusinessScope-DCgcSpOq.js";import"./useAllLocationsTracking-9ddOIEwl.js";import"./vendor-date-fns-D1v0qsob.js";import"./FilterMultiSelect-DhvoGHGS.js";import"./checkbox-DOrnCsT6.js";import"./label-Bk74TkBv.js";import"./popover-QqxJL8eJ.js";import"./KpiCard-B6u2QL8p.js";import"./discoveryFormat-D9eQ_hkm.js";import"./PaginatedTable-SQijrXAm.js";import"./select-Bix8n78g.js";import"./table-DbeS9igF.js";import"./usemobile-BuLrGuzN.js";import"./activatable-cWgvSTbQ.js";import"./SearchInput-DTaqHUou.js";import"./input-group-DrMNcVmx.js";import"./textarea-BekLdUF0.js";import"./vite-preload-helper-BXl3LOEh.js";import"./ResponsiveModal-Dq9MwiUf.js";import"./drawer-CX599GCC.js";import"./TopBar-MjVkmRVM.js";import"./app-back-btn-wWeMZhZJ.js";import"./useZocaAppActions-B3KlgEzE.js";import"./useFtuxAnchorRect-CoIvPJl_.js";import"./useDiscoveryNavTracking-OqYErmMV.js";import"./useTrialGating-BYssbf5Y.js";import"./useTrialChecklist-D1cu0VDF.js";import"./billingApi-CqqpMSlc.js";import"./TrialNudgeBanner-jWPy0e-E.js";import"./tooltip-DNw65Jni.js";import"./vendor-redux-CqVJnD2r.js";import"./vendor-lodash-DVjWl2dU.js";function ce(t){const r=new Set(t.prompts.filter(n=>n.isUserAdded).map(n=>n.id));return t.results.filter(n=>!r.has(n.promptId))}function Ie(t){return t.status==="success"&&!!(t.normalized&&t.score?.components)}function _(t){return t.replace(/^\s*(?:[-*]|\d+[).])\s*/,"").replace(/\[([^\]]+)]\([^)]+\)/g,"$1").replace(/[*_`]/g,"").replace(/[.,;:]+$/,"").replace(/\s+/g," ").trim().toLowerCase()}function St(t){return[...t.matchAll(/https?:\/\/[^\s)]+/gi)].map(r=>r[0].replace(/[.,;:]+$/,""))}function kt(t,r){const n=t.match(/^\s*(\d+)[.)]\s*(.+?)(?:\s+-\s+|\s*:\s*|$)/);if(!n?.[1]||!n?.[2])return null;const s=_(n[2]);return s===r||s.includes(r)||r.includes(s)?Number(n[1]):null}function Tt(t,r){const n=t.split(/\n+/).map(s=>s.trim()).find(s=>_(s).includes(r));return n?{evidenceText:n,rank:kt(n,r),citationUrls:St(n)}:null}function It(t,r){const n=_(r);if(!n)return null;const s=t.normalized?.observedBusinesses??[];if(s.length>0){const o=s.find(c=>!c.isSubjectBusiness&&_(c.businessName)===n);if(o)return{evidenceText:o.evidenceText,rank:o.rank??null,citationUrls:o.citationUrls??[]}}if(t.answerText){const o=Tt(t.answerText,n);if(o)return o}return t.normalized?.competitorEntities?.some(o=>_(o)===n)?{rank:null,citationUrls:[]}:null}const _t=["completed","completed_with_partial_data","failed"],Pt={openai:"ChatGPT",gemini:"Gemini",google_aio:"Google AI Overview",google_ai_mode:"Google AI Mode",perplexity:"Perplexity",bing:"Bing",copilot:"Copilot",claude:"Claude",grok:"Grok"},P={mentioned:{label:"Business mentioned",description:"The business name was found in the AI answer.",weight:2},topPlacement:{label:"Top placement",description:"The business appeared in the top third of the answer.",weight:2},correctLocation:{label:"Correct location",description:"The answer references the correct city or address.",weight:1},serviceIntentMatch:{label:"Service match",description:"The answer mentions the relevant service category or theme.",weight:1},trustOrReviewSignal:{label:"Trust signal",description:"The answer includes review, rating, or trust language.",weight:1},visitPathSignal:{label:"Visit path",description:"The answer includes booking, visit, or call language.",weight:1},hasCitation:{label:"Has citation",description:"At least one citation URL was attached to the answer.",weight:1},noWrongCity:{label:"No wrong city",description:"No incorrect city names were mentioned in the answer.",weight:1}},Et={branded_entity:"Branded entity",location:"Location",services:"Services",local_discovery:"Local discovery",service_specific:"Service specific",recommendation_list:"Recommendation list",category_discovery:"Category discovery",service_intent:"Service intent",symptom_problem:"Symptom / Problem",comparison:"Comparison",near_me:"Near me",trust_review:"Trust / Review",trust_safety:"Trust / Safety",convenience:"Convenience",price_offer:"Price / Offer",problem_aware:"Problem aware",visit_path:"Visit path"};function le(t){return Et[t]??t.replace(/_/g," ")}const Mt="success";function de(t){return Pt[t]??t}function Ot(t){return`${Math.round(t*100)}%`}function Lt(t){return!!(t&&_t.includes(t))}function Ut(t){const r=t.auditRun.providers.length;if(r===0)return!1;const n=new Map;for(const s of t.results)n.set(s.promptId,(n.get(s.promptId)??0)+1);return t.prompts.some(s=>s.isUserAdded&&(n.get(s.id)??0)<r)}function fe(t){if(!t||!Lt(t.auditRun.status)||Ut(t))return!0;const r=t.auditRun.summary?.dossierEnrichment;if(!r||typeof r!="object"||Array.isArray(r))return!1;const n=r.status;return n==="queued"||n==="running"}function me(t){return t.status!==Mt?null:typeof t.score?.total=="number"?t.score.total:null}function Dt(t){return t.trim().replace(/\/$/,"")}function Y(t,r){for(const n of r){if(!n)continue;const s=Dt(n);s&&t.add(s)}}function _e(t){const r=new Set,n=new Set;for(const s of t){Y(r,(s.citations??[]).map(o=>o.url));const a=s.normalized?.observedBusinesses?.filter(o=>o.isSubjectBusiness).flatMap(o=>o.citationUrls??[])??[];a.length>0?Y(n,a):s.score?.components.hasCitation===1&&Y(n,(s.citations??[]).map(o=>o.url))}return{totalUniqueCitationCount:r.size,businessCitedUniqueCitationCount:n.size}}function Bt(t){const r=t?ce(t):[],n=r.map(me).filter(i=>typeof i=="number"),s=n.reduce((i,m)=>i+m,0),a=n.length>0?Math.round(s/n.length*10)/10:null,o=r.filter(i=>i.normalized?.mentioned).length,c=r.reduce((i,m)=>i+(m.citations?.length??0),0),d=_e(r);return{averageScore:a,scoredResults:n.length,totalResults:r.length,mentionedResults:o,citationCount:c,...d}}function $t(t){const r=t?.prompts??[],n=t?.results??[];return r.map(s=>{const a=n.filter(o=>o.promptId===s.id).reduce((o,c)=>(o[c.provider]=c,o),{});return{promptId:s.id,prompt:s.prompt,intent:s.intent,theme:s.theme??"General",isUserAdded:s.isUserAdded??!1,providerResults:a}})}const B=p.memo(({label:t,value:r,helper:n,tooltip:s}
1)=>e.jsx(f,{className:"gap-3 border-border/70 bg-card py-4",children:e.jsxs(b,{className:"px-4",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:t}),e.jsx(R,{icon:S,content:s,iconClassName:"h-3 w-3 text-muted-foreground/40"})]}),e.jsx("p",{className:"mt-2 text-3xl font-bold text-foreground",children:r}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:n})]})}));function Ft(t){const r=ce(t).flatMap(n=>n.status==="success"&&n.score?.components?[{...n,score:n.score}]:[]);return r.length===0?null:Object.keys(P).map(n=>{const s=r.filter(a=>a.score.components[n]===1).length;return{key:n,rate:s/r.length,earned:s,total:r.length}})}const zt=p.memo(({report:t,metrics:r,reviewStats:n})=>{const s=t.business,a=n?.averageRating??s.rating,o=n?.totalReviewCount??s.reviewCount,c=typeof a=="number"&&a>0,d=typeof o=="number"&&o>0,i=c&&typeof a=="number"?`${a.toFixed(1)} rating`:null,m=d&&typeof o=="number"?`${o} reviews`:null,h=r.averageScore===null?"Not scored":`${r.averageScore}/10`,u=`${r.businessCitedUniqueCitationCount}/${r.totalUniqueCitationCount}`,v=x.useMemo(()=>Ft(t),[t]);return e.jsxs("div",{className:"space-y-4",children:[e.jsx(f,{className:"border-border/70 bg-card",children:e.jsx(b,{className:"space-y-4 px-5",children:e.jsxs("div",{className:"flex flex-col gap-3 @min-[560px]:flex-row @min-[560px]:items-start @min-[560px]:justify-between",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("h2",{className:"text-xl font-semibold text-foreground",children:s.name}),s.primaryCategory&&e.jsx(j,{variant:"outline",className:"rounded-full",children:s.primaryCategory}),s.categories&&s.categories.filter(l=>l!==s.primaryCategory).slice(0,3).map(l=>e.jsx(j,{variant:"outline",className:"rounded-full text-xs",children:l},l))]}),s.address&&e.jsxs("p",{className:"mt-2 flex items-start gap-2 text-sm text-muted-foreground",children:[e.jsx(ae,{className:"mt-0.5 h-4 w-4 shrink-0"}),e.jsx("span",{children:s.address})]}),e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-x-4 gap-y-0.5",children:[s.websiteUri&&e.jsxs("a",{href:ze(s.websiteUri)??void 0,target:"_blank",rel:"noreferrer",className:"flex items-center gap-1.5 text-sm text-primary hover:underline",children:[e.jsx(qe,{className:"h-3.5 w-3.5"}),s.websiteUri.replace(/^https?:\/\//,"").replace(/\?.*$/,"").replace(/\/$/,"")]}),s.phoneNumber&&e.jsxs("span",{className:"flex items-center gap-1.5 text-sm text-muted-foreground",children:[e.jsx(Ge,{className:"h-3.5 w-3.5"}),s.phoneNumber]})]})]}),(c||d)&&e.jsxs("div",{className:"flex flex-wrap gap-2",children:[c&&e.jsxs(j,{className:"rounded-full bg-primary/10 text-primary hover:bg-primary/10",children:[e.jsx(Ke,{className:"h-3 w-3"}),i]}),d&&e.jsx(j,{variant:"outline",className:"rounded-full",children:m})]})]})})}),e.jsxs("div",{className:"grid grid-cols-2 gap-4 @min-[760px]:grid-cols-4",children:[e.jsx(B,{label:"AEO score",value:h,helper:`${r.scoredResults} scored provider responses`,tooltip:"Average visibility score across all successful AI provider responses. Ranges from 0 (not visible) to 10 (fully recommended with citations)."}),e.jsx(B,{label:"Mentions",value:`${r.mentionedResults}`,helper:`${r.totalResults} observed provider rows`,tooltip:"Number of AI responses where your business was mentioned by name. Higher is better â it means AI providers know your business."}),e.jsx(B,{label:"Prompts",value:`${t.promptCoverage.promptCount}`,helper:`${t.promptCoverage.resultCount} provider results`,tooltip:"Total questions sampled across service categories, intents, and local search patterns relevant to your business."}),e.jsx(B,{label:"Business citations",value:u,helper:"business cited / all unique URLs",tooltip:"Unique citation URLs tied to the audited business over all unique citation URLs found across successful provider answers."})]}),v&&e.jsx(f,{className:"border-border/70 bg-card",children:e.jsxs(b,{className:"px-5 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("h3",{className:"font-semibold text-foreground",children:"Score Signal Breakdown"}),e.jsx(R,{icon:S,content:"How often each scoring signal was earned across all successful provider responses. These 8 signals determine the AEO score.",iconClassName:"h-3 w-3 text-muted-foreground
1/40"})]}),e.jsx("div",{className:"grid gap-x-6 gap-y-2 @min-[480px]:grid-cols-2",children:v.map(l=>{const g=P[l.key],N=Math.round(l.rate*100);return e.jsxs("div",{className:"flex items-center justify-between py-1.5 border-b border-border/30",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[N>=50?e.jsx(E,{className:"h-3.5 w-3.5 text-green-600"}):e.jsx(ie,{className:"h-3.5 w-3.5 text-red-600"}),e.jsx("span",{className:"text-sm text-foreground",children:g.label}),e.jsx(R,{icon:S,content:g.description,iconClassName:"h-3 w-3 text-muted-foreground/40"})]}),e.jsxs("span",{className:"text-sm font-medium text-foreground",children:[N,"%"," ",e.jsxs("span",{className:"text-xs font-normal text-muted-foreground",children:["(",l.earned,"/",l.total,")"]})]})]},l.key)})})]})}),e.jsx(f,{className:"border-primary/15 bg-primary/5",children:e.jsxs(b,{className:"flex flex-col gap-3 px-5 text-sm text-muted-foreground @min-[480px]:flex-row @min-[480px]:items-center",children:[e.jsx(We,{className:"h-5 w-5 shrink-0 text-primary"}),e.jsx("p",{children:"This report only scores successful provider responses with observed answers. Not-triggered Google AI Overview results are shown separately and are not counted as failures or scored."}),e.jsx(He,{className:"hidden h-5 w-5 shrink-0 text-primary/40 @min-[480px]:block"})]})})]})}),$={high:0,medium:1,low:2};function qt(t,r){return ce(t).filter(n=>n.provider===r)}function be(t,r){return t.length===0?null:t.filter(r).length/t.length}function Gt(t){const r=t.map(n=>n.latencyMs).filter(n=>typeof n=="number");return r.length===0?null:Math.round(r.reduce((n,s)=>n+s,0)/r.length)}function Kt(t){const r=t.failed+t.unavailable,n=t.total>0?r/t.total:0,s=t.total>0?t.notTriggered/t.total:0;return t.success===0&&r>0?{priority:"high",type:"measurement_issue",statusLabel:"Provider collection issue",reason:"No successful answers were captured for this provider.",recommendedAction:"Fix provider execution or availability before interpreting this as an AI visibility problem."}:t.success>0&&t.scoredSuccess===0?{priority:"medium",type:"measurement_issue",statusLabel:"Scoring incomplete",reason:"Provider answers were captured but no scored and normalized rows are available.",recommendedAction:"Review scoring and normalization output before turning this provider into a content task."}:t.provider==="google_aio"&&s>=.5?{priority:"medium",type:"platform_behavior",statusLabel:"AI Overview not consistently triggered",reason:"Google AI Overview did not activate for much of this prompt set.",recommendedAction:"Treat this separately from visibility score; monitor trigger rate and expand prompt coverage where AI Overview appears."}:n>=.5?{priority:"medium",type:"measurement_issue",statusLabel:"Partial provider reliability issue",reason:"Provider errors or unavailable rows affect confidence in this audit.",recommendedAction:"Re-run after provider stability improves, then compare successful answer signals."}:t.scoredSuccess>0&&t.mentionRate===0?{priority:"high",type:"visibility_gap",statusLabel:"Entity not recognized",reason:"Successful answers from this provider did not mention the business.",recommendedAction:"Strengthen entity, location, service, and citation signals that this provider can resolve."}:t.averageScore!==null&&t.averageScore<4?{priority:"high",type:"visibility_gap",statusLabel:"Low visibility score",reason:"Successful answers are scored low for this provider.",recommendedAction:"Improve the missing score signals, then re-audit this provider for score lift."}:t.scoredSuccess>0&&t.citationRate===0?{priority:"medium",type:"citation_gap",statusLabel:"No cited proof",reason:"The provider answered but did not cite supporting URLs.",recommendedAction:"Create or improve owned and third-party pages this provider can cite for local recommendations."}:{priority:"low",type:"monitoring",statusLabel:"Monitor drift",reason:"No severe provider-specific issue was detected in this audit.",recommendedAction:"Keep tracking mention rate, citation rate, and score movement after content or GBP changes."}}function Wt(t){const n=t.engineBreakdown.map(s=>{const a=qt(t,s.provider),o=a.filter(Ie),c=be(o,m=>!!m.normalized.mentioned),d=be(o,m=>m.score?.components.hasCitation===1),i=Kt({provider:s.provider,averageScore:s.averageScore,mentionRate:c,citationRate:d,success:s.success,failed:s.failed,unavailable:s.unavailable,notTriggered:s.notTriggered,scoredSuccess:o.length,total:s.total});return{provider:s.provider,providerLabel:de(s.provider),averageScore:s.averageScore,mentionRate:c,citationRate:d,failureRate:s.total>0?(s.failed+s.unavailable)/s.total:0,notTriggeredRate:s.total>0?s.notTriggered/s.total:0,averageLatencyMs:Gt(a),model:a.find(m=>m.model)?.model??null,total:s.total,success:s.success,failed:s.failed,unavailable:s.unavailable,notTriggered:s.notTriggered,...i}}).sort((s,a)=>$[s.priority]!==$[a.priority]?$[s.priority]-$[a.priority]:(s.averageScore??11)-(a.averageScore??11));return{diagnostics:n,actionRequiredCount:n.filter(s=>s.priority!=="low").length,measurementIssueCount:n.filter(s=>s.type==="measurement_issue"||s.type==="platform_behavior").length,weakestProviderLabel:n[0]?.providerLabel??null}}const T=t=>`https://www.google.com/s2/favicons?sz=32&domain=${t}`,ue={openai:T("chatgpt.com"),gemini:T("gemini.google.com"),google_aio:T("google.com"),google_ai_mode:T("google.com"),perplexity:T("perplexity.ai"),bing:T("bing.com"),copilot:T("copilot.microsoft.com"),claude:T("claude.ai"),grok:T("grok.com")},Ht={high:"border-red-200 status-error",medium:"border-orange-200 status-warning",low:"border-border bg-muted text-muted-foreground"},Vt={high:"High priority",medium:"Medium priority",low:"Low priority"},A=p.memo(({label:t,value:r,valueClassName:n,className:s})=>
1e.jsxs("div",{className:w("rounded-lg border border-border/60 bg-background px-3 py-2",s),children:[e.jsx("p",{className:w("break-words text-lg font-semibold text-foreground",n),children:r}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:t})]})),H=p.memo(({icon:t,title:r,description:n,stats:s,className:a,contentClassName:o,infoTip:c,statsClassName:d})=>e.jsx(f,{className:w("border-primary/15 bg-primary/5",a),children:e.jsxs(b,{className:w("flex flex-col gap-4 px-5 @min-[640px]:flex-row @min-[640px]:items-center @min-[640px]:justify-between",o),children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[t,e.jsx("h3",{className:"font-semibold text-foreground",children:r}),c&&e.jsx(R,{icon:S,content:c,iconClassName:"h-3 w-3 text-muted-foreground/40"})]}),e.jsx("p",{className:"mt-1 max-w-3xl text-sm text-muted-foreground",children:n})]}),e.jsx("div",{className:w("grid grid-cols-3 gap-2 text-center @min-[640px]:min-w-[360px]",d),children:s.map(i=>e.jsx(A,{...i},i.label))})]})})),X=p.memo(({icon:t,label:r,value:n,className:s,framed:a=!0})=>e.jsxs("div",{className:w("flex min-w-0 items-start gap-2",a&&"rounded-lg border border-border/60 bg-muted/20 p-3",s
1),children:[e.jsx("span",{className:"mt-0.5 shrink-0 text-muted-foreground",children:t}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase text-muted-foreground",children:r}),e.jsx("p",{className:"break-words text-sm text-foreground",children:n})]})]})),pe=p.memo(({priority:t,className:r,label:n})=>e.jsx(j,{variant:"outline",className:w("rounded-full",Ht[t],r),children:n??Vt[t]})),Pe=p.memo(({provider:t,className:r,iconClassName:n})=>{const s=ue[t];return e.jsxs("span",{className:w("inline-flex items-center gap-1.5",r),children:[s&&e.jsx("img",{src:s,alt:"",className:w("h-4 w-4 rounded-sm",n)}),de(t)]})}),Ee=p.memo(({provider:t,className:r})=>e.jsx(j,{variant:"outline",className:w("gap-1 rounded-full text-[11px]",r),children:e.jsx(Pe,{provider:t,iconClassName:"h-3.5 w-3.5"})})),re=p.memo(({items:t,className:r,emptyFallback:n=null})=>t.length===0?n:e.jsx("div",{className:w("flex flex-wrap gap-2",r),children:t.map(s=>e.jsx(j,{variant:"outline",className:w("max-w-full rounded-full text-[11px]",s.className),children:s.label},s.id))}));function Me(t){return t===null?{ring:"#a1a1aa",text:"text-muted-foreground",track:"#e4e4e7",label:"N/A"}:t>=7?{ring:"#119655",text:"text-green-600",track:"#EAFBF2",label:"Good"}:t>=4?{ring:"#FF872B",text:"text-orange-500",track:"#FFF3E8",label:"Average"}:{ring:"#E5484D",text:"text-red-600",track:"#FFF2F2",label:"Needs work"}}function F(t){return t===null?"N/A":`${Math.round(t*100)}%`}const Qt=p.memo(({score:t})=>{const r=Me(t),n=38,s=2*Math.PI*n,a=t!==null?t/10*s:0;return e.jsxs("div",{className:"relative flex items-center justify-center",children:[e.jsxs("svg",{width:"96",height:"96",viewBox:"0 0 96 96",children:[e.jsx("circle",{cx:"48",cy:"48",r:n,fill:"none",stroke:r.track,strokeWidth:"7"}),e.jsx("circle",{cx:"48",cy:"48",r:n,fill:"none",stroke:r.ring,strokeWidth:"7",strokeLinecap:"round",strokeDasharray:s,strokeDashoffset:s-a,transform:"rotate(-90 48 48)",className:"transition-colors ease-out duration-(--motion-deliberate)"})]}),e.jsxs("div",{className:"absolute flex flex-col items-center",children:[e.jsx("span",{className:w("text-xl font-bold",r.text),children:t!==null?t.toFixed(1):"â"}),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:"/ 10"})]})]})}),z=p.memo(({icon:t,label:r,count:n,total:s,color:a,tooltip:o})=>e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:a,children:t}),e.jsx("span",{className:"text-xs text-muted-foreground",children:r}),o&&e.jsx(R,{icon:S,content:o,iconClassName:"h-3 w-3 text-muted-foreground/40"}),e.jsxs("span",{className:"ml-auto text-xs font-semibold text-foreground",children:[n,e.jsxs("span",{className:"font-normal text-muted-foreground",children:["/",s]})]})]})),Yt=p.memo(({diagnostic:t})=>{const r=Me(t.averageScore),n=ue[t.provider];return e.jsx(f,{className:"border-border/70 bg-card",children:e.jsxs(b,{className:"space-y-4 px-5",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[n&&e.jsx("img",{src:n,alt:"",className:"h-8 w-8 rounded-lg bg-muted/30 p-1"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("h3",{className:"text-base font-semibold text-foreground",children:t.providerLabel}),e.jsx(pe,{priority:t.priority})]}),e.jsx("p",{className:w("mt-1 text-xs font-medium",r.text),children:r.label})]})]}),e.jsxs("div",{className:"flex flex-col gap-4 @min-[420px]:flex-row @min-[420px]:items-center",children:[e.jsx("div",{className:"shrink-0 self-center",children:e.jsx(Qt,{score:t.averageScore})}),e.jsxs("div",{className:"min-w-0 flex-1 space-y-3",children:[e.jsxs("div",{className:"rounded-lg border border-border/60 bg-muted/20 p-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ae,{className:"h-4 w-4 text-primary"}),e.jsx("p",{className:"font-medium text-foreground",children:t.statusLabel})]}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:t.reason}),e.jsx("p",{className:"mt-2 text-sm text-foreground",children:t.recommendedAction})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx(A,{label:"Mention rate",value:F(t.mentionRate),className:"bg-muted/20",valueClassName:"text-sm"}),e.jsx(A,{label:"Citation rate",value:F(t.citationRate),className:"bg-muted/20",valueClassName:"text-sm"}),e.jsx(A,{label:"Failure rate",value:F(t.failureRate),className:"bg-muted/20",valueClassName:"text-sm"}),e.jsx(A,{label:"Not triggered",value:F(t.notTriggeredRate),className:"bg-muted/20",valueClassName:"text-sm"})]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-x-4 gap-y-1.5",children:[e.jsx(z,{icon:e.jsx(E,{className:"h-3.5 w-3.5"}),label:"Scanned",count:t.success,total:t.total,color:"text-green-600",tooltip:"Questions where the AI provider successfully returned an answer during the audit scan."}),e.jsx(z,{icon:e.jsx(Ve,{className:"h-3.5 w-3.5"}),label:"Not triggered",count:t.notTriggered,total:t.total,color:"text-muted-foreground",tooltip:"Questions where the AI feature did not activate for this query."}),e.jsx(z,{icon:e.jsx(ie,{className:"h-3.5 w-3.5"}),label:"Failed",count:t.failed,total:t.total,color:"text-red-600",tooltip:"Questions where the provider returned an error or could not process the request."}),e.jsx(z,{icon:e.jsx(Re,{className:"h-3.5 w-3.5"}),label:"Unavailable",count:t.unavailable,total:t.total,color:"text-orange-500",tooltip:"This provider is not yet supported or was not available during the audit run."})]})]})})}),Xt=p.memo(({report:t})=>{const r=x.useMemo(()=>Wt(t),[t]);return t.engineBreakdown.length===0?e.jsx(f,{className:"border-border/70 bg-card",children:e.jsx(b,{className:"px-5 text-sm text-muted-foreground",children:"No engine breakdown is available yet."})}):e.jsxs("div",{className:"space-y-4",children:[e.jsx(H,{icon:e.jsx(K,{className:"h-5 w-5 text-primary"}),title:"Provider diagnostics",description:"Use this to decide whether to improve source signals, fix measurement reliability, or simply monitor provider drift.",infoTip:"Provider actions separate visibility gaps from provider failures, unsupported rows, and Google AI Overview trigger behavior.",stats:[{label:"Providers",value:r.diagnostics.length},{label:"Needs action",value:r.actionRequiredCount},{label:"Measurement",value:r.measurementIssueCount}]}),e.jsx("div",{className:"grid gap-4 @min-[640px]:grid-cols-2",children:r.diagnostics.map(n=>e.jsx(Yt,{diagnostic:n},n.provider))})]})}),q={high:0,medium:1,low:2};function Zt(t){const r=t.map(n=>n.score?.total).filter(n=>typeof n=="number");return r.length===0?null:Math.round(r.reduce((n,s)=>n+s,0)/r.length*10)/10}function ve(t,r){return t.length===0?null:t.filter(r).length/t.length}function ne(t){return t.toLowerCase().replace(/\s+/g," ").trim()}function we(t){const r=ne(t);return!r||r.length<3?!1:!/^(not found|none|unknown|unavailable|no competitor|competitor not found)$/i.test(r)}function Jt(t){const r=new Map;for(const n of t){for(const s of n.normalized?.competitorEntities??[])we(s)&&r.set(ne(s),s);for(const s of n.normalized?.observedBusinesses??[])!s.isSubjectBusiness&&we(s.businessName)&&r.set(ne(s.businessName),s.businessName)}return Array.from(r.values()).slice(0,3)}function es(t){const r=new Map;for(const n of t){const s=n.score?.components;if(s)for(const a of Object.keys(P))s[a]===0&&r.set(a,(r.get(a)??0)+1)}return Array.from(r.entries()).sort((n,s)=>s[1]-n[1]).slice(0,3).map(([n])=>P[n].label)}function ts(t){return t.providerResultCount===0?"low":t.scoredProviderCount===0?"medium":t.mentionRate===0||t.competitorCount>0||t.averageScore!==null&&t.averageScore<4?"high":t.citationRate===0||t.averageScore!==null&&t.averageScore<7||t.mentionRate!==null&&t.mentionRate<1?"medium":"low"}function ss(t){return t.providerResultCount===0?{businessImpact:"Waiting for provider rows",recommendedAction:"Let the audit finish before deciding whether this prompt needs content or citation work."}:t.scoredProviderCount===0?{businessImpact:"Measurement gap, not a confirmed visibility failure",recommendedAction:"Check provider availability and re-run before creating content for this prompt."}:t.mentionRate===0?{businessImpact:"AI answers are not identifying the business",recommendedAction:"Strengthen GBP, service-page headings, schema, and local citations around this exact prompt language."}:t.competitorNames.length>0?{businessImpact:"Competitors are intercepting this prompt",recommendedAction:"Compare competitor proof and citations, then add stronger owned-page or listing evidence for this service/location intent."}:t.citationRate===0?{businessImpact:"Answers lack citable proof",recommendedAction:"Create or improve a page/listing that directly answers this prompt and can be cited by AI providers."}:t.averageScore!==null&&t.averageScore<7?{businessImpact:"Business appears, but the answer is weak",recommendedAction:`Improve ${t.missingSignals.length>0?t.missingSignals.join(", "):"low-score signals"} for this prompt cluster before the next audit.`}:{businessImpact:t.priority==="low"?"Defend current visibility":"Focused improvement",recommendedAction:"Keep this prompt monitored and preserve the source signals that are already working."}}function rs(t){const r=t.filter(a=>a.priority!=="low"),n=new Map;for(const a of r)n.set(a.intent,(n.get(a.intent)??0)+1);const[s]=Array.from(n.entries()).sort((a,o)=>o[1]-a[1])[0]??[];return s?le(s):null}function ns(t){const r=new Map;for(const a of t.results){const o=r.get(a.promptId)??[];o.push(a),r.set(a.promptId,o)}const s=t.prompts.map(a=>{const o=r.get(a.id)??[],c=o.filter(Ie),d=Zt(c),i=ve(c,g=>!!g.normalized?.mentioned),m=ve(c,g=>g.score?.components.hasCitation===1),h=Jt(c),u=es(c),v=ts({averageScore:d,mentionRate:i,competitorCount:h.length,citationRate:m,providerResultCount:o.length,scoredProviderCount:c.length}),l=ss({priority:v,averageScore:d,mentionRate:i,citationRate:m,competitorNames:h,providerResultCount:o.length,scoredProviderCount:c.length,missingSignals:u});return{promptId:a.id,prompt:a.prompt,intent:a.intent,theme:a.theme,priority:v,businessImpact:l.businessImpact,recommendedAction:l.recommendedAction,averageScore:d,scoredProviderCount:c.length,providerResultCount:o.length,mentionRate:i,citationRate:m,competitorNames:h,missingSignals:u}}).sort((a,o)=>q[a.priority]!==q[o.priority]?q[a.priority]-q[o.priority]:(a.averageScore??11)-(o.averageScore??11));return{opportunities:s,highPriorityCount:s.filter(a=>a.priority==="high").length,topPrompt:s[0]??null,primaryIntent:rs(s)}}const os={top:{label:"Top",icon:e.jsx(Ze,{className:"h-3 w-3"}),className:"border-green-200 status-success"},middle:{label:"Middle",icon:e.jsx(Xe,{className:"h-3 w-3"}),className:"border-orange-200 status-warning"},bottom:{label:"Bottom",icon:e.jsx(Ye,{className:"h-3 w-3"}),className:"border-red-200 status-error"},unknown:{label:"Unknown",icon:null,className:"border-gray-200 bg-gray-100 text-gray-600"}};function W(t,r,n){return`${t}-${r}-${n.slice(0,48)}`}function as(t){try{return new URL(t).hostname}catch{return t}}function is(t){const r=new Map;return t.map(n=>{const s=`${n.url}-${n.title??n.domain??"source"}
1`,a=r.get(s)??0;return r.set(s,a+1),{citation:n,renderKey:a===0?s:`${s}-${a+1}`}})}function O(t,r){return t.split(/(\*\*.+?\*\*|\[[^\]]+\]\([^)]+\))/g).map((s,a)=>{const o=W(r,a,s);if(s.startsWith("**")&&s.endsWith("**"))return e.jsx("strong",{className:"font-semibold",children:s.slice(2,-2)},o);const c=s.match(/^\[([^\]]+)\]\(([^)]+)\)$/);return c?e.jsx("a",{href:c[2],target:"_blank",rel:"noreferrer",className:"text-primary underline break-all",children:c[1]},o):s})}function Z(t,r){const n=t.match(/^(#{1,4})\s+(.+)$/);if(n){const s=n[1].length,a=n[2],o=s===1?"text-base font-bold":s===2?"text-sm font-bold":"text-sm font-semibold";return e.jsx("p",{className:w(o,"mt-1 text-foreground"),children:O(a,r)},r)}return O(t,r)}function cs(t){return t.split(/\n\n+/).map((n,s)=>{const a=n.trim();if(!a)return null;const o=W("paragraph",s,a),c=a.split(` 2`);return c.every(i=>/^\s*[-*]\s/.test(i)||/^\s*\d+[.)]\s/.test(i)||/^#{1,4}\s/.test(i)||i.trim()==="")?e.jsx(p.Fragment,{children:c.filter(i=>i.trim()).map((i,m)=>{const h=W(o,m,i);if(/^#{1,4}\s/.test(i))return Z(i,h);const u=i.replace(/^\s*[-*]\s*/,"").replace(/^\s*\d+[.)]\s*/,"");return e.jsx("ul",{className:"ml-4 list-disc",children:e.jsx("li",{className:"text-sm leading-relaxed",children:O(u,h)})},h)})},o):c.length>1?e.jsx("div",{className:"space-y-1",children:c.map((i,m)=>{const h=W(o,m,i);return/^#{1,4}\s/.test(i)?Z(i,h):e.jsx("p",{className:"text-sm leading-relaxed",children:O(i,h)},h)})},o):/^#{1,4}\s/.test(a)?Z(a,o):e.jsx("p",{className:"text-sm leading-relaxed",children:O(a,o)},o)})}const ls=p.memo(({componentKey:t,value:r})=>{const n=P[t];return e.jsxs("div",{className:"flex items-center gap-1.5",children:[r===1?e.jsx(E,{className:"h-3 w-3 text-green-600"}):e.jsx(ie,{className:"h-3 w-3 text-red-600"}),e.jsx("span",{className:"text-xs text-foreground",children:n.label})]})});function ds(t){return t>=7?{ring:"#119655",track:"#EAFBF2",text:"text-green-600"}:t>=4?{ring:"#FF872B",track:"#FFF3E8",text:"text-orange-500"}:{ring:"#E5484D",track:"#FFF2F2",text:"text-red-600"}}const ms=p.memo(({score:t})=>{const r=ds(t),n=16,s=2*Math.PI*n,a=t/10*s;return e.jsxs("div",{className:"relative flex items-center justify-center shrink-0 mr-4",children:[e.jsxs("svg",{width:"42",height:"42",viewBox:"0 0 42 42",children:[e.jsx("circle",{cx:"21",cy:"21",r:n,fill:"none",stroke:r.track,strokeWidth:"3"}),e.jsx("circle",{cx:"21",cy:"21",r:n,fill:"none",stroke:r.ring,strokeWidth:"3",strokeLinecap:"round",strokeDasharray:s,strokeDashoffset:s-a,transform:"rotate(-90 21 21)"})]}),e.jsx("span",{className:w("absolute text-xs font-bold",r.text),children:t})]})}),us=p.memo(({citation:t})=>{const r=t.domain||as(t.url);return e.jsxs("a",{href:t.url,target:"_blank",rel:"noreferrer",className:"group flex max-w-[280px] items-center gap-1.5 rounded-full border border-border/60 bg-background px-2.5 py-1 text-xs transition-colors hover:bg-muted/40",children:[e.jsx("img",{src:`https://www.google.com/s2/favicons?sz=16&domain=${r}`,alt:"",className:"h-3.5 w-3.5 shrink-0 rounded-sm"}),e.jsx("span",{className:"truncate text-foreground",children:t.title||r}),e.jsx(Se,{className:"h-3 w-3 shrink-0 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100"})]})}),ps=p.memo(({open:t,onOpenChange:r,result:n,promptText:s})=>{if(!n)return null;const a=me(n),o=n.normalized,c=o?.answerPosition,d=c?os[c]:null,i=ue[n.provider],m=de(n.provider),h=n.score?.components;return e.jsx(dt,{open:t,onOpenChange:r,children:e.jsxs(mt,{className:"sm:max-w-2xl max-h-[min(85vh,900px)] min-h-0 !flex flex-col gap-0 p-0 overflow-hidden",children:[e.jsxs(ut,{className:"shrink-0 px-5 pt-4 pr-16 pb-3 border-b border-border/40 space-y-3",children:[e.jsxs("div",{className:"flex min-h-9 items-center gap-3",children:[i&&e.jsx("img",{src:i,alt:"",className:"h-7 w-7 rounded-lg bg-muted/30 p-0.5"}),e.jsx(pt,{className:"text-base flex-1",children:m}),a!==null&&e.jsx(ms,{score:a})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[d&&e.jsxs(j,{variant:"outline",className:w("roun
2ded-full gap-1 text-xs",d.className),children:[d.icon,d.label," placement"]}),o?.mentioned&&e.jsxs(j,{variant:"outline",className:"rounded-full text-xs border-green-200 status-success",children:[e.jsx(E,{className:"h-3 w-3"}),"Mentioned"]}),o?.correctLocation&&e.jsxs(j,{variant:"outline",className:"rounded-full text-xs border-violet-200 bg-violet-100 text-violet-700",children:[e.jsx(ae,{className:"h-3 w-3"}),"Correct location"]})]}),h&&e.jsxs("div",{className:"flex flex-wrap gap-x-3 gap-y-1",children:[Object.keys(P).map(u=>e.jsx(ls,{componentKey:u,value:h[u]},u)),e.jsx(R,{icon:S,content:"Each signal contributes weighted points to the total AEO score (max 10). Green = earned, red = missed.",iconClassName:"h-3 w-3 text-muted-foreground/40"})]})]}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto px-5 py-4 space-y-4 bg-muted/10",children:[s&&e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx("div",{className:"max-w-[80%] rounded-2xl rounded-tr-sm bg-foreground px-4 py-2.5 text-sm text-background leading-relaxed",children:s}),e.jsx("div",{className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-full bg-muted",children:e.jsx(Qe,{className:"h-4 w-4 text-muted-foreground"})})]}),n.answerText&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx("div",{className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-full bg-muted/60",children:i?e.jsx("img",{src:i,alt:"",className:"h-4 w-4 rounded-sm"}):e.jsx("span",{className:"text-[10px] font-bold text-muted-foreground",children:"AI"})}),e.jsxs("div",{className:"max-w-[85%] space-y-2",children:[e.jsx("div",{className:"rounded-2xl rounded-tl-sm bg-white border border-border/60 px-4 py-3 shadow-sm break-words",children:e.jsx("div",{className:"space-y-2",children:cs(n.answerText)})}),n.citations&&n.citations.length>0&&e.jsxs("div",{className:"space-y-1.5 pl-1",children:[e.jsxs("p",{className:"text-[10px] font-medium uppercase text-muted-foreground tracking-wide",children:["Sources (",n.citations.length,")"]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:is(n.citations).map(u=>e.jsx(us,{citation:u.citation},u.renderKey))})]})]})]}),n.errorMessage&&e.jsx("div",{className:"rounded-lg border border-red-200 bg-red-100 p-3 text-sm text-red-600",children:n.errorMessage}),o?.competitorEntities&&o.competitorEntities.length>0&&e.jsxs("div",{className:"border-t border-border/30 pt-3",children:[e.jsx("p",{className:"text-[10px] font-medium uppercase text-muted-foreground tracking-wide mb-1.5",children:"Competitors mentioned"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:o.competitorEntities.map(u=>e.jsx(j,{variant:"outline",className:"rounded-full text-xs border-orange-200 status-warning",children:u},u))})]})]})]})})}),xs=500;function je(t){return t===null?"N/A":`${Math.round(t*100)}%`}const hs=p.memo(({isAddingCustomPrompt:t,onAddCustomPrompt:r})=>{const[n,s]=x.useState(""),a=n.trim(),o=!!a&&!t,c=x.useCallback(m=>{s(m.target.value)},[]),d=x.useCallback(()=>{!a||t||r(a,()=>s(""))},[t,r,a]),i=x.useCallback(m=>{m.key==="Enter"&&(m.preventDefault(),d())},[d]);return e.jsx(f,{className:"border-border/70 bg-card",children:e.jsxs(b,{className:"flex flex-col gap-2 px-5 @min-[640px]:flex-row @min-[640px]:items-center",children:[e.jsx(lt,{value:n,onChange:c,onKeyDown:i,maxLength:xs,placeholder:"Add your own prompt to measure across providers","aria-label":"Custom prompt",className:"flex-1"}),e.jsxs(se,{type:"button",onClick:d,disabled:!o,className:"gap-2 @min-[640px]:w-auto",children:[e.jsx(et,{className:"h-4 w-4"}),t?"Adding...":"Add prompt"]})]})})}),gs=p.memo(({opportunity:t})=>{const r=t.averageScore===null?"Not scored":`${t.averageScore}/10`;return e.jsxs("div",{className:"rounded-lg border border-border/70 bg-background p-3",children:[e.jsxs("div",{className:"flex flex-col gap-3 @min-[640px]:flex-row @min-[640px]:items-start @min-[640px]:justify-between",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(pe,{priority:t.priority}),e.jsx(j,{variant:"outline",className:"rounded-full",children:le(t.intent)}),t.theme&&e.jsx(j,{variant:"outline",className:"rounded-full",children:t.theme})]}),e.jsx("p",{className:"mt-2 break-words text-sm font-semibold text-foreground",children:t.prompt}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:t.businessImpact}),e.jsx("p",{className:"mt-2 text-sm text-foreground",children:t.recommendedAction})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 text-center @min-[640px]:min-w-[300px]",children:[e.jsx(A,{label:"Avg score",value:r,valueClassName:"text-sm"}),e.jsx(A,{label:"Mention rate",value:je(t.mentionRate),valueClassName:"text-sm"}),e.jsx(A,{label:"Citation rate",value:je(t.citationRate),valueClassName:"text-sm"})]})]}),e.jsx(re,{className:"mt-3",items:[{id:"provider-answers",label:`${t.scoredProviderCount}/${t.providerResultCount} provider answers`},...t.competitorNames.map(n=>({id:`competitor-${n}`,label:`Competitor: ${n}`})),...t.missingSignals.map(n=>({id:`missing-${n}`,label:`Missing: ${n}`}))]})]})}),fs=p.memo(({result:t,onClick:r})=>{if(!t)return e.jsxs("span",{className:"flex items-center gap-1 text-xs text-muted-foreground",children:[e.jsx(Te,{className:"h-3 w-3"}),"Queued"]});const n=me(t),s=!!t.answerText,a=t.status==="failed"||t.status==="unavailable"||t.status==="not_triggered";return e.jsxs("button",{type:"button",onClick:r,className:w("flex flex-col items-start gap-1 rounded-md p-1.5 -m-1.5 text-left w-full",s&&"hover:bg-muted/50 cursor-pointer transition-colors",!s&&"cursor-default"),disabled:!s,children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[n!==null?e.jsxs("span",{className:"text-base font-semibold text-foreground",children:[n,"/10"]}):e.jsx("span",{className:"text-sm text-muted-foreground",children:a?"N/A":"â"}),t.normalized?.mentioned&&e.jsx(E,{className:"h-3 w-3 text-green-600"}),t.normalized?.correctLocation&&e.jsx(ae,{className:"h-3 w-3 text-violet-500"})]}),s&&e.jsxs("span",{className:"flex items-center gap-1 text-[10px] text-primary",children:[e.jsx(tt,{className:"h-3 w-3"}),"View answer"]})]})}),bs=p.memo(({provider:t,row:r,onResultClick:n})=>{const s=r.providerResults[t],a=x.useCallback(()=>{s?.answerText&&n(s,r.prompt)},[n,s,r.prompt]);return e.jsx("td",{className:"px-3 py-4",children:e.jsx(fs,{result:s,onClick:s?.answerText?a:void 0})})}),vs=p.memo(({providers:t,row:r,onResultClick:n})=>e.jsxs("tr",{className:"border-b last:border-b-0",children:[e.jsxs("td",{className:"max-w-[360px] px-5 py-4 font-medium text-foreground",children:[e.jsxs("span",{className:"flex flex-wrap items-center gap-2",children:[r.prompt,r.isUserAdded&&e.jsx(j,{variant:"outline",className:"rounded-full border-primary/30 bg-primary/10 text-xs text-primary",children:"Custom"})]}),e.jsx("p",{className:"mt-1 text-xs font-normal text-muted-foreground",children:r.theme})]}),e.jsx("td",{className:"px-3 py-4",children:e.jsx(j,{variant:"outline",className:"whitespace-nowrap rounded-full text-xs",children:le(r.intent)})}),t.map(s=>e.jsx(bs,{provider:s,row:r,onResultClick:n},`${r.promptId}-${s}`))]})),ws=p.memo(({isAddingCustomPrompt:t,onAddCustomPrompt:r,providers:n,report:s,rows:a})=>{const[o,c]=x.useState(null),[d,i]=x.useState(""),[m,h]=x.useState(!1),u=x.useMemo(()=>ns(s),[s]),v=x.useCallback((l,g)=>{c(l),i(g),h(!0)},[]);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx(hs,{isAddingCustomPrompt:t,onAddCustomPrompt:r}),a.length===0&&e.jsx(f,{className:"border-border/70 bg-card",children:e.jsx(b,{className:"px-5 text-sm text-muted-foreground",children:"Prompts will appear here after the audit starts."})}),a.length>0&&e.jsx(H,{icon:e.jsx(Je,{className:"h-5 w-5 text-primary"}),title:"Prompt opportunities",description:"Start with prompts where AI answers omit the business, cite competitors, or miss the proof signals needed for recommendations.",infoTip:"Prompts are prioritized by business omission, competitor pressure, score, citation coverage, and successful provider rows.",stats:[{label:"Prompts",value:u.opportunities.length},{label:"High priority",value:u.highPriorityCount},{label:"Main intent",value:u.primaryIntent??"No intent gap",valueClassName:"text-sm"}]}),a.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(f,{className:"border-border/70 bg-card",children:e.jsxs(b,{className:"space-y-3 px-5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ke,{className:"h-4 w-4 text-primary"}),e.jsx("h3",{className:"font-semibold text-foreground",children:"What to improve by prompt"})]}),e.jsx("div",{className:"space-y-3",children:u.opportunities.map(l=>e.jsx(gs,{opportunity:l},l.promptId))})]})}),e.jsx(f,{className:"flex max-h-[640px] flex-col overflow-hidden border-border/70 bg-card py-0",children:e.jsx(b,{className:"min-h-0 overflow-auto px-0",children:e.jsxs("table",{className:"w-full min-w-[820px] text-left text-sm",children:[e.jsx("thead",{className:"sticky top-0 z-10 border-b bg-card text-xs uppercase text-muted-foreground shadow-[0_1px_0_0_theme(colors.border)]",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-5 py-3 font-medium",children:e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:["Question (Total: ",a.length,")",e.jsx(R,{icon:S,content:"Each question is a high-intent local search prompt sampled for your business category and location.",iconClassName:"h-3 w-3 text-muted-foreground
2/40"})]})}),e.jsx("th",{className:"px-3 py-3 font-medium",children:e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:["Intent",e.jsx(R,{icon:S,content:"The search intent classification: category discovery, service intent, comparison, near-me, trust/review, symptom/problem, or visit path.",iconClassName:"h-3 w-3 text-muted-foreground/40"})]})}),n.map(l=>e.jsx("th",{className:"px-3 py-3 font-medium",children:e.jsx(Pe,{provider:l})},l))]})}),e.jsx("tbody",{children:a.map(l=>e.jsx(vs,{providers:n,row:l,onResultClick:v},l.promptId))})]})})})]})]}),e.jsx(ps,{open:m,onOpenChange:h,result:o,promptText:d})]})}),J={owned_site:{label:"Owned site",description:"The AI answer cites the business website or one of its subdomains.",recommendedAction:"Keep this page accurate, service-specific, and easy for AI systems to quote."},google_surface:{label:"Google surface",description:"The citation points to Google-controlled local discovery surfaces.",recommendedAction:"Keep GBP categories, services, photos, Q&A, booking links, and review language aligned."},directory:{label:"Directory",description:"The citation points to a business directory or local listing surface.",recommendedAction:"Claim and correct the listing, then make service, address, phone, and website fields match GBP."},review_platform:{label:"Review platform",description:"The citation points to a review-heavy site that can influence trust language.",recommendedAction:"Audit rating, reviews, service tags, and profile completeness on this source."},social_community:{label:"Social / community",description:"The citation points to a social network, forum, or community discussion.",recommendedAction:"Treat this as reputation evidence and check whether the conversation is accurate and current."},third_party_authority:{label:"Third-party authority",description:"The citation points to an external page that may be shaping AI answers.",recommendedAction:"Evaluate whether this page can be influenced through outreach, partnerships, or better owned content."}},js=new Set(["angi.com","bbb.org","chamberofcommerce.com","foursquare.com","mapquest.com","nextdoor.com","thumbtack.com","yellowpages.com"].map(I)),Ns=new Set(["birdeye.com","healthgrades.com","ratemds.com","realself.com","trustpilot.com","yelp.com","zocdoc.com"].map(I)),ys=new Set(["facebook.com","instagram.com","linkedin.com","quora.com","reddit.com","tiktok.com","twitter.com","x.com","youtube.com"].map(I));function I(t){return t.toLowerCase().replace(/^https?:\/\//,"").replace(/^www\./,"").split("/")[0].split(":")[0].trim()}function xe(t){try{return I(new URL(t).hostname)}catch{return I(t)}}function oe(t,r){return t===r||t.endsWith(`.${r}`)}function Cs(t){const r=t.business.websiteUri;return r&&xe(r)||null}function ee(t,r){return Array.from(r).some(n=>oe(t,n))}function te(t,r){const n=I(t),s=r?oe(n,r):!1;return s?{sourceType:"owned_site",isOwnedDomain:s}:n==="google.com"||oe(n,"google.com")?{sourceType:"google_surface",isOwnedDomain:s}:ee(n,Ns)?{sourceType:"review_platform",isOwnedDomain:s}:ee(n,js)?{sourceType:"directory",isOwnedDomain:s}:ee(n,ys)?{sourceType:"social_community",isOwnedDomain:s}:{sourceType:"third_party_authority",isOwnedDomain:s}}function As(t){return t.missingOwnedCitation?"Create or strengthen owned pages AI providers can cite for service and location prompts.":t.thirdPartyDomainCount>t.ownedDomainCount?"Reduce dependence on external sources by improving owned service pages and schema.":"Maintain owned citations and keep third-party listings consistent."}function Rs(t){const r=new Map;for(const n of t){const s=I(n.domain||xe(n.url));r.set(s,(r.get(s)??0)+n.count)}return r}function Ss(t){const r=Cs(t),n=Rs(t.topCitations),s=Array.from(n.values()).reduce((l,g)=>l+g,0),a=t.citationShare.map(l=>{const g=I(l.domain),N=te(g,r);return{domain:g,count:l.count,share:l.share,sourceType:N.sourceType,sourceMeta:J[N.sourceType],isOwnedDomain:N.isOwnedDomain}}),o=new Set(a.map(l=>l.domain)),c=Array.from(n.entries()).filter(([l])=>!o.has(l)).map(([l,g])=>{const N=te(l,r);return{domain:l,count:g,share:s>0?g/s:0,sourceType:N.sourceType,sourceMeta:J[N.sourceType],isOwnedDomain:N.isOwnedDomain}}),d=[...a,...c],i=t.topCitations.map(l=>{const g=I(l.domain||xe(l.url)),N=te(g,r);return{url:l.url,domain:g,count:l.count,sourceType:N.sourceType,sourceMeta:J[N.sourceType],isOwnedDomain:N.isOwnedDomain}}),m=d.filter(l=>l.isOwnedDomain).length,h=d.length-m,u=!!r&&m===0,v=_e(t.results);return{summary:{totalDomains:d.length,...v,ownedDomainCount:m,thirdPartyDomainCount:h,missingOwnedCitation:u,primaryOpportunity:As({missingOwnedCitation:u,ownedDomainCount:m,thirdPartyDomainCount:h})},domainInsights:d,urlInsights:i}}const Ne={owned_site:"border-green-200 status-success",google_surface:"border-violet-200 bg-vi
2olet-100 text-violet-700",directory:"border-violet-200 bg-violet-100 text-violet-700",review_platform:"border-orange-200 status-warning",social_community:"border-violet-200 bg-violet-100 text-violet-700",third_party_authority:"border-border bg-muted text-muted-foreground"},ks=p.memo(({report:t})=>{const r=x.useMemo(()=>Ss(t),[t]);return t.citationShare.length===0&&t.topCitations.length===0?e.jsx(f,{className:"border-border/70 bg-card",children:e.jsx(b,{className:"px-5 text-sm text-muted-foreground",children:"Citation gaps will appear when providers return cited answers. Until then, do not treat missing citations as a visibility failure."})}):e.jsxs("div",{className:"space-y-4",children:[e.jsx(H,{icon:r.summary.missingOwnedCitation?e.jsx(Re,{className:"h-5 w-5 text-orange-500"}):e.jsx(E,{className:"h-5 w-5 text-primary"}),title:"Answer citation gap summary",description:r.summary.primaryOpportunity,infoTip:"Shows unique citation URLs tied to the audited business over all unique citation URLs found across prompts. Exter
2nal citations are answer evidence, not proof that the audited business was cited.",className:w(r.summary.missingOwnedCitation&&"border-orange-200 bg-orange-100"),stats:[{label:"Business cited",value:`${r.summary.businessCitedUniqueCitationCount}/${r.summary.totalUniqueCitationCount}`},{label:"Owned domains",value:r.summary.ownedDomainCount},{label:"External domains",value:r.summary.thirdPartyDomainCount}]}),e.jsxs("div",{className:"grid gap-4 @min-[640px]:grid-cols-2",children:[e.jsx(f,{className:"flex max-h-[640px] flex-col border-border/70 bg-card",children:e.jsxs(b,{className:"flex min-h-0 flex-col gap-4 px-5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("h3",{className:"font-semibold text-foreground",children:"Citation source mix"}),e.jsx(R,{icon:S,content:"Source type for domains cited by AI providers. Owned-site citations usually give Zoca the most direct control; external citations may belong to competitors or category evidence.",iconClassName:"h-3 w-3 text-muted-foreground/40"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Answer domains grouped by how actionable they are."})]}),e.jsxs("span",{className:"shrink-0 text-sm text-muted-foreground",children:[r.domainInsights.length," domains"]})]}),e.jsx("div",{className:"min-h-0 space-y-3 overflow-y-auto",children:r.domainInsights.map(n=>e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 text-sm",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"break-words font-medium text-foreground",children:n.domain}),e.jsx(j,{variant:"outline",className:w("mt-1 rounded-full text-[11px]",Ne[n.sourceType]),children:n.sourceMeta.label})]}),e.jsxs("span",{className:"shrink-0 text-muted-foreground",children:[Ot(n.share)," · ",n.count]})]}),e.jsx(xt,{value:Math.round(n.share*100),className:"h-2"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n.sourceMeta.recommendedAction})]},n.domain))})]})}),e.jsx(f,{className:"flex max-h-[640px] flex-col overflow-hidden border-border/70 bg-card",children:e.jsxs(b,{className:"flex min-h-0 min-w-0 flex-col gap-4 px-5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("h3",{className:"font-semibold text-foreground",children:"Pages shaping answers"}),e.jsx(R,{icon:S,content:"Specific pages AI providers cited. Use this to decide which owned pages to improve, which listings to claim, and which third-party pages may need outreach.",iconClassName:"h-3 w-3 text-muted-foreground/40"})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Most repeated URLs with action guidance."})]}),e.jsxs("span",{className:"shrink-0 text-sm text-muted-foreground",children:[r.urlInsights.length," URLs"]})]}),e.jsx("div",{className:"min-h-0 space-y-3 overflow-y-auto",children:r.urlInsights.map(n=>e.jsx("a",{href:n.url,target:"_blank",rel:"noreferrer",className:"block min-w-0 rounded-lg border border-border/70 p-3 text-sm hover:bg-muted/40",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[n.isOwnedDomain?e.jsx(st,{className:"h-4 w-4 shrink-0 text-green-600"}):e.jsx(rt,{className:"h-4 w-4 shrink-0 text-muted-foreground"}),e.jsx("span",{className:"break-words text-foreground",children:n.url})]}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[e.jsx(j,{variant:"outline",className:w("roun
2ded-full text-[11px]",Ne[n.sourceType]),children:n.sourceMeta.label}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[n.domain," · cited ",n.count," times"]})]}),e.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:n.sourceMeta.recommendedAction})]}),e.jsx(Se,{className:"h-4 w-4 shrink-0 text-muted-foreground"})]})},n.url))})]})})]})]})});function Ts(t){return Object.entries(t).filter(([,r])=>r>0).sort((r,n)=>n[1]-r[1]).map(([r])=>r)}function Is(t){const r=_(t);return!r||r.length<3?!1:!/^(not found|none|unknown|unavailable|no competitor|competitor not found)$/i.test(r)}function _s(t){return t.top3Count>0||t.affectedPromptCount>=3?"high":t.mentionCount>=2?"medium":"low"}function Ps(t){return t.top3Count>0?"Top placement in AI answers":t.citationCount>0||t.citationDomains.length>0?"Stronger cited proof":t.mentionCount>=2?"Repeated entity relevance":"Single prompt competitor signal"}function Es(t){return t==="Top placement in AI answers"?"Compare their GBP categories, reviews, service pages, and cited sources, then build stronger proof for the prompts where they rank above this business.":t==="Stronger cited proof"?"Audit the cited domains, fix equivalent listings for this business, and create owned pages that answer the same service/location intent.":t==="Repeated entity relevance"?"Tighten service and location language across GBP, website copy, schema, and local citations for the repeated prompt cluster.":"Review the answer evidence and decide whether this prompt needs a service page, GBP update, or directory correction."}function Ms(t,r){const n=_(r),s=new Map(t.prompts.map(o=>[o.id,o.prompt])),a=[];for(const o of t.results){const c=It(o,r);c&&a.push({id:`${o.id}:${n}`,promptId:o.promptId,provider:o.provider,promptText:s.get(o.promptId)??"Unknown prompt",evidenceText:c.evidenceText,rank:c.rank,citationUrls:c.citationUrls})}return a}function Os(t){return Array.from(new Set(t.map(r=>r.promptText))).slice(0,3)}function Ls(t){const n=t.competitorsCited.filter(s=>Is(s.name)).map(s=>{const a=Ms(t,s.name),o=new Set(a.map(d=>d.promptId)).size,c=Ps({top3Count:s.top3Count,citationCount:s.citationCount,citationDomains:s.citationDomains,mentionCount:s.mentionCount});return{name:s.name,priority:_s({top3Count:s.top3Count,mentionCount:s.mentionCount,affectedPromptCount:o}),mentionCount:s.mentionCount??s.count,citationCount:s.citationCount,top3Count:s.top3Count,averageRank:s.averageRank,affectedPromptCount:o,providers:Ts(s.providers),citationDomains:s.citationDomains,likelyAdvantage:c,recommendedAction:Es(c),verificationMetric:"Next audit shows fewer competitor mentions, lower competitor top-three share, or improved business placement on these prompts.",examplePrompts:Os(a),evidence:a}}).sort((s,a)=>{const o={high:0,medium:1,low:2};return o[s.priority]!==o[a.priority]?o[s.priority]-o[a.priority]:a.mentionCount-s.mentionCount});return{totalCompetitors:n.length,highPriorityCount:n.filter(s=>s.priority==="high").length,topCompetitorName:n[0]?.name??null,items:n}}const Us=p.memo(({item:t})=>e.jsx("div",{className:"border-t border-border/50 px-4 py-3",children:e.jsx("div",{className:"space-y-3",children:t.evidence.map(r=>e.jsx("div",{className:"rounded-lg border border-border/60 bg-muted/20 p-3",children:e.jsxs("div",{className:"flex flex-col gap-2 @min-[480px]:flex-row @min-[480px]:items-start @min-[480px]:justify-between",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(Ee,{provider:r.provider}),r.rank!==null&&e.jsxs(j,{variant:"outline",className:"rounded-full text-[11px]",children:["Rank #",r.rank]})]}),e.jsx("p",{className:"mt-2 break-words text-sm font-medium text-foreground",children:r.promptText}),r.evidenceText&&e.jsx("p",{className:"mt-1 line-clamp-3 text-xs text-muted-foreground",children:r.evidenceText})]}),r.citationUrls.length>0&&e.jsxs("div",{className:"min-w-0 @min-[480px]:max-w-[280px]",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase text-muted-foreground",children:"Cited sources"}),e.jsx("div",{className:"mt-1 space-y-1",children:r.citationUrls.slice(0,2).map(n=>e.jsx("a",{href:n,target:"_blank",rel:"noreferrer",className:"block break-all text-xs text-primary hover:underline",children:n},n))})]})]})},r.id))})}
2)),Ds=p.memo(({item:t,isExpanded:r,onToggle:n})=>{const s=x.useCallback(()=>{n(t.name)},[t.name,n]),a=t.averageRank===null?"Not ranked":`Average rank ${t.averageRank.toFixed(1)}`;return e.jsxs(f,{className:"overflow-hidden border-border/70 bg-card",children:[e.jsxs(b,{className:"space-y-4 px-4",children:[e.jsxs("div",{className:"flex flex-col gap-3 @min-[640px]:flex-row @min-[640px]:items-start @min-[640px]:justify-between",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(pe,{priority:t.priority}),e.jsx(j,{variant:"outline",className:"rounded-full",children:t.likelyAdvantage})]}),e.jsx("h3",{className:"mt-2 break-words text-base font-semibold text-foreground",children:t.name}),e.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:t.recommendedAction})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 text-center @min-[640px]:min-w-[300px]",children:[e.jsx(A,{label:"Mentions",value:t.mentionCount,className:"bg-muted/20",valueClassName:"text-base"}),e.jsx(A,{label:"Top 3",value:t.top3Count,className:"bg-muted/20",valueClassName:"text-base"}),e.jsx(A,{label:"Prompts",value:t.affectedPromptCount,className:"bg-muted/20",valueClassName:"text-base"})]})]}),e.jsxs("div",{className:"grid gap-3 @min-[640px]:grid-cols-3",children:[e.jsx(X,{icon:e.jsx(ot,{className:"h-4 w-4"}),label:"Placement",value:a}),e.jsx(X,{icon:e.jsx(Ae,{className:"h-4 w-4"}),label:"Verify",value:t.verificationMetric}),e.jsx(X,{icon:e.jsx(ke,{className:"h-4 w-4"}),label:"Citation signal",value:`${t.citationCount} citations`})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[t.providers.map(o=>e.jsx(Ee,{provider:o},o)),e.jsx(re,{items:t.citationDomains.map(o=>({id:o,label:o}))})]}),t.examplePrompts.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-[11px] font-medium uppercase text-muted-foreground",children:"Example prompts they influence"}),e.jsx(re,{items:t.examplePrompts.map(o=>({id:o,label:o,className:"bg-background text-muted-foreground whitespace-normal text-left"}))})]})]}),t.evidence.length>0&&e.jsxs("div",{children:[e.jsxs("button",{type:"button",className:"flex w-full items-center justify-between gap-3 border-t border-border/50 px-4 py-3 text-left text-sm hover:bg-muted/30",onClick:s,children:[e.jsxs("span",{className:"font-medium text-foreground",children:[t.evidence.length," answer evidence rows"]}),r?e.jsx(at,{className:"h-4 w-4 shrink-0 text-muted-foreground"}):e.jsx(it,{className:"h-4 w-4 shrink-0 text-muted-foreground"})]}),r&&e.jsx(Us,{item:t})]})]})}),Bs=p.memo(({report:t})=>{const[r,n]=x.useState(null),s=x.useMemo(()=>Ls(t),[t]),a=x.useCallback(o=>{n(c=>c===o?null:o)},[]);return s.items.length===0?e.jsx(f,{className:"border-border/70 bg-card",children:e.jsx(b,{className:"px-5 text-sm text-muted-foreground",children:"No competitor business mentions were detected in this report."})}):e.jsxs("div",{className:"space-y-4",children:[e.jsx(H,{icon:e.jsx(nt,{className:"h-5 w-5 text-primary"}),title:"Competitor playbook",description:"Use this to decide which competitors need source parity, stronger owned pages, or review/location proof before the next audit.",infoTip:"Competitors are prioritized by top-three placement, repeated prompt coverage, provider spread, and citation support in the current audit.",stats:[{label:"Competitors",value:s.totalCompetitors},{label:"High priority",value:s.highPriorityCount},{label:"Top threat",value:s.topCompetitorName,valueClassName:"text-sm"}]}),e.jsx("div",{className:"space-y-3",children:s.items.map(o=>e.jsx(Ds,{item:o,isExpanded:r===o.name,onToggle:a},o.name))})]})});function $s(t){const r=Date.now()-new Date(t).getTime(),n=Math.floor(r/6e4);if(n<1)return"just now";if(n<60)return`${n}m ago`;const s=Math.floor(n/60);return s<24?`${s}h ago`:`${Math.floor(s/24)}d ago`}const ye={overview:{title:"AI Search Overview",description:"High-level visibility score and key metrics across all AI search providers."},engines:{title:"AI Platforms",description:"Per-provider success rates, scores, and response status across all sampled prompts."},questions:{title:"AI Results",description:"Every prompt sampled in the audit with per-provider results, scores, and intent classification."},citations:{title:"Citations",description:"Which domains AI providers cite most often and the top URLs referenced in answers."},competitors:{title:"Competitors",description:"Businesses that AI providers recommended or cited alongside this location."}},Fs=p.memo(({activeSubTab:t,auditRunId:r,errorMessage:n,isAddingCustomPrompt:s,isCreating:a,isInitialLoading:o,isPolling:c,isSessionReady:d,locationEntityId:i,metrics:m,onAddCustomPrompt:h,onRunAudit:u,promptCoverageRows:v,report:l,reviewStats:g})=>{const N=!!i&&d&&!a&&!c,C=$e(t),L=ye[C]??ye[Fe],U=x.useMemo(()=>{const D=l?.auditRun.completedAt??l?.auditRun.createdAt;return D?$s(D):null},[l?.auditRun.completedAt,l?.auditRun.createdAt]);return e.jsxs("div",{className:"@container flex flex-col gap-5 p-6 pb-20",children:[e.jsxs("div",{className:"flex flex-col gap-4 @min-[640px]:flex-row @min-[640px]:items-start @min-[640px]:justify-between",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("h1",{className:"text-lg font-semibold text-foreground",children:L.title}),e.jsx(j,{className:"rounded-full bg-primary/10 text-primary hover:bg-primary/10",children:"Managed by Discovery"})]}),e.jsx("p",{className:"mt-2 max-w-3xl text-sm text-muted-foreground",children:L.description})]}),e.jsxs("div",{className:"flex shrink-0 flex-col items-end gap-1",children:[e.jsxs(se,{onClick:u,disabled:!N,className:"w-full gap-2 @min-[640px]:w-auto","aria-label":"Run AI Search audit",children:[e.jsx(V,{className:"h-4 w-4"}),a?"Starting audit...":"Run audit"]}),U&&e.jsxs("span",{className:"flex items-center gap-1 text-xs text-muted-foreground",children:[e.jsx(Te,{className:"h-3 w-3"}),"Last run ",U]})]})]}),c&&e.jsx(f,{className:"border-primary/20 bg-primary/5 py-3",children:e.jsxs(b,{className:"flex items-center gap-3 px-4 text-sm text-primary",children:[e.jsx(V,{className:"h-4 w-4 animate-spin"}),"Audit is running. This page will refresh as provider rows arrive."]})}),n&&e.jsx(f,{className:"border-red-200 bg-red-100 py-3",children:e.jsxs(b,{className:"flex items-start gap-3 px-4 text-sm text-red-600",children:[e.jsx(ct,{className:"mt-0.5 h-4 w-4 shrink-0"}),n]})}),!i&&e.jsx(f,{className:"border-border/70 bg-card",children:e.jsxs(b,{className:"flex min-h-[240px] flex-col items-center justify-center gap-3 p-6 text-center",children:[e.jsx(K,{className:"h-8 w-8 text-muted-foreground"}),e.jsx("h2",{className:"text-lg font-semibold text-foreground",children:"Select a location"}),e.jsx("p",{className:"max-w-xl text-sm text-muted-foreground",children:"AI Search audits run against the active GBP location in ZocaWeb."})]})}),i&&!d&&e.jsx(f,{className:"border-border/70 bg-card",children:e.jsxs(b,{className:"flex min-h-[240px] flex-col items-center justify-center gap-3 p-6 text-center",children:[e.jsx(K,{className:"h-8 w-8 text-muted-foreground"}),e.jsx("h2",{className:"text-lg font-semibold text-foreground",children:"Session is loading"}),e.jsx("p",{className:"max-w-xl text-sm text-muted-foreground",children:"AI Search audits can start after the authenticated ZocaWeb session is ready."})]})}),i&&d&&!r&&!l&&!o&&e.jsx(f,{className:"border-border/70 bg-card",children:e.jsxs(b,{className:"flex min-h-[280px] flex-col items-center justify-center gap-3 p-6 text-center",children:[e.jsx(K,{className:"h-8 w-8 text-primary"}),e.jsx("h2",{className:"text-lg font-semibold text-foreground",children:"Run AI Search audit"}),e.jsx("p",{className:"max-w-xl text-sm text-muted-foreground",children:"Start an audit to sample AI search prompts across the configured providers."}),e.jsxs(se,{onClick:u,disabled:!N,className:"mt-2 gap-2",children:[e.jsx(V,{className:"h-4 w-4"}),a?"Starting audit...":"Run audit"]})]})}),o&&!l&&e.jsx(f,{className:"border-border/70 bg-card",children:e.jsxs(b,{className:"min-h-[240px] space-y-4 px-5 py-5",children:[e.jsx(Be,{className:"h-4 w-48"}),e.jsx(De,{rows:4,lead:!1})]})}),l&&C==="overview"&&e.jsx(zt,{report:l,metrics:m,reviewStats:g}),l&&C==="engines"&&e.jsx(Xt,{report:l}),l&&C==="questions"&&e.jsx(ws,{isAddingCustomPrompt:s,onAddCustomPrompt:h,providers:l.auditRun.providers,report:l,rows:v}),l&&C==="citations"&&e.jsx(ks,{report:l}),l&&C==="competitors"&&e.jsx(Bs,{report:l})]})}),zs=4e3,Ce="aeo_last_audit_run_id";function qs(t){return t?`${Ce}:${t}`:Ce}function Gs(t){try{return sessionStorage.getItem(t)}catch{return null}}function G(t,r){try{sessionStorage.setItem(t,r)}catch{}}function Ks(t){if(!t)return null;if(wt(t)){const r=ft(t);if(Array.isArray(r))return r.join(", ");
2if(r)return r}return t instanceof Error?t.message:"Unable to load AI Search report."}function Ws(){const[t,r]=vt(),n=bt(),s=ht()??"",a=gt(y=>y.user?.accessToken??""),o=t.get("auditRunId")??"",c=!!a,d=x.useMemo(()=>qs(s),[s]),[i,m]=x.useState(()=>o||""),h=x.useRef(o);x.useEffect(()=>{o&&o!==h.current&&(m(o),G(d,o)),h.current=o},[d,o]),x.useEffect(()=>{if(o)return;if(!s){m("");return}const y=Gs(d);m(y??"")},[s,d,o]),x.useEffect(()=>{i&&G(d,i)},[i,d]);const u=Q({queryKey:[M.GET_LATEST_AEO_REPORT,s],queryFn:()=>yt({locationEntityId:s}),enabled:!i&&c&&!!s,staleTime:3e4});x.useEffect(()=>{const y=u.data?.auditRun?.id;if(!y||i||o)return;m(y),G(d,y);const k=new URLSearchParams(t);k.set("tab","ai-search"),k.set("auditRunId",y),r(k,{replace:!0})},[i,u.data?.auditRun?.id,t,r,d,o]);const v=Q({queryKey:[M.GET_AEO_REPORT,i],queryFn:()=>Ct(i),enabled:!!i&&c,refetchInterval:y=>fe(y.state.data)?zs:!1}),l=Q({queryKey:[At.GET_REVIEW_STATS,s],queryFn:()=>Rt(s),enabled:!!s&&c,staleTime:3e4}),g=ge({mutationKey:[M.CREATE_AEO_REPORT,s],mutationFn:jt}),N=x.useCallback(()=>{!s||!c||g.mutate({locationEntityId:s},{onSuccess:y=>{m(y.auditRunId),G(d,y.auditRunId);const k=new URLSearchParams(t);k.set("tab","ai-search"),k.set("auditRunId",y.auditRunId),r(k,{replace:!0})}})},[g,c,s,t,r,d]),C=ge({mutationKey:[M.ADD_AEO_CUSTOM_PROMPT,i],mutationFn:({prompt:y})=>Nt(i,y),onSuccess:()=>{n.invalidateQueries({queryKey:[M.GET_AEO_REPORT,i]})}}),L=x.useCallback((y,k)=>{const he=y.trim();!i||!he||C.mutate({prompt:he},{onSuccess:k})},[C,i]),U=x.useMemo(()=>Bt(v.data),[v.data]),D=x.useMemo(()=>$t(v.data),[v.data]),Oe=!!i&&!!v.data&&fe(v.data),Le=u.error??v.error??g.error??C.error,Ue=Ks(Le);return{auditRunId:i,errorMessage:Ue,isAddingCustomPrompt:C.isPending,isCreating:g.isPending,isInitialLoading:u.isLoading||v.isLoading,isPolling:Oe,isSessionReady:c,locationEntityId:s,metrics:U,onAddCustomPrompt:L,onRunAudit:N,promptCoverageRows:D,report:v.data,reviewStats:l.data}}const Vr=p.memo(({activeSubTab:t})=>{const r=Ws();return e.jsx(Fs,{...r,activeSubTab:t})});export{Vr 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.