@canonry/canonry 7.97.8 → 7.99.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/assets/agent-workspace/skills/aero/references/site-health.md +11 -1
  2. package/assets/agent-workspace/skills/canonry/references/canonry-cli.md +2 -0
  3. package/assets/assets/{AgentSetupPage-DiX4GptZ.js → AgentSetupPage-yOqSVJ-e.js} +1 -1
  4. package/assets/assets/{AuditHistoryPanel-de0zJkNC.js → AuditHistoryPanel-CiTzFgbw.js} +1 -1
  5. package/assets/assets/{BacklinksPage-BFfksR1M.js → BacklinksPage-DmRdQsFQ.js} +1 -1
  6. package/assets/assets/{HistoryPage-DQnGncRE.js → HistoryPage-DNE76LNh.js} +1 -1
  7. package/assets/assets/{MeasurementPropertyPage-DYCBQSnh.js → MeasurementPropertyPage-Cx64Fnmz.js} +1 -1
  8. package/assets/assets/{ProjectPage-BwwkYgfJ.js → ProjectPage-DNfgC82V.js} +1 -1
  9. package/assets/assets/{RunsPage-VeWCiQeM.js → RunsPage-BmPKBKKr.js} +1 -1
  10. package/assets/assets/{SettingsPage-BXPhnRMo.js → SettingsPage-Dl0TNeVK.js} +1 -1
  11. package/assets/assets/{SiteHealthSection-Ch9tNd8P.js → SiteHealthSection-DxQPaR--.js} +2 -2
  12. package/assets/assets/ToneBadge-BhjTBHi-.js +60 -0
  13. package/assets/assets/{TrafficPage-CIzz7gmK.js → TrafficPage-CJp0pS01.js} +1 -1
  14. package/assets/assets/{TrafficSourceDetailPage-6IbzMhJ6.js → TrafficSourceDetailPage-DKE8tSw5.js} +1 -1
  15. package/assets/assets/{account-context-DIWdmpj6.js → account-context-j3asaevn.js} +1 -1
  16. package/assets/assets/{agent-trust-copy-2Os0XoaQ.js → agent-trust-copy--U_DFYQE.js} +1 -1
  17. package/assets/assets/{card-CoYH9h6o.js → card-CQAQ-c3g.js} +1 -1
  18. package/assets/assets/{format-helpers-cRaGEIxc.js → format-helpers-BPugHeIX.js} +1 -1
  19. package/assets/assets/{index-vfNb458q.js → index-xlDLvgRC.js} +4 -4
  20. package/assets/assets/{query-client-Bf1oywTZ.js → query-client-CwZpfiiD.js} +1 -1
  21. package/assets/assets/{react-query-DYI08wkz.js → react-query-CBpNFR4t.js} +1 -1
  22. package/assets/assets/{react-sigma_core.esm.min-BEhi6Q9o.js → react-sigma_core.esm.min-BAq_-iP1.js} +1 -1
  23. package/assets/assets/{server-traffic-tgMckYtk.js → server-traffic-jKXLZyeC.js} +1 -1
  24. package/assets/assets/{service-CN0y5nRe.js → service-DFumlmXt.js} +1 -1
  25. package/assets/index.html +7 -7
  26. package/dist/{ads-F7ACQA6Z.js → ads-EYDUTG4U.js} +3 -3
  27. package/dist/{agent-FBSRQSUX.js → agent-KTK2IDB3.js} +7 -7
  28. package/dist/{agent-ask-VYSXDUCL.js → agent-ask-KPZOH6RY.js} +3 -3
  29. package/dist/{agent-conversations-IKAS3RE6.js → agent-conversations-BCWA4JJL.js} +3 -3
  30. package/dist/{agent-journeys-L3ABBCNC.js → agent-journeys-UBVLQ7JV.js} +3 -3
  31. package/dist/{agent-memory-SKWZDBMQ.js → agent-memory-24SYEGEX.js} +3 -3
  32. package/dist/{agent-providers-JBTFE5TJ.js → agent-providers-E7EWFE5P.js} +3 -3
  33. package/dist/{agent-transcript-YGLXXFF7.js → agent-transcript-QGJ45NW5.js} +3 -3
  34. package/dist/{analytics-ULDRQRRL.js → analytics-GHVG5CCT.js} +3 -3
  35. package/dist/{apply-KC4CCHY5.js → apply-7YLB2DPH.js} +3 -3
  36. package/dist/{backfill-5Y2GMEAH.js → backfill-WNQ6O5WP.js} +10 -10
  37. package/dist/{backlinks-NXWU4BPY.js → backlinks-ZBZR4D27.js} +3 -3
  38. package/dist/{bing-E2KM2CW6.js → bing-4VBSKPSX.js} +3 -3
  39. package/dist/{bootstrap-QYWTDUIZ.js → bootstrap-7ESCLP2G.js} +10 -10
  40. package/dist/{cdp-E7WXCN5U.js → cdp-WBL6FZTL.js} +7 -7
  41. package/dist/{chunk-KSB3UZMW.js → chunk-2RW5D55K.js} +2 -2
  42. package/dist/{chunk-RSJBMQMN.js → chunk-3MFYM2IS.js} +1 -1
  43. package/dist/{chunk-I6G5K5PM.js → chunk-3MKJ4LP6.js} +6 -6
  44. package/dist/{chunk-TUBFKC3O.js → chunk-3VPBRGPN.js} +1 -1
  45. package/dist/{chunk-7737JZP6.js → chunk-3WDQ5GPO.js} +1 -1
  46. package/dist/{chunk-ZN3KIIMP.js → chunk-47X24IJG.js} +24 -2
  47. package/dist/{chunk-GMCVZPKO.js → chunk-5ZOM5BJS.js} +1 -1
  48. package/dist/{chunk-4VSL2CMF.js → chunk-74V5EPZH.js} +7 -7
  49. package/dist/{chunk-7APKPDOV.js → chunk-AJD252SX.js} +2 -2
  50. package/dist/{chunk-NPCML7HY.js → chunk-AY7SDX6G.js} +3 -3
  51. package/dist/{chunk-TUQYYF4G.js → chunk-C55P75G4.js} +2 -2
  52. package/dist/{chunk-LPSKHUCV.js → chunk-DLOWRO5R.js} +3 -3
  53. package/dist/{chunk-AI2G7QMW.js → chunk-DMPSA7ZS.js} +4 -4
  54. package/dist/{chunk-66DTIEWN.js → chunk-L53ZSQN5.js} +28 -1
  55. package/dist/{chunk-NLN7EGU3.js → chunk-LM7HTNUO.js} +5 -5
  56. package/dist/{chunk-C3LS3ZKI.js → chunk-O6RXNSNW.js} +1 -1
  57. package/dist/{chunk-QM4PMS52.js → chunk-P764TJKQ.js} +1 -1
  58. package/dist/{chunk-FDVCTZXD.js → chunk-PT5HNVCM.js} +1 -1
  59. package/dist/{chunk-Q4KVK426.js → chunk-RRXLJPBN.js} +5 -5
  60. package/dist/{chunk-UBF2S3DF.js → chunk-SY3CWJR4.js} +2 -2
  61. package/dist/{chunk-X4DR2LK7.js → chunk-TVBOK4P2.js} +4 -4
  62. package/dist/{chunk-JYG3LUXU.js → chunk-UPHHKO3L.js} +357 -357
  63. package/dist/{chunk-4OGRTTZX.js → chunk-UY6SKAKW.js} +2 -2
  64. package/dist/{chunk-RABCSQBW.js → chunk-VADVPARO.js} +4 -4
  65. package/dist/{chunk-7TIX5NHC.js → chunk-VOVT2H25.js} +3 -3
  66. package/dist/{chunk-YO2OW67H.js → chunk-WA6APXI6.js} +3 -3
  67. package/dist/{chunk-MAWNTOQE.js → chunk-WXAF7AMC.js} +2 -2
  68. package/dist/{chunk-22LX5CWD.js → chunk-XPIMVXAI.js} +561 -359
  69. package/dist/{chunk-MA3ZD7TF.js → chunk-XQP3XHLJ.js} +2 -2
  70. package/dist/{chunk-RJNAUQSV.js → chunk-YACKJGY4.js} +1 -1
  71. package/dist/{chunk-5455IRP3.js → chunk-YBWATBX4.js} +1 -1
  72. package/dist/{chunk-WWGOMPYP.js → chunk-YEUULP44.js} +1 -1
  73. package/dist/{chunk-5X2N5OOF.js → chunk-YMHN4UIT.js} +1 -1
  74. package/dist/{chunk-FZIYHP67.js → chunk-ZGBLNKFN.js} +31 -5
  75. package/dist/{chunk-7CAOGKRV.js → chunk-ZN2TEBBX.js} +3 -3
  76. package/dist/{citations-CJ5Y3ZET.js → citations-N5MGNKJN.js} +3 -3
  77. package/dist/{cli-catalog-Z4XQIDYU.js → cli-catalog-FFU7PHW7.js} +3 -3
  78. package/dist/{cli-commands-3HZFXKVU.js → cli-commands-AMIDEUO2.js} +7 -7
  79. package/dist/cli.js +13 -13
  80. package/dist/{competitor-FC43JBCH.js → competitor-GRA2GMZR.js} +3 -3
  81. package/dist/{content-LS4EAVOS.js → content-YVAPTIV4.js} +3 -3
  82. package/dist/{dashboard-AZUFESTB.js → dashboard-33ACBR5A.js} +6 -6
  83. package/dist/{demo-LTVTVYGC.js → demo-AGXWBMR6.js} +1 -1
  84. package/dist/{demo-server-WHDXTUWQ.js → demo-server-W4YAC7GT.js} +12 -12
  85. package/dist/{discover-T5D7T5EZ.js → discover-BH33TO4Z.js} +3 -3
  86. package/dist/{discover-eval-FQWKYZD7.js → discover-eval-3CEA6DEE.js} +3 -3
  87. package/dist/{doctor-UEFC5WP7.js → doctor-ZAYTD5PC.js} +3 -3
  88. package/dist/{evidence-FXGHON3E.js → evidence-247GL7UK.js} +3 -3
  89. package/dist/{export-cmd-AF6KF2GP.js → export-cmd-HLKWFI5Q.js} +3 -3
  90. package/dist/{ga-RMYK4AQC.js → ga-BMING57Z.js} +3 -3
  91. package/dist/{gbp-5PAKGLBI.js → gbp-MIB5CXSD.js} +3 -3
  92. package/dist/{google-6NYRRHIS.js → google-5JP6RYAW.js} +4 -4
  93. package/dist/{google-marketing-6EVLEHKD.js → google-marketing-25OBMPS6.js} +1 -1
  94. package/dist/{health-cmd-WXDFHL7O.js → health-cmd-D5XSEL7H.js} +3 -3
  95. package/dist/{history-MZWTC4OE.js → history-6MDRFPQ3.js} +3 -3
  96. package/dist/index.d.ts +122 -12
  97. package/dist/index.js +25 -25
  98. package/dist/{init-OM64S7AT.js → init-RDR75N2Y.js} +12 -12
  99. package/dist/{insights-CYE3NXGD.js → insights-QZVMBGVM.js} +3 -3
  100. package/dist/intelligence-service-KQE7RO5I.js +16 -0
  101. package/dist/{journeys-YISJ3GH4.js → journeys-TABTZDFZ.js} +3 -3
  102. package/dist/{keys-L76I5EZI.js → keys-SL5YF7NQ.js} +3 -3
  103. package/dist/{keyword-54UML7XE.js → keyword-OCDEXRSW.js} +3 -3
  104. package/dist/{logs-ZG44USRX.js → logs-CSC7O364.js} +3 -3
  105. package/dist/{mcp-T7ZNR55S.js → mcp-P725OHAJ.js} +4 -4
  106. package/dist/mcp.js +9 -9
  107. package/dist/{measurement-plan-E7FAS5V3.js → measurement-plan-Z42GBJBO.js} +5 -5
  108. package/dist/{notify-ZB4V7B4L.js → notify-E5JBES4I.js} +5 -4
  109. package/dist/{organic-evidence-W5BJ37VR.js → organic-evidence-CUA3T64O.js} +3 -3
  110. package/dist/{overview-MULDZS6B.js → overview-UKQ52I72.js} +4 -4
  111. package/dist/{project-LFDGHF3H.js → project-2ULM64TV.js} +3 -3
  112. package/dist/{query-ZV3XX5YW.js → query-Y47IEFKJ.js} +3 -3
  113. package/dist/{research-HGAKJGVQ.js → research-DPFQZ3TE.js} +3 -3
  114. package/dist/{results-export-5HCHJGBM.js → results-export-KBHOBQAH.js} +3 -3
  115. package/dist/{run-5VYP7S3V.js → run-4CYHVIIU.js} +4 -4
  116. package/dist/{schedule-FD2VIHX7.js → schedule-GY4P3RON.js} +3 -3
  117. package/dist/{search-6TJJWFJB.js → search-AGVNZMJQ.js} +3 -3
  118. package/dist/{serve-4QZEQUER.js → serve-5LFKIXNL.js} +26 -26
  119. package/dist/{session-PA4SLGYI.js → session-YAYEDM3P.js} +13 -13
  120. package/dist/{settings-NOXPXCAY.js → settings-HUKMWRHY.js} +3 -3
  121. package/dist/{sitemaps-P52HCBCM.js → sitemaps-APTY7U6H.js} +3 -3
  122. package/dist/{skills-EBWXL2WN.js → skills-4BUONEIZ.js} +2 -2
  123. package/dist/{snapshot-IST2UAPI.js → snapshot-BXCWSF5P.js} +3 -3
  124. package/dist/{src-53VQLBQC.js → src-R7XZUX3D.js} +4 -2
  125. package/dist/{status-X2RYXIU5.js → status-SB6HPBYJ.js} +4 -4
  126. package/dist/{technical-aeo-HRQRU2L3.js → technical-aeo-G7UEMWZD.js} +3 -3
  127. package/dist/{telemetry-KQATCLNR.js → telemetry-H4S4Y7YV.js} +4 -4
  128. package/dist/{tools-VLQ3GZUE.js → tools-46XX6I4R.js} +11 -11
  129. package/dist/{traffic-WK6HEQWG.js → traffic-I6WRJN3W.js} +5 -5
  130. package/dist/{trends-353NF4OU.js → trends-AQK3GLWF.js} +3 -3
  131. package/dist/{users-YXBFZHVO.js → users-SNTVY6OB.js} +3 -3
  132. package/dist/{visibility-stats-N4KZ3N4P.js → visibility-stats-44QAD2XS.js} +3 -3
  133. package/dist/{wordpress-3IPY5TA3.js → wordpress-N7LTOW46.js} +3 -3
  134. package/package.json +2 -2
  135. package/assets/assets/ToneBadge-JbnFjl09.js +0 -60
  136. package/dist/intelligence-service-ILIYUOKY.js +0 -16
@@ -1,4 +1,4 @@
1
- import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{A as t,B as n,C as r,I as i,J as a,L as o,Q as s,T as c,U as l,Y as u,Z as d,a as f,b as p,c as m,i as h,lt as g,n as _,s as v,t as y,w as b}from"./vendor-lucide-DuOM7wVi.js";import{r as x}from"./vendor-markdown-BDQ1GKGP.js";import{E as S,_ as C,b as w,d as T,f as E,g as D,p as O,r as k,u as A,w as j}from"./vendor-tanstack-BNuZ37rE.js";import{c as M,f as N,i as P,l as F,m as I,o as L,p as R,r as ee,s as te,t as ne,u as re}from"./vendor-recharts-DhEHcK3G.js";import{$i as ie,$n as z,A as ae,An as B,Bi as V,Br as oe,Cr as se,Ct as ce,Dr as le,Dt as ue,Er as de,F as fe,Fi as pe,Fr as H,Ft as me,G as he,Gi as ge,Gr as _e,Hi as ve,Hr as ye,Ht as be,I as xe,Ii as Se,Ir as Ce,It as we,J as Te,Ji as Ee,Jn as U,Ki as De,Kn as Oe,Kr as W,Kt as ke,Li as Ae,Lr as je,Lt as Me,M as Ne,Nr as Pe,Nt as Fe,Or as Ie,P as Le,Pt as Re,Qn as ze,Rr as Be,Rt as Ve,Sr as He,Tr as Ue,Tt as We,U as Ge,Ur as Ke,Ut as qe,V as Je,Vi as Ye,Vr as Xe,Vt as Ze,Wi as Qe,Wr as $e,Wt as et,Xn as tt,Yn as nt,Zi as rt,Zn as it,_i as G,_t as at,a as ot,ai as st,an as ct,ar as lt,bi as ut,br as dt,c as ft,ca as pt,ci as mt,cn as ht,cr as gt,di as _t,dr as vt,dt as yt,ea as bt,er as xt,f as St,fi as Ct,g as wt,gi as Tt,gt as Et,h as Dt,hi as Ot,ht as kt,ia as At,ii as jt,ir as Mt,it as Nt,j as Pt,kn as Ft,l as It,ln as Lt,lr as Rt,lt as zt,m as Bt,mi as Vt,mt as K,na as Ht,nc as Ut,nn as Wt,nr as Gt,nt as Kt,o as qt,oa as Jt,oi as Yt,on as Xt,or as Zt,ot as Qt,p as $t,pi as en,qi as tn,qn as nn,qr as rn,r as q,ra as an,rc as on,ri as sn,rr as cn,rt as ln,s as un,sa as dn,sn as fn,sr as pn,t as J,tr as mn,u as hn,ua as gn,ui as _n,ur as vn,ut as yn,vi as bn,vn as xn,wr as Sn,wt as Y,x as Cn,xr as wn,yi as Tn,yr as En,yt as Dn,zi as On,zr as kn}from"./ToneBadge-JbnFjl09.js";import{_ as An,a as jn,b as Mn,d as Nn,g as Pn,h as Fn,i as In,l as Ln,m as Rn,n as zn,p as Bn,r as Vn,s as Hn,t as Un,u as Wn,v as Gn,y as Kn}from"./format-helpers-cRaGEIxc.js";import{r as qn}from"./account-context-DIWdmpj6.js";import{t as Jn}from"./async-handler-Bj3TnIRw.js";import{a as Yn,d as Xn,l as Zn,n as Qn,o as $n,s as er,t as tr,u as nr}from"./query-client-Bf1oywTZ.js";import{$ as rr,A as ir,An as ar,At as or,B as sr,Bt as cr,C as lr,Cn as ur,Ct as dr,D as fr,Dn as pr,Dt as mr,E as hr,En as gr,Et as _r,F as vr,Fn as yr,Ft as br,G as xr,H as Sr,Ht as Cr,I as wr,In as Tr,It as Er,J as Dr,K as Or,L as kr,Ln as Ar,Lt as jr,M as Mr,Mn as Nr,Mt as Pr,N as Fr,Nn as Ir,Nt as Lr,O as Rr,On as zr,Ot as Br,P as Vr,Pn as Hr,Pt as Ur,Q as Wr,R as Gr,Rn as Kr,Rt as qr,S as Jr,Sn as Yr,St as Xr,T as Zr,Tn as Qr,Tt as $r,U as ei,Ut as ti,V as ni,Vt as ri,W as ii,X as ai,Y as oi,Z as si,_ as ci,_n as li,_t as ui,an as di,at as fi,b as pi,bt as mi,c as hi,d as gi,dn as _i,et as vi,f as yi,fn as bi,ft as xi,g as Si,gn as Ci,gt as wi,h as Ti,ht as Ei,in as Di,it as Oi,j as ki,jn as Ai,jt as ji,k as Mi,kn as Ni,kt as Pi,l as Fi,lt as Ii,m as Li,n as Ri,o as zi,ot as Bi,p as Vi,pt as Hi,q as Ui,r as Wi,rt as Gi,s as Ki,t as qi,tn as Ji,tt as Yi,u as Xi,un as Zi,v as Qi,vt as $i,w as ea,wn as ta,wt as na,x as ra,xn as ia,xt as aa,y as oa,z as sa,zt as ca}from"./react-query-DYI08wkz.js";import{_ as la,a as ua,c as da,d as fa,f as pa,g as ma,h as ha,i as ga,l as _a,n as va,o as ya,p as ba,r as xa,s as Sa,t as Ca,u as wa}from"./ChartPrimitives-CvK6CQrj.js";import{t as X}from"./InfoTooltip-Drnst4ML.js";import{t as Z}from"./card-CoYH9h6o.js";import{$ as Ta,$t as Ea,A as Da,At as Oa,B as ka,Bt as Aa,C as ja,Ct as Ma,D as Na,Dt as Pa,E as Fa,Et as Ia,F as La,Ft as Ra,G as za,Gt as Ba,Ht as Va,I as Ha,It as Ua,J as Wa,Jt as Ga,K as Ka,Kt as qa,L as Ja,Lt as Ya,M as Xa,Mt as Za,N as Qa,Nt as $a,O as eo,Ot as to,P as no,Pt as ro,Q as io,Qt as ao,Rt as oo,St as so,Tt as co,U as lo,Ut as uo,V as fo,Vt as po,W as mo,Wt as ho,X as go,Xt as _o,Y as vo,Yt as yo,Z as bo,Zt as xo,_ as So,_t as Co,a as wo,an as To,b as Eo,bt as Do,c as Oo,cn as ko,ct as Ao,dt as jo,en as Mo,fn as No,ft as Po,gt as Fo,hn as Io,i as Lo,in as Ro,it as zo,j as Bo,jt as Vo,k as Ho,kt as Uo,l as Wo,ln as Go,mn as Ko,mt as qo,nn as Jo,nt as Yo,o as Xo,on as Zo,ot as Qo,pn as $o,pt as es,q as ts,qt as ns,r as rs,rn as is,s as as,st as os,tn as ss,tt as cs,u as ls,un as us,ut as ds,vt as fs,wt as ps,x as ms,xt as hs,y as gs,yt as _s,z as vs,zt as ys}from"./index-vfNb458q.js";import{a as bs,c as xs,d as Ss,f as Cs,i as ws,l as Ts,o as Es,p as Ds,r as Os,s as ks,t as As,u as js}from"./SiteHealthSection-Ch9tNd8P.js";import{t as Ms}from"./Hint-c4a4W87X.js";import{t as Ns}from"./AuditHistoryPanel-de0zJkNC.js";import{a as Ps,i as Fs,l as Is,n as Ls,o as Rs,r as zs,t as Bs}from"./service-CN0y5nRe.js";import{a as Vs,c as Hs,s as Us,t as Ws}from"./server-traffic-tgMckYtk.js";import{i as Gs,n as Ks,r as qs}from"./agent-trust-copy-2Os0XoaQ.js";function Js(e){return e.split(/[?#]/)[0]||`/`}var Ys=1e6;function Xs(e,t=`USD`,n={}){let r=new Intl.NumberFormat(`en-US`,{style:`currency`,currency:t,...n.fractionDigits===void 0?{}:{minimumFractionDigits:n.fractionDigits,maximumFractionDigits:n.fractionDigits}}),i=r.format(e/Ys);if(n.showTinyAsLessThan&&e>0&&i===r.format(0)){let e=10**-(r.resolvedOptions().maximumFractionDigits??0);return`<${r.format(e)}`}return i}var Q=e(g(),1),Zs={projectWide:`Project-wide`,projectWideHelp:`This tab covers the whole project. Your measurement scope stays selected for AI Visibility and Queries.`,savedScopeUnavailable:`Saved scope unavailable`};function Qs(e,t){return e!==`viewer`||t!==null}function $s(e,t){return e===`research`&&!t?`tracked`:e}function ec(e,t){return t.measurementScope===`project`?!1:!t.measurementScopeKey||!(t.measurementScope===`group`?e.groups:t.measurementScope===`property`?e.targets:e.markets).some(e=>e.stableKey===t.measurementScopeKey)}function tc(e,t){return e.find(e=>e.kind===t.measurementScope&&(e.kind===`project`||e.id===t.measurementScopeKey))}function nc(e){return e.measurementScope!==`project`||e.marketKey!==void 0}function rc(e){if(e.embedded)return{kind:`none`};let{tab:t}=e;switch(t){case`overview`:return e.surface===`advanced-overview`?{kind:`report-picker`}:{kind:`none`};case`queries`:case`discovery`:{let{tracking:t}=e;return e.queryWorkspace!==`tracked`||t.state!==`ready`||t.mode!==`advanced`?{kind:`none`}:t.scopeUnavailable?{kind:`scope-unavailable`}:{kind:`tracking-picker`}}case`search-console`:case`activity`:case`technical-aeo`:case`conversions`:case`local`:case`backlinks`:case`history`:return e.scoped&&e.surface===`advanced-overview`?{kind:`project-wide`}:{kind:`none`};case`client-queries`:case`settings`:case`portfolio`:case`seo-data`:case`journeys`:return{kind:`none`};default:return t}}var $=x();function ic({state:e,label:t,className:n}){return(0,$.jsx)(J,{tone:us(e),className:n,children:t??Gn(e)})}var ac=[{value:`non-brand`,label:`Non-brand`},{value:`branded`,label:`Branded`}],oc={"non-brand":`Non-brand`,branded:`Branded`,pooled:`All queries`},sc={"non-brand":`On queries that do not contain your name: of the brand names written into the answer text, the share that were yours. Branded queries are scored separately because you are named on nearly all of them and a competitor cannot be.`,branded:`On queries that contain your name: of the brand names written into the answer text, the share that were yours. This is recognition, not competitive placement, and it is never pooled with the non-brand figure.`,pooled:`This project has no brand name or domain to match on, so branded and non-brand queries could not be separated. This figure pools both and is not a competitive read. Set a display name or aliases to split them.`},cc=`Mentioned = brand in the answer. Cited = domain in the sources. Neither implies the other.`;function lc(e,t){return t.unavailable?{headline:`No data`,numeric:!1,detail:`could not load, refresh to retry`,showRows:!1}:t.noRun?{headline:`No data`,numeric:!1,detail:`no check has run yet`,showRows:!1}:e.snapshotsTotal===0?t.otherClassHasData?{headline:`No non-brand queries`,numeric:!1,detail:`every tracked query names your brand`,showRows:!1}:{headline:`No queries`,numeric:!1,detail:`none tracked`,showRows:!1}:e.snapshotsWithAnswerText===0?{headline:`No answers`,numeric:!1,detail:`no answer text in this run`,showRows:!1}:t.hasCompetitors?e.combinedMentionSnapshots===0||e.score===null?{headline:`No mentions`,numeric:!1,detail:`no brand named in ${e.snapshotsWithAnswerText} answers`,showRows:!1}:{headline:G(e.score,rt.percent),numeric:!0,detail:`${e.projectMentionSnapshots} of ${e.combinedMentionSnapshots} brand mentions`,showRows:!0}:{headline:`Add competitors`,numeric:!1,detail:`you were named in ${e.projectMentionSnapshots} of ${e.snapshotsWithAnswerText} answers`,showRows:!1}}function uc({breakdown:e,projectLabel:t}){if(e.ranking.length===0)return null;let n=e.ranking.map(e=>({label:e.kind===`project`?`${t} (you)`:e.domain??``,mentions:e.mentionSnapshots,share:e.share,isYou:e.kind===`project`}));return(0,$.jsxs)(`table`,{className:`mention-share-table`,children:[(0,$.jsx)(`caption`,{className:`sr-only`,children:`Brand mentions by domain, most mentioned first`}),(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{className:`mention-share-row mention-share-row-head`,children:[(0,$.jsx)(`th`,{scope:`col`,className:`mention-share-row-label`,children:`Domain`}),(0,$.jsx)(`th`,{"aria-hidden":`true`}),(0,$.jsxs)(`th`,{scope:`col`,className:`mention-share-count`,children:[`Mentions`,(0,$.jsx)(X,{text:cc})]}),(0,$.jsx)(`th`,{scope:`col`,className:`mention-share-share`,children:`Share`})]})}),(0,$.jsx)(`tbody`,{className:`mention-share-rows`,children:n.map(e=>(0,$.jsxs)(`tr`,{className:`mention-share-row`,children:[(0,$.jsx)(`th`,{scope:`row`,className:`mention-share-row-label ${e.isYou?`text-heading text-label-14-strong`:`text-secondary`}`,children:e.label}),(0,$.jsx)(`td`,{"aria-hidden":`true`,children:(0,$.jsx)(`div`,{className:`mention-share-bar`,children:(0,$.jsx)(`div`,{className:`mention-share-bar-fill ${e.isYou?`bg-positive-500/70`:`bg-mono-500/60`}`,style:{width:`${e.share>0?Math.max(e.share*100,1.5):0}%`}})})}),(0,$.jsx)(`td`,{className:`mention-share-count`,children:e.mentions}),(0,$.jsx)(`td`,{className:`mention-share-share`,children:G(e.share)})]},e.label))})]})}function dc({summary:e,projectLabel:t,competitorDomains:n}){let[r,i]=(0,Q.useState)(`non-brand`),a=(0,Q.useId)(),o=e.scope===`pooled`,s=!o&&e.branded.snapshotsTotal>0,c=s?r:`non-brand`,l=o?`pooled`:c,u=c===`branded`?e.branded:e.breakdown,d=c===`branded`?e.breakdown:e.branded,f=lc(u,{hasCompetitors:n.length>0,unavailable:e.unavailable===!0,noRun:e.breakdown.snapshotsTotal===0&&e.branded.snapshotsTotal===0,otherClassHasData:d.snapshotsTotal>0}),p=Pn(f.headline),m=l===`non-brand`?ko[e.tone]:`text-secondary`;function h(e){let t=ac.findIndex(e=>e.value===c),n=null;e.key===`ArrowRight`||e.key===`ArrowDown`?n=(t+1)%ac.length:e.key===`ArrowLeft`||e.key===`ArrowUp`?n=(t-1+ac.length)%ac.length:e.key===`Home`?n=0:e.key===`End`&&(n=ac.length-1),n!==null&&(e.preventDefault(),i(ac[n].value),e.currentTarget.querySelectorAll(`[role="radio"]`)[n]?.focus())}return(0,$.jsxs)(`div`,{className:`mention-share`,children:[(0,$.jsxs)(`div`,{className:`mention-share-head`,children:[(0,$.jsxs)(`div`,{className:`mention-share-label`,children:[(0,$.jsx)(`h3`,{id:a,className:`mention-share-label-text`,children:`Mention share`}),(0,$.jsx)(X,{text:sc[l]})]}),s?(0,$.jsx)(`div`,{role:`radiogroup`,"aria-labelledby":a,className:`segmented flex-wrap`,onKeyDown:h,children:ac.map(e=>{let t=e.value===c;return(0,$.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":t,tabIndex:t?0:-1,onClick:()=>i(e.value),className:`segmented-option min-h-11 ${t?`segmented-option-active`:``}`,children:e.label},e.value)})}):(0,$.jsx)(`span`,{className:`mention-share-class`,children:oc[l]})]}),f.numeric?(0,$.jsxs)(`p`,{className:`mention-share-value ${m}`,children:[p.figure,p.sign?(0,$.jsx)(`span`,{className:`text-faint`,children:p.sign}):null]}):(0,$.jsx)(`p`,{className:`mention-share-value-text`,children:f.headline}),(0,$.jsxs)(`p`,{className:`mention-share-caption`,children:[(0,$.jsx)(`span`,{className:`mention-share-caption-scope`,children:oc[l]}),` · ${f.detail}`]}),o&&(0,$.jsx)(`p`,{className:`mention-share-note`,children:`Set a brand name to split branded from non-brand.`}),f.showRows&&(0,$.jsx)(uc,{breakdown:u,projectLabel:t})]})}function fc({items:e,label:t=`Details`}){return e.length===0?null:(0,$.jsxs)(`details`,{className:`av-details`,children:[(0,$.jsx)(`summary`,{children:t}),(0,$.jsx)(`ul`,{className:`av-details-list`,children:e.map((e,t)=>(0,$.jsx)(`li`,{children:e},t))})]})}var pc=[{value:`7d`,label:`7 days`},{value:`30d`,label:`30 days`},{value:`90d`,label:`90 days`},{value:`all`,label:`All`}],mc={"7d":`last 7 days`,"30d":`last 30 days`,"90d":`last 90 days`,all:`all checks`},hc={"non-brand":`Non-brand`,branded:`Branded`,all:`All queries`},gc={"non-brand":`Counts queries that do not name your brand.`,branded:`Counts queries that name your brand.`,all:`Counts every tracked query, so mention share is not shown.`},_c={"select-query-class":`no query type selected`,"answer-selection":`answers selected by the brands they named`,"no-competitors":`no competitors configured`,"insufficient-observed":`needs 3 observed competitors, each named in 3 or more answers`,"no-answers":`no answer text`,"no-mentions":`no brands named`,unavailable:`competitor data unavailable`},vc=`Mention share: your share of the brand mentions in these answers, each brand counted at most once per answer. Named: answers that name the brand. Cited: answers whose sources link to its site. Company names in answers are observations. Only competitor sites count toward mention share.`,yc=100;function bc(e){return e?e.evidence.answeredResults>0||e.evidence.sourceResults>0?`measured`:`not-measured`:`unavailable`}function xc(e){return e===`unavailable`?`Unavailable`:`Not measured`}function Sc(e){switch(e){case`own`:return`Your domain`;case`direct-competitor`:return`Competitor`;case`ota-aggregator`:return`Aggregator`;case`editorial-media`:return`Editorial`;case`other`:return`Other`;default:return`Unclassified`}}function Cc(e,t,n){return e===1?t:n}function wc(e){let t=e.label.trim(),n=ie(e.domain);return t&&t.toLowerCase()!==e.domain.toLowerCase()&&t.toLowerCase()!==n.toLowerCase()?t:null}function Tc({row:e,aliases:t=[],autoAliases:n=[]}){let r=wc(e),i=[...t.map(e=>({alias:e,auto:!1})),...n.map(e=>({alias:e,auto:!0}))],a=i.length>0?(0,$.jsxs)(`span`,{className:`av-of block`,children:[`Also named`,` `,i.map(({alias:e,auto:t},n)=>(0,$.jsxs)(`span`,{children:[n>0?`, `:``,e,t?(0,$.jsx)(`span`,{className:`av-alias-auto`,title:`Detected automatically from this project's stored answers`,children:` (auto)`}):null]},`${t?`auto`:`curated`}:${e}`))]}):null;return r?(0,$.jsxs)($.Fragment,{children:[r,` `,(0,$.jsx)(`span`,{className:`av-of`,children:e.domain}),a]}):(0,$.jsxs)($.Fragment,{children:[e.domain,a]})}function Ec(e){let t=wc(e);return t?`${t} (${e.domain})`:e.domain}function Dc(e,t){return t&&e>=yc?(0,$.jsxs)($.Fragment,{children:[`top `,(0,$.jsx)(`strong`,{children:e})]}):(0,$.jsx)(`strong`,{children:e})}function Oc({action:e,domain:t,mutation:n}){let[r,i]=(0,Q.useState)(!1),[a,o]=(0,Q.useState)(null);async function s(){if(!r){i(!0),o(null);try{await n(t)===!1&&o(`Could not ${e} competitor. Try again.`)}catch{o(`Could not ${e} competitor. Try again.`)}finally{i(!1)}}}return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(q,{type:`button`,size:`sm`,variant:`outline`,disabled:r,onClick:()=>{s()},children:[e===`pin`?`Pin`:`Unpin`,` `,(0,$.jsx)(`span`,{className:`sr-only`,children:t})]}),a?(0,$.jsx)(`span`,{role:`alert`,className:`sr-only`,children:a}):null]})}function kc({urls:e}){return(0,$.jsxs)(`details`,{className:`inline-disclosure text-left text-label-12 text-secondary`,children:[(0,$.jsx)(`summary`,{children:`Source URLs`}),(0,$.jsx)(`ul`,{className:`mt-2 max-w-72 space-y-1 text-label-12-mono`,children:e.map(e=>(0,$.jsx)(`li`,{className:`break-all`,children:e},e))})]})}function Ac({count:e,of:t,state:n,toneClass:r}){return n===`measured`?(0,$.jsxs)(`span`,{className:`whitespace-nowrap`,children:[(0,$.jsx)(`span`,{className:`av-n-sm ${r}`,children:e}),` `,(0,$.jsxs)(`span`,{className:`av-of`,children:[`of `,t]})]}):(0,$.jsx)(`span`,{className:`text-label-13 text-secondary`,children:xc(n)})}function jc({percent:e,state:t,toneClass:n}){if(t!==`measured`||e===null)return(0,$.jsx)(`span`,{className:`text-label-13 text-secondary`,children:t===`measured`?`Not measured`:xc(t)});let{figure:r,sign:i}=Pn(G(e,rt.percent));return(0,$.jsxs)(`span`,{className:`av-n-sm ${n}`,children:[r,i?(0,$.jsx)(`span`,{className:`text-faint`,children:i}):null]})}function Mc({rows:e,state:t,named:n,cited:r,onPin:i}){return(0,$.jsx)(`div`,{className:`overflow-x-auto`,children:(0,$.jsxs)(`table`,{className:`av-grid av-grid-dense`,"aria-label":`Other competitors seen`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{scope:`col`,children:`Competitor`}),(0,$.jsx)(`th`,{scope:`col`,children:`Type`}),(0,$.jsx)(`th`,{scope:`col`,children:`Named`}),(0,$.jsx)(`th`,{scope:`col`,children:`Cited`}),(0,$.jsx)(`th`,{scope:`col`,children:(0,$.jsx)(`span`,{className:`sr-only`,children:`Actions`})})]})}),(0,$.jsx)(`tbody`,{children:e.map(e=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{scope:`row`,className:`av-row-label`,children:(0,$.jsx)(Tc,{row:e})}),(0,$.jsx)(`td`,{className:`text-label-13 text-secondary`,children:Sc(e.surfaceClass)}),(0,$.jsx)(`td`,{children:(0,$.jsx)(Ac,{count:e.mentionCount,of:n,state:t,toneClass:`text-primary`})}),(0,$.jsx)(`td`,{children:(0,$.jsx)(Ac,{count:e.citationCount,of:r,state:t,toneClass:`text-primary`})}),(0,$.jsx)(`td`,{children:(0,$.jsxs)(`div`,{className:`flex min-w-max items-start gap-2`,children:[t===`measured`&&e.sampleUrls.length>0?(0,$.jsx)(kc,{urls:e.sampleUrls}):null,i?(0,$.jsx)(Oc,{action:`pin`,domain:e.domain,mutation:i}):null]})})]},e.domain))})]})})}function Nc({onAddCompetitor:e}){let t=(0,Q.useId)(),[n,r]=(0,Q.useState)(``),[i,a]=(0,Q.useState)(!1),[o,s]=(0,Q.useState)(null);async function c(){let t=n.trim();if(t&&!i){a(!0),s(null);try{if(await e(t)===!1){s(`Could not add competitor. Try again.`);return}r(``)}catch{s(`Could not add competitor. Try again.`)}finally{a(!1)}}}return(0,$.jsxs)(`details`,{className:`inline-disclosure`,children:[(0,$.jsx)(`summary`,{children:`Manage competitors`}),(0,$.jsxs)(`form`,{className:`mt-3 flex flex-wrap items-end gap-2`,onSubmit:e=>{e.preventDefault(),c()},"aria-busy":i,children:[(0,$.jsxs)(`label`,{htmlFor:t,className:`min-w-56 flex-1 text-label-14-strong text-heading`,children:[`Competitor domain`,(0,$.jsx)(`input`,{id:t,type:`text`,value:n,onChange:e=>r(e.target.value),placeholder:`competitor.com`,className:`mt-1 h-10 w-full rounded-md border border-default bg-surface px-3 text-label-14 text-primary placeholder-mono-400 focus:outline-none focus:ring-2 focus:ring-mono-400`})]}),(0,$.jsx)(q,{type:`submit`,size:`sm`,className:`min-h-10`,disabled:i||!n.trim(),children:i?`Adding…`:`Add competitor`}),o?(0,$.jsx)(`p`,{role:`alert`,className:`w-full text-copy-14 text-negative`,children:o}):null]})]})}function Pc({window:e,landscape:t,pinnedFallback:n=[],competitorAliases:r={},competitorAutoAliases:i={},canWrite:a,isEmbed:o,onWindowChange:s,onPin:c,onUnpin:l,onAddCompetitor:u,error:d,onRetry:f,isLoading:p=!1,scopeLabel:m,advancedPortfolio:h=!1}){let g=(0,Q.useId)(),_=a&&!o,v=t?.pinned??n,y=t?.observed??[],b=t?.otherSources??[],x=t?.evidence,S=bc(t),C=t?.basis===`observed`,w=C?y.filter(e=>e.shareOfVoice!==null):v,T=C?y.filter(e=>e.shareOfVoice===null):y,E=t?.filters.queryClass,D=t?.marketState?.draft?.pendingCompetitorDomains.length??0,O=t?.truncated===!0,k=x?.answeredResults??0,A=x?x.answeredResults+x.missingAnswerTextResults:0,j=E===`non-brand`&&t?.project.shareOfVoice!=null?ko[Go(t.project.shareOfVoice)]:`text-primary`,M=e=>_?e.pinned?l?(0,$.jsx)(Oc,{action:`unpin`,domain:e.domain,mutation:l}):null:c?(0,$.jsx)(Oc,{action:`pin`,domain:e.domain,mutation:c}):null:null,N=w.some(e=>M(e)!==null),P=[m,E?hc[E]:null,mc[e],t?.basis?C?`observed competitors only`:`tracked competitors only`:null].filter(Boolean).join(` · `),F=[];if(t&&!C&&w.length===0&&F.push({key:`no-pins`,text:`No pinned competitors.`}),t?.reason&&F.push({key:`reason`,text:`Mention share: ${_c[t.reason]}`}),t&&T.length>0){let e=T.length;F.push({key:`others`,text:O&&e>=yc?`${yc} or more other competitors seen`:`${e} other ${Cc(e,`competitor`,`competitors`)} seen`})}D>0&&F.push({key:`pending`,text:`${t?.scope.kind===`all-markets`?`Pending publication across markets`:`Pending publication`}: ${D} ${Cc(D,`competitor`,`competitors`)}`});let I=[x&&x.missingAnswerTextResults>0?`Answer data incomplete`:null,x&&x.incompleteSourceResults>0?`Citation data incomplete`:null].filter(Boolean);I.length>0&&F.push({key:`incomplete`,text:I.join(` · `),className:ko.caution});let L=[];if(t&&x){L.push(t.runCount===void 0?(0,$.jsxs)($.Fragment,{children:[`Base: `,(0,$.jsx)(`strong`,{children:x.answeredResults}),` `,Cc(x.answeredResults,`answer`,`answers`)]}):(0,$.jsxs)($.Fragment,{children:[`Base: `,(0,$.jsx)(`strong`,{children:t.runCount}),` `,Cc(t.runCount,`check`,`checks`),`, `,(0,$.jsx)(`strong`,{children:x.answeredResults}),` `,Cc(x.answeredResults,`answer`,`answers`)]})),!t.reason&&S===`measured`&&t.project.shareOfVoice!==null&&L.push((0,$.jsxs)($.Fragment,{children:[`Mention share: you `,(0,$.jsx)(`strong`,{children:t.project.mentionCount}),w.map(e=>(0,$.jsxs)(Q.Fragment,{children:[`, `,e.domain,` `,(0,$.jsx)(`strong`,{children:e.mentionCount})]},e.domain)),` `,`of `,(0,$.jsx)(`strong`,{children:x.mentionCredits}),` `,C?`brand mentions`:`tracked-brand mentions`]})),L.push((0,$.jsxs)($.Fragment,{children:[`Answers with source links: `,(0,$.jsx)(`strong`,{children:x.sourceResults})]})),T.length===0&&L.push(`Other competitors seen: none`),x.missingAnswerTextResults>0&&L.push((0,$.jsxs)($.Fragment,{children:[`No answer text: `,(0,$.jsx)(`strong`,{children:x.missingAnswerTextResults}),` `,Cc(x.missingAnswerTextResults,`answer`,`answers`),`, left out of mention share`]})),x.incompleteSourceResults>0&&L.push((0,$.jsxs)($.Fragment,{children:[`Incomplete source lists: `,(0,$.jsx)(`strong`,{children:x.incompleteSourceResults}),` `,Cc(x.incompleteSourceResults,`answer`,`answers`),`, not counted as misses`]}));let e=x.excludedProbeResults+x.excludedNonCompletedResults;e>0&&L.push((0,$.jsxs)($.Fragment,{children:[`Left out: `,(0,$.jsx)(`strong`,{children:e}),` `,Cc(e,`answer`,`answers`),` from spot checks or unfinished checks`]}))}let R=[...t?[{name:`You`,row:t.project}]:[],...w.map(e=>({name:e.domain,row:e}))].filter(e=>e.row.sampleUrls.length>0);S===`measured`&&R.length>0&&L.push((0,$.jsxs)(`details`,{className:`av-subdetails`,children:[(0,$.jsx)(`summary`,{children:`Sample pages cited`}),(0,$.jsx)(`div`,{className:`av-subdetails-body`,children:R.map(({name:e,row:t})=>(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{children:e}),(0,$.jsx)(`ul`,{className:`space-y-1 text-label-12-mono text-muted`,children:t.sampleUrls.map(e=>(0,$.jsx)(`li`,{className:`break-all`,children:e},e))})]},t.domain))})]})),t&&T.length>0&&L.push((0,$.jsxs)(`details`,{className:`av-subdetails`,children:[(0,$.jsxs)(`summary`,{children:[`Other competitors seen: `,Dc(T.length,O)]}),(0,$.jsx)(`div`,{className:`av-subdetails-body`,children:(0,$.jsx)(Mc,{rows:T,state:S,named:k,cited:A,onPin:_?c:void 0})})]}));let ee=t?.observedNames??[];if(ee.length>0){let e=t?.observedNamesTotal??ee.length;L.push((0,$.jsxs)(`details`,{className:`av-subdetails`,children:[(0,$.jsxs)(`summary`,{children:[`Company names in answers: `,e>ee.length?(0,$.jsxs)($.Fragment,{children:[`top `,(0,$.jsx)(`strong`,{children:ee.length}),` of `,(0,$.jsx)(`strong`,{children:e})]}):(0,$.jsx)(`strong`,{children:ee.length})]}),(0,$.jsx)(`ul`,{className:`av-subdetails-body`,children:ee.map(e=>(0,$.jsxs)(`li`,{children:[e.name,` · `,e.answerCount,` `,Cc(e.answerCount,`answer`,`answers`)]},e.name))})]}))}return b.length>0&&L.push((0,$.jsxs)(`details`,{className:`av-subdetails`,children:[(0,$.jsxs)(`summary`,{children:[`Other sites cited: `,Dc(b.length,O)]}),(0,$.jsx)(`ul`,{className:`av-subdetails-body`,children:b.map(e=>(0,$.jsxs)(`li`,{children:[(0,$.jsxs)(`span`,{children:[Ec(e),` · `,Sc(e.surfaceClass),` · `,e.citationCount,` `,Cc(e.citationCount,`citation`,`citations`)]}),e.sampleUrls.length>0?(0,$.jsx)(`ul`,{className:`mt-1 space-y-1 text-label-12-mono text-muted`,children:e.sampleUrls.map(e=>(0,$.jsx)(`li`,{className:`break-all`,children:e},e))}):null]},e.domain))})]})),(0,$.jsxs)(`section`,{"aria-labelledby":g,"aria-busy":p,className:`overview-brief`,children:[(0,$.jsxs)(`div`,{className:`av-card-head`,children:[(0,$.jsxs)(`div`,{className:`inline-flex items-center`,children:[(0,$.jsx)(`h2`,{id:g,className:`av-card-title`,children:`Competitors over time`}),(0,$.jsx)(X,{text:E?`${gc[E]} ${vc}`:vc})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[(0,$.jsx)(`p`,{className:`av-card-meta`,children:P}),(0,$.jsx)(fs,{label:`Competitors over time window`,className:`flex-wrap`,options:pc,value:e,onChange:s})]})]}),(0,$.jsxs)(`div`,{className:`av-card-body space-y-3`,children:[d?(0,$.jsxs)(`div`,{role:`alert`,className:`flex flex-wrap items-center gap-3 border-y border-negative-800/40 bg-negative-950/20 py-3 text-label-14 text-negative`,children:[(0,$.jsx)(`span`,{children:d}),f?(0,$.jsx)(q,{type:`button`,size:`sm`,variant:`outline`,onClick:f,children:`Retry competitors over time`}):null]}):null,p&&!t&&v.length===0?(0,$.jsx)(`div`,{role:`status`,"aria-live":`polite`,className:`h-24 animate-pulse rounded-md bg-surface`,children:(0,$.jsx)(`span`,{className:`sr-only`,children:`Loading competitors over time`})}):t||w.length>0?(0,$.jsxs)(`table`,{className:`av-grid av-grid-brands`,"aria-label":`Competitors over time`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{scope:`col`,children:(0,$.jsx)(`span`,{className:`sr-only`,children:`Brand`})}),(0,$.jsx)(`th`,{scope:`col`,className:`av-brand-type`,children:`Type`}),(0,$.jsx)(`th`,{scope:`col`,children:`Mention share`}),(0,$.jsx)(`th`,{scope:`col`,children:`Named`}),(0,$.jsx)(`th`,{scope:`col`,children:`Cited`}),N?(0,$.jsx)(`th`,{scope:`col`,className:`av-brand-actions`,children:(0,$.jsx)(`span`,{className:`sr-only`,children:`Actions`})}):null]})}),(0,$.jsxs)(`tbody`,{children:[t?(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{scope:`row`,className:`av-row-label`,children:t.project.label.trim()?(0,$.jsxs)($.Fragment,{children:[t.project.label.trim(),` `,(0,$.jsx)(`span`,{className:`av-of`,children:`(you)`})]}):`You`}),(0,$.jsx)(`td`,{className:`av-brand-type text-label-13 text-secondary`,children:`Your brand`}),(0,$.jsx)(`td`,{children:(0,$.jsx)(jc,{percent:t.project.shareOfVoice,state:S,toneClass:j})}),(0,$.jsx)(`td`,{children:(0,$.jsx)(Ac,{count:t.project.mentionCount,of:k,state:S,toneClass:j})}),(0,$.jsxs)(`td`,{children:[(0,$.jsx)(Ac,{count:t.project.citationCount,of:A,state:S,toneClass:j}),h&&S===`measured`?(0,$.jsx)(`span`,{className:`block text-label-13 text-secondary`,children:Fn(t.project.domain,`cited`)}):null]}),N?(0,$.jsx)(`td`,{className:`av-brand-actions`}):null]}):null,w.map(e=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{scope:`row`,className:`av-row-label`,children:(0,$.jsx)(Tc,{row:e,aliases:e.pinned?r[e.domain]:void 0,autoAliases:e.pinned?i[e.domain]:void 0})}),(0,$.jsx)(`td`,{className:`av-brand-type text-label-13 text-secondary`,children:Sc(e.surfaceClass)}),(0,$.jsx)(`td`,{children:(0,$.jsx)(jc,{percent:e.shareOfVoice,state:S,toneClass:`text-primary`})}),(0,$.jsx)(`td`,{children:(0,$.jsx)(Ac,{count:e.mentionCount,of:k,state:S,toneClass:`text-primary`})}),(0,$.jsx)(`td`,{children:(0,$.jsx)(Ac,{count:e.citationCount,of:A,state:S,toneClass:`text-primary`})}),N?(0,$.jsx)(`td`,{className:`av-brand-actions`,children:M(e)}):null]},e.domain))]})]}):null,F.length>0?(0,$.jsx)(`div`,{className:`space-y-1 text-label-13 text-secondary`,children:F.map(e=>(0,$.jsx)(`p`,{className:e.className,children:e.text},e.key))}):null]}),(0,$.jsx)(fc,{items:L}),_&&u?(0,$.jsx)(`div`,{className:`border-t border-subtle px-5 py-3`,children:(0,$.jsx)(Nc,{onAddCompetitor:u})}):null]})}function Fc({history:e,maxDots:t=12,signal:n=`citations`}){let r=e.slice(-t);if(r.length===0)return(0,$.jsx)(`span`,{className:`text-label-13 text-secondary`,children:`No data`});let i=n===`mentions`?`Mention`:`Citation`,a=n===`mentions`?{cited:`mentioned`,"not-cited":`not mentioned`,lost:`mention lost`,emerging:`new mention`,pending:`mention pending`}:{cited:`cited`,"not-cited":`not cited`,lost:`citation lost`,emerging:`new citation`,pending:`citation pending`},o={cited:`bg-positive-400`,"not-cited":`bg-mono-600`,lost:`bg-negative-400`,emerging:`bg-caution-400 ring-1 ring-caution-300/60`},s={cited:`rounded-full`,"not-cited":`rounded-sm`,lost:`rotate-45 rounded-[1px]`,emerging:`rounded-full`},c=r.length-1,l=new Date(r[0].createdAt).toLocaleDateString(void 0,{month:`short`,day:`numeric`}),u=new Date(r[c].createdAt).toLocaleDateString(void 0,{month:`short`,day:`numeric`}),d=`${r.length} ${r.length===1?`run`:`runs`}`,f=r.map((e,t)=>{let n=new Date(e.createdAt).toLocaleDateString();return`${t===c?`Latest run, `:``}${n}: ${a[e.citationState]??e.citationState}${e.model?`, model ${e.model}`:``}`}).join(`; `);return(0,$.jsxs)(`div`,{className:`inline-flex w-max items-center gap-2 whitespace-nowrap`,role:`img`,"aria-label":`${i} history across ${d}. ${f}`,children:[r.length>1?(0,$.jsx)(`span`,{className:`text-label-12 text-secondary shrink-0`,"aria-hidden":`true`,children:l}):null,(0,$.jsx)(`div`,{className:`flex shrink-0 items-center gap-[3px]`,title:d,"aria-hidden":`true`,children:r.map((e,t)=>{let n=!!(e.model&&t>0&&r[t-1]?.model&&r[t-1].model!==e.model),i=t===c;return(0,$.jsx)(`span`,{className:`h-2.5 w-2.5 shrink-0 ${s[e.citationState]??`rounded-sm`} ${o[e.citationState]??`bg-mono-700`} ${n?`ring-1 ring-caution-300/80 ring-offset-1 ring-offset-bg`:``} ${i?`outline outline-1 outline-offset-2 outline-mono-400`:``}`,title:[a[e.citationState]??e.citationState,new Date(e.createdAt).toLocaleDateString(),e.model?`model ${e.model}`:null,n?`model changed`:null,i?`latest run`:null].filter(Boolean).join(` · `)},`${e.runId}:${e.createdAt}`)})}),(0,$.jsxs)(`span`,{className:`text-label-12 shrink-0 text-secondary`,"aria-hidden":`true`,children:[u,` `,(0,$.jsx)(`span`,{children:`latest`})]})]})}function Ic(e){let t=new Map;for(let n of e)for(let e of n.runHistory){let n=t.get(e.createdAt);n?n.states.push(e.citationState):t.set(e.createdAt,{states:[e.citationState],runId:e.runId})}return[...t.entries()].sort(([e],[t])=>e.localeCompare(t)).map(([e,{states:t,runId:n}])=>({runId:n,createdAt:e,citationState:t.includes(`cited`)?`cited`:t.includes(`emerging`)?`emerging`:`not-cited`}))}var Lc=320;function Rc(e){return e===`branded`?`Branded`:e===`non-brand`?`Non-brand`:`Unclassified`}function zc(e){return e===`non-brand`?0:e===`branded`?1:2}function Bc(e){let t=[];for(let n of e){let e=t.at(-1);e&&e.queryClass===n.queryClass?e.rows.push(n):t.push({queryClass:n.queryClass,rows:[n]})}return t}function Vc(e){return e.phrase}function Hc(e,t){return t===`citations`?e.citationState:e.visibilityState===`pending`||e.answerMentioned==null&&e.visibilityState==null?`pending`:e.visibilityState===`visible`||e.answerMentioned===!0?`cited`:`not-cited`}function Uc(e,t){if(t===`mentions`)switch(e){case`cited`:return`Mentioned`;case`not-cited`:return`Not Mentioned`;case`pending`:return`Pending`;case`emerging`:return`Newly Mentioned`;case`lost`:return`No Longer Mentioned`}switch(e){case`cited`:return`Cited`;case`not-cited`:return`Not Cited`;case`lost`:return`Lost`;case`emerging`:return`Emerging`;case`pending`:return`Pending`}}function Wc(e,t){return e.map(e=>Gc(e,t))}function Gc(e,t){return t===`citations`?e:{...e,citationState:Hc(e,t),runHistory:e.runHistory.map(e=>({...e,citationState:Hc(e,t)}))}}function Kc(e,t){let n=t===`mentions`?`mention`:`citation`,r=t===`mentions`?`Mention`:`Citation`;if(e.length===0)return{key:t,label:`${r} pending`,tone:`pending`};let i=e[e.length-1].citationState,a=e.length>=2?e[e.length-2].citationState:null,o=i===`cited`||i===`emerging`,s=a===`cited`||a===`emerging`;return i===`lost`||a!==null&&s&&!o?{key:t,label:`Lost ${n}`,tone:`negative`}:i===`emerging`||a!==null&&!s&&o?{key:t,label:`New ${n}`,tone:`positive`}:a===null&&o?{key:t,label:`First ${n}`,tone:`positive`}:o?{key:t,label:t===`mentions`?`Still mentioned`:`Still cited`,tone:`neutral`}:{key:t,label:`No ${n}`,tone:`neutral`}}function qc(e){let t=Ic(Wc(e,`mentions`)),n=Ic(e);return[Kc(t,`mentions`),Kc(n,`citations`)]}function Jc({signal:e}){let t=e.tone===`positive`?`text-positive`:e.tone===`negative`?`text-negative`:e.tone===`pending`?`text-caution`:`text-secondary`;return(0,$.jsx)(`span`,{className:t,children:e.label})}function Yc({items:e}){return(0,$.jsx)(`div`,{className:`query-evidence-signals`,"aria-label":`Latest run mention and citation signals`,children:qc(e).map(e=>(0,$.jsx)(Jc,{signal:e},e.key))})}function Xc({queryClass:e,actions:t}){return(0,$.jsxs)($.Fragment,{children:[t?(0,$.jsx)(`div`,{className:`query-evidence-toolbar`,children:(0,$.jsxs)(`div`,{className:`query-evidence-actions`,children:[!e&&(0,$.jsx)(eo,{}),t]})}):null,e?(0,$.jsx)(Ho,{queryClass:e,manage:!!t}):null]})}function Zc({evidence:e,compareLocations:t=!1,defaultDensity:n=`detailed`,providerSelection:r,onProviderSelectionChange:i,addedQueries:a=[],actions:o,actionPanel:s}){let{openEvidence:c}=Ta(),l=(0,Q.useId)(),[d,f]=(0,Q.useState)(new Set),p=Xa(),[m,h]=(0,Q.useState)(`mentions`),[g,_]=(0,Q.useState)(n),[v,y]=(0,Q.useState)(`all`),[b,x]=(0,Q.useState)(``),S=r??b,C=e=>{x(e),i?.(e)},w=(0,Q.useMemo)(()=>[...new Set([...e.map(e=>e.provider).filter(Boolean),...S?[S]:[]])].sort(),[e,S]),T=(0,Q.useMemo)(()=>{let n=new Map;for(let r of e){if(S&&r.provider!==S)continue;let e=r.query,i=r.queryClass??null,a=t?r.location??null:null,o=JSON.stringify([e,i,a]),s=n.get(o)??{key:o,phrase:e,queryClass:i,location:a,items:[],rawItems:[]};s.items.push(Gc(r,m)),s.rawItems.push(r),n.set(o,s)}return[...n.values()].sort((e,t)=>zc(e.queryClass)-zc(t.queryClass))},[e,m,t,S]),E=(0,Q.useMemo)(()=>T.filter(e=>v===`all`||(v===`unclassified`?e.queryClass===null:e.queryClass===v)),[T,v]),D=Ds({rows:E,getSearchText:Vc}),O=(0,Q.useMemo)(()=>{let e=new Map;for(let t of D.filteredRows){let n=e.get(t.queryClass)??new Set;n.add(t.phrase),e.set(t.queryClass,n)}return e},[D.filteredRows]),k=(0,Q.useMemo)(()=>new Set(a.map(Pe)),[a]),A=p?6:5,j=D.rows.map(e=>e.key),M=j.length>0&&j.every(e=>d.has(e)),N=e=>{f(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},P=m===`mentions`?`mentioned`:`cited`,F=m===`mentions`?`Mention History`:`Citation History`,I=m===`mentions`?`mentioned`:`cited`;return(0,$.jsxs)(`div`,{className:`query-evidence`,children:[(0,$.jsx)(Xc,{queryClass:v,actions:o}),s,(0,$.jsxs)(`div`,{className:`query-evidence-view-row`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(`div`,{className:`query-evidence-tabs`,role:`tablist`,"aria-label":`Citation tracking view`,children:[`mentions`,`citations`].map(e=>(0,$.jsx)(`button`,{id:`${l}-${e}`,type:`button`,role:`tab`,"aria-controls":l,"aria-selected":m===e,tabIndex:m===e?0:-1,onClick:()=>h(e),onKeyDown:t=>{if(![`ArrowLeft`,`ArrowRight`,`Home`,`End`].includes(t.key))return;t.preventDefault();let n=t.key===`Home`?`mentions`:t.key===`End`||e===`mentions`?`citations`:`mentions`;h(n),document.getElementById(`${l}-${n}`)?.focus()},children:e===`mentions`?`Mentions`:`Citations`},e))}),(0,$.jsx)(X,{text:`Mentions track your brand or domain in answer text. Citations track your domain in source links. Each signal is measured independently.`})]}),(0,$.jsxs)(`div`,{className:`query-evidence-display-controls`,children:[(0,$.jsxs)(`label`,{className:`query-evidence-preview-toggle`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:g===`detailed`,onChange:e=>_(e.target.checked?`detailed`:`compact`)}),`Show answer previews`]}),(0,$.jsx)(q,{type:`button`,variant:`ghost`,className:`pointer-coarse:min-h-11`,disabled:j.length===0,onClick:()=>{f(e=>{let t=new Set(e);for(let e of j)M?t.delete(e):t.add(e);return t})},children:M?`Collapse page`:`Expand page`})]})]}),e.length>0||S?(0,$.jsxs)(`div`,{className:`query-evidence-filters`,children:[(0,$.jsx)(js,{value:D.query,onChange:D.setQuery,label:`Find a query`,placeholder:`Find a query`,className:`query-evidence-search`}),(0,$.jsxs)(`label`,{className:`query-evidence-filter`,children:[(0,$.jsx)(`span`,{className:`sr-only`,children:`Answer engine`}),(0,$.jsxs)(`select`,{value:S,onChange:e=>{C(e.target.value),D.setPage(1)},children:[(0,$.jsx)(`option`,{value:``,children:`All engines`}),w.map(e=>(0,$.jsx)(`option`,{value:e,children:po(e)},e))]})]}),(0,$.jsxs)(`label`,{className:`query-evidence-filter`,children:[(0,$.jsx)(`span`,{className:`sr-only`,children:`Query class`}),(0,$.jsxs)(`select`,{value:v,onChange:e=>{y(e.target.value),D.setPage(1)},children:[(0,$.jsx)(`option`,{value:`all`,children:`All queries`}),(0,$.jsx)(`option`,{value:`branded`,children:`Branded`}),(0,$.jsx)(`option`,{value:`non-brand`,children:`Non-brand`}),(0,$.jsx)(`option`,{value:`unclassified`,children:`Unclassified`})]})]})]}):null,(0,$.jsxs)(`div`,{id:l,role:`tabpanel`,"aria-labelledby":`${l}-${m}`,children:[(0,$.jsx)(`div`,{className:`query-evidence-table-wrap`,children:(0,$.jsxs)(`table`,{className:`evidence-table query-evidence-table`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{scope:`col`,children:`Query`}),(0,$.jsx)(`th`,{scope:`col`,children:`Status`}),p&&(0,$.jsx)(`th`,{scope:`col`,"aria-label":`Sentiment`,children:(0,$.jsxs)(`span`,{className:`inline-flex items-center`,children:[`Sentiment`,(0,$.jsx)(X,{text:`Branded query rows show the favorable share of judged answers. Non-brand rows show only their unfavorable and mixed answers. Expanded engine rows show each stored answer’s sentiment; factual and unmentioned answers are not judgments.`})]})}),(0,$.jsx)(`th`,{scope:`col`,children:F}),(0,$.jsx)(`th`,{scope:`col`,children:`Latest run`}),(0,$.jsx)(`th`,{children:(0,$.jsx)(`span`,{className:`sr-only`,children:`Answer`})})]})}),Bc(D.rows).map(e=>(0,$.jsxs)(`tbody`,{children:[(0,$.jsx)(`tr`,{className:`query-evidence-group`,children:(0,$.jsxs)(`th`,{scope:`rowgroup`,colSpan:A,children:[Rc(e.queryClass),` (`,O.get(e.queryClass)?.size??0,`)`]})}),e.rows.map(({key:e,phrase:n,queryClass:r,location:i,items:a,rawItems:o})=>{let s=d.has(e),f=j.indexOf(e),h=`${l}-query-${f}`,_=k.has(Pe(n)),v=a.map(e=>e.citationState),y=v.includes(`cited`)?`cited`:v.includes(`emerging`)?`emerging`:v.includes(`lost`)?`lost`:v.every(e=>e===`pending`)?`pending`:`not-cited`,b=[...new Set(o.map(e=>e.queryId).filter(e=>!!e))],x=o.map(e=>e.sourceSnapshotId).filter(e=>!!e),S=Ic(a),C=a.filter(e=>e.citationState===pe.cited||e.citationState===`emerging`).length;return(0,$.jsxs)(Q.Fragment,{children:[(0,$.jsxs)(`tr`,{className:`query-evidence-row`,onClick:()=>N(e),children:[(0,$.jsx)(`td`,{className:`evidence-query-cell`,children:(0,$.jsxs)(`button`,{type:`button`,className:`query-evidence-query`,"aria-label":n,"aria-describedby":h,"aria-expanded":s,onClick:t=>{t.stopPropagation(),N(e)},children:[(0,$.jsx)(u,{size:16,"aria-hidden":`true`,className:s?`rotate-90`:``}),(0,$.jsxs)(`span`,{className:`min-w-0`,children:[(0,$.jsx)(`span`,{children:n}),(0,$.jsxs)(`span`,{id:h,className:`query-evidence-meta`,children:[(0,$.jsx)(`span`,{children:Rc(r)}),t&&(0,$.jsx)(`span`,{children:i??`No location`}),a.filter(e=>e.provider).map(e=>(0,$.jsx)(`span`,{children:po(e.provider)},e.id))]})]})]})}),(0,$.jsx)(`td`,{children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(ic,{state:y,label:Uc(y,m),className:`rounded-none border-0 bg-transparent p-0 text-label-14`}),(0,$.jsxs)(`span`,{className:`text-label-14 text-secondary tabular-nums`,"aria-label":`${C} of ${a.length} engines ${I}`,title:`${C} of ${a.length} engines ${I}`,children:[C,`/`,a.length]})]})}),p&&(0,$.jsx)(`td`,{children:(0,$.jsx)(Da,{queryId:b.length===1?b[0]:null,sourceSnapshotIds:b.length>1?[]:x,queryClass:r,location:t?i:void 0})}),(0,$.jsx)(`td`,{children:(0,$.jsx)(Fc,{history:S,signal:m})}),(0,$.jsx)(`td`,{className:`evidence-change-cell`,children:_?(0,$.jsx)(`span`,{className:`query-evidence-new`,children:`new query`}):(0,$.jsx)(Yc,{items:o})}),(0,$.jsx)(`td`,{})]}),s&&a.map((e,t)=>(0,$.jsxs)(Q.Fragment,{children:[(0,$.jsxs)(`tr`,{className:`query-evidence-engine-row`,children:[(0,$.jsx)(`td`,{className:`evidence-query-cell`,children:(0,$.jsx)(`span`,{className:`text-label-14 text-secondary`,children:e.provider?po(e.provider):`Awaiting engine`})}),(0,$.jsx)(`td`,{children:(0,$.jsx)(ic,{state:e.citationState,className:`rounded-none border-0 bg-transparent p-0 text-label-14`,label:Uc(e.citationState,m)})}),p&&(0,$.jsx)(`td`,{children:(0,$.jsx)(Na,{queryId:e.queryId,sourceSnapshotIds:e.sourceSnapshotId?[e.sourceSnapshotId]:[],queryClass:e.queryClass,provider:e.provider,location:e.location??null})}),(0,$.jsx)(`td`,{children:(0,$.jsx)(Fc,{history:e.runHistory,signal:m})}),(0,$.jsx)(`td`,{className:`evidence-change-cell`,children:_?null:(0,$.jsx)(Yc,{items:[o[t]??e]})}),(0,$.jsx)(`td`,{children:(0,$.jsx)(q,{variant:`ghost`,className:`pointer-coarse:min-h-11`,type:`button`,title:`View ${e.provider?po(e.provider):`saved`} answer for ${e.query}`,onClick:t=>{t.stopPropagation(),c(e.id)},children:`View`})})]}),g===`detailed`&&(0,$.jsx)(`tr`,{className:`query-evidence-preview-row`,children:(0,$.jsx)(`td`,{colSpan:A,children:(0,$.jsx)(el,{item:e,mode:m,onViewFull:()=>c(e.id)},m)})})]},e.id))]},e)})]},e.queryClass??`unclassified`))]})}),D.totalRows===0&&(D.hasQuery||v!==`all`||S)?(0,$.jsx)(`p`,{className:`supporting-copy mt-3`,children:`No tracked queries match this filter.`}):null,(0,$.jsx)(Ts,{page:D.page,pageSize:D.pageSize,visibleRows:D.rows.length,totalRows:D.totalRows,onPageChange:D.setPage,itemLabel:D.hasQuery||v!==`all`||S?`matches`:`queries`})]}),(0,$.jsxs)(`p`,{className:`sr-only`,"aria-live":`polite`,children:[`Showing `,P===`cited`?`citations (sources)`:`mentions (answer text)`,`.`]})]})}function Qc(e){let t=(e.matchedTerms??[]).filter(e=>e.trim().length>2),n=Qo(e),r=[];return t.length>0&&r.push({terms:t,className:`answer-highlight-brand`}),n.length>0&&r.push({terms:n,className:`answer-highlight-competitor`}),r}function $c(e,t){let n=t.toLowerCase().replace(/^www\./,``);return(e.citedCompetitorDomains??[]).some(e=>e.toLowerCase().replace(/^www\./,``)===n)}function el({item:e,mode:t,onViewFull:n}){let[r,i]=(0,Q.useState)(!1),[a,o]=(0,Q.useState)(!1);if(t===`mentions`)return(0,$.jsx)(tl,{item:e,onViewFull:n});let s=e.evidenceUrls.length>0?e.evidenceUrls.map(t=>({uri:t,title:e.groundingSources.find(e=>e.uri===t)?.title})):e.groundingSources;return(0,$.jsxs)(`div`,{className:`query-evidence-preview space-y-3`,children:[(0,$.jsx)(`p`,{className:`text-copy-13-strong text-secondary`,children:e.evidenceUrls.length>0?`Cited sources`:s.length>0?`Grounding sources`:`Cited domains`}),s.length>0?(0,$.jsx)(`ul`,{className:`space-y-4`,children:s.slice(0,a?void 0:6).map((t,n)=>(0,$.jsxs)(`li`,{className:`min-w-0`,children:[(0,$.jsx)(os,{url:t.uri,title:t.title}),$c(e,bt(t.uri)??``)&&(0,$.jsx)(`p`,{className:`mt-1 text-copy-13 text-secondary`,children:`Competitor source`})]},`${n}-${t.uri}`))}):e.citedDomains.length>0?(0,$.jsx)(`ul`,{className:`space-y-1 text-label-14 text-secondary`,children:e.citedDomains.slice(0,a?void 0:6).map(t=>(0,$.jsxs)(`li`,{className:`[overflow-wrap:anywhere]`,children:[t,$c(e,t)?` · competitor source`:``]},t))}):(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:`No cited sources captured for this run.`}),(s.length>6||s.length===0&&e.citedDomains.length>6)&&(0,$.jsx)(q,{type:`button`,variant:`ghost`,className:`pointer-coarse:min-h-11`,"aria-expanded":a,onClick:()=>o(e=>!e),children:a?`Show fewer sources`:`View all sources`}),e.answerSnippet.trim()?(0,$.jsxs)(`details`,{open:r,className:`border-t border-subtle pt-1`,children:[(0,$.jsx)(`summary`,{className:`min-h-11 cursor-pointer py-3 text-label-14 text-secondary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-mono-400`,onClick:e=>{e.preventDefault(),i(e=>!e)},children:`Answer text`}),r&&(0,$.jsx)(tl,{item:e,onViewFull:n,contextOnly:!0})]}):(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:`No answer text captured for this run.`})]})}function tl({item:e,onViewFull:t,contextOnly:n=!1}){let{matchedTerms:r,mentionedCompetitorDomains:i,mentionedCompetitorTerms:a,recommendedCompetitors:o}=e,s=(0,Q.useMemo)(()=>Qc({matchedTerms:r,mentionedCompetitorDomains:i,mentionedCompetitorTerms:a,recommendedCompetitors:o}),[r,i,a,o]);if(!(e.answerSnippet.trim().length>0))return(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:`No answer text captured for this run.`});let c=e.answerSnippet.length>Lc;return(0,$.jsxs)(`div`,{className:`query-evidence-preview space-y-3`,children:[!n&&(0,$.jsx)(`p`,{className:`text-copy-13-strong text-secondary`,children:`Answer text`}),(0,$.jsx)(Ja,{headingLevel:4,highlightGroups:s,previewLength:Lc,children:e.answerSnippet}),(!n&&e.citedDomains.length>0||(e.mentionedCompetitorDomains?.length??0)>0)&&(0,$.jsxs)(`dl`,{className:`space-y-2 text-label-13 text-secondary`,children:[!n&&e.citedDomains.length>0&&(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`dt`,{className:`text-label-13-strong`,children:`Cited domains`}),(0,$.jsxs)(`dd`,{className:`flex flex-wrap gap-x-3 gap-y-1`,children:[e.citedDomains.slice(0,6).map(t=>(0,$.jsxs)(`span`,{className:`[overflow-wrap:anywhere]`,children:[t,$c(e,t)?` · competitor source`:``]},`c-${t}`)),e.citedDomains.length>6&&(0,$.jsxs)(`span`,{children:[`+`,e.citedDomains.length-6,` more`]})]})]}),(e.mentionedCompetitorDomains?.length??0)>0&&(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`dt`,{className:`text-label-13-strong`,children:`Competitors in answer`}),(0,$.jsxs)(`dd`,{className:`flex flex-wrap gap-x-3 gap-y-1`,children:[e.mentionedCompetitorDomains.slice(0,4).map(e=>(0,$.jsx)(`span`,{className:`[overflow-wrap:anywhere]`,children:e},`co-${e}`)),e.mentionedCompetitorDomains.length>4&&(0,$.jsxs)(`span`,{children:[`+`,e.mentionedCompetitorDomains.length-4,` more`]})]})]})]}),c&&(0,$.jsx)(q,{type:`button`,variant:`ghost`,className:`pointer-coarse:min-h-11`,onClick:e=>{e.stopPropagation(),t()},children:`View full answer`})]})}function nl({windows:e,value:t,onChange:n,label:r,formatOption:i,disabled:a=!1}){return(0,$.jsx)(`div`,{className:`segmented`,role:`group`,"aria-label":r,children:e.map(e=>(0,$.jsx)(`button`,{type:`button`,"aria-pressed":t===e,disabled:a,className:`segmented-option ${t===e?`segmented-option-active`:``}`,onClick:()=>{e!==t&&B(`window`),n(e)},children:i?i(e):e},e))})}var rl=`baseline`;function il(e,t=[]){let n=(e?.series??[]).map((e,t)=>({dataKey:`s${t}`,key:e.key,label:e.label})),r=new Map;for(let t of e?.days??[])r.set(t.date,t.values);let i=new Map(t.map(e=>[e.date,e.value]));return{rows:[...new Set([...r.keys(),...i.keys()])].sort().map(e=>{let t=r.get(e),a={date:e,[rl]:i.get(e)??null};for(let e of n)a[e.dataKey]=t?.[e.key]??0;return a}),series:n}}var al=`text-label-12-strong normal-case text-muted`;function ol({id:e,title:t,tooltip:n,meta:r,actions:i}){return(0,$.jsxs)(`div`,{className:`mb-4 flex flex-wrap items-start justify-between gap-3`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`h2`,{id:e,className:`text-heading-16 text-primary`,children:t}),n&&(0,$.jsx)(X,{text:n})]}),r&&(0,$.jsx)(`p`,{className:`mt-1 text-copy-13 text-secondary`,children:r})]}),i]})}function sl({children:e}){return(0,$.jsx)(`div`,{className:`[&>details:first-child]:border-t-0`,children:e})}function cl({label:e,meta:t,children:n}){let[r,i]=(0,Q.useState)(!1);return(0,$.jsxs)(`details`,{className:`visibility-disclosure`,"aria-label":e,onToggle:e=>i(e.currentTarget.open),children:[(0,$.jsxs)(`summary`,{className:`visibility-disclosure-summary`,children:[(0,$.jsx)(`span`,{className:`visibility-disclosure-label`,children:e}),(0,$.jsx)(`span`,{className:`visibility-disclosure-meta`,children:t})]}),r&&(0,$.jsx)(`div`,{className:`visibility-disclosure-panel`,children:n})]})}var ll={3:`lg:grid-cols-3`,4:`lg:grid-cols-4`,5:`lg:grid-cols-5`};function ul({items:e,label:t}){return(0,$.jsx)(`div`,{role:`group`,"aria-label":t,children:(0,$.jsx)(`dl`,{className:`grid grid-cols-2 gap-x-6 gap-y-4 border-y border-default py-4 sm:grid-cols-3 ${ll[e.length]??`lg:grid-cols-4`}`,children:e.map(e=>(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsxs)(`dt`,{className:`flex items-center gap-1 text-label-13 text-secondary`,children:[e.label,e.tooltip&&(0,$.jsx)(X,{text:e.tooltip})]}),(0,$.jsx)(`dd`,{className:`mt-1 truncate text-label-20-strong text-primary tabular-nums`,title:e.value,children:e.value}),e.detail&&(0,$.jsx)(`dd`,{className:`mt-0.5 text-label-13 text-secondary tabular-nums`,children:e.detail})]},e.label))})})}function dl({label:e,sortKey:t,current:n,dir:r,onSort:i,align:a}){let o=n===t;return(0,$.jsx)(`th`,{className:`py-2 ${a===`right`?`pl-4 text-right`:`text-left`}`,"aria-sort":o?r===`asc`?`ascending`:`descending`:void 0,children:(0,$.jsxs)(`button`,{type:`button`,className:`${al} cursor-pointer select-none rounded transition-colors hover:text-neutral focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-mono-400`,onClick:()=>i(t),children:[e,o&&(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`ml-0.5`,children:r===`asc`?`↑`:`↓`})]})})}function fl({label:e,align:t}){return(0,$.jsx)(`th`,{className:`py-2 ${t===`right`?`pl-4 text-right`:`text-left`}`,children:(0,$.jsx)(`span`,{className:al,children:e})})}function pl(e,t,n=`desc`){return e.key===t?{key:t,dir:e.dir===`desc`?`asc`:`desc`}:{key:t,dir:n}}function ml(e,t){return(n,r)=>{let i=n[e],a=r[e],o=typeof i==`string`&&typeof a==`string`?i.localeCompare(a):Number(i)-Number(a);return t===`asc`?o:-o}}function hl({groups:e,groupLabel:t,caption:n,childColumns:r,childRowKey:i,renderChildCells:a,pinLast:o}){let s=(0,Q.useId)(),[c,l]=(0,Q.useState)(new Set),[f,p]=(0,Q.useState)({key:`sessions`,dir:`desc`}),m=(0,Q.useMemo)(()=>{let t=ml(f.key,f.dir);return[...e].sort((e,n)=>Number(o?.(e)??!1)-Number(o?.(n)??!1)||t(e,n))},[e,f,o]),h=e=>p(t=>pl(t,e,e===`label`?`asc`:`desc`)),g=e=>l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n});return(0,$.jsx)(`div`,{className:`overflow-x-auto`,children:(0,$.jsxs)(`table`,{className:`w-full min-w-[36rem] text-label-14`,children:[(0,$.jsx)(`caption`,{className:`sr-only`,children:n}),(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{className:`border-b border-default`,children:[(0,$.jsx)(dl,{label:t,sortKey:`label`,current:f.key,dir:f.dir,onSort:h,align:`left`}),(0,$.jsx)(dl,{label:`Sessions`,sortKey:`sessions`,current:f.key,dir:f.dir,onSort:h,align:`right`}),(0,$.jsx)(dl,{label:`Organic`,sortKey:`organicSessions`,current:f.key,dir:f.dir,onSort:h,align:`right`}),(0,$.jsx)(dl,{label:`Paid`,sortKey:`paidSessions`,current:f.key,dir:f.dir,onSort:h,align:`right`}),(0,$.jsx)(fl,{label:`Share`,align:`right`})]})}),(0,$.jsx)(`tbody`,{children:m.map((e,t)=>{let n=c.has(e.label),o=`${s}-group-${t}`,l=e.sources.length;return(0,$.jsxs)(Q.Fragment,{children:[(0,$.jsxs)(`tr`,{className:`border-t border-subtle`,children:[(0,$.jsx)(`td`,{className:`py-2 pr-3`,children:(0,$.jsxs)(`button`,{type:`button`,"aria-expanded":n,"aria-controls":n?o:void 0,onClick:()=>g(e.label),className:`inline-flex min-h-8 max-w-full items-center gap-2 rounded text-left text-strong hover:text-primary focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-mono-400`,children:[n?(0,$.jsx)(d,{"aria-hidden":`true`,className:`size-3.5 shrink-0 text-secondary`}):(0,$.jsx)(u,{"aria-hidden":`true`,className:`size-3.5 shrink-0 text-muted`}),(0,$.jsx)(`span`,{className:`truncate`,title:e.label,children:e.label}),(0,$.jsxs)(`span`,{className:`shrink-0 text-label-12 text-secondary tabular-nums`,children:[l,` `,l===1?`source`:`sources`]})]})}),(0,$.jsx)(`td`,{className:`py-2 pl-4 text-right text-primary tabular-nums`,children:e.sessions.toLocaleString()}),(0,$.jsx)(`td`,{className:`py-2 pl-4 text-right text-secondary tabular-nums`,children:e.organicSessions.toLocaleString()}),(0,$.jsx)(`td`,{className:`py-2 pl-4 text-right text-secondary tabular-nums`,children:e.paidSessions.toLocaleString()}),(0,$.jsx)(`td`,{className:`py-2 pl-4 text-right text-secondary tabular-nums`,children:G(e.share)})]}),n&&(0,$.jsx)(`tr`,{id:o,children:(0,$.jsx)(`td`,{colSpan:5,className:`pb-3 pl-6`,children:(0,$.jsx)(`div`,{className:`overflow-x-auto material-base px-3 pb-1`,children:(0,$.jsxs)(`table`,{className:`w-full min-w-[32rem] text-label-13`,children:[(0,$.jsx)(`caption`,{className:`sr-only`,children:`${e.label} sources`}),(0,$.jsx)(`thead`,{children:(0,$.jsx)(`tr`,{children:r.map(e=>(0,$.jsx)(fl,{label:e.label,align:e.align},e.label))})}),(0,$.jsx)(`tbody`,{children:e.sources.map(e=>(0,$.jsx)(`tr`,{className:`border-t border-subtle`,children:a(e)},i(e)))})]})})})})]},e.label)})})]})})}function gl(e,t){return e===`other`?ga.textDim:ua[t%ua.length]}function _l({input:e,baseline:t,baselineLabel:n,label:r,height:i=224}){let{rows:a,series:o}=(0,Q.useMemo)(()=>il(e,t),[e,t]),[s,c]=(0,Q.useState)(new Set),[l,u]=(0,Q.useState)(!1);if(a.length===0)return null;let d=o.filter(e=>!s.has(e.key)),f=new Map(o.map(e=>[e.dataKey,e.label])),p=e=>c(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n});return(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{role:`img`,"aria-label":r,style:{height:i},children:(0,$.jsx)(I,{width:`100%`,height:`100%`,children:(0,$.jsxs)(ne,{data:a,margin:{top:4,right:4,bottom:0,left:0},children:[(0,$.jsx)(M,{stroke:xa,vertical:!1}),(0,$.jsx)(P,{dataKey:`date`,tick:va,tickLine:!1,axisLine:{stroke:Ca},tickFormatter:fa,minTickGap:24}),(0,$.jsx)(ee,{tick:va,tickLine:!1,axisLine:!1,allowDecimals:!1,width:36}),(0,$.jsx)(N,{...Sa,labelFormatter:_a,formatter:(e,t)=>[typeof e==`number`?e.toLocaleString():String(e??0),t===`baseline`?n??`Total`:f.get(String(t))??String(t)]}),d.map(e=>{let t=gl(e.key,o.indexOf(e));return(0,$.jsx)(L,{type:`monotone`,dataKey:e.dataKey,name:e.dataKey,stackId:`stack`,stroke:t,fill:t,fillOpacity:.35,strokeWidth:1.5},e.dataKey)}),l&&n&&(0,$.jsx)(te,{type:`monotone`,dataKey:`baseline`,name:`baseline`,stroke:ga.textFaint,strokeWidth:1.5,strokeDasharray:`5 4`,dot:!1,connectNulls:!1})]})})}),(0,$.jsxs)(`fieldset`,{className:`mt-2 flex flex-wrap gap-x-5 text-label-13 text-secondary`,children:[(0,$.jsx)(`legend`,{className:`sr-only`,children:`${r} series`}),o.map((e,t)=>(0,$.jsxs)(`label`,{className:`flex min-h-9 items-center gap-2`,children:[(0,$.jsx)(`input`,{type:`checkbox`,className:`size-4 accent-mono-200 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-mono-400`,checked:!s.has(e.key),onChange:()=>p(e.key)}),(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`inline-block size-2.5 shrink-0 rounded-sm`,style:{backgroundColor:gl(e.key,t)}}),e.label]},e.key)),n&&(0,$.jsxs)(`label`,{className:`flex min-h-9 items-center gap-2`,children:[(0,$.jsx)(`input`,{type:`checkbox`,className:`size-4 accent-mono-200 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-mono-400`,checked:l,onChange:()=>u(e=>!e)}),(0,$.jsx)(`svg`,{"aria-hidden":`true`,width:`18`,height:`10`,viewBox:`0 0 18 10`,className:`shrink-0`,children:(0,$.jsx)(`line`,{x1:`0`,y1:`5`,x2:`18`,y2:`5`,stroke:ga.textFaint,strokeWidth:`2`,strokeDasharray:`5 3`})}),n]})]})]})}var vl=[`sessions`,`activeUsers`,`organicSessions`,`engagementRate`,`keyEvents`],yl=`canonry.siteTraffic.slots`;function bl(e){return typeof e==`string`&&Ce.some(t=>t===e)}function xl(){try{let e=JSON.parse(window.localStorage.getItem(yl)??`null`);if(Array.isArray(e)&&e.length===vl.length&&e.every(bl))return[...e]}catch{}return[...vl]}function Sl(e){try{window.localStorage.setItem(yl,JSON.stringify(e))}catch{}}function Cl(e,t,n){let r=$e(e,t);return r===null||t===null?{kind:`note`,text:`No earlier data`}:{kind:`delta`,amount:G(Math.abs(t),rt.percent),direction:t>0?`up`:t<0?`down`:`flat`,tone:r===Xe.better?`better`:r===Xe.worse?`worse`:`neutral`,basis:n}}function wl({overview:e,refreshing:t=!1}){let[n,r]=(0,Q.useState)(xl),[i,a]=(0,Q.useState)(0),o=rn(e.window)?Be[e.window]:null,s=o===null?`This period`:`Last ${o} days`,c=o===null?`vs the previous period`:`vs prior ${o} days`,l=(e,t)=>r(n=>{let r=[...n],i=r.indexOf(t);return i!==-1&&i!==e&&(r[i]=r[e]),r[e]=t,Sl(r),r}),u=n.map((t,n)=>({key:t,slot:`slot-${n}`,label:H[t].label,value:Ke(t,e.totals[t],{compact:!0}),exactValue:Ke(t,e.totals[t]),change:Cl(t,e.changePct[t],c),series:e.days.map(e=>({date:e.date,previousDate:e.previousDate,current:e.values[t],previous:e.previousValues[t]})),interactive:!0,picker:{ariaLabel:`Figure ${n+1}`,value:t,options:Ce.map(e=>({value:e,label:H[e].label})),onChange:e=>{bl(e)&&l(n,e)}},formatValue:e=>Ke(t,e,{compact:!0}),formatExact:e=>Ke(t,e),allowDecimals:H[t].unit!==ye.count})),d=n[i]??vl[0],f=e.current.startDate&&e.current.endDate&&e.previous.startDate&&e.previous.endDate?`${Tl(e.current.startDate,e.current.endDate,!0)} vs ${Tl(e.previous.startDate,e.previous.endDate,!1)}`:void 0;return(0,$.jsx)(Os,{name:`Site traffic figures`,groups:[{key:`site-traffic`,figures:u}],selected:[d],onSelect:e=>{let t=n.indexOf(e);t!==-1&&a(t)},span:f,currentLabel:s,previous:{label:`Previous period`,available:!0},notice:e.syncedAt===null?`These figures fill in after the next GA4 sync.`:void 0,emptyChartMessage:`No daily ${H[d].label.toLowerCase()} yet.`,refreshing:t})}function Tl(e,t,n){let r=(e,t)=>new Date(`${e}T00:00:00Z`).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`,...t?{year:`numeric`}:{},timeZone:`UTC`});return`${r(e,!1)} to ${r(t,n)}`}function El(e){return e?_a(e.slice(0,10)):`—`}function Dl({children:e,onClick:t,disabled:n,title:r}){return(0,$.jsx)(`button`,{type:`button`,title:r,disabled:n,onClick:t,className:`rounded px-1.5 py-0.5 text-button-14 text-secondary hover:bg-surface-hover hover:text-strong focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-mono-400 disabled:cursor-not-allowed disabled:opacity-50`,children:e})}function Ol({rows:e,expanded:t,loading:n,onToggle:r,actions:i,lastReadLabel:a,empty:o}){let s=i?6:5,c=(e,a)=>{let o=t.has(e.url),s=n?.has(e.url)??!1;return(0,$.jsxs)(`tr`,{className:`group`,children:[(0,$.jsx)(`td`,{className:`max-w-md ${a?`pl-9`:``}`,children:(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-0.5`,children:[e.isIndex&&!a&&(0,$.jsx)(`button`,{type:`button`,"aria-expanded":o,"aria-label":`${o?`Hide`:`Show`} the sitemaps in ${e.label}`,className:`rounded p-0.5 text-secondary hover:text-strong focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-mono-400`,onClick:()=>r(e.url),children:o?(0,$.jsx)(d,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}):(0,$.jsx)(u,{className:`h-3.5 w-3.5`,"aria-hidden":`true`})}),(0,$.jsx)(Ss,{value:e.label,title:e.url,className:`font-mono text-label-13 text-neutral`}),e.isIndex&&(0,$.jsx)(`span`,{className:`shrink-0 text-label-12 text-secondary`,children:s?`Loading…`:e.files?`Index · ${e.files.length} ${e.files.length===1?`sitemap`:`sitemaps`}`:`Index`}),e.kind&&(0,$.jsx)(`span`,{className:`shrink-0 text-label-12 text-secondary`,children:e.kind}),e.isDefault&&(0,$.jsxs)(`span`,{className:`flex shrink-0 items-center gap-1 text-label-12 text-secondary`,children:[`Default`,(0,$.jsx)(X,{text:`Canonry uses this sitemap when a command names none.`})]})]})}),(0,$.jsx)(`td`,{children:(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 whitespace-nowrap`,children:[(0,$.jsx)(J,{tone:e.status.tone,children:e.status.label}),e.status.detail&&(0,$.jsx)(`span`,{className:`text-label-12 text-secondary`,children:e.status.detail})]})}),(0,$.jsx)(`td`,{className:`text-right tabular-nums text-secondary`,children:e.urls===null?`—`:e.urls.toLocaleString()}),(0,$.jsx)(`td`,{className:`whitespace-nowrap tabular-nums text-secondary`,children:e.missing?`—`:e.submittedAt?El(e.submittedAt):a?(0,$.jsx)(`span`,{title:`Submitted through its sitemap index.`,children:`Via index`}):(0,$.jsx)(`span`,{title:`Nobody submitted it: the engine found it on its own.`,children:`Not submitted`})}),(0,$.jsx)(`td`,{className:`whitespace-nowrap tabular-nums text-secondary`,children:e.missing?`—`:e.lastReadAt?El(e.lastReadAt):`Not yet`}),i&&(0,$.jsx)(`td`,{className:`text-right`,children:(0,$.jsx)(`div`,{className:`flex justify-end gap-0.5 whitespace-nowrap ${e.missing?``:`opacity-0 transition-opacity group-hover:opacity-100 group-focus-within:opacity-100 pointer-coarse:opacity-100`}`,children:i(e,a)})})]},`${a?.url??``}|${e.url}`)};return(0,$.jsx)(`div`,{className:`overflow-x-auto`,children:(0,$.jsxs)(`table`,{className:`data-table w-full text-label-14`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{className:`text-left`,children:`Sitemap`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Status`}),(0,$.jsx)(`th`,{className:`text-right`,children:`URLs`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Submitted`}),(0,$.jsx)(`th`,{className:`text-left`,children:a}),i&&(0,$.jsx)(`th`,{className:`text-right`,children:(0,$.jsx)(`span`,{className:`sr-only`,children:`Actions`})})]})}),(0,$.jsxs)(`tbody`,{children:[e.length===0&&(0,$.jsx)(`tr`,{children:(0,$.jsx)(`td`,{colSpan:s,className:`py-6 text-center text-secondary`,children:o})}),e.map(e=>(0,$.jsxs)(Q.Fragment,{children:[c(e,null),e.isIndex&&t.has(e.url)&&(e.files??[]).map(t=>c(t,e))]},e.url))]})]})})}var kl=10,Al={ok:`positive`,pending:`neutral`,warnings:`caution`,errors:`negative`,other:`neutral`},jl={site:`on your site`,google:`in Google`,bing:`in Bing`};function Ml(e){return e.map(e=>jl[e]).join(` and `)}function Nl(e){let t=[e.errors?`${e.errors} error${e.errors===1?``:`s`}`:``,e.warnings?`${e.warnings} warning${e.warnings===1?``:`s`}`:``].filter(Boolean);return t.length>0?t.join(` · `):void 0}function Pl(e){let{engine:t,data:n,label:r}=e,[i,a]=(0,Q.useState)(!1),[o,s]=(0,Q.useState)(``),[c,l]=(0,Q.useState)(new Set),[u,d]=(0,Q.useState)(new Set),[f,p]=(0,Q.useState)(``),m=n?.sitemaps??[],h=t=>({url:t.url,label:r(t.url),isIndex:t.isIndex,kind:!t.isIndex&&t.type&&!/^sitemap$/i.test(t.type)?t.type:void 0,status:{label:t.statusLabel,tone:Al[t.state],detail:Nl(t)},urls:t.urlCount,submittedAt:t.submittedAt,lastReadAt:t.lastReadAt,isDefault:e.defaultUrl===t.url}),g=(n?.missing??[]).map(e=>({url:e.url,label:r(e.url),isIndex:!1,status:u.has(e.url)?{label:`Sent`,tone:`neutral`,detail:`shows after the next sync`}:{label:`Missing`,tone:`caution`,detail:Ml(e.foundIn)},urls:null,submittedAt:null,lastReadAt:null,missing:!0})),_=m.filter(e=>e.parentUrl===null).map(e=>({...h(e),files:e.isIndex?m.filter(t=>t.parentUrl===e.url).map(h):void 0})),v=Ds({rows:[...g,..._],getSearchText:e=>`${e.url} ${e.files?.map(e=>e.url).join(` `)??``}`,pageSize:kl});async function y(t){let n=await e.onSubmit(t);return n.length>0&&d(e=>new Set([...e,...n])),n}let b=g.filter(e=>!u.has(e.url)).length,x=_.filter(e=>e.isIndex).length;return(0,$.jsxs)(Z,{className:`surface-card`,children:[(0,$.jsxs)(`div`,{className:`section-head section-head-inline`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`h3`,{children:`Sitemaps`}),(0,$.jsx)(X,{text:`Canonry compares the sitemaps your site lists (from the latest Site Health scan) with what ${t} and the other engine have, and shows what ${t} is missing. Submitting asks ${t} to read a sitemap; it does not guarantee indexing.`})]}),b>0&&(0,$.jsx)(X,{tone:`caution`,label:`${b} missing`,text:`${b===1?`One sitemap your site or the other engine has is`:`${b} sitemaps your site or the other engine has are`} not in ${t}. Add ${b===1?`it`:`them`} from the list.`})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[n&&(0,$.jsxs)(`span`,{className:`text-label-13 text-secondary`,children:[`As of `,Nn(n.syncedAt)]}),!e.readOnly&&(e.canSubmit?(0,$.jsx)(q,{type:`button`,variant:`ghost`,size:`sm`,disabled:i||e.submitting,onClick:()=>a(!0),children:`Add another`}):e.submitBlocked)]})]}),i&&e.canSubmit&&!e.readOnly&&(0,$.jsxs)(`form`,{className:`mb-3 flex flex-col gap-2 sm:flex-row`,onSubmit:e=>{e.preventDefault();let t=o.trim();t&&y([t]).then(e=>{e.includes(t)&&(s(``),a(!1))})},children:[(0,$.jsx)(`input`,{"aria-label":`Sitemap URL`,className:`flex-1 rounded border border-strong bg-transparent px-2 py-1.5 font-mono text-label-13 text-strong placeholder-mono-400 focus:border-mono-500 focus:outline-none`,type:`url`,autoFocus:!0,placeholder:`https://example.com/sitemap.xml`,value:o,onChange:e=>s(e.target.value)}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(q,{type:`submit`,size:`sm`,disabled:e.submitting||!o.trim(),children:e.submitting?`Submitting…`:`Submit to ${t}`}),(0,$.jsx)(q,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>{a(!1),s(``)},children:`Cancel`})]})]}),e.loadError?(0,$.jsxs)(`p`,{className:`text-copy-14 text-negative`,children:[`Could not load sitemaps: `,e.loadError]}):n===void 0?(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:`Loading sitemaps…`}):n===null?e.notRead:(0,$.jsxs)($.Fragment,{children:[(_.length>0||g.length>0)&&(0,$.jsxs)(`div`,{className:`mb-2 flex flex-wrap items-center justify-between gap-2`,children:[(0,$.jsx)(js,{className:`w-full sm:w-64`,value:f,onChange:e=>{p(e),v.setQuery(e)},label:`Filter sitemaps`,placeholder:`Filter sitemaps…`}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,$.jsxs)(`span`,{className:`text-label-13 text-secondary`,children:[_.length,` in `,t,x>0?`, ${x} ${x===1?`index`:`indexes`}`:``]}),e.bulk]})]}),(0,$.jsx)(Ol,{rows:v.rows,expanded:c,onToggle:e=>l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),lastReadLabel:`Last read`,empty:`${t} lists no sitemaps for this site, and Canonry found none to add.`,actions:e.readOnly?void 0:n=>n.missing?(0,$.jsx)(Dl,{disabled:!e.canSubmit||e.submitting||u.has(n.url),onClick:()=>void y([n.url]),children:u.has(n.url)?`Sent`:`Add to ${t}`}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Dl,{disabled:!e.canSubmit||e.submitting,onClick:()=>void y([n.url]),children:n.submittedAt?`Resubmit`:`Submit`}),e.onInspect&&(0,$.jsx)(Dl,{disabled:e.inspecting,onClick:()=>e.onInspect(n.url),children:`Inspect URLs`}),e.onSetDefault&&!n.isDefault&&(0,$.jsx)(Dl,{disabled:e.settingDefault,title:`Canonry uses this sitemap when a command names none.`,onClick:()=>e.onSetDefault(n.url),children:`Set as default`})]})}),v.totalRows>kl&&(0,$.jsx)(Ts,{page:v.page,pageSize:kl,visibleRows:v.rows.length,totalRows:v.totalRows,onPageChange:v.setPage,itemLabel:`sitemaps`})]})]})}function Fl({label:e,items:t,disabled:n=!1,menuLabel:r}){let[i,a]=(0,Q.useState)(!1),o=(0,Q.useRef)(null),s=(0,Q.useRef)(null),c=(0,Q.useId)();return(0,Q.useEffect)(()=>{if(!i)return;o.current?.querySelector(`[role="menuitem"]:not([disabled])`)?.focus();let e=e=>{o.current&&!o.current.contains(e.target)&&a(!1)},t=e=>{e.key===`Escape`&&(a(!1),s.current?.focus())};return document.addEventListener(`pointerdown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`pointerdown`,e),document.removeEventListener(`keydown`,t)}},[i]),(0,$.jsxs)(`div`,{className:`relative inline-flex`,ref:o,children:[(0,$.jsxs)(q,{ref:s,type:`button`,variant:`outline`,size:`sm`,disabled:n,"aria-haspopup":`menu`,"aria-expanded":i,"aria-controls":i?c:void 0,onClick:()=>a(e=>!e),children:[e,(0,$.jsx)(d,{className:`h-3.5 w-3.5`,"aria-hidden":`true`})]}),i&&(0,$.jsx)(`div`,{id:c,role:`menu`,"aria-label":r,className:`project-subnav-menu min-w-[16rem]`,onKeyDown:e=>{let t=[...e.currentTarget.querySelectorAll(`[role="menuitem"]:not([disabled])`)],n=t.indexOf(document.activeElement),r=e.key===`ArrowDown`?(n+1)%t.length:e.key===`ArrowUp`?(n-1+t.length)%t.length:null;r!==null&&(e.preventDefault(),t[r]?.focus())},onBlur:e=>{o.current?.contains(e.relatedTarget)||a(!1)},children:t.map(e=>(0,$.jsxs)(`button`,{type:`button`,role:`menuitem`,tabIndex:-1,disabled:e.disabled,className:`project-subnav-menu-item flex flex-col items-start gap-0.5 text-left disabled:cursor-not-allowed disabled:opacity-50`,onClick:()=>{a(!1),e.onSelect()},children:[(0,$.jsx)(`span`,{children:e.label}),e.description&&(0,$.jsx)(`span`,{className:`text-label-13 text-secondary`,children:e.description})]},e.key))})]})}function Il(e){let t=e.details;if(e.code!==`FORBIDDEN`||!t||t.reason!==`gsc-api-disabled`)return null;let n=typeof t.projectNumber==`string`?t.projectNumber:void 0;return{title:`Enable the Search Console API`,message:`Your Google Cloud project${n?` (${n})`:``} hasn't enabled the Search Console API. Enable the Search Console API and the Indexing API, wait ~2–5 minutes, then retry.`,enableUrl:typeof t.enableUrl==`string`?t.enableUrl:void 0,indexingApiUrl:typeof t.indexingApiUrl==`string`?t.indexingApiUrl:void 0,projectNumber:n}}var Ll=`Search Console is not connected yet. Your Canonry team can set this up.`,Rl=[`7d`,`30d`,`90d`,`all`],zl=500,Bl=[{key:`clicks`,label:`Clicks`,color:ua[1],format:e=>e.toLocaleString()},{key:`impressions`,label:`Impressions`,color:ua[4],format:e=>e.toLocaleString()},{key:`ctr`,label:`CTR`,color:ya.caution,format:e=>G(e)},{key:`position`,label:`Avg position`,color:ua[2],inverted:!0,format:e=>e.toFixed(1)}],Vl=25,Hl=`canonry:google-oauth-complete`;function Ul(e,t,n){if(!e)return{kind:`note`,text:`No comparison period`};if(!e.comparable)return{kind:`note`,text:`Property-level comparison unavailable`};let r=`${e.days} ${e.days===1?`day`:`days`}`,i=`vs prior ${r}`,a=e=>e===!!n?`worse`:`better`,o=t===`ctr`||t===`position`?e.difference?.[t]:void 0;if(o!=null&&Number.isFinite(o))return o===0?{kind:`delta`,amount:t===`ctr`?`0 pts`:`0`,direction:`flat`,tone:`neutral`,basis:i}:{kind:`delta`,amount:t===`ctr`?`${bn(Math.abs(o)).magnitude} pts`:Tn(o),direction:o>0?`up`:`down`,tone:a(o>0),basis:i};let s=e.change[t];if(s===null||!Number.isFinite(s)){let n=e.prior[t],i=e.trailing[t];return n!==null&&i!==null&&n<=0&&i>0?{kind:`note`,text:`New in the last ${r}`}:n===null||n<=0?{kind:`note`,text:`No prior ${r} to compare`}:i===null?{kind:`note`,text:`No value in the last ${r}`}:{kind:`note`,text:`Comparison unavailable`}}return s===0?{kind:`delta`,amount:`0%`,direction:`flat`,tone:`neutral`,basis:i}:{kind:`delta`,amount:G(Math.abs(s)),direction:s>0?`up`:`down`,tone:a(s>0),basis:i}}var Wl=[{key:`google-indexed`,engine:`google`,color:ua[0]},{key:`bing-indexed`,engine:`bing`,color:ua[6]}];function Gl(e){if(!e)return`Tile percentages compare the selected window with the equal-length period before it.`;let{days:t,basis:n,prior:r,trailing:i}=e,a=t===1?`day`:`days`,o=`${r.startDate} to ${r.endDate}`,s=`Tile percentages compare these ${t} ${a} (${`${i.startDate} to ${i.endDate}`}) with the ${t} ${a} before them (${o}).`;return n===`split-window`?`${s} That is the trailing half of the selected window against its own earlier half: there is no equal-length period before the window with synced data to compare it against.`:s}function Kl(e,t){let n;try{n=new URL(e)}catch{return e}let r=`${n.pathname}${n.search}`;if(t?.startsWith(`sc-domain:`)){if(n.hostname===t.slice(10))return r}else if(t&&e.startsWith(t.replace(/\/?$/,`/`)))return`/${e.slice(t.replace(/\/?$/,`/`).length)}`;return`${n.host}${r}`}function ql({projectName:e,refreshNonce:t}){let n=S(),{isAdmin:r}=qn(),i=We(),[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)([]),[l,u]=(0,Q.useState)([]),[d,f]=(0,Q.useState)([]),[p,m]=(0,Q.useState)(null),[h,g]=(0,Q.useState)([]),[_,v]=(0,Q.useState)([]),[y,b]=(0,Q.useState)(null),[x,C]=(0,Q.useState)(``),[T,E]=(0,Q.useState)(``),[D,O]=(0,Q.useState)(`30`),[k,M]=(0,Q.useState)(!1),[N,P]=(0,Q.useState)(`30d`),[F,I]=(0,Q.useState)(null),L=w({...Zi({client:K,path:{name:e},query:F?{surface:`index-coverage`,...F}:{surface:`index-coverage`,window:N}}),staleTime:Qn,placeholderData:j}),[R,ee]=(0,Q.useState)([`clicks`,`impressions`]),[te,ne]=(0,Q.useState)(!0),[re,ie]=(0,Q.useState)(null),[z,ae]=(0,Q.useState)(0),[B,V]=(0,Q.useState)({startDate:``,endDate:``,query:``,page:``}),[oe,se]=(0,Q.useState)(0),[ce,le]=(0,Q.useState)(!1),[ue,de]=(0,Q.useState)(0),[fe,pe]=(0,Q.useState)(!1),[H,me]=(0,Q.useState)(``),[he,ge]=(0,Q.useState)(!0),[_e,ve]=(0,Q.useState)(!1),[ye,be]=(0,Q.useState)(!1),[xe,Ce]=(0,Q.useState)(!1),[we,Te]=(0,Q.useState)(!1),[Ee,U]=(0,Q.useState)(!1),[De,Oe]=(0,Q.useState)(!1),[W,ke]=(0,Q.useState)(null),[je,Me]=(0,Q.useState)(!1),[Ne,Pe]=(0,Q.useState)(null),[Fe,Ie]=(0,Q.useState)(!1),[Le,Re]=(0,Q.useState)(!1),[ze,Be]=(0,Q.useState)(!1),[He,Ue]=(0,Q.useState)(!1),[Ge,Ke]=(0,Q.useState)(`indexed`),[Je,Ye]=(0,Q.useState)(null),Xe=!!(B.query.trim()||B.page.trim()||Je),Qe=Je!==null,$e=(0,Q.useMemo)(()=>{if(!Je)return d;let{key:e,dir:t}=Je;return[...d].sort((n,r)=>{let i=e===zn.CTR?Number.isFinite(n.ctr)?n.ctr:0:n[e],a=e===zn.CTR?Number.isFinite(r.ctr)?r.ctr:0:r[e];return t===`asc`?i-a:a-i})},[d,Je]),et=Ds({rows:$e,pageSize:25}),tt=fe?et.rows:$e,[nt,rt]=(0,Q.useState)([]),[it,ot]=(0,Q.useState)(null),[st,ct]=(0,Q.useState)(1),lt=(0,Q.useMemo)(()=>{if(nt.length<2)return null;let e=nt[nt.length-1],t=nt[nt.length-2];return{indexed:e.indexed-t.indexed,notIndexed:e.notIndexed-t.notIndexed}},[nt]);(0,Q.useEffect)(()=>{ct(1)},[W,Ge,it]);let ut=(0,Q.useMemo)(()=>it?(W?.reasonGroups??[]).find(e=>e.reason===it):void 0,[W,it]),dt=(0,Q.useMemo)(()=>W?Ge===`indexed`?W.indexed:Ge===`deindexed`?W.deindexed:Ge===`notIndexed`?it?ut?.urls??[]:(W.reasonGroups??[]).length===0?W.notIndexed:[]:[]:[],[W,Ge,it,ut]),ft=Math.max(1,Math.ceil(dt.length/Vl)),pt=Math.min(Math.max(1,st),ft),mt=(pt-1)*Vl,ht=(0,Q.useMemo)(()=>W?.indexed.slice(mt,mt+Vl)??[],[W,mt]),gt=(0,Q.useMemo)(()=>W?.notIndexed.slice(mt,mt+Vl)??[],[W,mt]),vt=(0,Q.useMemo)(()=>W?.deindexed.slice(mt,mt+Vl)??[],[W,mt]),bt=(0,Q.useMemo)(()=>(ut?.urls??[]).slice(mt,mt+Vl),[ut,mt]),[xt,St]=(0,Q.useState)(!1),[Ct,wt]=(0,Q.useState)(null),[Tt,Et]=(0,Q.useState)(null),[Dt,Ot]=(0,Q.useState)(null),[kt,At]=(0,Q.useState)(null);function jt(e,t){let n=Fo(e),r=Il(n);r?(Et(r),wt(null)):(Et(null),wt(n.message||t))}let Mt=s.find(e=>e.connectionType===`gsc`),Nt=(Mt?.scopes??[]).includes(`https://www.googleapis.com/auth/webmasters`),Pt=w({...Cr({client:K,path:{name:e}}),staleTime:Qn,enabled:!!Mt?.propertyId&&!i}),Ft=Pt.data?.google?.sitemaps??[],It=Ft.filter(e=>e.parentUrl===null),Lt=It.filter(e=>e.isIndex).map(e=>e.url),Rt=Lt.length>0?Lt:It.map(e=>e.url),zt=Lt.length,Bt=zt===1?`Resubmit sitemap index`:zt>1?`Resubmit sitemap indexes`:`Resubmit all sitemaps`,Vt=d.length>0||h.length>0||_.length>0,Ht=gs(),Ut=Eo();async function Gt(t,r=!1){if(i)u([]);else if(!t)u([]),C(``);else{be(!0);try{let{sites:i}=await n.fetchQuery({...oi({client:K,path:{name:e}}),staleTime:r?0:Qn});u(i),C(t.propertyId??i[0]?.siteUrl??``),Et(null)}catch(e){u([]),jt(e,`Failed to load Search Console properties`)}finally{be(!1)}}}async function qt(t){Te(!0);let r=t??oe;try{let t=Xe?zl:25,i=Xe?0:r,a={limit:String(t)};B.startDate&&(a.startDate=B.startDate),B.endDate&&(a.endDate=B.endDate),B.query&&(a.query=B.query),B.page&&(a.page=B.page),i>0&&(a.offset=String(i)),N&&N!==`all`&&!B.startDate&&(a.window=N);let o=await n.fetchQuery({...Dr({client:K,path:{name:e},query:a}),staleTime:Qn}),s=o.rows;Xe?(le(!1),f(s),de(s.length),pe(!0)):(le(i+s.length<o.totalMatching),f(s),de(0),pe(!1))}catch(e){f([]),le(!1),de(0),wt(e instanceof Error?e.message:`Failed to load GSC performance data`)}finally{Te(!1)}}async function Jt(){try{let t={};B.startDate&&(t.startDate=B.startDate),B.endDate&&(t.endDate=B.endDate),N&&N!==`all`&&!B.startDate&&(t.window=N);let r=await n.fetchQuery({...Ui({client:K,path:{name:e},query:t}),staleTime:Qn});m(r),I(t.startDate||t.endDate?{...t.startDate?{startDate:t.startDate}:{},...t.endDate?{endDate:t.endDate}:{}}:null)}catch{m(null)}}async function Yt(t=!1){U(!0);try{let r=H.trim()||void 0,i={limit:`20`};r&&(i.url=r);let[a,o]=await Promise.all([n.fetchQuery({...Or({client:K,path:{name:e},query:i}),staleTime:t?0:Qn}),n.fetchQuery({...xr({client:K,path:{name:e}}),staleTime:t?0:Qn})]);g(a),v(o)}catch(e){g([]),v([]),wt(e instanceof Error?e.message:`Failed to load GSC inspection history`)}finally{U(!1)}}async function Xt(t=!1){Me(!0);try{let[r,i]=await Promise.all([n.fetchQuery({...ii({client:K,path:{name:e}}),staleTime:t?0:Qn}),n.fetchQuery({...ei({client:K,path:{name:e}}),staleTime:t?0:Qn}).catch(()=>[])]);ke(r),rt(i)}catch(e){ke(null),rt([]),wt(e instanceof Error?e.message:`Failed to load coverage data`)}finally{Me(!1)}}async function Zt(t){St(!0),wt(null);try{let{succeeded:n,failed:r,total:i}=(await Ve(e,{urls:t})).summary;Xn({title:`Indexing requested`,detail:r===0?`${n} URL${n===1?``:`s`} submitted for indexing.`:`${n}/${i} submitted successfully, ${r} failed.`,tone:r===0?`positive`:`caution`,dedupeKey:`gsc:indexing:${e}`,dedupeMode:`replace`})}catch(e){wt(e instanceof Error?e.message:`Failed to request indexing`)}finally{St(!1)}}async function Qt(){St(!0),wt(null);try{let{succeeded:t,failed:n,total:r}=(await Ve(e,{urls:[],allUnindexed:!0})).summary;Xn({title:`Indexing requested`,detail:n===0?`${t} unindexed URL${t===1?``:`s`} submitted for indexing.`:`${t}/${r} submitted successfully, ${n} failed.`,tone:n===0?`positive`:`caution`,dedupeKey:`gsc:indexing-all:${e}`,dedupeMode:`replace`})}catch(e){wt(e instanceof Error?e.message:`Failed to request indexing`)}finally{St(!1)}}async function $t(t){let n=[];if(!Nt||t.length===0)return n;let r=[...new Set(t)];Re(!0),wt(null),Pe({completed:0,total:r.length});let i=0,a=0,o=0,s=null;try{for(let t=0;t<r.length;t+=50){let c=r.slice(t,t+50);try{let t=await Wt(e,c);n.push(...t.results.filter(e=>e.status===`accepted`).map(e=>e.sitemapUrl)),i+=t.summary.accepted,a+=t.summary.failed,o+=c.length,Pe({completed:o,total:r.length})}catch(t){o+=c.length;let l=c.length,u=r.length-o,d=t instanceof Error?t.message:`The batch request failed`,f=`${i} accepted, ${a} failed, ${l} unconfirmed, ${u} not attempted. Google may still process accepted sitemaps; indexing is not guaranteed.`;return s=`Sitemap submission stopped after a batch request failed. ${f} ${d}`,wt(s),Xn({title:`Sitemap resubmission partially completed`,detail:f,tone:`caution`,dedupeKey:`gsc:sitemap-submit:${e}`,dedupeMode:`replace`}),n}}let t=r.length;Xn({title:a===0?`Sitemap submitted to Google`:`Some sitemap submissions need attention`,detail:a===0?`Google accepted the sitemap submission/refetch request; indexing is not guaranteed.`:`Google accepted ${i}/${t} sitemap submissions; ${a} failed. Indexing is not guaranteed.`,tone:a===0?`positive`:`caution`,dedupeKey:`gsc:sitemap-submit:${e}`,dedupeMode:`replace`})}catch(e){wt(e instanceof Error?e.message:`Failed to submit sitemap to Google`)}finally{Re(!1),Pe(null),s&&wt(s)}return n}async function en(){let e=Ft.filter(e=>!e.isIndex).map(e=>e.url),t=Lt.filter(e=>!Ft.some(t=>t.parentUrl===e));await $t([...e,...t])}async function tn(t){Ie(!0),wt(null);try{await qe(e,`gsc`,t),await Zn(n,`google`),c(e=>e.map(e=>e.connectionType===`gsc`?{...e,sitemapUrl:t}:e)),Xn({title:`Default sitemap updated`,detail:t,tone:`positive`,dedupeKey:`gsc:sitemap-default:${e}`,dedupeMode:`replace`})}catch(e){wt(e instanceof Error?e.message:`Failed to set the default sitemap`)}finally{Ie(!1)}}async function nn(t){try{await Ut.mutateAsync({projectName:e,projectLabel:e,opts:t?{sitemapUrl:t}:void 0})}catch{}}async function rn(){try{let t=(await n.fetchQuery({..._r({client:K,path:{name:e},query:{kind:Se[`gsc-sync`],limit:1}}),staleTime:Qn}))[0];At(t?.status===Ae.failed&&t.error?`Last saved Search Console sync failed: ${On(t.error)}`:null)}catch{At(`Saved Search Console sync status is unavailable.`)}}async function on(){ge(!0),wt(null);try{let[t,a]=await Promise.all([i||!r?Promise.resolve(null):Kt().catch(()=>null),n.fetchQuery({...Sr({client:K,path:{name:e}}),staleTime:Qn}).catch(()=>[])]);o(!!t?.google?.configured),c(a);let s=a.find(e=>e.connectionType===`gsc`);C(s?.propertyId??``),await Promise.all([!i&&s&&!s.propertyId?Gt(s):Promise.resolve(),!i&&s?rn():Promise.resolve(),qt(),Jt(),Yt(),Xt()])}finally{ge(!1)}}(0,Q.useEffect)(()=>{u([]),Be(!1),At(null),Et(null),Ot(null)},[e]);let sn=(0,Q.useRef)(t);(0,Q.useEffect)(()=>{on(),sn.current!==t&&(sn.current=t,L.refetch())},[e,t,r]),(0,Q.useEffect)(()=>{se(0),ie(null),V(e=>e.startDate||e.endDate?{...e,startDate:``,endDate:``}:e),ae(e=>e+1),Jt()},[N]);let cn=(0,Q.useRef)(!1);(0,Q.useEffect)(()=>{cn.current?(se(0),et.setPage(1),qt(0)):cn.current=!0},[z]);function ln(e){let t=re===e?null:e;ie(t),V(e=>({...e,startDate:t??``,endDate:t??``})),ae(e=>e+1)}let un=(0,Q.useRef)(!1);(0,Q.useEffect)(()=>{un.current?(se(0),qt(0)):un.current=!0},[Qe]);async function dn(){if(!a)wt(`Google OAuth app credentials are not configured yet. Set them on the Settings page first.`);else{ve(!0),wt(null),Ot(null);try{let{authUrl:t,redirectUri:r}=await yn(e,`gsc`);if(!t.startsWith(`https://accounts.google.com/`)){wt(`Unexpected OAuth redirect URL. Please try again.`);return}let i=window.open(t,`_blank`,`width=600,height=700`);if(!i){window.location.assign(t);return}let a=r?new URL(r).origin:window.location.origin,o=!1,s=null,c=()=>{s!==null&&window.clearInterval(s),window.removeEventListener(`message`,u)},l=async e=>{if(!o){o=!0,c(),Ot(e?`Google connected. Refreshing access…`:`Refreshing Google connection…`);try{await Zn(n,`google`),await on()}finally{Ot(null)}}};function u(e){if(e.source!==i||e.origin!==a||!e.data||typeof e.data!=`object`)return;let t=e.data;t.type===Hl&&t.connectionType===`gsc`&&l(!0)}window.addEventListener(`message`,u),Ot(`Finish the Google consent flow in the popup. This page will refresh automatically.`),s=window.setInterval(()=>{i.closed&&l(!1)},1e3)}catch(e){wt(e instanceof Error?e.message:`Failed to start OAuth flow`)}finally{ve(!1)}}}async function fn(){wt(null),Ot(null);try{await yt(e,`gsc`),await Zn(n,`google`),c(e=>e.filter(e=>e.connectionType!==`gsc`)),u([]),C(``)}catch(e){wt(e instanceof Error?e.message:`Failed to disconnect`)}}async function pn(){if(x){Ce(!0),wt(null);try{await Ze(e,`gsc`,x),await Zn(n,`google`),c(e=>e.map(e=>e.connectionType===`gsc`?{...e,propertyId:x}:e)),Xn({title:`GSC property updated`,detail:`${e} is now linked to ${x}.`,tone:`positive`,dedupeKey:`gsc:property:${e}`,dedupeMode:`drop`})}catch(e){wt(e instanceof Error?e.message:`Failed to save GSC property`)}finally{Ce(!1)}}}async function mn(){wt(null),Ot(null);try{await Ht.mutateAsync({projectName:e,projectLabel:e,opts:{days:parseInt(D,10)||void 0,full:k||void 0}}),await Zn(n,`gsc`)}catch{}}async function hn(){if(T.trim()){Oe(!0),wt(null),Ot(null);try{let t=await at(e,T.trim());await Zn(n,`gsc`),b(t),E(``),await Yt()}catch(e){wt(e instanceof Error?e.message:`Failed to inspect URL`)}finally{Oe(!1)}}}return(0,$.jsxs)(`section`,{className:`page-section-divider`,children:[(0,$.jsx)(`div`,{className:`section-head section-head-inline`,children:(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`eyebrow eyebrow-soft`,children:`Search Console`}),(0,$.jsx)(`h2`,{children:`Google Search Console`})]})}),kt&&(0,$.jsx)(`p`,{role:`status`,className:`mb-3 text-copy-14 text-caution`,children:kt}),Tt&&(0,$.jsx)(`div`,{className:`mb-3 rounded-md border border-caution-800/40 bg-caution-950/20 px-3 py-2.5 text-label-14 text-caution-200`,children:(0,$.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`text-copy-14-strong text-caution-100`,children:Tt.title}),(0,$.jsx)(`p`,{className:`mt-0.5 text-caution-200/90`,children:Tt.message}),(Ao(Tt.enableUrl)||Ao(Tt.indexingApiUrl))&&(0,$.jsxs)(`div`,{className:`mt-2 flex flex-wrap gap-3`,children:[Ao(Tt.enableUrl)&&(0,$.jsx)(`a`,{href:Ao(Tt.enableUrl),target:`_blank`,rel:`noopener noreferrer`,className:`text-label-14-strong text-caution-100 underline decoration-caution-500/50 underline-offset-2 hover:text-caution-50`,children:`Enable Search Console API ↗`}),Ao(Tt.indexingApiUrl)&&(0,$.jsx)(`a`,{href:Ao(Tt.indexingApiUrl),target:`_blank`,rel:`noopener noreferrer`,className:`text-label-14-strong text-caution-100 underline decoration-caution-500/50 underline-offset-2 hover:text-caution-50`,children:`Enable Indexing API ↗`})]})]}),(0,$.jsx)(`button`,{type:`button`,className:`text-caution-400 hover:text-caution-200`,onClick:()=>Et(null),children:`×`})]})}),Ct&&(0,$.jsxs)(`div`,{className:`mb-3 rounded-md border border-negative-800/40 bg-negative-950/20 px-3 py-2 text-label-14 text-negative`,children:[Ct,(0,$.jsx)(`button`,{type:`button`,className:`ml-2 text-negative-400 hover:text-negative-200`,onClick:()=>wt(null),children:`×`})]}),Dt&&(0,$.jsxs)(`div`,{className:`mb-3 rounded-md border border-positive-800/40 bg-positive-950/20 px-3 py-2 text-label-14 text-positive`,children:[Dt,(0,$.jsx)(`button`,{type:`button`,className:`ml-2 text-positive-400 hover:text-positive-200`,onClick:()=>Ot(null),children:`×`})]}),he?(0,$.jsx)(`p`,{className:`text-copy-14 text-muted`,children:`Loading…`}):(0,$.jsxs)(`div`,{className:`space-y-3`,children:[Mt?(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 px-1 text-label-12 text-muted`,children:[(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-positive-500`}),(0,$.jsx)(`span`,{className:`text-neutral`,children:`Authorized`})]}),(0,$.jsx)(`span`,{className:`text-mono-700`,children:`·`}),(0,$.jsx)(`code`,{className:`text-secondary`,children:Mt.domain}),(0,$.jsx)(`span`,{className:`text-mono-700`,children:`·`}),(0,$.jsxs)(`span`,{children:[`Coverage measured`,` `,W?.lastInspectedAt?Nn(W.lastInspectedAt):`never`]}),!i&&(0,$.jsx)(`button`,{type:`button`,className:`ml-auto text-muted transition-colors hover:text-negative-400`,onClick:Jn(fn),children:`Disconnect`})]}):r?(0,$.jsxs)(Z,{className:`surface-card`,children:[(0,$.jsxs)(`div`,{className:`section-head section-head-inline`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`eyebrow eyebrow-soft`,children:`Connection`}),(0,$.jsx)(`h3`,{children:`Domain authorization`})]}),(0,$.jsx)(J,{tone:a?`caution`:`negative`,children:a?`Ready to connect`:`App credentials missing`})]}),(0,$.jsxs)(`div`,{className:`mt-3 material-base px-4 py-5`,children:[(0,$.jsx)(`p`,{className:`text-copy-14 text-neutral`,children:a?`Generate a Google OAuth link for this project and have the client sign in with a Google account that already has access to the correct Search Console property.`:`Set Google OAuth client credentials first. Once configured, you can generate a consent link for this project domain.`}),(0,$.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-2`,children:[a?(0,$.jsx)(q,{type:`button`,variant:`outline`,size:`sm`,disabled:_e,onClick:Jn(dn),children:_e?`Opening…`:`Connect Google Search Console`}):(0,$.jsx)(q,{type:`button`,variant:`outline`,size:`sm`,asChild:!0,children:(0,$.jsx)(A,{to:`/settings`,children:`Open Settings`})}),!a&&(0,$.jsx)(`p`,{className:`text-copy-13 text-muted`,children:`The same Google OAuth app credentials are shared across all projects.`})]})]})]}):(0,$.jsx)(Z,{className:`surface-card`,children:(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:Ll})}),(Mt||Vt)&&(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsxs)(Z,{className:`surface-card`,children:[(0,$.jsxs)(`div`,{className:`section-head section-head-inline`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`eyebrow eyebrow-soft`,children:`Performance`}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`h3`,{children:`Search performance`}),(0,$.jsx)(X,{text:`${Gl(p?.periodComparison)} The optional trend line shows the fitted direction. Click any day to filter the table below to that date. Query and page filters match case-insensitive substrings and run on Apply filters. Filtering and sorting examine up to ${zl.toLocaleString()} matching rows while the table shows 25 per page.`})]}),p?.window?.startDate&&p.window.endDate&&(0,$.jsxs)(`p`,{className:`text-copy-13 text-muted`,children:[p.window.startDate,` to `,p.window.endDate,(p.window.daysSinceLatestData??0)>0&&` · latest data ${p.window.daysSinceLatestData} day${p.window.daysSinceLatestData===1?``:`s`} ago`]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(nl,{windows:Rl,value:N,onChange:e=>{P(e),se(0),et.setPage(1)},label:`Search Console time period`,formatOption:e=>e===`all`?`All`:e}),(0,$.jsx)(q,{type:`button`,variant:`outline`,size:`sm`,disabled:we,onClick:()=>{se(0),et.setPage(1),qt(0),Jt()},children:we?`Loading…`:`Apply filters`})]})]}),p&&p.daily.length>0&&(()=>{let{totals:e,daily:t,trends:n,periodComparison:r}=p,i=t=>e[t]??null,a=Wl.flatMap(e=>{let t=L.data?.groups.find(t=>t.key===e.engine),n=t?.figures.find(e=>e.key===`indexed`);return t&&n?[{...e,label:t.label,figure:n}]:[]}),o=new Map(t.map(e=>[e.date,e])),s=new Map(a.map(e=>[e.key,new Map(e.figure.series.map(e=>[e.date,e.value]))])),c=t[t.length-1].date,l=a.filter(e=>R.includes(e.key)).map(e=>e.figure.series.at(-1)?.date).filter(e=>!!e).sort().at(-1),u=l&&l>c?l:c,d=_t(t[0].date,u).map(e=>{let t={...o.get(e)??{date:e}};for(let n of a)t[n.key]=s.get(n.key)?.get(e)??null;return t}),f=[...Bl.filter(e=>R.includes(e.key)).map(e=>({dataKey:e.key,label:e.label,color:e.color,axisId:e.key,inverted:e.inverted,formatValue:e.format,trend:te?n?.[e.key]??null:null})),...a.filter(e=>R.includes(e.key)).map(e=>({dataKey:e.key,label:`${e.label} indexed pages`,color:e.color,axisId:e.key,formatValue:e=>e.toLocaleString(),connectNulls:!0}))],m={key:`performance`,label:`Google search`,basis:r?.comparable?`vs prior ${r.days} ${r.days===1?`day`:`days`}`:void 0,figures:Bl.map(e=>{let t=i(e.key);return{key:e.key,label:e.label,color:e.color,value:t===null?`—`:e.format(t),change:Ul(r,e.key,e.inverted),interactive:!0,disabled:t===null}})},h=a.length===0?null:{key:`indexed`,label:`Indexed pages`,basis:Es(a.map(e=>e.figure)),figures:a.map(e=>({key:e.key,label:e.label,color:e.color,value:e.figure.value===null?`—`:e.figure.value.toLocaleString(),change:bs(e.figure.change,e.figure.unit),interactive:!0,disabled:e.figure.value===null}))};return(0,$.jsxs)(`div`,{className:`mt-3`,children:[(0,$.jsx)(Os,{name:`Search performance figures`,frame:`none`,mode:`compare`,groups:h?[m,h]:[m],selected:R,onSelect:e=>ee(t=>t.includes(e)?t.length===1?t:t.filter(t=>t!==e):[...t,e]),chart:(0,$.jsx)(da,{data:d,xKey:`date`,series:f,xTickFormatter:fa,labelFormatter:_a,onSelectX:ln,selectedX:re}),legendExtra:(0,$.jsxs)(`label`,{className:`flex min-h-9 cursor-pointer items-center gap-2 pointer-coarse:min-h-11`,children:[(0,$.jsx)(`input`,{type:`checkbox`,className:`size-4 accent-mono-200 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-mono-400`,checked:te,onChange:e=>ne(e.target.checked)}),`Trend line`]})}),(0,$.jsx)(`div`,{role:`group`,"aria-label":`Filter the table to a single day`,children:t.map(e=>(0,$.jsxs)(`button`,{type:`button`,className:`sr-only focus:not-sr-only focus:inline-block focus:rounded focus:border focus:border-strong focus:bg-surface-active focus:px-2 focus:py-1 focus:text-button-14 focus:text-strong`,"aria-pressed":re===e.date,onClick:()=>ln(e.date),children:[_a(e.date),`: `,e.clicks,` clicks, `,e.impressions,` impressions`]},e.date))}),re&&(0,$.jsxs)(`div`,{className:`mt-1 flex items-center gap-2 text-label-12`,children:[(0,$.jsxs)(`span`,{className:`text-secondary`,children:[`Table showing `,_a(re)]}),(0,$.jsxs)(`button`,{type:`button`,className:`text-link hover:underline`,onClick:()=>ln(re),children:[`Show all `,e.days,` days`]})]}),e.position!==null&&(e.positionDays??e.days)<e.days&&(0,$.jsxs)(`p`,{className:`mt-1 text-copy-13 text-muted`,children:[`Average position covers `,e.positionDays,` of `,e.days,` days. The rest have no property-level position recorded.`]}),(e.position===null||e.position===void 0)&&(0,$.jsxs)(`p`,{className:`mt-1 text-copy-13 text-muted`,children:[`Average position needs a property-level sync. Run `,(0,$.jsx)(`code`,{children:`canonry google sync`}),` to record it.`]})]})})(),(0,$.jsxs)(`div`,{className:`mt-3 grid gap-2 lg:grid-cols-4`,children:[(0,$.jsx)(`input`,{className:`rounded border border-strong bg-transparent px-2 py-1.5 text-label-14 text-strong placeholder-mono-400 focus:border-mono-500 focus:outline-none`,type:`date`,"aria-label":`Start date`,title:`Start date (inclusive). Leave blank to use the window above.`,value:B.startDate,onChange:e=>V(t=>({...t,startDate:e.target.value}))}),(0,$.jsx)(`input`,{className:`rounded border border-strong bg-transparent px-2 py-1.5 text-label-14 text-strong placeholder-mono-400 focus:border-mono-500 focus:outline-none`,type:`date`,"aria-label":`End date`,title:`End date (inclusive).`,value:B.endDate,onChange:e=>V(t=>({...t,endDate:e.target.value}))}),(0,$.jsx)(js,{value:B.query,onChange:e=>V(t=>({...t,query:e})),label:`Filter search queries`,placeholder:`Contains query…`}),(0,$.jsx)(js,{value:B.page,onChange:e=>V(t=>({...t,page:e})),label:`Filter page URLs`,placeholder:`Contains page URL…`})]}),d.length>0?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`mt-3 overflow-x-auto`,children:(0,$.jsxs)(`table`,{className:`data-table w-full text-label-14`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{className:`text-left`,children:`Date`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Query`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Page`}),Object.values(zn).map(e=>(0,$.jsx)(`th`,{className:`text-right`,"aria-sort":Je?.key===e?Je.dir===`asc`?`ascending`:`descending`:`none`,children:(0,$.jsxs)(`button`,{type:`button`,className:`w-full cursor-pointer select-none text-right hover:text-strong focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-mono-400 rounded px-1 -mx-1`,onClick:()=>{et.setPage(1),Ye(t=>t?.key===e?t.dir===`desc`?{key:e,dir:`asc`}:null:{key:e,dir:`desc`})},children:[Un[e],Je?.key===e?Je.dir===`desc`?` ↓`:` ↑`:``]})},e))]})}),(0,$.jsx)(`tbody`,{children:tt.map((e,t)=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{className:`text-secondary`,children:e.date}),(0,$.jsx)(`td`,{className:`max-w-xs truncate text-strong`,children:e.query}),(0,$.jsx)(`td`,{className:`max-w-xs text-secondary`,children:(0,$.jsx)(Ss,{value:e.page})}),(0,$.jsx)(`td`,{className:`text-right tabular-nums text-neutral`,children:e.clicks.toLocaleString()}),(0,$.jsx)(`td`,{className:`text-right tabular-nums text-secondary`,children:e.impressions.toLocaleString()}),(0,$.jsx)(`td`,{className:`text-right tabular-nums text-secondary`,children:G(e.ctr)}),(0,$.jsx)(`td`,{className:`text-right tabular-nums text-secondary`,children:e.position.toFixed(1)})]},`${e.date}:${e.query}:${e.page}:${t}`))})]})}),(0,$.jsx)(Ts,{page:fe?et.page:Math.floor(oe/25)+1,pageSize:25,visibleRows:tt.length,totalRows:fe?ue:void 0,hasNextPage:fe?void 0:ce,disabled:we,itemLabel:fe?`matches`:`rows`,onPageChange:e=>{if(fe){et.setPage(e);return}let t=(e-1)*25;se(t),qt(t)}}),fe&&ue>=zl?(0,$.jsxs)(`p`,{className:`mt-2 text-copy-13 text-muted`,children:[`Results are capped at `,zl.toLocaleString(),`; narrow the filters to search beyond this set.`]}):null]}):(0,$.jsx)(`p`,{className:`mt-3 text-copy-14 text-muted`,children:`No performance rows match the current filters yet.`})]}),(0,$.jsxs)(Z,{className:`surface-card`,children:[(0,$.jsxs)(`div`,{className:`section-head section-head-inline`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`eyebrow eyebrow-soft`,children:`Coverage`}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`h3`,{children:`Index coverage`}),(0,$.jsx)(X,{text:`Google's Indexing API is intended for eligible JobPosting and BroadcastEvent pages. Sitemap resubmission is the general-site bulk path.`})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[W&&W.notIndexed.length>0&&(0,$.jsx)(q,{type:`button`,variant:`outline`,size:`sm`,disabled:xt,onClick:()=>void Qt(),children:xt?`Requesting…`:`Request indexing (${W.notIndexed.length})`}),(0,$.jsx)(q,{type:`button`,variant:`outline`,size:`sm`,disabled:je,onClick:()=>void Xt(!0),children:je?`Loading…`:`Reload saved coverage`})]})]}),W&&W.summary.total>0?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`mt-6 flex flex-col items-center`,children:(()=>{let e=W.summary.indexedShare??0,t=W.summary.notIndexedShare??0,n=2*Math.PI*54,r=n*(1-e),i=n*t,a=n*e;return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`relative h-48 w-48`,children:[(0,$.jsxs)(`svg`,{viewBox:`0 0 128 128`,className:`h-full w-full`,"aria-hidden":`true`,children:[(0,$.jsx)(`circle`,{cx:`64`,cy:`64`,r:54,fill:`none`,stroke:ga.trackSubtle,strokeWidth:`14`}),(0,$.jsx)(`circle`,{cx:`64`,cy:`64`,r:54,fill:`none`,stroke:ya.positiveDeep,strokeWidth:`14`,strokeDasharray:n,strokeDashoffset:r,strokeLinecap:`round`,transform:`rotate(-90 64 64)`,style:{transition:`stroke-dashoffset 0.6s ease`}}),W.summary.notIndexed>0&&(0,$.jsx)(`circle`,{cx:`64`,cy:`64`,r:54,fill:`none`,stroke:ga.textFaint,strokeWidth:`14`,strokeDasharray:`${i} ${n-i}`,strokeDashoffset:-a,transform:`rotate(-90 64 64)`,style:{transition:`stroke-dasharray 0.6s ease, stroke-dashoffset 0.6s ease`}})]}),(0,$.jsxs)(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center`,children:[(0,$.jsx)(`span`,{className:`text-heading-32 tabular-nums text-primary`,children:G(W.summary.indexedShare)}),(0,$.jsx)(`span`,{className:`text-label-12 normal-case text-muted mt-0.5`,children:`Indexed`})]})]}),(0,$.jsxs)(`div`,{className:`mt-4 flex items-center justify-center gap-8`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`inline-block h-2.5 w-2.5 rounded-full bg-positive-500`}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`text-copy-24-strong tabular-nums text-primary`,children:W.summary.indexed.toLocaleString()}),(0,$.jsx)(`p`,{className:`text-label-12 normal-case text-muted`,children:`Indexed`})]})]}),(0,$.jsx)(`div`,{className:`h-8 w-px bg-mono-800`}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`inline-block h-2.5 w-2.5 rounded-full bg-mono-500`}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`text-copy-24-strong tabular-nums text-primary`,children:W.summary.notIndexed.toLocaleString()}),(0,$.jsxs)(`p`,{className:`text-label-12 normal-case text-muted`,children:[`Not indexed`,(W.reasonGroups??[]).length>0&&(0,$.jsxs)(`span`,{className:`ml-1 text-faint`,children:[`· `,(W.reasonGroups??[]).length,` `,(W.reasonGroups??[]).length===1?`reason`:`reasons`]})]})]})]}),W.summary.deindexed>0&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`h-8 w-px bg-mono-800`}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`inline-block h-2.5 w-2.5 rounded-full bg-negative-500`}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`text-copy-24-strong tabular-nums text-primary`,children:W.summary.deindexed.toLocaleString()}),(0,$.jsx)(`p`,{className:`text-label-12 normal-case text-muted`,children:`Deindexed`})]})]})]})]})]})})()}),(0,$.jsx)(`div`,{className:`mt-3 flex border-b border-default`,role:`tablist`,"aria-label":`Coverage status`,children:[`indexed`,`notIndexed`,`deindexed`].map(e=>{let t=e===`indexed`?W.indexed.length:e===`notIndexed`?W.notIndexed.length:W.deindexed.length;return(0,$.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":Ge===e,className:`border-b-2 px-3 py-2 text-button-14 transition-colors ${Ge===e?`border-accent text-heading`:`border-transparent text-secondary hover:border-mono-600 hover:text-strong`}`,onClick:()=>{Ke(e),ot(null)},children:[e===`indexed`?`Indexed`:e===`notIndexed`?`Not Indexed`:`Deindexed`,` (`,t,`)`]},e)})}),(0,$.jsxs)(`div`,{className:`mt-3 overflow-x-auto`,children:[Ge===`indexed`&&W.indexed.length>0&&(0,$.jsxs)(`table`,{className:`data-table w-full text-label-14`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{className:`text-left`,children:`URL`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Verdict`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Last Crawl`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Mobile`})]})}),(0,$.jsx)(`tbody`,{children:ht.map(e=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{className:`max-w-sm truncate text-strong`,children:e.url}),(0,$.jsx)(`td`,{className:`text-secondary`,children:e.verdict??`Unknown`}),(0,$.jsx)(`td`,{className:`text-secondary`,children:e.crawlTime?e.crawlTime.split(`T`)[0]:`—`}),(0,$.jsx)(`td`,{className:`text-secondary`,children:e.isMobileFriendly===!0?`Yes`:e.isMobileFriendly===!1?`No`:`—`})]},e.id))})]}),Ge===`notIndexed`&&!it&&(W.reasonGroups??[]).length>0&&(0,$.jsxs)(`table`,{className:`data-table w-full text-label-14`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{className:`text-left`,children:`Reason`}),(0,$.jsx)(`th`,{className:`text-right`,children:`Pages`})]})}),(0,$.jsx)(`tbody`,{children:(W.reasonGroups??[]).map(e=>(0,$.jsxs)(`tr`,{className:`cursor-pointer hover:bg-surface-inset-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-mono-400`,onClick:()=>ot(e.reason),onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),ot(e.reason))},tabIndex:0,role:`button`,"aria-label":`View ${e.reason} pages`,children:[(0,$.jsx)(`td`,{className:`text-strong`,children:e.reason}),(0,$.jsx)(`td`,{className:`text-right tabular-nums text-secondary`,children:e.count})]},e.reason))})]}),Ge===`notIndexed`&&!it&&(W.reasonGroups??[]).length===0&&W.notIndexed.length>0&&(0,$.jsxs)(`table`,{className:`data-table w-full text-label-14`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{className:`text-left`,children:`URL`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Indexing State`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Coverage`})]})}),(0,$.jsx)(`tbody`,{children:gt.map(e=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{className:`max-w-sm truncate text-strong`,children:e.url}),(0,$.jsx)(`td`,{className:`text-secondary`,children:e.indexingState??`Unknown`}),(0,$.jsx)(`td`,{className:`text-secondary`,children:e.coverageState??`Unknown`})]},e.id))})]}),Ge===`notIndexed`&&it&&(()=>{let e=(W.reasonGroups??[]).find(e=>e.reason===it);return e?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`flex items-center gap-2 mb-3`,children:(0,$.jsxs)(`button`,{type:`button`,className:`text-button-14 text-secondary hover:text-strong transition-colors`,onClick:()=>ot(null),children:[`←`,` Back to reasons`]})}),(0,$.jsxs)(`div`,{className:`mb-3 flex items-center justify-between material-base p-3`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`text-copy-14-strong text-strong`,children:e.reason}),(0,$.jsxs)(`p`,{className:`mt-1 text-copy-13 text-muted`,children:[e.count,` affected page`,e.count===1?``:`s`]})]}),(0,$.jsx)(q,{type:`button`,variant:`outline`,size:`sm`,disabled:xt,onClick:()=>void Zt(e.urls.map(e=>e.url)),children:xt?`Requesting…`:`Request indexing (${e.count})`})]}),(0,$.jsxs)(`table`,{className:`data-table w-full text-label-14`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{className:`text-left`,children:`URL`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Last Crawl`}),(0,$.jsx)(`th`,{className:`w-8`})]})}),(0,$.jsx)(`tbody`,{children:bt.map(e=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{className:`max-w-sm truncate text-strong`,children:e.url}),(0,$.jsx)(`td`,{className:`text-secondary`,children:e.crawlTime?e.crawlTime.split(`T`)[0]:`—`}),(0,$.jsx)(`td`,{children:(0,$.jsx)(`button`,{type:`button`,className:`text-button-14 text-muted hover:text-strong transition-colors`,disabled:xt,onClick:()=>void Zt([e.url]),title:`Request indexing`,children:`Index`})})]},e.id))})]})]}):null})(),Ge===`deindexed`&&W.deindexed.length>0&&(0,$.jsxs)(`table`,{className:`data-table w-full text-label-14`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{className:`text-left`,children:`URL`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Previous`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Current`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Detected`})]})}),(0,$.jsx)(`tbody`,{children:vt.map((e,t)=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{className:`max-w-sm truncate text-strong`,children:e.url}),(0,$.jsx)(`td`,{className:`text-secondary`,children:e.previousState}),(0,$.jsx)(`td`,{className:`text-secondary`,children:e.currentState}),(0,$.jsx)(`td`,{className:`text-secondary`,children:e.transitionDate.split(`T`)[0]})]},`${e.url}-${t}`))})]}),(Ge===`indexed`&&W.indexed.length===0||Ge===`notIndexed`&&!it&&W.notIndexed.length===0||Ge===`deindexed`&&W.deindexed.length===0)&&(0,$.jsx)(`p`,{className:`text-copy-14 text-muted`,children:`No URLs in this category.`}),(0,$.jsx)(Ts,{page:pt,pageSize:Vl,visibleRows:Math.min(Vl,dt.length-mt),totalRows:dt.length,onPageChange:ct,itemLabel:`URLs`})]}),(0,$.jsxs)(`div`,{className:`mt-4 border-t border-default pt-3`,children:[(0,$.jsxs)(`button`,{type:`button`,className:`flex w-full items-center justify-between text-left text-button-14 text-secondary hover:text-strong focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-mono-400`,"aria-expanded":He,onClick:()=>Ue(e=>!e),children:[(0,$.jsx)(`span`,{children:`Coverage history`}),(0,$.jsx)(`span`,{children:He?`Hide snapshots`:nt.length>0?`View ${nt.length} snapshots`:`View history`})]}),(0,$.jsxs)(`p`,{className:`mt-1 text-copy-13 text-muted`,children:[`Current: `,W.summary.indexed.toLocaleString(),` indexed, `,W.summary.notIndexed.toLocaleString(),` not indexed.`,lt&&(0,$.jsxs)($.Fragment,{children:[` Since the last snapshot: `,lt.indexed>=0?`+`:``,lt.indexed.toLocaleString(),` indexed, `,lt.notIndexed>=0?`+`:``,lt.notIndexed.toLocaleString(),` not indexed.`]})]}),He&&(0,$.jsx)(`div`,{className:`mt-3 overflow-x-auto`,children:nt.length>0?(0,$.jsxs)(`table`,{className:`data-table w-full text-label-14`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{className:`text-left`,children:`Date`}),(0,$.jsx)(`th`,{className:`text-right`,children:`Indexed`}),(0,$.jsx)(`th`,{className:`text-right`,children:`Not indexed`})]})}),(0,$.jsx)(`tbody`,{children:nt.map(e=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{className:`text-secondary`,children:e.date}),(0,$.jsx)(`td`,{className:`text-right tabular-nums text-neutral`,children:e.indexed.toLocaleString()}),(0,$.jsx)(`td`,{className:`text-right tabular-nums text-secondary`,children:e.notIndexed.toLocaleString()})]},e.date))})]}):(0,$.jsx)(`p`,{className:`text-copy-14 text-muted`,children:`No saved coverage snapshots yet.`})})]})]}):(0,$.jsx)(`p`,{className:`mt-3 text-copy-14 text-muted`,children:je?`Loading coverage data…`:`No coverage data yet. Inspect your sitemap to populate this view.`})]}),!i&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Pl,{engine:`Google`,data:Pt.isError?null:Pt.isPending&&Pt.fetchStatus!==`idle`?void 0:Pt.data?.google??null,loadError:Pt.isError?an(Pt.error):null,label:e=>Kl(e,Mt?.propertyId),canSubmit:Nt,submitBlocked:Mt?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{tone:`caution`,label:`Read-only access`,text:`Canonry's Google access can read Search Console but not submit sitemaps. Reconnect to allow submitting.`}),(0,$.jsx)(q,{type:`button`,variant:`outline`,size:`sm`,onClick:Jn(dn),children:`Reconnect`})]}):void 0,onSubmit:$t,submitting:Le,defaultUrl:Mt?.sitemapUrl??null,onSetDefault:e=>void tn(e),settingDefault:Fe,onInspect:e=>void nn(e),inspecting:Ut.isPending,notRead:(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:`Google's sitemap list arrives with the next Google sync. Refresh search data to read it now.`}),bulk:It.length>0?(0,$.jsx)(Fl,{label:Ne?`Submitting ${Ne.completed} of ${Ne.total}`:`Resubmit all`,menuLabel:`Resubmit sitemaps to Google`,disabled:!Nt||Le,items:[{key:`primary`,label:Bt,description:zt>0?`Google rereads every sitemap the index lists.`:`Each sitemap in the list, once.`,disabled:Rt.length===0,onSelect:()=>void $t(Rt)},{key:`files`,label:`Resubmit all files`,description:`Every file inside each index, one by one.`,onSelect:()=>void en()}]}):void 0}),(0,$.jsxs)(Z,{className:`surface-card`,children:[(0,$.jsx)(`div`,{className:`section-head`,children:(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`eyebrow eyebrow-soft`,children:`Inspection`}),(0,$.jsx)(`h3`,{children:`Inspect a URL`})]})}),(0,$.jsxs)(`div`,{className:`mt-3 flex flex-col gap-2 lg:flex-row`,children:[(0,$.jsx)(`input`,{className:`flex-1 rounded border border-strong bg-transparent px-2 py-1.5 text-label-14 text-strong placeholder-mono-400 focus:border-mono-500 focus:outline-none`,type:`url`,placeholder:`https://example.com/page`,value:T,onChange:e=>E(e.target.value),onKeyDown:e=>e.key===`Enter`&&void hn()}),(0,$.jsx)(q,{type:`button`,size:`sm`,disabled:De||!Mt?.propertyId||!T.trim(),onClick:Jn(hn),children:De?`Inspecting…`:`Inspect URL`})]}),y&&(0,$.jsxs)(`div`,{className:`mt-3 grid gap-3 md:grid-cols-2 xl:grid-cols-4`,children:[(0,$.jsxs)(`div`,{className:`material-base p-3`,children:[(0,$.jsx)(`p`,{className:`text-label-12 normal-case text-muted`,children:`Indexing state`}),(0,$.jsx)(`p`,{className:`mt-1 text-copy-14 text-strong`,children:y.indexingState??`Unknown`})]}),(0,$.jsxs)(`div`,{className:`material-base p-3`,children:[(0,$.jsx)(`p`,{className:`text-label-12 normal-case text-muted`,children:`Verdict`}),(0,$.jsx)(`p`,{className:`mt-1 text-copy-14 text-strong`,children:y.verdict??`Unknown`})]}),(0,$.jsxs)(`div`,{className:`material-base p-3`,children:[(0,$.jsx)(`p`,{className:`text-label-12 normal-case text-muted`,children:`Mobile friendly`}),(0,$.jsx)(`p`,{className:`mt-1 text-copy-14 text-strong`,children:jn(y.isMobileFriendly??null)})]}),(0,$.jsxs)(`div`,{className:`material-base p-3`,children:[(0,$.jsx)(`p`,{className:`text-label-12 normal-case text-muted`,children:`Last crawl`}),(0,$.jsx)(`p`,{className:`mt-1 text-copy-14 text-strong`,children:Nn(y.crawlTime)})]})]})]})]}),(0,$.jsxs)(Z,{className:`surface-card`,children:[(0,$.jsxs)(`div`,{className:`section-head section-head-inline`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`eyebrow eyebrow-soft`,children:`History`}),(0,$.jsx)(`h3`,{children:`Inspection log`})]}),(0,$.jsx)(q,{type:`button`,variant:`outline`,size:`sm`,disabled:Ee,onClick:()=>void Yt(!0),children:Ee?`Loading…`:`Refresh history`})]}),(0,$.jsxs)(`div`,{className:`mt-3 flex flex-col gap-2 lg:flex-row`,children:[(0,$.jsx)(`input`,{className:`flex-1 rounded border border-strong bg-transparent px-2 py-1.5 text-label-14 text-strong placeholder-mono-400 focus:border-mono-500 focus:outline-none`,type:`text`,placeholder:`Filter exact URL`,value:H,onChange:e=>me(e.target.value)}),(0,$.jsx)(q,{type:`button`,size:`sm`,variant:`outline`,disabled:Ee,onClick:()=>void Yt(!0),children:`Apply filter`})]}),h.length>0?(0,$.jsx)(`div`,{className:`mt-3 overflow-x-auto`,children:(0,$.jsxs)(`table`,{className:`data-table w-full text-label-14`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{className:`text-left`,children:`URL`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Indexing`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Verdict`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Coverage`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Mobile`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Inspected`})]})}),(0,$.jsx)(`tbody`,{children:h.map(e=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{className:`max-w-sm truncate text-strong`,children:e.url}),(0,$.jsx)(`td`,{className:`text-neutral`,children:e.indexingState??`Unknown`}),(0,$.jsx)(`td`,{className:`text-secondary`,children:e.verdict??`Unknown`}),(0,$.jsx)(`td`,{className:`text-secondary`,children:e.coverageState??`Unknown`}),(0,$.jsx)(`td`,{className:`text-secondary`,children:jn(e.isMobileFriendly??null)}),(0,$.jsx)(`td`,{className:`text-secondary`,children:Nn(e.inspectedAt)})]},e.id))})]})}):(0,$.jsx)(`p`,{className:`mt-3 text-copy-14 text-muted`,children:`No inspection history yet.`})]}),(0,$.jsxs)(Z,{className:`surface-card`,children:[(0,$.jsx)(`div`,{className:`section-head`,children:(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`eyebrow eyebrow-soft`,children:`Deindexed`}),(0,$.jsx)(`h3`,{children:`Recent indexing losses`})]})}),_.length>0?(0,$.jsx)(`div`,{className:`mt-3 overflow-x-auto`,children:(0,$.jsxs)(`table`,{className:`data-table w-full text-label-14`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{className:`text-left`,children:`URL`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Previous`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Current`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Changed at`})]})}),(0,$.jsx)(`tbody`,{children:_.map(e=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{className:`max-w-sm truncate text-strong`,children:e.url}),(0,$.jsx)(`td`,{className:`text-secondary`,children:e.previousState??`Unknown`}),(0,$.jsx)(`td`,{className:`text-neutral`,children:e.currentState??`Unknown`}),(0,$.jsx)(`td`,{className:`text-secondary`,children:Nn(e.transitionDate)})]},`${e.url}:${e.transitionDate}`))})]})}):(0,$.jsx)(`p`,{className:`mt-3 text-copy-14 text-muted`,children:`No deindexed transitions recorded.`})]})]}),Mt&&!i&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`border-t border-default pt-3`,children:(0,$.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-2 text-left`,onClick:()=>{ze||Gt(Mt),Be(e=>!e)},children:[(0,$.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 20 20`,fill:`currentColor`,className:`h-4 w-4 text-muted transition-transform ${ze?`rotate-90`:``}`,"aria-hidden":`true`,children:(0,$.jsx)(`path`,{fillRule:`evenodd`,d:`M7.21 14.77a.75.75 0 01.02-1.06L11.168 10 7.23 6.29a.75.75 0 111.04-1.08l4.5 4.25a.75.75 0 010 1.08l-4.5 4.25a.75.75 0 01-1.06-.02z`,clipRule:`evenodd`})}),(0,$.jsx)(`span`,{className:`text-label-12 normal-case text-muted`,children:`Setup & Configuration`})]})}),ze&&(0,$.jsx)(`div`,{className:`space-y-3`,children:(0,$.jsxs)(`div`,{className:`grid gap-3 xl:grid-cols-2`,children:[(0,$.jsxs)(Z,{className:`surface-card`,children:[(0,$.jsx)(`div`,{className:`section-head`,children:(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`eyebrow eyebrow-soft`,children:`Property`}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`h3`,{children:`Pick the Search Console property`}),(0,$.jsx)(X,{text:`The selected property is used for future syncs and URL inspections for this project.`})]})]})}),(0,$.jsxs)(`div`,{className:`mt-3 space-y-2`,children:[(0,$.jsx)(`label`,{className:`text-label-12 text-muted`,htmlFor:`gsc-property-${e}`,children:`Property URL`}),(0,$.jsx)(`select`,{id:`gsc-property-${e}`,className:`w-full rounded border border-strong bg-transparent px-2 py-1.5 text-label-14 text-strong focus:border-mono-500 focus:outline-none`,value:x,disabled:ye||l.length===0,onChange:e=>C(e.target.value),children:l.length===0?(0,$.jsx)(`option`,{value:``,children:ye?`Loading properties…`:`No properties available`}):l.map(e=>(0,$.jsxs)(`option`,{value:e.siteUrl,children:[e.siteUrl,` · `,e.permissionLevel]},e.siteUrl))}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(q,{type:`button`,size:`sm`,variant:`outline`,disabled:ye,onClick:()=>void Gt(Mt,!0),children:ye?`Refreshing…`:`Refresh properties`}),(0,$.jsx)(q,{type:`button`,size:`sm`,disabled:!x||xe,onClick:Jn(pn),children:xe?`Saving…`:`Save property`})]})]})]}),(0,$.jsxs)(Z,{className:`surface-card`,children:[(0,$.jsx)(`div`,{className:`section-head`,children:(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`eyebrow eyebrow-soft`,children:`Sync`}),(0,$.jsx)(`h3`,{children:`Import GSC performance data`})]})}),(0,$.jsxs)(`div`,{className:`mt-3 space-y-3`,children:[(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-[160px_1fr]`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`text-label-12 text-muted`,htmlFor:`gsc-sync-days-${e}`,children:`Days`}),(0,$.jsx)(`input`,{id:`gsc-sync-days-${e}`,type:`number`,min:`1`,className:`mt-0.5 w-full rounded border border-strong bg-transparent px-2 py-1.5 text-label-14 text-strong placeholder-mono-400 focus:border-mono-500 focus:outline-none`,value:D,onChange:e=>O(e.target.value)})]}),(0,$.jsxs)(`label`,{className:`flex items-center gap-2 rounded-md border border-default bg-surface-subtle px-3 py-2 text-label-14 text-neutral`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:k,onChange:e=>M(e.target.checked)}),`Replace existing imported rows for the requested range`]})]}),(0,$.jsx)(q,{type:`button`,size:`sm`,disabled:Ht.isPending||!Mt.propertyId,onClick:Jn(mn),children:Ht.isPending?`Queueing…`:`Queue sync`}),!Mt.propertyId&&(0,$.jsx)(`p`,{className:`text-copy-13 text-caution-400`,children:`Select a Search Console property before queueing a sync.`})]})]})]})})]})]})]})}var Jl=[`7d`,`30d`,`90d`,`all`],Yl=10,Xl=[{key:`clicks`,label:`Clicks`,color:ua[1],format:e=>e.toLocaleString()},{key:`impressions`,label:`Impressions`,color:ua[4],format:e=>e.toLocaleString()},{key:`ctr`,label:`CTR`,color:ya.caution,format:e=>G(e)},{key:`position`,label:`Avg position`,color:ua[2],inverted:!0,format:e=>e.toFixed(1)}],Zl=`bing-indexed`,Ql=`Impression-weighted across the queries Bing names. Bing reports these per week, so the line moves weekly.`,$l=`Asks Bing directly. Counts against the shared Bing request limit for this key.`;function eu(e){if(!e)return{kind:`note`,text:`No comparison period`};let t=e.difference.avgImpressionPosition,n=`vs prior ${e.days} ${e.days===1?`day`:`days`}`;return t===null?{kind:`note`,text:`No position in the prior ${e.days} days`}:t===0?{kind:`delta`,amount:`0`,direction:`flat`,tone:`neutral`,basis:n}:{kind:`delta`,amount:Tn(t),direction:t>0?`up`:`down`,tone:t>0?`worse`:`better`,basis:n}}function tu(e){return e==null?`—`:e.toFixed(1)}function nu(e){return e==null?`—`:Math.round(e).toLocaleString()}function ru(e){return e.replace(/^https?:\/\//,``).replace(/\/+$/,``)}function iu(e,t){let n=t.replace(/\/+$/,``);return e.startsWith(n)?e.slice(n.length)||`/`:e}function au(e,t){return e?.find(e=>e.kind===t)}function ou(e){let t=e?.payload;return t&&typeof t.dailyQuota==`number`&&typeof t.monthlyQuota==`number`?{dailyQuota:t.dailyQuota,monthlyQuota:t.monthlyQuota}:null}function su(e){let t=e?.payload;return t&&typeof t.crawlBoostAvailable==`boolean`?{crawlBoostAvailable:t.crawlBoostAvailable,crawlBoostEnabled:t.crawlBoostEnabled===!0,crawlRate:Array.isArray(t.crawlRate)?t.crawlRate:[]}:null}function cu(e){return Array.isArray(e?.payload)?e.payload.filter(e=>typeof e==`object`&&!!e):null}var lu=new Set([`entityType`,`requestType`,`type`,`role`]);function uu(e,t){return e==null||e===``?`—`:typeof e==`boolean`?e?`Yes`:`No`:typeof e==`number`?e.toLocaleString():typeof e==`string`?/^\d{4}-\d{2}-\d{2}(?:T00:00:00(?:\.000)?Z)?$/.test(e)?_a(e.slice(0,10)):lu.has(t)&&/^[a-z]+(?:-[a-z]+)*$/.test(e)?e.charAt(0).toUpperCase()+e.slice(1).replaceAll(`-`,` `):e:JSON.stringify(e)}function du({status:e,right:t,children:n}){return(0,$.jsxs)(`section`,{className:`page-section-divider`,children:[(0,$.jsxs)(`div`,{className:`section-head section-head-inline`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h2`,{children:`Bing Webmaster Tools`}),e]}),t]}),n]})}function fu({projectName:e,refreshNonce:t}){let n=S(),r=w({...Qi({client:K,path:{name:e}}),staleTime:Qn}),i=r.data??null,a=w({...ci({client:K,path:{name:e}}),staleTime:Qn,enabled:!(!i?.connected||i.siteUrl)}),[o,s]=(0,Q.useState)(``),[c,l]=(0,Q.useState)(``),[u,d]=(0,Q.useState)(null);(0,Q.useEffect)(()=>{t>0&&r.refetch()},[t]);async function f(){if(o.trim()){d(null);try{await St(e,o.trim()),s(``),await Zn(n,`bing`)}catch(e){d(an(e))}}}async function p(){d(null);try{await $t(e),l(``),await Zn(n,`bing`)}catch(e){d(an(e))}}async function m(){if(c){d(null);try{await Dt(e,c),await Zn(n,`bing`)}catch(e){d(an(e))}}}if(r.isPending)return(0,$.jsx)(du,{children:(0,$.jsx)(Z,{className:`surface-card`,children:(0,$.jsx)(`div`,{className:`text-label-14 text-secondary`,children:`Loading Bing data…`})})});if(r.isError)return(0,$.jsx)(du,{children:(0,$.jsxs)(Z,{className:`surface-card`,children:[(0,$.jsxs)(`p`,{className:`text-copy-14 text-negative`,children:[`Could not load the Bing connection: `,an(r.error)]}),(0,$.jsx)(q,{type:`button`,variant:`outline`,size:`sm`,className:`mt-3`,onClick:()=>void r.refetch(),children:`Retry`})]})});if(!i?.connected)return(0,$.jsx)(du,{children:(0,$.jsxs)(Z,{className:`surface-card`,children:[(0,$.jsxs)(`div`,{className:`section-head section-head-inline`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`eyebrow eyebrow-soft`,children:`Connection`}),(0,$.jsx)(`h3`,{children:`Domain authorization`})]}),(0,$.jsx)(J,{tone:`caution`,children:`Not connected`})]}),Y()?(0,$.jsx)(`p`,{className:`text-copy-14 text-neutral`,children:`Bing Webmaster Tools is not connected for this project.`}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`p`,{className:`text-copy-14 text-neutral`,children:`Connect Bing Webmaster Tools to inspect URLs, monitor index coverage, and submit pages for indexing.`}),(0,$.jsxs)(`div`,{className:`mt-3`,children:[(0,$.jsx)(`label`,{className:`text-label-12 text-muted`,htmlFor:`bing-api-key`,children:`API Key`}),(0,$.jsxs)(`div`,{className:`mt-1 flex items-center gap-2`,children:[(0,$.jsx)(`input`,{id:`bing-api-key`,type:`password`,className:`flex-1 rounded border border-strong bg-transparent px-2 py-1.5 text-label-14 text-strong placeholder-mono-400 focus:border-mono-500 focus:outline-none`,placeholder:`Bing Webmaster Tools API key`,value:o,onChange:e=>s(e.target.value),onKeyDown:e=>{e.key===`Enter`&&f()}}),(0,$.jsx)(vs,{size:`sm`,disabled:!o.trim(),onClick:Jn(f),children:`Connect`})]}),(0,$.jsxs)(`p`,{className:`mt-1 text-copy-14 text-secondary`,children:[`Get your API key from`,` `,(0,$.jsx)(`a`,{href:`https://www.bing.com/webmasters/`,target:`_blank`,rel:`noopener noreferrer`,className:`text-secondary underline underline-offset-2 hover:text-neutral`,children:`Bing Webmaster Tools`})]})]})]}),u&&(0,$.jsx)(`p`,{className:`mt-3 text-copy-13 text-negative`,children:u})]})});if(!i.siteUrl){let e=a.data?.sites??[];return(0,$.jsx)(du,{children:(0,$.jsxs)(Z,{className:`surface-card`,children:[(0,$.jsxs)(`div`,{className:`section-head section-head-inline`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`eyebrow eyebrow-soft`,children:`Connection`}),(0,$.jsx)(`h3`,{children:`Domain authorization`})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(J,{tone:`positive`,children:`Connected`}),!Y()&&(0,$.jsx)(vs,{size:`sm`,variant:`ghost`,onClick:Jn(p),children:`Disconnect`})]})]}),(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsxs)(`div`,{className:`material-base px-4 py-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(`span`,{className:`h-2 w-2 rounded-full bg-positive-500`}),(0,$.jsx)(`span`,{className:`text-label-14 text-strong`,children:`Authorized for this project domain`}),(0,$.jsx)(`span`,{className:`text-label-12 text-muted`,children:i.domain})]}),(0,$.jsx)(`p`,{className:`mt-2 text-copy-13 text-muted`,children:`The API key is connected, but no Bing site is selected yet. Pick the verified site that should receive inspections and indexing requests.`})]}),(0,$.jsxs)(`div`,{className:`grid gap-3 lg:grid-cols-2`,children:[(0,$.jsxs)(`div`,{className:`material-base p-3`,children:[(0,$.jsx)(`p`,{className:`text-label-12 normal-case text-muted`,children:`Registered domain`}),(0,$.jsx)(`p`,{className:`mt-1 text-copy-14 text-strong`,children:i.domain})]}),(0,$.jsxs)(`div`,{className:`material-base p-3`,children:[(0,$.jsx)(`p`,{className:`text-label-12 normal-case text-muted`,children:`Last auth update`}),(0,$.jsx)(`p`,{className:`mt-1 text-copy-14 text-strong`,children:i.updatedAt?Nn(i.updatedAt):`—`})]})]}),(0,$.jsxs)(`div`,{className:`material-base p-3`,children:[(0,$.jsx)(`p`,{className:`text-label-12 normal-case text-muted`,children:`Select site`}),e.length>0?(0,$.jsxs)(`div`,{className:`mt-3 flex flex-col gap-2 lg:flex-row`,children:[(0,$.jsxs)(`select`,{"aria-label":`Bing site`,className:`flex-1 rounded border border-strong bg-bg-elevated px-2 py-1.5 text-label-14 text-strong focus:border-mono-500 focus:outline-none`,value:c,onChange:e=>l(e.target.value),children:[(0,$.jsx)(`option`,{value:``,children:`Select a site...`}),e.map(e=>(0,$.jsxs)(`option`,{value:e.url,children:[e.url,e.verified?` (verified)`:``]},e.url))]}),!Y()&&(0,$.jsx)(vs,{size:`sm`,disabled:!c,onClick:Jn(m),children:`Set Site`})]}):(0,$.jsx)(`p`,{className:`mt-3 text-copy-13 text-muted`,children:a.isPending?`Loading sites…`:`No verified Bing sites are available yet. Verify the domain in Bing Webmaster Tools, then use the page-level refresh to reload everything.`})]})]}),u&&(0,$.jsx)(`p`,{className:`mt-3 text-copy-13 text-negative`,children:u})]})})}return(0,$.jsx)(pu,{projectName:e,connection:i,siteUrl:i.siteUrl,onDisconnect:p,error:u})}function pu({projectName:e,connection:t,siteUrl:n,onDisconnect:r,error:i}){let[a,o]=(0,Q.useState)(`30d`),s={name:e},c=w({...oa({client:K,path:s,query:{window:a}}),staleTime:Qn,placeholderData:j}),l=w({...Ti({client:K,path:s}),staleTime:Qn}),u=w({...Si({client:K,path:s}),staleTime:Qn}),f=!!(c.data?.latestAvailableDate||l.data?.syncedAt||u.data?.syncedAt),p=!c.isPending&&!l.isPending&&!u.isPending,m=[c,l,u].find(e=>e.isError)?.error??null,h=cu(au(l.data?.snapshots,`blocked-urls`))?.length??0;return(0,$.jsx)(du,{status:(0,$.jsxs)(`p`,{className:`mt-1 flex flex-wrap items-center gap-x-1.5 gap-y-1 text-label-13 text-secondary`,children:[(0,$.jsx)(`span`,{className:`h-2 w-2 rounded-full bg-positive-500`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{children:`Connected`}),(0,$.jsx)(`span`,{"aria-hidden":`true`,children:`·`}),(0,$.jsx)(`span`,{className:`font-mono`,title:n,children:ru(n)}),c.data?.latestAvailableDate&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,children:`·`}),(0,$.jsxs)(`span`,{children:[`Data through `,_a(c.data.latestAvailableDate)]})]}),l.data?.syncedAt&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,children:`·`}),(0,$.jsxs)(`span`,{children:[`Synced `,Nn(l.data.syncedAt)]})]}),h>0&&(0,$.jsx)(`span`,{className:`ml-1.5`,children:(0,$.jsx)(X,{tone:`caution`,label:`${h} blocked URL${h===1?``:`s`}`,text:`Bing is keeping ${h===1?`one URL`:`${h} URLs`} out of its results, which also keeps ${h===1?`it`:`them`} out of Copilot answers. See Site settings.`})})]}),right:(0,$.jsxs)(`details`,{className:`group`,children:[(0,$.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center gap-1 rounded px-2 py-1 text-button-14 text-secondary hover:text-strong focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-mono-400 [&::-webkit-details-marker]:hidden`,children:[`Connection `,(0,$.jsx)(d,{className:`h-3.5 w-3.5 transition-transform group-open:rotate-180`,"aria-hidden":`true`})]}),(0,$.jsxs)(`div`,{className:`material-base mt-2 space-y-2 p-3 text-copy-13`,children:[(0,$.jsxs)(`p`,{children:[(0,$.jsx)(`span`,{className:`text-secondary`,children:`Domain`}),` `,(0,$.jsx)(`span`,{className:`text-strong`,children:t.domain})]}),(0,$.jsxs)(`p`,{children:[(0,$.jsx)(`span`,{className:`text-secondary`,children:`Site`}),` `,(0,$.jsx)(`span`,{className:`font-mono text-strong`,children:n})]}),(0,$.jsxs)(`p`,{children:[(0,$.jsx)(`span`,{className:`text-secondary`,children:`Last auth update`}),` `,(0,$.jsx)(`span`,{className:`text-strong`,children:t.updatedAt?Nn(t.updatedAt):`—`})]}),!Y()&&(0,$.jsx)(vs,{size:`sm`,variant:`ghost`,onClick:Jn(r),children:`Disconnect`})]})]}),children:(0,$.jsxs)(`div`,{className:`space-y-3`,children:[i&&(0,$.jsx)(`p`,{className:`text-copy-13 text-negative`,children:i}),p&&!f&&m?(0,$.jsxs)(Z,{className:`surface-card`,children:[(0,$.jsxs)(`p`,{className:`text-copy-14 text-negative`,children:[`Could not load Bing data: `,an(m)]}),(0,$.jsx)(q,{type:`button`,variant:`outline`,size:`sm`,className:`mt-3`,onClick:()=>{c.refetch(),l.refetch(),u.refetch()},children:`Retry`})]}):p&&!f?(0,$.jsx)(gu,{projectName:e,loadedAt:l.dataUpdatedAt}):(0,$.jsx)(_u,{projectName:e,siteUrl:n,range:a,onRangeChange:o}),(0,$.jsx)(Su,{projectName:e,siteUrl:n,snapshots:l.data?.snapshots}),f&&(0,$.jsx)(Cu,{projectName:e,siteUrl:n}),f&&(0,$.jsx)(bu,{projectName:e}),f&&(0,$.jsx)(Tu,{siteUrl:n,snapshots:l.data?.snapshots??[]})]})})}var mu=5e3;function hu(e){return e?.status===Ae.queued||e?.status===Ae.running}function gu({projectName:e,loadedAt:t}){let n=S(),r=w({..._r({client:K,path:{name:e},query:{kind:Se[`bing-sync`],limit:1}}),refetchInterval:e=>hu(e.state.data?.[0])?mu:!1,enabled:!Y()}),i=r.data?.[0],a=hu(i),[o,s]=(0,Q.useState)(!1),c=i&&!a&&i.finishedAt?Date.parse(i.finishedAt):0;(0,Q.useEffect)(()=>{c>t&&ka(n,Se[`bing-sync`],e)},[c,t,n,e]);async function l(){s(!0);try{let t=await Xt(e);Zo({id:t.id,projectId:t.projectId,kind:Se[`bing-sync`],projectLabel:e,sourceAction:`bing-sync`}),await r.refetch(),Xn({title:`Bing sync started`,detail:`Search data appears here when it finishes.`,tone:`neutral`,dedupeKey:`bing:sync:${e}`,dedupeMode:`replace`})}catch(t){Xn({title:`Bing sync could not start`,detail:an(t),tone:`negative`,dedupeKey:`bing:sync:${e}`,dedupeMode:`replace`})}finally{s(!1)}}let u=!a&&i?.status===Ae.failed;return(0,$.jsxs)(Z,{className:`surface-card`,children:[(0,$.jsx)(`h3`,{className:`text-heading-16 text-strong`,children:`No Bing search data yet`}),(0,$.jsx)(`p`,{className:`mt-1 text-copy-14 text-secondary`,children:a?`Bing sync ${i?.status===Ae.queued?`queued`:`running`}. Search data appears here when it finishes.`:`It arrives with the daily refresh.`}),u&&(0,$.jsxs)(`p`,{className:`mt-1 text-copy-13 text-negative`,children:[`Last sync failed`,i?.error?`: ${On(i.error)}`:`.`]}),!Y()&&(0,$.jsx)(vs,{className:`mt-3`,size:`sm`,disabled:a||o,onClick:Jn(l),children:a||o?`Sync running…`:u?`Try the sync again`:`Sync Bing data now`})]})}function _u({projectName:e,siteUrl:t,range:n,onRangeChange:r}){let i={name:e},a=w({...oa({client:K,path:i,query:{window:n}}),staleTime:Qn,placeholderData:j}),o=w({...Vi({client:K,path:i,query:{window:n,groupBy:`week`}}),staleTime:Qn,placeholderData:j}),s=w({...Zi({client:K,path:i,query:{surface:`index-coverage`,window:n}}),staleTime:Qn,placeholderData:j}),[c,l]=(0,Q.useState)([`clicks`,`impressions`]),[u,d]=(0,Q.useState)(!0),f=a.data,p=s.data?.groups.find(e=>e.key===`bing`)?.figures.find(e=>e.key===`indexed`)??null,m=f?.periodComparison??null,h;if(a.isPending)h=(0,$.jsx)(`p`,{className:`mt-3 text-copy-14 text-secondary`,children:`Loading Bing search data…`});else if(a.isError||!f)h=(0,$.jsxs)(`p`,{className:`mt-3 text-copy-14 text-negative`,children:[`Could not load Bing search data: `,an(a.error)]});else{let r=o.data?.totals?.avgImpressionPosition??null,i=eu(o.data?.comparison),s=m?.comparable?`vs prior ${m.days} ${m.days===1?`day`:`days`}`:void 0,g={key:`performance`,label:`Bing search`,basis:s!==void 0&&(i.kind!==`delta`||i.basis===s)?s:void 0,figures:Xl.map(e=>{if(e.key===`position`)return{key:e.key,label:e.label,help:Ql,color:e.color,value:r===null?`—`:e.format(r),change:i,interactive:!0,disabled:r===null};let t=f.totals[e.key];return{key:e.key,label:e.label,color:e.color,value:e.format(t),change:Ul(m,e.key,!1),interactive:!0,disabled:f.rows.length===0}})},_=p?{key:`indexed`,label:`Indexed pages`,basis:Es([p]),figures:[{key:Zl,label:`Bing`,color:ua[6],value:p.value===null?`—`:p.value.toLocaleString(),change:bs(p.change,p.unit),interactive:!0,disabled:p.value===null}]}:null,v=f.rows[0]?.date,y=f.rows.at(-1)?.date,b=f.earliestAvailableDate,x=f.window.startDate&&b&&f.window.startDate>b?f.window.startDate:b??f.window.startDate??v,S=f.window.endDate??y,C=new Map(f.rows.map(e=>[e.date,e])),w=new Map((o.data?.weekly??[]).map(e=>[e.date,e.avgImpressionPosition])),T=new Map((p?.series??[]).map(e=>[e.date,e.value])),E=x&&S?_t(x,S).map(e=>{let t=C.get(e);return{date:e,clicks:t?.clicks??0,impressions:t?.impressions??0,ctr:t&&t.impressions>0?t.ctr:null,position:w.get(e)??null,[Zl]:T.get(e)??null}}):[],D=[...Xl.filter(e=>c.includes(e.key)).map(e=>({dataKey:e.key,label:e.label,color:e.color,axisId:e.key,inverted:`inverted`in e?e.inverted:void 0,formatValue:e.format,trend:u&&e.key!==`position`?f.trends[e.key]:null,connectNulls:e.key===`position`})),...c.includes(Zl)&&p?[{dataKey:Zl,label:`Bing indexed pages`,color:ua[6],axisId:Zl,formatValue:e=>e.toLocaleString(),connectNulls:!0}]:[]];h=(0,$.jsxs)(`div`,{className:`mt-3`,children:[(0,$.jsx)(Os,{name:`Bing search figures`,frame:`none`,mode:`compare`,groups:_?[g,_]:[g],selected:c,refreshing:a.isFetching&&a.isPlaceholderData,onSelect:e=>l(t=>t.includes(e)?t.length===1?t:t.filter(t=>t!==e):[...t,e]),chart:E.length>0?(0,$.jsx)(da,{data:E,xKey:`date`,series:D,xTickFormatter:fa,labelFormatter:_a,ariaLabel:`Daily Bing search figures`}):void 0,emptyChartMessage:`Bing reported no search traffic in this window.`,legendExtra:(0,$.jsxs)(`label`,{className:`flex min-h-9 cursor-pointer items-center gap-2 pointer-coarse:min-h-11`,children:[(0,$.jsx)(`input`,{type:`checkbox`,className:`size-4 accent-mono-200 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-mono-400`,checked:u,onChange:e=>d(e.target.checked)}),`Trend line`]})}),(0,$.jsx)(vu,{projectName:e,siteUrl:t,range:n})]})}return(0,$.jsxs)(Z,{className:`surface-card`,children:[(0,$.jsxs)(`div`,{className:`section-head section-head-inline`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`h3`,{children:`Search performance`}),(0,$.jsx)(X,{text:`${Gl(m)} Clicks, impressions and CTR are Bing's daily totals for the whole site. The queries and pages below are the ones Bing names, reported per week, so they do not add up to the site total.`})]}),f?.window.startDate&&f.window.endDate&&(0,$.jsxs)(`p`,{className:`text-copy-13 text-muted`,children:[_a(f.window.startDate),` to `,_a(f.window.endDate)]})]}),(0,$.jsx)(nl,{windows:Jl,value:n,onChange:r,label:`Bing time period`,formatOption:e=>e===`all`?`All`:e})]}),h]})}function vu({projectName:e,siteUrl:t,range:n}){let[r,i]=(0,Q.useState)(`queries`),[a,o]=(0,Q.useState)(``),[s,c]=(0,Q.useState)(void 0),[l,f]=(0,Q.useState)(1),[p,m]=(0,Q.useState)(null),h={name:e},g=(l-1)*Yl;(0,Q.useEffect)(()=>{let e=a.trim()||void 0;if(e===void 0){c(void 0);return}let t=setTimeout(()=>c(e),300);return()=>clearTimeout(t)},[a]);let _=w({...Vi({client:K,path:h,query:{window:n,query:s,limit:Yl,offset:g}}),staleTime:Qn,placeholderData:j,enabled:r===`queries`}),v=w({...yi({client:K,path:h,query:{window:n,page:s,limit:Yl,offset:g}}),staleTime:Qn,placeholderData:j,enabled:r===`pages`}),y=r===`queries`?_:v,b=r===`queries`?(_.data?.rows??[]).map(e=>({key:e.query,...e})):(v.data?.rows??[]).map(e=>({key:e.page,...e})),x=y.data?.totalMatching??0,S=r===`queries`?`Query`:`Page`;return(0,Q.useEffect)(()=>{f(1),m(null)},[r,n,s]),(0,$.jsxs)(`div`,{className:`mt-4`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-end justify-between gap-3 border-b border-base`,children:[(0,$.jsx)(`div`,{className:`flex gap-1`,role:`tablist`,"aria-label":`Bing search rows`,children:[`queries`,`pages`].map(e=>(0,$.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":r===e,className:`border-b-2 px-3 py-1.5 text-button-14 transition-colors ${r===e?`border-mono-200 text-strong`:`border-transparent text-muted hover:text-neutral`}`,onClick:()=>i(e),children:e===`queries`?`Queries`:`Pages`},e))}),(0,$.jsx)(js,{className:`mb-1.5 w-full sm:w-64`,value:a,onChange:o,label:r===`queries`?`Filter Bing queries`:`Filter Bing pages`,placeholder:r===`queries`?`Contains query…`:`Contains page URL…`})]}),y.isError?(0,$.jsxs)(`p`,{className:`mt-3 text-copy-14 text-negative`,children:[`Could not load Bing `,r,`: `,an(y.error)]}):(0,$.jsx)(`div`,{className:`mt-2 overflow-x-auto`,children:(0,$.jsxs)(`table`,{className:`data-table w-full text-label-14`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{className:`w-7`,children:(0,$.jsx)(`span`,{className:`sr-only`,children:`Expand`})}),(0,$.jsx)(`th`,{className:`text-left`,children:S}),(0,$.jsx)(`th`,{className:`text-right`,children:`Clicks`}),(0,$.jsx)(`th`,{className:`text-right`,children:`Impressions`}),(0,$.jsx)(`th`,{className:`text-right`,children:`CTR`}),(0,$.jsx)(`th`,{className:`text-right`,children:`Position`})]})}),(0,$.jsxs)(`tbody`,{children:[b.length===0&&(0,$.jsx)(`tr`,{children:(0,$.jsx)(`td`,{colSpan:6,className:`py-6 text-center text-secondary`,children:y.isPending?`Loading…`:s?`No ${r} match "${s}" in this window.`:`Bing named no ${r} in this window.`})}),b.map(i=>{let a=p===i.key;return(0,$.jsxs)(Q.Fragment,{children:[(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{children:(0,$.jsx)(`button`,{type:`button`,"aria-expanded":a,"aria-label":`${a?`Hide`:`Show`} details for ${i.key}`,className:`rounded p-0.5 text-secondary hover:text-strong focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-mono-400`,onClick:()=>m(a?null:i.key),children:a?(0,$.jsx)(d,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}):(0,$.jsx)(u,{className:`h-3.5 w-3.5`,"aria-hidden":`true`})})}),(0,$.jsx)(`td`,{className:`max-w-md text-strong`,children:r===`pages`?(0,$.jsx)(Ss,{value:iu(i.key,t),title:i.key,className:`font-mono text-label-13`}):(0,$.jsx)(`span`,{className:`block truncate`,title:i.key,children:i.key})}),(0,$.jsx)(`td`,{className:`text-right tabular-nums text-neutral`,children:i.clicks.toLocaleString()}),(0,$.jsx)(`td`,{className:`text-right tabular-nums text-secondary`,children:i.impressions.toLocaleString()}),(0,$.jsx)(`td`,{className:`text-right tabular-nums text-secondary`,children:G(i.ctr)}),(0,$.jsx)(`td`,{className:`text-right tabular-nums text-secondary`,children:tu(i.avgImpressionPosition)})]}),a&&(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{}),(0,$.jsx)(`td`,{colSpan:5,className:`pb-4`,children:(0,$.jsx)(yu,{projectName:e,siteUrl:t,range:n,tab:r,rowKey:i.key})})]})]},i.key)})]})]})}),(0,$.jsx)(`div`,{className:`mt-2 flex justify-end`,children:(0,$.jsx)(Ts,{page:l,pageSize:Yl,visibleRows:b.length,totalRows:x,disabled:y.isFetching,itemLabel:r,onPageChange:f})})]})}function yu({projectName:e,siteUrl:t,range:n,tab:r,rowKey:i}){let a={name:e},[o,s]=(0,Q.useState)(!1),c=w({...Vi({client:K,path:a,query:{window:n,query:i,match:`exact`,groupBy:`week`}}),staleTime:Qn,enabled:r===`queries`}),l=w({...yi({client:K,path:a,query:{window:n,page:i,match:`exact`,groupBy:`week`}}),staleTime:Qn,enabled:r===`pages`}),u=w({...Li({client:K,path:a,query:{query:i}}),staleTime:Qn,retry:!1,enabled:o&&r===`queries`}),d=w({...gi({client:K,path:a,query:{page:i}}),staleTime:Qn,retry:!1,enabled:o&&r===`pages`}),f=(r===`queries`?c.data?.weekly:l.data?.weekly)??[],m=r===`queries`?u:d,h=m.data?.rows??[],g=r===`queries`?`Pages`:`Queries`;return(0,$.jsxs)(`div`,{className:`grid gap-6 lg:grid-cols-[minmax(260px,1fr)_minmax(280px,1.4fr)]`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`mb-1.5 text-label-13-strong text-strong`,children:`By week`}),(0,$.jsxs)(`table`,{className:`data-table w-full text-label-13`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{className:`text-left`,children:`Week`}),(0,$.jsx)(`th`,{className:`text-right`,children:`Clicks`}),(0,$.jsx)(`th`,{className:`text-right`,children:`Impr.`}),(0,$.jsx)(`th`,{className:`text-right`,children:`Pos.`})]})}),(0,$.jsxs)(`tbody`,{children:[f.length===0&&(0,$.jsx)(`tr`,{children:(0,$.jsx)(`td`,{colSpan:4,className:`py-3 text-secondary`,children:(r===`queries`?c:l).isPending?`Loading…`:`No weeks in this window.`})}),f.map(e=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{className:`tabular-nums`,children:_a(e.date)}),(0,$.jsx)(`td`,{className:`text-right tabular-nums`,children:e.clicks.toLocaleString()}),(0,$.jsx)(`td`,{className:`text-right tabular-nums text-secondary`,children:e.impressions.toLocaleString()}),(0,$.jsx)(`td`,{className:`text-right tabular-nums text-secondary`,children:tu(e.avgImpressionPosition)})]},e.date))]})]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`p`,{className:`mb-1.5 flex items-baseline gap-2 text-label-13-strong text-strong`,children:[g,` for this `,r===`queries`?`query`:`page`,m.isSuccess&&(0,$.jsx)(`span`,{className:`text-label-12 text-secondary`,children:`from Bing, by week`})]}),!o&&(Y()?(0,$.jsx)(`p`,{className:`text-copy-13 text-secondary`,children:`Not available here.`}):(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsxs)(q,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>s(!0),children:[(0,$.jsx)(y,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),`Load `,g.toLowerCase(),` from Bing`]}),(0,$.jsx)(X,{label:`Live`,text:$l})]})),o&&m.isPending&&(0,$.jsx)(`p`,{className:`text-copy-13 text-secondary`,children:`Asking Bing…`}),o&&m.isError&&(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(X,{tone:`caution`,label:`Bing refused this read`,text:`${an(m.error)} Nothing was stored.`}),(0,$.jsxs)(q,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>void m.refetch(),children:[(0,$.jsx)(p,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),`Retry`]})]}),o&&m.isSuccess&&(h.length===0?(0,$.jsxs)(`p`,{className:`text-copy-13 text-secondary`,children:[`Bing named no `,g.toLowerCase(),` for this `,r===`queries`?`query`:`page`,`.`]}):(0,$.jsxs)(`table`,{className:`data-table w-full text-label-13`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{className:`text-left`,children:`Week`}),(0,$.jsx)(`th`,{className:`text-left`,children:r===`queries`?`Page`:`Query`}),(0,$.jsx)(`th`,{className:`text-right`,children:`Clicks`}),(0,$.jsx)(`th`,{className:`text-right`,children:`Impr.`}),(0,$.jsx)(`th`,{className:`text-right`,children:`Pos.`})]})}),(0,$.jsx)(`tbody`,{children:h.map((e,n)=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{className:`tabular-nums text-secondary`,children:e.date?_a(e.date):`—`}),(0,$.jsx)(`td`,{className:`max-w-xs`,children:r===`queries`?(0,$.jsx)(Ss,{value:iu(e.key,t),title:e.key,className:`font-mono`}):(0,$.jsx)(`span`,{className:`block truncate`,title:e.key,children:e.key})}),(0,$.jsx)(`td`,{className:`text-right tabular-nums`,children:e.clicks.toLocaleString()}),(0,$.jsx)(`td`,{className:`text-right tabular-nums text-secondary`,children:e.impressions.toLocaleString()}),(0,$.jsx)(`td`,{className:`text-right tabular-nums text-secondary`,children:tu(e.avgImpressionPosition)})]},`${e.date}:${e.key}:${n}`))})]}))]})]})}function bu({projectName:e}){let t=w({...Xi({client:K,path:{name:e}}),staleTime:Qn}),[n,r]=(0,Q.useState)(null),i=t.data?.market,a=t.data?.rows??[];return(0,$.jsxs)(Z,{className:`surface-card`,children:[(0,$.jsxs)(`div`,{className:`section-head section-head-inline`,children:[(0,$.jsx)(`h3`,{children:`Search demand`}),i&&(0,$.jsx)(X,{label:`${i.country.toUpperCase()} · ${i.language}`,text:`Exact-match Bing searches per week for your tracked queries, averaged over the weeks stored. This is demand, not your traffic. Refreshed weekly.`})]}),t.isError?(0,$.jsxs)(`p`,{className:`text-copy-14 text-negative`,children:[`Could not load search demand: `,an(t.error)]}):(0,$.jsx)(`div`,{className:`overflow-x-auto`,children:(0,$.jsxs)(`table`,{className:`data-table w-full text-label-14`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{className:`w-7`,children:(0,$.jsx)(`span`,{className:`sr-only`,children:`Expand`})}),(0,$.jsx)(`th`,{className:`text-left`,children:`Tracked query`}),(0,$.jsx)(`th`,{className:`text-right`,children:`Searches / week`}),(0,$.jsx)(`th`,{className:`text-right`,children:`Latest week`})]})}),(0,$.jsxs)(`tbody`,{children:[a.length===0&&(0,$.jsx)(`tr`,{children:(0,$.jsx)(`td`,{colSpan:4,className:`py-6 text-center text-secondary`,children:t.isPending?`Loading…`:`No search demand stored yet. It is read weekly for tracked queries.`})}),a.map(t=>{let i=n===t.query;return(0,$.jsxs)(Q.Fragment,{children:[(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{children:(0,$.jsx)(`button`,{type:`button`,"aria-expanded":i,"aria-label":`${i?`Hide`:`Show`} weekly searches for ${t.query}`,className:`rounded p-0.5 text-secondary hover:text-strong focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-mono-400`,onClick:()=>r(i?null:t.query),children:i?(0,$.jsx)(d,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}):(0,$.jsx)(u,{className:`h-3.5 w-3.5`,"aria-hidden":`true`})})}),(0,$.jsx)(`td`,{className:`text-strong`,children:t.query}),(0,$.jsx)(`td`,{className:`text-right tabular-nums text-neutral`,children:nu(t.avgWeeklyImpressions)}),(0,$.jsx)(`td`,{className:`text-right tabular-nums text-secondary`,children:nu(t.latestImpressions)})]}),i&&(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{}),(0,$.jsx)(`td`,{colSpan:3,className:`pb-4`,children:(0,$.jsx)(xu,{projectName:e,query:t.query})})]})]},t.query)})]})]})})]})}function xu({projectName:e,query:t}){let n=w({...Xi({client:K,path:{name:e},query:{query:t}}),staleTime:Qn}),r=n.data?.history??[];return n.isPending?(0,$.jsx)(`p`,{className:`text-copy-13 text-secondary`,children:`Loading…`}):r.length===0?(0,$.jsx)(`p`,{className:`text-copy-13 text-secondary`,children:`No weeks stored.`}):(0,$.jsxs)(`table`,{className:`data-table w-full max-w-md text-label-13`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{className:`text-left`,children:`Week`}),(0,$.jsx)(`th`,{className:`text-right`,children:`Exact`}),(0,$.jsx)(`th`,{className:`text-right`,children:`Broad`})]})}),(0,$.jsx)(`tbody`,{children:r.map(e=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{className:`tabular-nums`,children:_a(e.date)}),(0,$.jsx)(`td`,{className:`text-right tabular-nums`,children:e.impressions.toLocaleString()}),(0,$.jsx)(`td`,{className:`text-right tabular-nums text-secondary`,children:e.broadImpressions.toLocaleString()})]},e.date))})]})}function Su({projectName:e,siteUrl:t,snapshots:n}){let r=S(),i={name:e},a=w({...Ki({client:K,path:i}),staleTime:Qn}),o=w({...Fi({client:K,path:i}),staleTime:Qn}),s=w({...hi({client:K,path:i,query:{days:`30`}}),staleTime:Qn}),[c,l]=(0,Q.useState)(`not-indexed`),[u,d]=(0,Q.useState)(!1),[f,p]=(0,Q.useState)(``),[m,h]=(0,Q.useState)(null),[g,_]=(0,Q.useState)(null),v=ou(au(n,`url-submission-quota`)),y=a.data?.summary,b=s.data?.rows[0],x=a.data?.notIndexed??[],C=a.data?.unknown??[],T=a.data?.indexed??[],E=o.data??[];async function D(t,n){d(!0),_(null);try{let{succeeded:i,failed:a,total:o}=(await Bt(e,t)).summary;Xn({title:a===0?`Sent to Bing`:`Some URLs were not sent`,detail:a===0?`${i} of ${o} URL${o===1?``:`s`} submitted.`:`${i} of ${o} submitted, ${a} not sent.`,tone:a===0?`positive`:`caution`,dedupeKey:`bing:indexing:${e}:${n}`,dedupeMode:`replace`}),await Zn(r,`bing`)}catch(t){let r=an(t);_(r),Xn({title:`Bing submission failed`,detail:r,tone:`negative`,dedupeKey:`bing:indexing:${e}:${n}`,dedupeMode:`replace`})}finally{d(!1)}}async function O(){if(f.trim()){_(null);try{let t=await Et(e,f.trim());h(t),await Zn(r,`bing`)}catch(e){_(an(e))}}}let k=y?[{label:`Indexed`,value:y.indexed.toLocaleString()},{label:`Not in index`,value:(y.notIndexed+(y.unknown??0)).toLocaleString(),tooltip:`Pages Bing has not confirmed in its index, including those with an unknown status.`},{label:`Status unknown`,value:(y.unknown??0).toLocaleString()},{label:`Coverage`,value:G(y.percentage,rt.percent)}]:[],A=Ds({rows:c===`not-indexed`?x:c===`unknown`?C:c===`indexed`?T:[],pageSize:Yl}),j=Ds({rows:E,pageSize:Yl}),M=Ds({rows:s.data?.rows??[],pageSize:Yl}),N=[{key:`not-indexed`,label:`Not indexed (${x.length})`},{key:`unknown`,label:`Status unknown (${C.length})`},{key:`indexed`,label:`Indexed (${T.length})`},{key:`inspections`,label:`Inspections (${E.length})`},{key:`crawl`,label:`Crawl by day`}],P=!Y()&&(c===`not-indexed`||c===`unknown`)&&(c===`not-indexed`?x.length:C.length)>0;return(0,$.jsxs)(Z,{className:`surface-card`,children:[(0,$.jsxs)(`div`,{className:`section-head section-head-inline`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1`,children:[(0,$.jsx)(`h3`,{children:`Index and crawl`}),b&&b.crawlErrors>0&&(0,$.jsx)(X,{tone:`caution`,label:`${b.crawlErrors.toLocaleString()} crawl error${b.crawlErrors===1?``:`s`}`,text:`Bingbot got errors from ${b.crawlErrors===1?`one URL`:`${b.crawlErrors.toLocaleString()} URLs`} on ${_a(b.date)}. Crawl by day has the codes.`})]}),(0,$.jsx)(`p`,{className:`text-copy-13 text-muted`,children:a.data?.lastInspectedAt?`Last inspected ${Nn(a.data.lastInspectedAt)}`:`No inspection history yet`})]}),(0,$.jsx)(`div`,{className:`space-y-4`,children:k.length>0?(0,$.jsx)(ul,{label:`Bing index coverage`,items:k}):(0,$.jsx)(`p`,{className:`text-copy-13 text-muted`,children:`No coverage data yet. Inspect URLs to build coverage data.`})}),(0,$.jsxs)(`div`,{className:`mt-4 flex flex-wrap items-end justify-between gap-3 border-b border-base`,children:[(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1`,role:`tablist`,"aria-label":`Bing index and crawl lists`,children:N.map(e=>(0,$.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":c===e.key,className:`border-b-2 px-3 py-1.5 text-button-14 transition-colors ${c===e.key?`border-mono-200 text-strong`:`border-transparent text-muted hover:text-neutral`}`,onClick:()=>{l(e.key),A.setPage(1)},children:e.label},e.key))}),P&&(0,$.jsxs)(`div`,{className:`mb-1.5 flex flex-wrap items-center gap-2`,children:[v&&(0,$.jsxs)(`span`,{className:`text-label-13 text-secondary`,children:[v.dailyQuota.toLocaleString(),` submissions left today`]}),(0,$.jsx)(vs,{size:`sm`,variant:`outline`,disabled:u,onClick:Jn(()=>D({allUnindexed:!0},`all`)),children:u?`Submitting…`:`Submit all to Bing`})]})]}),g&&(0,$.jsx)(`p`,{className:`mt-2 text-copy-13 text-negative`,children:g}),(0,$.jsxs)(`div`,{className:`mt-2 overflow-x-auto`,children:[(c===`not-indexed`||c===`unknown`||c===`indexed`)&&(()=>{let e=c!==`indexed`&&!Y();return(0,$.jsxs)(`table`,{className:`data-table w-full text-label-14`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{className:`text-left`,children:`URL`}),(0,$.jsx)(`th`,{className:`text-right`,children:c===`not-indexed`?`HTTP`:`Last crawled`}),e&&(0,$.jsx)(`th`,{className:`text-right`,children:(0,$.jsx)(`span`,{className:`sr-only`,children:`Action`})})]})}),(0,$.jsxs)(`tbody`,{children:[A.totalRows===0&&(0,$.jsx)(`tr`,{children:(0,$.jsx)(`td`,{colSpan:e?3:2,className:`py-6 text-center text-secondary`,children:a.isPending?`Loading…`:`None.`})}),A.rows.map(n=>(0,$.jsxs)(`tr`,{className:`group`,children:[(0,$.jsx)(`td`,{className:`max-w-lg`,children:(0,$.jsx)(Ss,{value:iu(n.url,t),title:n.url,className:`font-mono text-label-13 text-neutral`})}),(0,$.jsx)(`td`,{className:`text-right tabular-nums text-secondary`,children:c===`not-indexed`?n.httpCode??`—`:n.lastCrawledDate?Nn(n.lastCrawledDate):`—`}),e&&(0,$.jsx)(`td`,{className:`text-right`,children:(0,$.jsx)(`div`,{className:`opacity-0 transition-opacity group-hover:opacity-100 group-focus-within:opacity-100 pointer-coarse:opacity-100`,children:(0,$.jsx)(vs,{size:`sm`,variant:`ghost`,disabled:u,onClick:Jn(()=>D({urls:[n.url]},n.url)),children:`Submit`})})})]},n.id))]})]})})(),(c===`not-indexed`||c===`unknown`||c===`indexed`)&&(0,$.jsx)(Ts,{page:A.page,pageSize:Yl,visibleRows:A.rows.length,totalRows:A.totalRows,onPageChange:A.setPage,itemLabel:`URLs`}),c===`inspections`&&(0,$.jsxs)(`div`,{className:`space-y-3 pt-2`,children:[!Y()&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 lg:flex-row`,children:[(0,$.jsx)(`input`,{type:`text`,"aria-label":`URL to inspect`,className:`flex-1 rounded border border-strong bg-transparent px-2 py-1.5 text-label-14 text-strong placeholder-mono-400 focus:border-mono-500 focus:outline-none`,placeholder:`URL to inspect`,value:f,onChange:e=>p(e.target.value),onKeyDown:e=>{e.key===`Enter`&&O()}}),(0,$.jsx)(vs,{size:`sm`,disabled:!f.trim(),onClick:Jn(O),children:`Inspect`})]}),m&&(0,$.jsxs)(`div`,{className:`material-base space-y-1 p-3 text-label-13`,children:[(0,$.jsx)(`div`,{className:`text-label-13-strong text-strong`,children:m.url}),(0,$.jsxs)(`div`,{className:`text-secondary`,children:[`In index: `,(0,$.jsx)(`span`,{className:m.inIndex?`text-positive`:`text-negative`,children:m.inIndex?`Yes`:`No`}),` · `,`HTTP: `,m.httpCode??`—`,` · `,`Crawled: `,m.lastCrawledDate??`—`]})]}),(0,$.jsxs)(`table`,{className:`data-table w-full text-label-14`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{className:`text-left`,children:`URL`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Index`}),(0,$.jsx)(`th`,{className:`text-right`,children:`HTTP`}),(0,$.jsx)(`th`,{className:`text-right`,children:`Inspected`})]})}),(0,$.jsxs)(`tbody`,{children:[E.length===0&&(0,$.jsx)(`tr`,{children:(0,$.jsx)(`td`,{colSpan:4,className:`py-6 text-center text-secondary`,children:o.isPending?`Loading…`:`No inspections yet.`})}),j.rows.map(e=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{className:`max-w-lg`,children:(0,$.jsx)(Ss,{value:iu(e.url,t),title:e.url,className:`font-mono text-label-13 text-neutral`})}),(0,$.jsx)(`td`,{children:(0,$.jsx)(J,{tone:e.inIndex?`positive`:`negative`,children:e.inIndex?`Yes`:`No`})}),(0,$.jsx)(`td`,{className:`text-right tabular-nums text-secondary`,children:e.httpCode??`—`}),(0,$.jsx)(`td`,{className:`text-right tabular-nums text-secondary`,children:Nn(e.inspectedAt)})]},e.id))]})]}),(0,$.jsx)(Ts,{page:j.page,pageSize:Yl,visibleRows:j.rows.length,totalRows:j.totalRows,onPageChange:j.setPage,itemLabel:`inspections`})]}),c===`crawl`&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`table`,{className:`data-table w-full text-label-13`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{className:`text-left`,children:`Day`}),(0,$.jsx)(`th`,{className:`text-right`,children:`Crawled`}),(0,$.jsx)(`th`,{className:`text-right`,children:`Errors`}),(0,$.jsx)(`th`,{className:`text-right`,children:`In index`}),(0,$.jsx)(`th`,{className:`text-right`,children:`2xx`}),(0,$.jsx)(`th`,{className:`text-right`,children:`301`}),(0,$.jsx)(`th`,{className:`text-right`,children:`302`}),(0,$.jsx)(`th`,{className:`text-right`,children:`4xx`}),(0,$.jsx)(`th`,{className:`text-right`,children:`5xx`}),(0,$.jsx)(`th`,{className:`text-right`,children:`Other`}),(0,$.jsx)(`th`,{className:`text-right`,children:`Robots.txt`}),(0,$.jsx)(`th`,{className:`text-right`,children:`Timeouts`}),(0,$.jsx)(`th`,{className:`text-right`,children:`DNS`}),(0,$.jsx)(`th`,{className:`text-right`,children:`Malware`}),(0,$.jsx)(`th`,{className:`text-right`,children:`Inbound links`})]})}),(0,$.jsxs)(`tbody`,{children:[(s.data?.rows??[]).length===0&&(0,$.jsx)(`tr`,{children:(0,$.jsx)(`td`,{colSpan:15,className:`py-6 text-center text-secondary`,children:s.isPending?`Loading…`:`No crawl stats stored yet.`})}),M.rows.map(e=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{className:`tabular-nums`,children:_a(e.date)}),[e.crawledPages,e.crawlErrors,e.inIndex,e.code2xx,e.code301,e.code302,e.code4xx,e.code5xx,e.allOtherCodes,e.blockedByRobotsTxt,e.connectionTimeout,e.dnsFailures,e.containsMalware,e.inLinks].map((e,t)=>(0,$.jsx)(`td`,{className:`text-right tabular-nums text-secondary`,children:e.toLocaleString()},t))]},e.date))]})]}),(0,$.jsx)(Ts,{page:M.page,pageSize:Yl,visibleRows:M.rows.length,totalRows:M.totalRows,onPageChange:M.setPage,itemLabel:`days`})]})]})]})}function Cu({projectName:e,siteUrl:t}){let{canWrite:n}=qn(),r=w({...Cr({client:K,path:{name:e}}),staleTime:Qn}),[i,a]=(0,Q.useState)(!1),[o,s]=(0,Q.useState)(!1);async function c(t){a(!0);let n=[];try{for(let r of t)await wt(e,r),n.push(r);let r=n.length;Xn({title:r===1?`Sent to Bing`:`${r} sitemaps sent to Bing`,detail:`Bing reads it soon. A new sitemap shows in the list after the next Bing sync.`,tone:`positive`,dedupeKey:`bing:submit-sitemap:${e}`,dedupeMode:`replace`})}catch(r){Xn({title:n.length>0?`Bing took ${n.length} of ${t.length}`:`Bing did not take the sitemap`,detail:an(r),tone:`negative`,dedupeKey:`bing:submit-sitemap:${e}`,dedupeMode:`replace`})}finally{a(!1)}return n}async function l(t){s(!0);try{await kt(e,{sitemapUrl:t}),Xn({title:`Checking sitemap URLs in Bing`,detail:`Coverage updates when the check finishes.`,tone:`neutral`,dedupeKey:`bing:inspect-sitemap:${e}`,dedupeMode:`replace`})}catch(t){Xn({title:`Sitemap check could not start`,detail:an(t),tone:`negative`,dedupeKey:`bing:inspect-sitemap:${e}`,dedupeMode:`replace`})}finally{s(!1)}}return(0,$.jsx)(Pl,{engine:`Bing`,data:r.isError?null:r.isPending?void 0:r.data.bing,loadError:r.isError?an(r.error):null,label:e=>iu(e,t),canSubmit:n,onSubmit:c,submitting:i,onInspect:e=>void l(e),inspecting:o,notRead:(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:`Bing's sitemap list arrives with the next Bing sync.`}),readOnly:Y()})}var wu=`Bing shows this only to the site owner key. Not a failure.`;function Tu({siteUrl:e,snapshots:t}){let n=ou(au(t,`url-submission-quota`)),r=ou(au(t,`content-submission-quota`)),i=su(au(t,`crawl-settings`)),a=[{kind:`blocked-urls`,label:`Blocked URLs`,columns:[{key:`url`,label:`URL`},{key:`entityType`,label:`Type`},{key:`requestType`,label:`Removal`},{key:`daysToExpire`,label:`Days left`},{key:`date`,label:`Added`}]},{kind:`page-preview-blocks`,label:`Preview blocks`,columns:[]},{kind:`deep-link-blocks`,label:`Sitelink blocks`,columns:[]},{kind:`query-parameters`,label:`URL parameters`,columns:[{key:`parameter`,label:`Parameter`},{key:`isEnabled`,label:`Enabled`},{key:`source`,label:`Source`},{key:`date`,label:`Added`}]},{kind:`country-region-settings`,label:`Geo-targeting`,columns:[{key:`url`,label:`URL`},{key:`countryCode`,label:`Country`},{key:`type`,label:`Applies to`},{key:`date`,label:`Added`}]},{kind:`crawl-issues`,label:`Crawl issues`,columns:[{key:`url`,label:`URL`},{key:`httpCode`,label:`HTTP`},{key:`issues`,label:`Issues`},{key:`inLinks`,label:`Inbound links`}]},{kind:`fetched-urls`,label:`Fetch as Bingbot`,columns:[{key:`url`,label:`URL`},{key:`fetched`,label:`Fetched`},{key:`expired`,label:`Expired`},{key:`date`,label:`Requested`}]},{kind:`connected-pages`,label:`Connected pages`,columns:[]},{kind:`site-roles`,label:`Users and roles`,columns:[{key:`email`,label:`User`},{key:`role`,label:`Role`},{key:`expired`,label:`Expired`},{key:`date`,label:`Added`}]}];function o(e,t){if(!e)return{value:`—`,help:`Not read yet.`};if(e.status===`unauthorized`)return{value:`Owner key needed`,help:wu};if(e.status===`failed`&&t===null)return{value:`—`,help:`The last read failed: ${e.error??`no detail`}`};let n=t?.length??0;return{value:n===0?`None`:n.toLocaleString()}}let s=a.map(({kind:n,label:r,columns:i})=>{let a=au(t,n),s=cu(a),{value:c,help:l}=o(a,s),u=a?.status===`failed`&&s!==null,d=i.length>0||!s?i:[...new Set(s.flatMap(e=>Object.keys(e)))].filter(e=>e!==`__type`).map(e=>({key:e,label:e}));return(0,$.jsx)(Eu,{label:r,value:c,help:l,note:u?`from an earlier sync`:void 0,children:s&&s.length>0?(0,$.jsxs)(`div`,{className:`overflow-x-auto`,children:[u&&(0,$.jsxs)(`p`,{className:`mb-2 text-copy-13 text-caution`,children:[`The last read failed, so these rows are from an earlier sync: `,a?.error??`no detail`]}),(0,$.jsxs)(`table`,{className:`data-table w-full text-label-13`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsx)(`tr`,{children:d.map(e=>(0,$.jsx)(`th`,{className:`text-left`,children:e.label},e.key))})}),(0,$.jsx)(`tbody`,{children:s.map((t,n)=>(0,$.jsx)(`tr`,{children:d.map(n=>{let r=t[n.key]??t[n.key.charAt(0).toUpperCase()+n.key.slice(1)];return(0,$.jsx)(`td`,{className:n.key.toLowerCase()===`url`?`max-w-md`:`text-secondary`,children:n.key.toLowerCase()===`url`&&typeof r==`string`?(0,$.jsx)(Ss,{value:iu(r,e),title:r,className:`font-mono text-neutral`}):uu(r,n.key)},n.key)})},n))})]})]}):void 0},n)}),c=e=>s[a.findIndex(t=>t.kind===e)],l=e=>e?`${e.dailyQuota.toLocaleString()} today \u00b7 ${e.monthlyQuota.toLocaleString()} this month`:`—`;return(0,$.jsxs)(Z,{className:`surface-card`,children:[(0,$.jsx)(`div`,{className:`section-head section-head-inline`,children:(0,$.jsx)(`h3`,{children:`Site settings`})}),(0,$.jsxs)(`div`,{role:`list`,"aria-label":`Bing site settings`,children:[c(`blocked-urls`),c(`crawl-issues`),(0,$.jsx)(Eu,{label:`URL submissions left`,value:l(n),help:`URL submissions Bing will still accept, as of the last sync.`}),(0,$.jsx)(Eu,{label:`Content submissions left`,value:l(r)}),(0,$.jsx)(Eu,{label:`Crawl boost`,value:i?i.crawlBoostEnabled?`On`:i.crawlBoostAvailable?`Off`:`Not offered`:`—`}),i&&i.crawlRate.length===24&&(0,$.jsx)(Eu,{label:`Crawl rate by hour`,value:`24 hours`,children:(0,$.jsx)(`div`,{className:`overflow-x-auto`,children:(0,$.jsxs)(`table`,{className:`data-table text-label-13`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsx)(`tr`,{children:i.crawlRate.map((e,t)=>(0,$.jsx)(`th`,{className:`text-right`,children:t},t))})}),(0,$.jsx)(`tbody`,{children:(0,$.jsx)(`tr`,{children:i.crawlRate.map((e,t)=>(0,$.jsx)(`td`,{className:`text-right tabular-nums text-secondary`,children:e},t))})})]})})}),c(`fetched-urls`),c(`query-parameters`),c(`country-region-settings`),c(`page-preview-blocks`),c(`deep-link-blocks`),c(`connected-pages`),c(`site-roles`)]})]})}function Eu({label:e,value:t,help:n,note:r,children:i}){let[a,o]=(0,Q.useState)(!1),s=(0,$.jsx)(`span`,{className:`flex-1 text-label-14 text-strong`,children:e}),c=(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5 text-label-14 tabular-nums text-secondary`,children:[r&&(0,$.jsx)(`span`,{className:`text-label-12 text-caution`,children:r}),t]});return i?(0,$.jsx)(`div`,{role:`listitem`,className:`border-t border-default first:border-t-0`,children:(0,$.jsxs)(`details`,{className:`group`,onToggle:e=>o(e.currentTarget.open),children:[(0,$.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center gap-2 py-2.5 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-mono-400 [&::-webkit-details-marker]:hidden`,children:[(0,$.jsx)(u,{className:`h-3.5 w-3.5 shrink-0 text-secondary transition-transform group-open:rotate-90`,"aria-hidden":`true`}),s,c]}),a&&(0,$.jsx)(`div`,{className:`pb-4 pl-5.5`,children:i})]})}):(0,$.jsxs)(`div`,{role:`listitem`,className:`flex items-center gap-2 border-t border-default py-2.5 first:border-t-0`,children:[(0,$.jsx)(`span`,{className:`w-3.5 shrink-0`,"aria-hidden":`true`}),s,c,n&&(0,$.jsx)(X,{text:n})]})}var Du=ua[0],Ou=ua[1],ku=ua[2],Au=ua[3],ju=ua[4],Mu=[`both`,`server`,`ga4`],Nu=[`days`,`months`],Pu={serverLoading:`Loading monthly server visits…`,gaLoading:`Loading monthly GA4 visits…`,gaStatusLoading:`Checking the GA4 connection…`,serverError:`Could not load monthly server visits.`,gaError:`Could not load monthly GA4 visits.`,gaStatusError:`Could not check the GA4 connection.`,retryServer:`Retry monthly server visits`,retryGa:`Retry monthly GA4 visits`,retryGaStatus:`Retry GA4 connection check`,connectGa:`Connect Google Analytics 4 to see monthly visits.`,emptyMonths:`No monthly visits recorded yet.`},Fu=e=>new Date(`${e}-01T00:00:00.000Z`),Iu=e=>Fu(e).toLocaleDateString(void 0,{month:`short`,timeZone:`UTC`}),Lu=e=>Fu(String(e)).toLocaleDateString(void 0,{month:`long`,year:`numeric`,timeZone:`UTC`}),Ru=e=>Number(e.slice(0,4))*12+Number(e.slice(5,7)),zu={fontSize:12,paddingTop:6},Bu=e=>typeof e==`number`?Tt(Math.round(e)):String(e),Vu=`Visits, server`,Hu=`${Vu} (older count)`,Uu=`${Vu} (part month)`,Wu=`Visits, GA4 (part month)`,Gu=e=>typeof e==`number`&&Number.isFinite(e)?e:0;function Ku(e,t){if(!e||t<2)return Array(t).fill(null);let n=e.endIndex-e.startIndex;if(n<=0)return Array(t).fill(null);let r=(e.end-e.start)/n;return Array.from({length:t},(t,n)=>n<e.startIndex||n>e.endIndex?null:e.start+(n-e.startIndex)*r)}function qu(e,t){if(!e||t<e.startMonth||t>e.endMonth)return null;let n=Ru(e.endMonth)-Ru(e.startMonth);return n<=0?null:e.start+(e.end-e.start)*((Ru(t)-Ru(e.startMonth))/n)}function Ju(e,t){if(!e||t<e.startDate||t>e.endDate)return null;let n=Date.parse(`${e.startDate}T00:00:00.000Z`),r=Date.parse(`${e.endDate}T00:00:00.000Z`)-n;return r<=0?null:e.start+(e.end-e.start)*((Date.parse(`${t}T00:00:00.000Z`)-n)/r)}function Yu(e){let t=e=>e.measured!==!1;if(e.length===0||t(e[0]))return null;let n=e.findIndex(t)-1;return n<0?{from:e[0].bucket,to:e[e.length-1].bucket}:{from:e[0].bucket,to:e[n].bucket}}function Xu(e,t){if(!t)return null;let n=e.find(e=>e.measured!==!1),r=e[e.length-1]?.bucket;return!n||!r||t<n.bucket?null:{from:n.bucket,to:t<r?t:r}}function Zu(e,t,n=!1){return r=>{let{cx:i,cy:a,index:o,key:s}=r,c=o??-1,l=e[c]!=null&&e[c-1]==null&&e[c+1]==null;return e[c]==null||!n&&!l||i===void 0||a===void 0?(0,$.jsx)(`g`,{},s):n?(0,$.jsx)(`circle`,{cx:i,cy:a,r:3.2,fill:`none`,stroke:t,strokeWidth:1.6},s):(0,$.jsx)(`circle`,{cx:i,cy:a,r:2.6,fill:t,stroke:`none`},s)}}function Qu({projectName:e,sinceMinutes:t}){let[n,r]=(0,Q.useState)(!0),[i,a]=(0,Q.useState)(!0),[o,s]=(0,Q.useState)(`both`),[c,l]=(0,Q.useState)(`days`),u=c===`months`,d=(0,Q.useMemo)(()=>{let e=new Date;return{since:new Date(Date.UTC(e.getUTCFullYear(),e.getUTCMonth()-11,1)).toISOString(),until:e.toISOString()}},[]),f=Vs(e,{range:d,granularity:`month`,limit:1},{enabled:u}),p=Vs(e,{sinceMinutes:t,granularity:`day`,limit:1}),m=Us(e),h=w({...ir({client:K,path:{name:e}}),enabled:!!e,staleTime:er}),g=h.data?.connected===!0,_=w({...hr({client:K,path:{name:e},query:{window:t>=259200?`180d`:t>=129600?`90d`:t>=43200?`30d`:`7d`}}),enabled:!!e&&g,staleTime:er}),v=w({...hr({client:K,path:{name:e},query:{startDate:d.since.slice(0,10)}}),enabled:!!e&&g&&u,staleTime:er}),y=(0,Q.useMemo)(()=>p.data?.series?.points??[],[p.data]),b=(0,Q.useMemo)(()=>{let e=_.data;return new Map((e?.days??[]).map(e=>[e.date,e.sessions]))},[_.data]),x=_.data?.trend??null,S=(0,Q.useMemo)(()=>Yu(y),[y]),C=p.data?.series?.coverageStart??null,T=p.data?.series?.aiReferralCountingChangedAt??null,E=(0,Q.useMemo)(()=>Xu(y,T?.slice(0,10)),[T,y]),D=p.data?.series?.trends,O=(0,Q.useMemo)(()=>{let e=Ku(D?.crawlerContentHits,y.length),t=Ku(D?.aiUserFetchHits,y.length),n=Ku(D?.aiReferralLandedHits,y.length);return y.map((r,i)=>({...r,crawlerContentHits:r.measured===!1?null:Gu(r.crawlerContentHits),aiUserFetchHits:r.measured===!1?null:Gu(r.aiUserFetchHits),aiReferralLandedHits:r.measured===!1?null:Gu(r.aiReferralLandedHits),ga4Visits:b.get(r.bucket)??null,ga4Trend:Ju(x,r.bucket),crawlTrend:e[i],fetchTrend:t[i],visitTrend:n[i]}))},[y,b,x,D]),k=f.data?.series,A=v.data,j=(0,Q.useMemo)(()=>k?.points??[],[k]),ie=(0,Q.useMemo)(()=>{let e=new Set(k?.partialBuckets??[]),t=new Map((A?.months??[]).map(e=>[e.month,e])),n=Ku(k?.trends?.aiReferralLandedHits,j.length),r=new Map(j.map((e,t)=>[e.bucket,{point:e,trend:n[t]}])),i=[...new Set([...r.keys(),...t.keys()])].sort().map(n=>{let i=r.get(n),a=i?.point,o=a&&a.measured!==!1?Gu(a.aiReferralLandedHits):null,s=t.get(n);return{bucket:n,aiReferralLandedHits:e.has(n)?null:o,serverPartial:e.has(n)?o:null,ga4Visits:s?.complete?s.sessions:null,ga4Partial:s&&!s.complete?s.sessions:null,visitTrend:i?.trend??null,ga4Trend:qu(A?.monthlyTrend,n),recorded:o!==null||(s?.sessions??null)!==null}}),a=i.findIndex(e=>e.recorded);return a>0?i.slice(a):i},[j,k,A]),z=u?ie:O,ae=(0,Q.useMemo)(()=>{if(o===`ga4`)return null;if(!u)return S;let e=new Set(ie.map(e=>e.bucket));return Yu(j.filter(t=>e.has(t.bucket)))},[o,u,j,ie,S]),B=(0,Q.useMemo)(()=>u?Xu(j,k?.aiReferralCountingChangedAt?.slice(0,7)):E,[u,j,k,E]),V=B!==null&&o!==`ga4`,oe=(e,t,n)=>{let r=n.payload?.bucket;return B&&t===Vu&&r!==void 0&&r<=B.to?[Bu(e),Hu]:Bu(e)},se=(A?.months??[]).filter(e=>e.complete&&e.sessions!==null).at(-1)??null,ce=ie.filter(e=>e.aiReferralLandedHits!==null).at(-1)??null,le=o===`server`?ce?.bucket??null:o===`ga4`?se?.month??null:se?.month??ce?.bucket??null,ue=le?ie.find(e=>e.bucket===le)?.aiReferralLandedHits??null:null,de=A?.monthlyTrend??null,fe=u&&o!==`ga4`,pe=u&&o!==`server`,H=pe&&g,me=fe&&f.isSuccess||H&&v.isSuccess,he=(!fe||f.isSuccess)&&(!pe||h.isSuccess&&(!g||v.isSuccess)),ge=ie.some(e=>fe&&(e.aiReferralLandedHits!==null||e.serverPartial!==null)||H&&(e.ga4Visits!==null||e.ga4Partial!==null)),_e=ie.find(e=>e.bucket===d.until.slice(0,7)),ve=H?_e?.ga4Partial??null:null,ye=fe?_e?.serverPartial??null:null,be=ve!==null||ye!==null,xe=p.data?.totals,Se=xe&&{crawlers:Gu(xe.crawlerContentHits),fetches:Gu(xe.aiUserFetchHits),visits:Gu(xe.aiReferralLandedHits)},Ce=(0,Q.useMemo)(()=>y.reduce((e,t)=>({crawlers:e.crawlers+Gu(t.crawlerContentHits),fetches:e.fetches+Gu(t.aiUserFetchHits),visits:e.visits+Gu(t.aiReferralLandedHits)}),{crawlers:0,fetches:0,visits:0}),[y]),we=Se??Ce,Te=we.crawlers>0||we.fetches>0||we.visits>0,Ee=null;if(p.isLoading)Ee=(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:`Loading AI traffic history…`});else if(p.isError)Ee=(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`p`,{role:`alert`,className:`text-copy-14 text-negative`,children:`Could not load AI traffic history.`}),(0,$.jsx)(X,{text:`The request failed, so this is not a reading of zero activity. Retry, or check the traffic source.`})]});else if(!Te){let e=m.data?.sources,t=e!==void 0&&e.length===0,n=!t&&C===null;Ee=(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:t?`No server-side traffic source connected yet.`:n?`No AI activity recorded yet.`:`No AI activity recorded in this period.`}),(0,$.jsx)(X,{text:t?`Connect a traffic source to see how AI engines read this site over time.`:n?`The source is connected but has not reported anything yet. A new source can take a few hours to appear.`:`The window was measured and nothing was recorded. Try a longer range.`})]})}return(0,$.jsxs)(`div`,{children:[Ee??(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`mb-5`,children:(0,$.jsx)(ul,{label:`AI traffic totals`,items:[{label:`AI crawlers`,value:Tt(we.crawlers),detail:`pages crawled`,tooltip:`Requests from AI crawlers for a real content page. Robots.txt and sitemap re-fetches are excluded, because they are not a page an engine read.`},{label:`AI page fetches`,value:Tt(we.fetches),detail:`reading a page to answer`,tooltip:`An AI engine fetching a page live while answering someone, rather than crawling it for an index.`},{label:`AI visitors`,value:Tt(we.visits),detail:E?`older days may read high`:`arrived from an AI answer`,tooltip:`Visits your server answered that came from an AI engine. Requests answered with a redirect are excluded: a redirect is a hop, not an arrival.`+(E?` Days through ${_a(E.to)} were counted by an older rule that also counted a visitor's later pages, so they can read high and cannot be recounted.`:``)}]})}),y.length>0&&(0,$.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-5 gap-y-1 pb-3 mb-4 border-b border-default text-label-12 text-muted`,children:[(0,$.jsx)(`span`,{className:`text-secondary text-label-12-strong`,children:`Latest day (UTC)`}),(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`span`,{className:`text-heading text-label-12-strong tabular-nums mr-1`,children:Gu(y[y.length-1].crawlerContentHits).toLocaleString()}),`pages crawled`]}),(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`span`,{className:`text-heading text-label-12-strong tabular-nums mr-1`,children:Gu(y[y.length-1].aiUserFetchHits).toLocaleString()}),`page fetches`]}),(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`span`,{className:`text-heading text-label-12-strong tabular-nums mr-1`,children:Gu(y[y.length-1].aiReferralLandedHits).toLocaleString()}),`visits, server`]}),(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`span`,{className:`text-heading text-label-12-strong tabular-nums mr-1`,children:b.get(y[y.length-1].bucket)?.toLocaleString()??`—`}),`visits, GA4`]}),(0,$.jsx)(`span`,{className:`text-faint`,children:`still filling`})]}),(0,$.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`h3`,{className:`text-heading-14 text-heading`,children:`Machines reading your site`}),(0,$.jsx)(X,{text:`Crawlers index pages for later. Page fetches happen while an engine is answering someone. Both are machines, not people.`})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,$.jsxs)(`label`,{className:`flex items-center gap-1.5 text-label-12 text-secondary cursor-pointer`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:n,onChange:e=>r(e.target.checked),className:`accent-current`}),`Page fetches`]}),(0,$.jsxs)(`label`,{className:`flex items-center gap-1.5 text-label-12 text-secondary cursor-pointer`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:i,onChange:e=>a(e.target.checked),className:`accent-current`}),`Trend line`]})]})]}),(0,$.jsx)(I,{width:`100%`,height:206,children:(0,$.jsxs)(ne,{data:O,margin:{top:4,right:8,left:-18,bottom:0},children:[(0,$.jsx)(M,{stroke:`var(--chart-grid, #2e2e2e)`,vertical:!1}),(0,$.jsx)(P,{dataKey:`bucket`,tick:va,stroke:`var(--chart-axis, #2e2e2e)`,tickFormatter:fa,minTickGap:28}),(0,$.jsx)(ee,{tick:va,stroke:`var(--chart-axis, #2e2e2e)`,width:48,allowDecimals:!1}),(0,$.jsx)(N,{contentStyle:Sa.contentStyle,labelStyle:Sa.labelStyle,itemStyle:Sa.itemStyle,labelFormatter:_a,formatter:Bu}),S&&(0,$.jsx)(F,{x1:S.from,x2:S.to,fill:`var(--color-overlay-hover)`,fillOpacity:.5,stroke:`none`,label:{value:`not measured`,position:`insideTop`,fontSize:12,fill:`var(--chart-neutral-text-dim, #a1a1a1)`}}),(0,$.jsx)(R,{wrapperStyle:zu,iconType:`plainline`,iconSize:14}),(0,$.jsx)(L,{type:`monotone`,dataKey:`crawlerContentHits`,name:`Pages crawled`,stroke:Du,fill:Du,fillOpacity:.22,strokeWidth:1.8}),n&&(0,$.jsx)(L,{type:`monotone`,dataKey:`aiUserFetchHits`,name:`Page fetches`,stroke:Ou,fill:Ou,fillOpacity:.18,strokeWidth:1.6}),i&&(0,$.jsx)(te,{type:`linear`,dataKey:`crawlTrend`,legendType:`none`,name:`Pages crawled trend`,dot:!1,tooltipType:`none`,stroke:Du,strokeWidth:1.4,strokeDasharray:`5 4`,connectNulls:!0}),i&&n&&(0,$.jsx)(te,{type:`linear`,dataKey:`fetchTrend`,legendType:`none`,name:`Page fetches trend`,dot:!1,tooltipType:`none`,stroke:Ou,strokeWidth:1.3,strokeDasharray:`5 4`,connectNulls:!0})]})})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3 mt-5 mb-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`h3`,{className:`text-heading-14 text-heading`,children:`People arriving from AI`}),(0,$.jsx)(X,{text:`Two independent counts of the same thing. Server reads your own logs and misses nothing a browser blocks, but cannot see a page served from cache. GA4 needs the browser to run a tag. They rarely match, and neither is the correction of the other.`})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[(0,$.jsx)(nl,{windows:Nu,value:c,onChange:l,label:`Visits by day or month`,formatOption:e=>e===`months`?`Months`:`Days`}),(0,$.jsx)(nl,{windows:Mu,value:o,onChange:s,label:`Visit measurement source`,formatOption:e=>e===`ga4`?`GA4`:e===`both`?`Both`:`Server`})]})]}),fe&&f.isLoading&&(0,$.jsx)(`p`,{role:`status`,className:`text-copy-14 text-secondary`,children:Pu.serverLoading}),H&&v.isLoading&&(0,$.jsx)(`p`,{role:`status`,className:`text-copy-14 text-secondary`,children:Pu.gaLoading}),pe&&h.isLoading&&(0,$.jsx)(`p`,{role:`status`,className:`text-copy-14 text-secondary`,children:Pu.gaStatusLoading}),pe&&h.isError&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`p`,{role:`alert`,className:`text-copy-14 text-negative`,children:Pu.gaStatusError}),(0,$.jsx)(q,{variant:`outline`,size:`sm`,"aria-label":Pu.retryGaStatus,disabled:h.isFetching,onClick:()=>{h.refetch()},children:`Retry`})]}),fe&&f.isError&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`p`,{role:`alert`,className:`text-copy-14 text-negative`,children:Pu.serverError}),(0,$.jsx)(q,{variant:`outline`,size:`sm`,"aria-label":Pu.retryServer,disabled:f.isFetching,onClick:()=>{f.refetch()},children:`Retry`})]}),H&&v.isError&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`p`,{role:`alert`,className:`text-copy-14 text-negative`,children:Pu.gaError}),(0,$.jsx)(q,{variant:`outline`,size:`sm`,"aria-label":Pu.retryGa,disabled:v.isFetching,onClick:()=>{v.refetch()},children:`Retry`})]}),u&&o===`ga4`&&h.isSuccess&&!g&&(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:Pu.connectGa}),me&&he&&!ge&&(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:Pu.emptyMonths}),u&&le&&(0,$.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-5 gap-y-1 pb-3 mb-3 text-label-12 text-muted`,children:[(0,$.jsx)(`span`,{className:`text-secondary text-label-12-strong`,children:Lu(le)}),o!==`server`&&se?.month===le&&(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`span`,{className:`text-heading text-label-12-strong tabular-nums mr-1`,children:Tt(se.sessions??0)}),`visits, GA4`]}),o!==`ga4`&&ue!==null&&(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`span`,{className:`text-heading text-label-12-strong tabular-nums mr-1`,children:Tt(ue)}),`visits, server`]}),o!==`server`&&de?.changePct!=null&&(0,$.jsxs)(`span`,{children:[(0,$.jsxs)(`span`,{className:`text-heading text-label-12-strong tabular-nums mr-1`,children:[de.changePct>0?`▲`:de.changePct<0?`▼`:``,G(Math.abs(de.changePct),rt.percent)]}),`trend since `,Iu(de.startMonth)]}),o!==`server`&&se?.month===le&&se.engines[0]&&(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`span`,{className:`text-heading text-label-12-strong tabular-nums mr-1`,children:Tt(se.engines[0].sessions)}),`from `,se.engines[0].label]})]}),be&&_e&&(0,$.jsxs)(`div`,{role:`group`,"aria-label":`Month so far`,className:`flex flex-wrap items-center gap-x-5 gap-y-1 mb-3 text-label-13 text-secondary`,children:[(0,$.jsxs)(`span`,{className:`text-label-13-strong`,children:[Lu(_e.bucket),` so far`]}),ve!==null&&(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`span`,{className:`text-heading text-label-13-strong tabular-nums mr-1`,children:Tt(ve)}),`visits, GA4`]}),ye!==null&&(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`span`,{className:`text-heading text-label-13-strong tabular-nums mr-1`,children:Tt(ye)}),`visits, server`]}),(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[`Hollow dots: partial months`,(0,$.jsx)(X,{text:`Hollow dots show part-month totals. The current month is still filling; earlier partial months have incomplete coverage. Partial months are kept off the connecting line and out of the trend.`})]})]}),(u?me&&ge:!Ee)&&(0,$.jsx)(I,{width:`100%`,height:176,children:(0,$.jsxs)(ne,{data:z,margin:{top:4,right:8,left:-18,bottom:0},children:[(0,$.jsx)(M,{stroke:`var(--chart-grid, #2e2e2e)`,vertical:!1}),(0,$.jsx)(P,{dataKey:`bucket`,tick:va,stroke:`var(--chart-axis, #2e2e2e)`,tickFormatter:u?Iu:fa,minTickGap:u?8:28}),(0,$.jsx)(ee,{tick:va,stroke:`var(--chart-axis, #2e2e2e)`,width:48,allowDecimals:!1}),(0,$.jsx)(N,{contentStyle:Sa.contentStyle,labelStyle:Sa.labelStyle,itemStyle:Sa.itemStyle,labelFormatter:u?Lu:_a,formatter:oe}),ae&&ae.from!==ae.to&&(0,$.jsx)(F,{x1:ae.from,x2:ae.to,fill:`var(--color-overlay-hover)`,fillOpacity:.5,stroke:`none`,label:{value:`not measured`,position:`insideTop`,fontSize:12,fill:`var(--chart-neutral-text-dim, #a1a1a1)`}}),B&&V&&(0,$.jsx)(F,{x1:B.from,x2:B.to,fill:`var(--color-overlay-hover)`,fillOpacity:.3,stroke:`none`}),B&&V&&(0,$.jsx)(re,{x:B.to,stroke:ju,strokeDasharray:`4 4`,strokeWidth:1.5}),(0,$.jsx)(R,{wrapperStyle:zu,iconType:`plainline`,iconSize:14}),o!==`ga4`&&(0,$.jsx)(te,{type:`monotone`,dataKey:`aiReferralLandedHits`,name:Vu,stroke:ku,strokeWidth:2,connectNulls:!1,dot:u?Zu(z.map(e=>e.aiReferralLandedHits??null),ku):!1}),u&&o!==`ga4`&&(0,$.jsx)(te,{type:`monotone`,dataKey:`serverPartial`,name:Uu,legendType:`none`,connectNulls:!1,stroke:ku,strokeWidth:0,activeDot:!1,dot:Zu(z.map(e=>e.serverPartial??null),ku,!0)}),o!==`server`&&(0,$.jsx)(te,{type:`monotone`,dataKey:`ga4Visits`,name:`Visits, GA4`,connectNulls:!1,stroke:Au,strokeWidth:1.8,strokeDasharray:`5 3`,dot:Zu(z.map(e=>e.ga4Visits??null),Au)}),u&&o!==`server`&&(0,$.jsx)(te,{type:`monotone`,dataKey:`ga4Partial`,name:Wu,legendType:`none`,connectNulls:!1,stroke:Au,strokeWidth:0,activeDot:!1,dot:Zu(z.map(e=>e.ga4Partial??null),Au,!0)}),i&&o!==`ga4`&&(0,$.jsx)(te,{type:`linear`,dataKey:`visitTrend`,legendType:`none`,name:`Visits trend`,dot:!1,tooltipType:`none`,stroke:ku,strokeWidth:1.3,strokeDasharray:`5 4`,connectNulls:!0}),i&&o!==`server`&&(0,$.jsx)(te,{type:`linear`,dataKey:`ga4Trend`,legendType:`none`,name:`GA4 visits trend`,dot:!1,tooltipType:`none`,stroke:Au,strokeWidth:1.6,strokeDasharray:`1 4`,strokeLinecap:`round`,connectNulls:!0})]})})]})}function $u(e){return e.replace(/\+/g,` `)}var ed=je,td={"7d":10080,"30d":43200,"90d":129600,"180d":259200};function nd(e){return Cs(e.landingPage)}var rd=25,id=10,ad={days:[],sources:[],totalSessions:0,totalPaidSessions:0,totalOrganicSessions:0,byEngine:{series:[],otherCount:0,days:[]}},od={siteTrafficTooltip:`GA4's own figures for the complete days ending yesterday, as GA4 counts them, each against the period of the same length before it. Pick a figure in any slot to chart it by day.`,siteTrafficFallbackTooltip:`Sessions, Google organic search sessions and distinct users from GA4. Distinct users are unavailable when the selected range has no stored GA4 aggregate.`,channelTooltip:`GA4 sessions split into five channels that do not overlap. AI sessions are taken out of the channel GA4 filed them under before the rest is counted.`,organicTooltip:`Sessions from Google organic search, after AI sessions are taken out.`,socialTooltip:`Organic Social and Paid Social sessions, after AI sessions are taken out.`,directTooltip:`Sessions with no source: bookmarks, typed URLs, untagged email and in-app browsers. AI visits that send no referrer land here too.`,aiTooltip:`Sessions in GA4's AI Assistant channel or from a known AI source. Paid AI comes from paid UTM values or a GA4 paid channel group. AI visits that send no referrer count as Direct, so this is a floor.`,otherTooltip:`Every other GA4 channel, such as Referral, Email, Paid Search, Display and Video.`,aiEnginesTooltip:`AI referral sessions by engine. Open an engine to see the sources GA4 reported. Unattributed AI is AI traffic whose source names no engine.`,aiChartLabel:`AI sessions by engine`,socialTooltip2:`Sessions GA4 classifies as Organic Social or Paid Social, grouped by platform. Open a platform to see the sources GA4 reported for it.`,platformsTooltip:`Platforms with sessions in this period. A source no platform matches counts as its own platform.`,paidSocialTooltip:`Sessions in GA4's Paid Social channel.`,socialChartLabel:`Social sessions by platform`,noAiReferrals:`No AI referrals in this period.`,noAiLandingPages:`No AI landing pages in this period.`,noSocial:`No social sessions in this period.`,noneInPeriod:`None in this period`,aiHistoryTooltip:`Daily AI crawls, page fetches and visits from connected traffic sources, with GA4 visits beside server visits.`};function sd(e){let t=Date.now()-new Date(e).getTime(),n=Math.floor(t/6e4);if(n<1)return`just now`;if(n<60)return`${n}m ago`;let r=Math.floor(n/60);return r<24?`${r}h ago`:`${Math.floor(r/24)}d ago`}function cd(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toLocaleString()}function ld(e,t){return!e||!t?null:`${new Date(`${e}T00:00:00`).toLocaleDateString(void 0,{month:`short`,day:`numeric`})} to ${new Date(`${t}T00:00:00`).toLocaleDateString(void 0,{month:`short`,day:`numeric`,year:`numeric`})}`}function ud({projectName:e}){let{data:t,isLoading:n,isError:r}=Hs(e),i=t?.sources??[];return(0,$.jsxs)(`section`,{"aria-labelledby":`server-activity-heading`,children:[(0,$.jsx)(ol,{id:`server-activity-heading`,title:`Server activity`,tooltip:`Crawler, AI fetch and AI referral activity from connected traffic sources over the last 24 hours.`,meta:`Last 24 hours`,actions:!Y()&&i.length>0?(0,$.jsx)(A,{to:`/traffic`,className:`text-label-14 text-link hover:underline`,children:`Manage sources`}):void 0}),n?(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:`Loading server activity…`}):r?(0,$.jsx)(`p`,{role:`alert`,className:`text-copy-14 text-negative`,children:`Could not load server activity.`}):i.length===0?(0,$.jsxs)(`p`,{className:`text-copy-14 text-secondary`,children:[`No traffic source connected.`,` `,!Y()&&(0,$.jsx)(A,{to:`/traffic`,className:`text-link hover:underline`,children:`Connect a source`})]}):(0,$.jsx)(`div`,{className:`overflow-x-auto`,children:(0,$.jsxs)(`table`,{className:`w-full min-w-[36rem] text-label-14`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{className:`border-b border-default`,children:[(0,$.jsx)(fl,{label:`Source`,align:`left`}),(0,$.jsx)(fl,{label:`Status`,align:`left`}),(0,$.jsx)(fl,{label:`Crawler hits`,align:`right`}),(0,$.jsx)(fl,{label:`AI hits`,align:`right`}),(0,$.jsx)(fl,{label:`AI sessions`,align:`right`}),(0,$.jsx)(fl,{label:`Last sync`,align:`right`}),(0,$.jsx)(`th`,{className:`py-2`,"aria-label":`Detail`})]})}),(0,$.jsx)(`tbody`,{children:i.map(t=>(0,$.jsxs)(`tr`,{className:`border-t border-subtle`,children:[(0,$.jsx)(`td`,{className:`py-2 pr-3 text-strong`,children:t.displayName}),(0,$.jsx)(`td`,{className:`py-2 pr-3`,children:(0,$.jsx)(J,{tone:Ws(t.status),children:t.status})}),(0,$.jsx)(`td`,{className:`py-2 pl-4 text-right tabular-nums text-primary`,children:t.totals24h.crawlerHits.toLocaleString(`en-US`)}),(0,$.jsx)(`td`,{className:`py-2 pl-4 text-right tabular-nums text-primary`,children:(0,$.jsxs)(`span`,{className:`inline-flex items-center justify-end gap-1`,children:[t.totals24h.aiUserFetchHits.toLocaleString(`en-US`),t.totals24h.aiUserFetchLikelyFakeHits>0&&(0,$.jsx)(X,{text:qs(t.totals24h.aiUserFetchLikelyFakeHits)})]})}),(0,$.jsx)(`td`,{className:`py-2 pl-4 text-right tabular-nums text-primary`,children:t.totals24h.aiReferralLandedHits.toLocaleString(`en-US`)}),(0,$.jsx)(`td`,{className:`py-2 pl-4 text-right text-secondary`,children:t.lastSyncedAt?sd(t.lastSyncedAt):`never`}),(0,$.jsx)(`td`,{className:`py-2 pl-3 text-right`,children:!Y()&&(0,$.jsx)(A,{to:`/traffic/$projectName/$sourceId`,params:{projectName:e,sourceId:t.id},className:`text-link hover:underline`,"aria-label":`${t.displayName} detail`,children:`Detail`})})]},t.id))})]})})]})}function dd({projectName:e}){let[t,n]=(0,Q.useState)(`30d`);return(0,$.jsxs)(`div`,{children:[(0,$.jsx)(ud,{projectName:e}),(0,$.jsx)(`div`,{className:`page-section-divider`}),(0,$.jsx)(bd,{projectName:e,window:t,periodControl:(0,$.jsx)(nl,{windows:ed,value:t,onChange:n,label:`Traffic time period`}),between:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`page-section-divider`}),(0,$.jsxs)(`section`,{"aria-labelledby":`ai-traffic-history-heading`,children:[(0,$.jsx)(ol,{id:`ai-traffic-history-heading`,title:`AI traffic history`,tooltip:od.aiHistoryTooltip}),(0,$.jsx)(Qu,{projectName:e,sinceMinutes:td[t]})]})]})})]})}var fd={session:`Session`,first_user:`First visit`,manual_utm:`UTM`},pd={session:`Detected via GA4 sessionSource (referrer or utm_source for this session)`,first_user:`Detected via GA4 firstUserSource (referrer from the user's first-ever visit)`,manual_utm:`Detected via GA4 sessionManualSource (explicit utm_source parameter for the session)`},md=[{label:`Source`,align:`left`},{label:`Medium`,align:`left`},{label:`Class`,align:`left`},{label:`Attribution`,align:`left`},{label:`Sessions`,align:`right`},{label:`Share`,align:`right`}],hd=[{label:`Source`,align:`left`},{label:`Medium`,align:`left`},{label:`Channel`,align:`left`},{label:`Sessions`,align:`right`},{label:`Share`,align:`right`}];function gd(e){return e.engine===null}function _d({row:e}){return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`td`,{className:`max-w-[220px] truncate py-1.5 pr-3 text-strong`,title:e.source,children:e.source}),(0,$.jsx)(`td`,{className:`max-w-[160px] truncate py-1.5 pr-3 text-secondary`,title:e.medium,children:e.medium}),(0,$.jsx)(`td`,{className:`py-1.5 pr-3 text-secondary`,title:e.trafficClass===`paid`?`Paid AI traffic, from paid UTM values or a GA4 paid channel group`:`AI traffic without a paid attribution signal`,children:e.trafficClass===`paid`?`Paid`:`Organic`}),(0,$.jsx)(`td`,{className:`py-1.5 pr-3 text-secondary`,title:pd[e.sourceDimension]??``,children:fd[e.sourceDimension]??e.sourceDimension}),(0,$.jsx)(`td`,{className:`py-1.5 pl-4 text-right text-primary tabular-nums`,children:e.sessions.toLocaleString()}),(0,$.jsx)(`td`,{className:`py-1.5 pl-4 text-right text-secondary tabular-nums`,children:G(e.share)})]})}function vd({row:e}){return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`td`,{className:`max-w-[240px] truncate py-1.5 pr-3 text-strong`,title:e.source,children:$u(e.source)}),(0,$.jsx)(`td`,{className:`max-w-[160px] truncate py-1.5 pr-3 text-secondary`,title:e.medium,children:$u(e.medium)}),(0,$.jsx)(`td`,{className:`py-1.5 pr-3 text-secondary`,title:`GA4 channel group: ${e.channelGroup}`,children:e.channelGroup===`Paid Social`?`Paid social`:`Organic social`}),(0,$.jsx)(`td`,{className:`py-1.5 pl-4 text-right text-primary tabular-nums`,children:e.sessions.toLocaleString()}),(0,$.jsx)(`td`,{className:`py-1.5 pl-4 text-right text-secondary tabular-nums`,children:G(e.share)})]})}function yd(e,t){let n=S(),[r,i]=(0,Q.useState)(null),[a,o]=(0,Q.useState)(null),[s,c]=(0,Q.useState)(!0),[l,u]=(0,Q.useState)(!1),[d,f]=(0,Q.useState)(!1),[p,m]=(0,Q.useState)(null),[h,g]=(0,Q.useState)(null),[_,v]=(0,Q.useState)(ad),[y,b]=(0,Q.useState)([]),[x,C]=(0,Q.useState)(null);async function w(r){c(!0),m(null);try{let a=await n.fetchQuery({...ir({client:K,path:{name:e}}),staleTime:er});if(r.current)return;if(i(a),!a.connected){o(null),v(ad),b([]),C(null),c(!1);return}let s=t===`all`?void 0:t,[l,u,d,f]=await Promise.all([n.fetchQuery({...ki({client:K,path:{name:e},query:s?{window:s}:void 0}),staleTime:er}),n.fetchQuery({...hr({client:K,path:{name:e},query:s?{window:s}:void 0}),staleTime:er}).catch(()=>ad),n.fetchQuery({...Mi({client:K,path:{name:e},query:s?{window:s}:void 0}),staleTime:er}).catch(()=>[]),n.fetchQuery({...fr({client:K,path:{name:e},query:{window:rn(t)?t:`30d`}}),staleTime:er}).catch(()=>null)]);if(r.current)return;o(l),v(u),b(d),C(f),c(!1)}catch(e){if(r.current)return;m(e instanceof Error?e.message:`Failed to load GA4 data`),c(!1)}}(0,Q.useEffect)(()=>{let e={current:!1};return w(e),()=>{e.current=!0}},[e,t,n]);async function T(){u(!0),m(null),g(null);try{let r=await ht(e,rn(t)?Be[t]:void 0);g(`Synced ${r.rowCount.toLocaleString()} page rows, ${r.aiReferralCount.toLocaleString()} AI and ${r.socialReferralCount.toLocaleString()} social referral rows (${r.days} days)`),await Zn(n,`ga`),await w({current:!1})}catch(e){m(e instanceof Error?e.message:`Sync failed`)}finally{u(!1)}}async function E(){f(!0),m(null),g(null);try{await Pt(e),await Zn(n,`ga`),i({connected:!1,propertyId:null,clientEmail:null,lastSyncedAt:null,createdAt:null,updatedAt:null}),o(null),C(null),g(`GA4 disconnected`)}catch(e){m(e instanceof Error?e.message:`Disconnect failed`)}finally{f(!1)}}async function D(){await Zn(n,`ga`),await w({current:!1})}return{status:r,traffic:a,loading:s,syncing:l,disconnecting:d,error:p,notice:h,aiDaily:_,sessionHistory:y,overview:x,handleSync:T,handleDisconnect:E,handleConnected:D}}function bd({projectName:e,window:t,periodControl:n,between:r}){let i=yd(e,t??`30d`);return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(xd,{ga:i,projectName:e,periodControl:n}),r,(0,$.jsx)(Sd,{ga:i,projectName:e})]})}function xd({ga:e,projectName:t,periodControl:n}){let{status:r,traffic:i,syncing:a,disconnecting:o,handleSync:s,handleDisconnect:c}=e,l=r?.connected===!0,u=l&&!Y()&&!We(),d=i?ld(i.windowStart,i.windowEnd):null,m;return m=e.loading&&!r?(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:`Loading traffic data…`}):l?i&&e.overview?(0,$.jsx)(wl,{overview:e.overview,refreshing:e.loading}):i?(0,$.jsx)($.Fragment,{children:(0,$.jsx)(ul,{label:`Site traffic`,items:[{label:`Total sessions`,value:cd(i.totalSessions),detail:i.totalSessions.toLocaleString()},{label:`Organic sessions`,value:cd(i.totalOrganicSessions),detail:`${i.organicSharePctDisplay} of total`},{label:`Total users`,value:i.totalUsers===null?`n/a`:cd(i.totalUsers),detail:i.totalUsers===null?`Unavailable for this range`:i.totalUsers.toLocaleString()}]})}):(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 border-y border-default py-4`,children:[(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:`No traffic data yet.`}),!Y()&&!We()&&(0,$.jsxs)(q,{variant:`outline`,size:`sm`,disabled:a,onClick:Jn(s),children:[(0,$.jsx)(p,{className:`mr-1.5 size-3.5 ${a?`animate-spin`:``}`}),`Sync from GA4`]})]}):Y()||We()?(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:`No Google Analytics 4 property connected.`}):(0,$.jsx)(jd,{projectName:t,onConnected:()=>{e.handleConnected()}}),(0,$.jsxs)(`section`,{"aria-labelledby":`site-traffic-heading`,children:[(0,$.jsx)(ol,{id:`site-traffic-heading`,title:`Site traffic`,tooltip:e.overview?od.siteTrafficTooltip:d?`${od.siteTrafficFallbackTooltip} Data covers ${d}.`:od.siteTrafficFallbackTooltip,meta:l?(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`inline-block size-2 rounded-full bg-positive-500`}),`GA4 property `,(0,$.jsx)(`span`,{className:`text-strong`,children:r.propertyId}),r.clientEmail&&(0,$.jsxs)(`span`,{className:`text-muted`,children:[`· `,r.clientEmail]})]}):void 0,actions:n||u?(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[n,u&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(q,{variant:`outline`,size:`sm`,disabled:a,onClick:Jn(s),children:[(0,$.jsx)(p,{className:`mr-1.5 size-3.5 ${a?`animate-spin`:``}`}),a?`Syncing…`:`Sync`]}),(0,$.jsxs)(q,{variant:`ghost`,size:`sm`,className:`text-negative-400 hover:text-negative`,disabled:o,onClick:Jn(c),children:[(0,$.jsx)(f,{className:`mr-1.5 size-3.5`}),`Disconnect`]})]})]}):void 0}),e.error&&(0,$.jsx)(`div`,{role:`alert`,className:`mb-4 rounded-md border border-negative-800/60 bg-negative-900/20 px-4 py-2 text-label-14 text-negative`,children:e.error}),e.notice&&(0,$.jsx)(`div`,{role:`status`,className:`mb-4 rounded-md border border-positive-800/60 bg-positive-900/20 px-4 py-2 text-label-14 text-positive`,children:e.notice}),m]})}function Sd({ga:e,projectName:t}){let{traffic:n,aiDaily:r,sessionHistory:i}=e,[a,o]=(0,Q.useState)({key:`sessions`,dir:`desc`}),[s,c]=(0,Q.useState)({key:`sessions`,dir:`desc`}),l=(0,Q.useMemo)(()=>{if(!n?.topPages)return[];let{key:e,dir:t}=a;return[...n.topPages].sort((n,r)=>{let i=n[e],a=r[e],o=typeof i==`string`&&typeof a==`string`?i.localeCompare(a):Number(i)-Number(a);return t===`asc`?o:-o})},[n?.topPages,a]),u=Ds({rows:l,getSearchText:e=>Cs(e.landingPage),pageSize:id}),d=(0,Q.useMemo)(()=>{if(!n?.aiReferralLandingPages)return[];let{key:e,dir:t}=s;return[...n.aiReferralLandingPages].sort((n,r)=>{let i=n[e],a=r[e],o=typeof i==`string`&&typeof a==`string`?i.localeCompare(a):Number(i)-Number(a);return t===`asc`?o:-o})},[n?.aiReferralLandingPages,s]),f=Ds({rows:d,getSearchText:nd,pageSize:rd}),p=(0,Q.useMemo)(()=>i.map(e=>({date:e.date,value:e.sessions})),[i]);function m(e){u.setPage(1),o(t=>t.key===e?{key:e,dir:t.dir===`desc`?`asc`:`desc`}:{key:e,dir:`desc`})}function h(e){f.setPage(1),c(t=>t.key===e?{key:e,dir:t.dir===`desc`?`asc`:`desc`}:{key:e,dir:`desc`})}if(!e.status?.connected)return null;let g=n?ld(n.windowStart,n.windowEnd):null,_=n?.channelBreakdown,v=n?.paidAiSessionsBySession??0,y=n?.aiEngines??[],b=n?.socialPlatforms??[],x=b[0]??null,S=f.totalRows>0?`${f.totalRows.toLocaleString()} ${f.hasQuery?f.totalRows===1?`match`:`matches`:f.totalRows===1?`row`:`rows`}`:f.hasQuery&&(n?.aiReferralLandingPages.length??0)>0?`0 matches`:null;return(0,$.jsxs)($.Fragment,{children:[n&&_&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`page-section-divider`}),(0,$.jsxs)(`section`,{"aria-labelledby":`traffic-by-channel-heading`,children:[(0,$.jsx)(ol,{id:`traffic-by-channel-heading`,title:`Traffic by channel`,tooltip:od.channelTooltip,meta:g}),(0,$.jsx)(ul,{label:`Sessions by channel`,items:[{label:`Organic search`,value:_.organic.sharePctDisplay,detail:`${_.organic.sessions.toLocaleString()} sessions`,tooltip:od.organicTooltip},{label:`Social`,value:_.social.sharePctDisplay,detail:`${_.social.sessions.toLocaleString()} sessions`,tooltip:od.socialTooltip},{label:`Direct`,value:_.direct.sharePctDisplay,detail:`${_.direct.sessions.toLocaleString()} sessions`,tooltip:od.directTooltip},{label:`AI (at least)`,value:_.ai.sharePctDisplay,detail:v>0?`${_.ai.sessions.toLocaleString()} sessions · ${v.toLocaleString()} paid`:`${_.ai.sessions.toLocaleString()} sessions`,tooltip:od.aiTooltip},{label:`Other channels`,value:_.other.sharePctDisplay,detail:`${_.other.sessions.toLocaleString()} sessions`,tooltip:od.otherTooltip}]}),(0,$.jsxs)(sl,{children:[(0,$.jsx)(cl,{label:od.aiChartLabel,meta:r.days.length>0?Cd(r.totalSessions,`session`):od.noneInPeriod,children:r.days.length>0?(0,$.jsx)(_l,{input:r.byEngine,baseline:p,baselineLabel:`Total sessions`,label:od.aiChartLabel}):(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:od.noAiReferrals})}),(0,$.jsx)(cl,{label:`Where AI visitors came from`,meta:y.length>0?`${Cd(y.filter(e=>e.engine!==null).length,`engine`)} · ${Cd(n.aiReferrals.length,`source`)}`:od.noneInPeriod,children:y.length>0?(0,$.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,$.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,$.jsx)(hl,{groups:y,groupLabel:`Engine`,caption:`AI referral sessions by engine`,childColumns:md,childRowKey:e=>`${e.source}:${e.medium}:${e.sourceDimension}:${e.trafficClass}`,renderChildCells:e=>(0,$.jsx)(_d,{row:e}),pinLast:gd})}),(0,$.jsx)(X,{text:od.aiEnginesTooltip})]}):(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:od.noAiReferrals})}),(0,$.jsx)(cl,{label:`Pages AI visitors landed on`,meta:S??od.noneInPeriod,children:n.aiReferralLandingPages.length>0?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(js,{value:f.query,onChange:f.setQuery,label:`Filter landing page URLs or query parameters`,placeholder:`Filter URL or query parameters`,className:`mb-4 max-w-md`}),f.totalRows>0?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`overflow-x-auto`,children:(0,$.jsxs)(`table`,{className:`w-full min-w-[36rem] text-label-14`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{className:`border-b border-default`,children:[(0,$.jsx)(dl,{label:`Landing page`,sortKey:`landingPage`,current:s.key,dir:s.dir,onSort:h,align:`left`}),(0,$.jsx)(dl,{label:`Source`,sortKey:`source`,current:s.key,dir:s.dir,onSort:h,align:`left`}),(0,$.jsx)(fl,{label:`Attribution`,align:`left`}),(0,$.jsx)(dl,{label:`Sessions`,sortKey:`sessions`,current:s.key,dir:s.dir,onSort:h,align:`right`})]})}),(0,$.jsx)(`tbody`,{children:f.rows.map(e=>(0,$.jsx)(Nd,{row:e},`${e.landingPage}:${e.source}:${e.medium}:${e.sourceDimension}`))})]})}),(0,$.jsx)(Ts,{page:f.page,pageSize:f.pageSize,visibleRows:f.rows.length,totalRows:f.totalRows,onPageChange:f.setPage,itemLabel:f.hasQuery?`matches`:`rows`})]}):(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 py-4`,children:[(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:`No landing pages match this filter`}),(0,$.jsx)(q,{variant:`outline`,size:`sm`,onClick:()=>f.setQuery(``),children:`Clear filter`})]})]}):(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:od.noAiLandingPages})})]})]}),(0,$.jsx)(`div`,{className:`page-section-divider`}),(0,$.jsxs)(`section`,{"aria-labelledby":`social-heading`,children:[(0,$.jsx)(ol,{id:`social-heading`,title:`Social`,tooltip:od.socialTooltip2,meta:g}),(0,$.jsx)(ul,{label:`Social sessions`,items:[{label:`Social sessions`,value:n.socialSessions.toLocaleString(),detail:`${n.socialSharePctDisplay} of all sessions`},{label:`Platforms`,value:String(b.length),detail:`${n.socialReferrals.length} sources`,tooltip:od.platformsTooltip},{label:`Paid social`,value:(n.paidSocialSessions??0).toLocaleString(),detail:`${G(n.paidSocialShare??0)} of social`,tooltip:od.paidSocialTooltip},{label:`Top platform`,value:x?.label??`None`,detail:x?`${x.sessions.toLocaleString()} sessions`:void 0}]}),(0,$.jsxs)(sl,{children:[(0,$.jsx)(cl,{label:od.socialChartLabel,meta:b.length>0?Cd(n.socialSessions,`session`):od.noneInPeriod,children:b.length>0?(0,$.jsx)(_l,{input:n.socialPlatformDaily,label:od.socialChartLabel}):(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:od.noSocial})}),(0,$.jsx)(cl,{label:`Social platforms`,meta:b.length>0?`${Cd(b.length,`platform`)} · ${Cd(n.socialReferrals.length,`source`)}`:od.noneInPeriod,children:b.length>0?(0,$.jsx)(hl,{groups:b,groupLabel:`Platform`,caption:`Social sessions by platform`,childColumns:hd,childRowKey:e=>`${e.source}:${e.medium}:${e.channelGroup}`,renderChildCells:e=>(0,$.jsx)(vd,{row:e})}):(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:od.noSocial})})]})]})]}),n&&n.topPages.length>0&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`page-section-divider`}),(0,$.jsxs)(`section`,{"aria-labelledby":`top-landing-pages-heading`,children:[(0,$.jsx)(ol,{id:`top-landing-pages-heading`,title:`Top landing pages`,tooltip:`Landing pages by sessions. Organic share is the share of a page's sessions that came from Google organic search.`}),(0,$.jsx)(js,{value:u.query,onChange:u.setQuery,label:`Filter landing page URLs`,placeholder:`Filter landing pages`,className:`mb-4 max-w-md`}),(0,$.jsx)(`div`,{className:`overflow-x-auto`,children:(0,$.jsxs)(`table`,{className:`w-full min-w-[36rem] text-label-14`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{className:`border-b border-default`,children:[(0,$.jsx)(dl,{label:`Landing page`,sortKey:`landingPage`,current:a.key,dir:a.dir,onSort:m,align:`left`}),(0,$.jsx)(dl,{label:`Sessions`,sortKey:`sessions`,current:a.key,dir:a.dir,onSort:m,align:`right`}),(0,$.jsx)(dl,{label:`Organic`,sortKey:`organicSessions`,current:a.key,dir:a.dir,onSort:m,align:`right`}),(0,$.jsx)(fl,{label:`Organic share`,align:`right`})]})}),(0,$.jsx)(`tbody`,{children:u.rows.map(e=>(0,$.jsx)(Md,{page:e},e.landingPage))})]})}),u.totalRows===0&&u.hasQuery&&(0,$.jsx)(`p`,{className:`mt-3 text-copy-14 text-secondary`,children:`No landing pages match this filter`}),(0,$.jsx)(Ts,{page:u.page,pageSize:u.pageSize,visibleRows:u.rows.length,totalRows:u.totalRows,onPageChange:u.setPage,itemLabel:u.hasQuery?`matches`:`pages`})]})]}),(0,$.jsx)(Ad,{projectName:t}),(0,$.jsx)(`p`,{className:`mt-6 text-copy-13 text-secondary`,children:n?.lastSyncedAt?`Last synced ${sd(n.lastSyncedAt)}`:`Never synced`})]})}function Cd(e,t){return`${e.toLocaleString()} ${e===1?t:`${t}s`}`}var wd=25,Td=`n/a`,Ed={heading:`Google organic search traffic`,tooltip:`GA4's "Google organic search traffic: Landing page + query string" report, from the property's Search Console link. Each window ends yesterday in the property time zone, as GA4's own date ranges do. The Total row is GA4's own total for all pages, not a sum of the rows, and it does not change with the filter. Search Console data arrives about two days late.`,windowLabel:`Google organic search time period`,loading:`Loading Google organic search pages…`,loadError:`Could not load Google organic search pages.`,neverSynced:`No Google organic search data has been synced yet.`,neverSyncedAction:`Sync GA4 to load the Search Console landing-page report.`,unavailable:`GA4 did not return Search Console data for this property.`,unavailableAction:`Link Search Console to this GA4 property (Admin, Product links, Search Console links), then sync GA4 again.`,refreshFailed:`The last refresh failed.`,noSearchTraffic:`No landing pages had Google organic search traffic in this window.`,noSearchTrafficAction:`If this property should have some, check its Search Console link in GA4 (Admin, Product links, Search Console links).`,noSearchTrafficConfirmed:`Search Console also recorded no impressions for these days.`,notLinkedBadge:`Search Console not linked`,notLinked:e=>`GA4 has no Search Console data for this site, but Search Console recorded ${e.toLocaleString()} impressions in this window. Link the site's Search Console property in GA4 (Admin, Product links, Search Console links).`,thresholded:`GA4 applied thresholding to this report, so it may withhold some rows.`,retry:`Retry`,refreshFailedBadge:`Last refresh failed`,unavailableBadge:`Search Console unavailable`,thresholdedBadge:`Thresholded`,previousSnapshot:`Showing the last good snapshot, synced`,totalLabel:`Total`,totalScope:`all pages`,noFilterMatch:`No landing pages match this filter`,noFilterMatchInLoaded:e=>`No landing pages in the top ${e.toLocaleString()} by clicks match this filter. The filter searches only the pages loaded here.`};function Dd(e,t){switch(t){case`landingPage`:return e.landingPage;case`clicks`:return e.organicGoogleSearchClicks;case`impressions`:return e.organicGoogleSearchImpressions;case`ctr`:return e.organicGoogleSearchClickThroughRate;case`position`:return e.organicGoogleSearchAveragePosition;case`activeUsers`:return e.activeUsers}}function Od(e){return e===null?Td:e.toFixed(1)}function kd(e){return e===null?Td:G(e)}function Ad({projectName:e}){let[t,n]=(0,Q.useState)(`28d`),[r,i]=(0,Q.useState)(`clicks`),[a,o]=(0,Q.useState)(`desc`),s=w({...Rr({client:K,path:{name:e},query:{window:t,limit:kn}}),staleTime:er}),c=s.data,l=(0,Q.useMemo)(()=>[...c?.rows??[]].sort((e,t)=>{let n=Dd(e,r),i=Dd(t,r);return n===null||i===null?n===i?0:n===null?1:-1:typeof n==`string`&&typeof i==`string`?a===`asc`?n.localeCompare(i):i.localeCompare(n):a===`asc`?n-i:i-n}),[c?.rows,r,a]),u=Ds({rows:l,getSearchText:e=>Cs(W(e.landingPage)),pageSize:wd});function d(e){u.setPage(1),r===e?o(e=>e===`desc`?`asc`:`desc`):(i(e),o(e===`landingPage`?`asc`:`desc`))}let f=c?.total??null,p=c?.searchConsoleLink?.state===`not-linked`,m=!Y()&&!We();return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`page-section-divider`}),(0,$.jsxs)(`section`,{"aria-labelledby":`ga-search-landing-heading`,children:[(0,$.jsxs)(`div`,{className:`mb-4 flex flex-wrap items-start justify-between gap-3`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`h2`,{id:`ga-search-landing-heading`,className:`text-heading-16 text-primary`,children:Ed.heading}),(0,$.jsx)(X,{text:Ed.tooltip})]}),c?.windowStart&&c.windowEnd&&(0,$.jsxs)(`p`,{className:`text-copy-14 text-secondary mt-1`,children:[en(c.windowStart),` to `,en(c.windowEnd),c.timeZone?` (${c.timeZone})`:``]})]}),(0,$.jsx)(nl,{windows:oe,value:t,onChange:e=>{u.setPage(1),n(e)},label:Ed.windowLabel})]}),s.isPending?(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary py-6 text-center`,children:Ed.loading}):s.isError||!c?(0,$.jsxs)(`div`,{role:`alert`,className:`flex flex-wrap items-center gap-3 px-4 py-2 rounded-md bg-negative-900/20 border border-negative-800/60 text-label-14 text-negative`,children:[(0,$.jsx)(`span`,{children:Ed.loadError}),(0,$.jsx)(q,{variant:`outline`,size:`sm`,onClick:()=>{s.refetch()},children:Ed.retry})]}):(0,$.jsxs)($.Fragment,{children:[(c.status===`error`||c.status===`unavailable`||c.subjectToThresholding||p)&&(0,$.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-center gap-2`,"data-testid":`ga-search-landing-status`,children:[p&&(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1`,"data-testid":`ga-search-landing-not-linked`,children:[(0,$.jsx)(J,{tone:`caution`,children:Ed.notLinkedBadge}),(0,$.jsx)(X,{text:Ed.notLinked(c.searchConsoleLink?.searchConsoleImpressions??0)})]}),c.status===`error`&&(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,$.jsx)(J,{tone:`negative`,children:Ed.refreshFailedBadge}),c.error&&(0,$.jsx)(X,{text:c.error})]}),c.status===`unavailable`&&(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,$.jsx)(J,{tone:`caution`,children:Ed.unavailableBadge}),c.error&&(0,$.jsx)(X,{text:c.error})]}),c.subjectToThresholding&&(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,$.jsx)(J,{tone:`caution`,children:Ed.thresholdedBadge}),(0,$.jsx)(X,{text:Ed.thresholded})]}),c.status!==`ready`&&f&&c.syncedAt&&(0,$.jsxs)(`span`,{className:`text-label-14 text-secondary`,children:[Ed.previousSnapshot,` `,sd(c.syncedAt),`.`]}),c.status===`unavailable`&&f&&(0,$.jsx)(`p`,{className:`w-full text-copy-14 text-secondary`,children:Ed.unavailableAction})]}),f?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(js,{value:u.query,onChange:u.setQuery,label:`Filter Google organic search landing pages`,placeholder:`Filter landing pages`,className:`mb-4 max-w-md`}),(0,$.jsx)(`div`,{className:`overflow-x-auto`,children:(0,$.jsxs)(`table`,{className:`w-full min-w-[40rem] text-label-14`,"aria-labelledby":`ga-search-landing-heading`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{className:`border-b border-default`,children:[(0,$.jsx)(dl,{label:`Landing page`,sortKey:`landingPage`,current:r,dir:a,onSort:d,align:`left`}),(0,$.jsx)(dl,{label:`Clicks`,sortKey:`clicks`,current:r,dir:a,onSort:d,align:`right`}),(0,$.jsx)(dl,{label:`Impressions`,sortKey:`impressions`,current:r,dir:a,onSort:d,align:`right`}),(0,$.jsx)(dl,{label:`CTR`,sortKey:`ctr`,current:r,dir:a,onSort:d,align:`right`}),(0,$.jsx)(dl,{label:`Avg. position`,sortKey:`position`,current:r,dir:a,onSort:d,align:`right`}),(0,$.jsx)(dl,{label:`Active users`,sortKey:`activeUsers`,current:r,dir:a,onSort:d,align:`right`})]})}),(0,$.jsxs)(`tbody`,{children:[(0,$.jsxs)(`tr`,{className:`border-t border-subtle text-label-14-strong`,"data-testid":`ga-search-landing-total`,children:[(0,$.jsxs)(`td`,{className:`py-1.5 text-primary`,children:[Ed.totalLabel,` `,(0,$.jsx)(`span`,{className:`text-label-14 text-secondary`,children:Ed.totalScope})]}),(0,$.jsx)(`td`,{className:`py-1.5 pl-4 text-right text-primary tabular-nums`,children:f.organicGoogleSearchClicks.toLocaleString()}),(0,$.jsx)(`td`,{className:`py-1.5 pl-4 text-right text-primary tabular-nums`,children:f.organicGoogleSearchImpressions.toLocaleString()}),(0,$.jsx)(`td`,{className:`py-1.5 pl-4 text-right text-primary tabular-nums`,children:kd(f.organicGoogleSearchClickThroughRate)}),(0,$.jsx)(`td`,{className:`py-1.5 pl-4 text-right text-primary tabular-nums`,children:Od(f.organicGoogleSearchAveragePosition)}),(0,$.jsx)(`td`,{className:`py-1.5 pl-4 text-right text-primary tabular-nums`,children:f.activeUsers.toLocaleString()})]}),u.rows.map(e=>(0,$.jsxs)(`tr`,{className:`border-t border-subtle`,children:[(0,$.jsx)(`td`,{className:`py-1.5 text-neutral max-w-[400px] truncate`,title:W(e.landingPage),children:W(e.landingPage)}),(0,$.jsx)(`td`,{className:`py-1.5 pl-4 text-right text-strong tabular-nums`,children:e.organicGoogleSearchClicks.toLocaleString()}),(0,$.jsx)(`td`,{className:`py-1.5 pl-4 text-right text-secondary tabular-nums`,children:e.organicGoogleSearchImpressions.toLocaleString()}),(0,$.jsx)(`td`,{className:`py-1.5 pl-4 text-right text-secondary tabular-nums`,children:kd(e.organicGoogleSearchClickThroughRate)}),(0,$.jsx)(`td`,{className:`py-1.5 pl-4 text-right text-secondary tabular-nums`,children:Od(e.organicGoogleSearchAveragePosition)}),(0,$.jsx)(`td`,{className:`py-1.5 pl-4 text-right text-secondary tabular-nums`,children:e.activeUsers.toLocaleString()})]},e.landingPage))]})]})}),!_e(f)&&!p&&(0,$.jsxs)(`div`,{className:`text-label-14 text-secondary mt-3 space-y-1`,children:[(0,$.jsx)(`p`,{children:Ed.noSearchTraffic}),(0,$.jsx)(`p`,{children:c.searchConsoleLink?.state===`no-search-data`?Ed.noSearchTrafficConfirmed:Ed.noSearchTrafficAction})]}),u.totalRows===0&&u.hasQuery&&(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary mt-3`,children:c.totalRows>c.rows.length?Ed.noFilterMatchInLoaded(c.rows.length):Ed.noFilterMatch}),(0,$.jsx)(Ts,{page:u.page,pageSize:u.pageSize,visibleRows:u.rows.length,totalRows:u.totalRows,onPageChange:u.setPage,itemLabel:u.hasQuery?`matches`:`pages`}),(c.totalRows>c.rows.length||c.rowsCapped)&&(0,$.jsxs)(`p`,{className:`text-copy-14 text-secondary mt-3`,children:[c.totalRows>c.rows.length?`Showing the top ${c.rows.length.toLocaleString()} of ${c.totalRows.toLocaleString()} stored pages by clicks.`:``,c.totalRows>c.rows.length&&c.rowsCapped?` `:``,c.rowsCapped&&c.reportRowCount!==null?`GA4 reported ${c.reportRowCount.toLocaleString()} pages; the ${c.totalRows.toLocaleString()} with the most clicks are stored.`:``]}),c.syncedAt&&(0,$.jsxs)(`p`,{className:`mt-2 text-copy-13 text-muted`,children:[`Synced `,sd(c.syncedAt)]})]}):(0,$.jsx)(Z,{className:`p-5`,children:c.status===`unavailable`?(0,$.jsxs)(`div`,{className:`text-label-14 text-secondary space-y-1`,children:[(0,$.jsx)(`p`,{className:`text-neutral`,children:Ed.unavailable}),(0,$.jsx)(`p`,{children:Ed.unavailableAction})]}):c.status===`error`?(0,$.jsxs)(`div`,{className:`text-label-14 text-secondary space-y-1`,children:[(0,$.jsx)(`p`,{className:`text-neutral`,children:Ed.refreshFailed}),c.error&&(0,$.jsx)(`p`,{children:c.error})]}):(0,$.jsxs)(`div`,{className:`text-label-14 text-secondary space-y-1`,children:[(0,$.jsx)(`p`,{className:`text-neutral`,children:Ed.neverSynced}),m&&(0,$.jsx)(`p`,{children:Ed.neverSyncedAction})]})})]})]})]})}function jd({projectName:e,onConnected:t}){let[n,r]=(0,Q.useState)(``),[i,a]=(0,Q.useState)(null),[o,s]=(0,Q.useState)(null),[c,l]=(0,Q.useState)(!1),[u,d]=(0,Q.useState)(null),f=(0,Q.useRef)(null),p=(0,Q.useCallback)(e=>{let t=e.target.files?.[0];if(!t)return;d(null),a(t.name);let n=new FileReader;n.onload=()=>{let e=n.result;try{let t=JSON.parse(e);if(!t.client_email||!t.private_key){d(`JSON file is missing required fields: client_email and private_key. Make sure you downloaded a service account key (not an OAuth client).`),s(null);return}s(e)}catch{d(`File is not valid JSON. Please upload a service account key file (.json) downloaded from Google Cloud Console.`),s(null)}},n.onerror=()=>{d(`Failed to read file.`),s(null)},n.readAsText(t)},[]);async function m(){if(d(null),!n.trim())d(`Property ID is required.`);else if(!o)d(`Please upload a service account key file.`);else{l(!0);try{await Cn(e,{propertyId:n.trim(),keyJson:o});try{await ht(e)}catch{}t()}catch(e){d(e instanceof Error?e.message:`Failed to connect GA4`)}finally{l(!1)}}}return(0,$.jsxs)(Z,{className:`surface-card p-6`,children:[(0,$.jsx)(`h3`,{className:`text-heading-16 text-primary mb-1`,children:`Connect Google Analytics 4`}),(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary mb-5`,children:`Connect a GA4 property to see traffic data for this project. You'll need a service account key file from Google Cloud Console.`}),u&&(0,$.jsx)(`div`,{className:`mb-4 px-4 py-2 rounded-md bg-negative-900/20 border border-negative-800/60 text-label-14 text-negative`,children:u}),(0,$.jsxs)(`div`,{className:`mb-4`,children:[(0,$.jsx)(`label`,{htmlFor:`ga4-property-id`,className:`block text-label-12-strong text-secondary mb-1.5`,children:`GA4 Property ID`}),(0,$.jsx)(`input`,{id:`ga4-property-id`,type:`text`,placeholder:`e.g. 123456789`,value:n,onChange:e=>r(e.target.value),className:`w-full rounded-md bg-bg-elevated/60 border border-default px-3 py-2 text-label-14 text-strong placeholder-mono-400 focus:outline-none focus:ring-1 focus:ring-mono-600`}),(0,$.jsx)(`p`,{className:`mt-1 text-copy-13 text-muted`,children:`Find this in GA4 → Admin → Property Settings. It's a numeric ID, not the Measurement ID (G-XXXXXX).`})]}),(0,$.jsxs)(`div`,{className:`mb-5`,children:[(0,$.jsx)(`label`,{className:`block text-label-12-strong text-secondary mb-1.5`,children:`Service Account Key File`}),(0,$.jsx)(`input`,{ref:f,type:`file`,accept:`.json,application/json`,onChange:p,className:`hidden`}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>f.current?.click(),className:`flex items-center gap-2 w-full rounded-md bg-bg-elevated/60 border border-default border-dashed px-4 py-3 text-button-14 text-secondary hover:border-mono-600 hover:text-neutral transition-colors cursor-pointer`,children:[(0,$.jsx)(h,{className:`w-4 h-4 shrink-0`}),i?(0,$.jsx)(`span`,{className:`text-strong truncate`,children:i}):(0,$.jsx)(`span`,{children:`Upload .json key file`})]}),(0,$.jsxs)(`p`,{className:`mt-1 text-copy-13 text-muted`,children:[`Download from Google Cloud Console → IAM & Admin → Service Accounts → Keys → Add Key → JSON. The service account must have `,(0,$.jsx)(`span`,{className:`text-secondary`,children:`Viewer`}),` access on the GA4 property.`]})]}),(0,$.jsx)(q,{variant:`default`,size:`sm`,disabled:c||!n.trim()||!o,onClick:Jn(m),children:c?`Connecting & syncing…`:`Connect GA4`})]})}function Md({page:e}){return(0,$.jsxs)(`tr`,{className:`border-t border-subtle`,children:[(0,$.jsx)(`td`,{className:`max-w-[400px] truncate py-1.5 pr-3 text-strong`,title:e.landingPage,children:e.landingPage}),(0,$.jsx)(`td`,{className:`py-1.5 pl-4 text-right text-primary tabular-nums`,children:e.sessions.toLocaleString()}),(0,$.jsx)(`td`,{className:`py-1.5 pl-4 text-right text-secondary tabular-nums`,children:e.organicSessions.toLocaleString()}),(0,$.jsx)(`td`,{className:`py-1.5 pl-4 text-right text-secondary tabular-nums`,children:G(e.organicShare)})]})}function Nd({row:e}){return(0,$.jsxs)(`tr`,{className:`border-t border-subtle`,children:[(0,$.jsx)(`td`,{className:`max-w-[400px] py-1.5 pr-3 text-strong`,children:(0,$.jsx)(Ss,{value:e.landingPage,className:`whitespace-nowrap`})}),(0,$.jsx)(`td`,{className:`max-w-[220px] truncate py-1.5 pr-3 text-secondary`,title:e.source,children:e.source}),(0,$.jsx)(`td`,{className:`py-1.5 pr-3 text-secondary`,title:pd[e.sourceDimension]??``,children:fd[e.sourceDimension]??e.sourceDimension}),(0,$.jsx)(`td`,{className:`py-1.5 pl-4 text-right text-primary tabular-nums`,children:e.sessions.toLocaleString()})]})}var Pd=new Set([`gbp-listing-discrepancy`,`gbp-lodging-gap`,`gbp-cta-gap`,`gbp-metric-drop`,`gbp-keyword-drop`]);function Fd({projectName:e,projectId:t}){let n=S(),[r,i]=(0,Q.useState)(null),[a,o]=(0,Q.useState)(null),[s,c]=(0,Q.useState)(!1),l=w(Sr({client:K,path:{name:e}})),u=l.data?.find(e=>e.connectionType===`gbp`),d=!!u,f=r?{locationName:r}:void 0,p=w({...Fr({client:K,path:{name:e}}),enabled:d}),m=w({...kr({client:K,path:{name:e},query:f}),enabled:d}),h=w({...Mr({client:K,path:{name:e},query:f}),enabled:d}),g=w({...Vr({client:K,path:{name:e},query:f}),enabled:d}),_=w({...vr({client:K,path:{name:e},query:f}),enabled:d}),v=w({...wr({client:K,path:{name:e},query:f}),enabled:d}),y=w({queryKey:[`gbp-section-insights`,e],queryFn:()=>Je(e),enabled:d});function b(){Zn(n,`gbp`)}let x=C({...Yr(),onSuccess:n=>{Zo({id:n.runId,projectId:t,kind:Se[`gbp-sync`],projectLabel:e,sourceAction:`gbp-sync`}),Xn({title:`Business Profile sync started`,detail:`${e} will refresh when the sync completes.`,tone:`neutral`,dedupeKey:`gbp-sync:${e}`,dedupeMode:`replace`})}}),T=(0,Q.useSyncExternalStore)(To,is,is),E=Object.values(T.runs).some(e=>e.kind===Se[`gbp-sync`]&&e.projectId===t),D=x.isPending||E,O=C({...Hr(),onSuccess:()=>b()});if((0,Q.useEffect)(()=>{if(!r||!p.data)return;let e=p.data.locations.filter(e=>e.selected);(e.length<=1||!e.some(e=>e.locationName===r))&&i(null)},[r,p.data]),(0,Q.useEffect)(()=>{a&&p.data&&((r?[r]:p.data.locations.filter(e=>e.selected).map(e=>e.locationName)).includes(a)||o(null))},[a,p.data,r]),l.isLoading)return null;if(!u){let t=[{title:`Connect your Google account`,command:`canonry gbp connect ${e}`,note:`Opens Google OAuth. Grant Business Profile (business.manage) access.`},{title:`Choose the account`,command:`canonry gbp accounts ${e}`,note:`Pick which Business Profile account this project tracks.`},{title:`Select locations`,command:`canonry gbp locations discover ${e}`,note:(0,$.jsxs)($.Fragment,{children:[`Then adopt the ones to sync: `,(0,$.jsxs)(`code`,{className:`rounded bg-bg-elevated/80 px-1 py-0.5 text-label-12-mono text-secondary`,children:[`canonry gbp locations select `,e,` <location>`]})]})},{title:`Sync, and keep it fresh`,command:`canonry gbp sync ${e}`,note:(0,$.jsxs)($.Fragment,{children:[`Schedule it: `,(0,$.jsxs)(`code`,{className:`rounded bg-bg-elevated/80 px-1 py-0.5 text-label-12-mono text-secondary`,children:[`canonry schedule set `,e,` --kind gbp-sync --preset daily`]})]})}];return(0,$.jsx)(`section`,{className:`page-section-divider`,children:(0,$.jsxs)(Z,{className:`surface-card`,children:[(0,$.jsx)(`p`,{className:`eyebrow eyebrow-soft`,children:`Local presence`}),(0,$.jsx)(`h2`,{children:`Connect Google Business Profile`}),(0,$.jsx)(`p`,{className:`mt-2 max-w-2xl text-copy-14 text-muted`,children:`Track local performance, search terms, place-action CTAs, and how your public Maps listing compares to the profile you control. Four steps from the CLI:`}),(0,$.jsx)(`ol`,{className:`mt-5 space-y-4`,children:t.map((e,t)=>(0,$.jsxs)(`li`,{className:`grid grid-cols-[1.5rem_1fr] gap-x-3`,children:[(0,$.jsx)(`span`,{className:`mt-0.5 inline-flex h-6 w-6 items-center justify-center rounded-full bg-mono-800 text-label-12-strong tabular-nums text-neutral`,"aria-hidden":`true`,children:t+1}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`p`,{className:`text-copy-14-strong text-strong`,children:e.title}),(0,$.jsx)(`code`,{className:`mt-1.5 inline-block w-fit max-w-full overflow-x-auto rounded bg-bg-elevated/80 px-2 py-1 text-label-12-mono text-neutral`,children:e.command}),(0,$.jsx)(`p`,{className:`mt-1 text-copy-13 text-muted`,children:e.note})]})]},e.title))})]})})}let k=m.data,A=p.data?.locations??[],j=A.filter(e=>e.selected),M=h.data?.keywords??[],N=g.data?.lodging??[],P=_.data?.placeActions??[],F=v.data?.places??[],I=A.length>0?A[0].accountName:u.domain,L=r?A.find(e=>e.locationName===r)?.displayName??null:null,R=r?A.filter(e=>e.locationName===r):j,ee=new Set(R.map(e=>e.locationName)),te=N.filter(e=>ee.has(e.locationName)),ne=P.filter(e=>ee.has(e.locationName)),re=F.filter(e=>ee.has(e.locationName)),ie=new Set(j.map(e=>e.locationName)),z=r?M:M.filter(e=>ie.has(e.locationName)),ae=!r&&j.length>1,B=(y.data??[]).filter(e=>!e.dismissed&&Pd.has(e.type)&&(!L||e.query===L||e.query===r||e.title.startsWith(L)));return(0,$.jsx)(`section`,{className:`page-section-divider`,children:(0,$.jsxs)(Z,{className:`surface-card`,children:[(0,$.jsxs)(`div`,{className:`section-head section-head-inline`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`eyebrow eyebrow-soft`,children:`Local presence`}),(0,$.jsxs)(`h2`,{className:`flex items-center gap-2`,children:[`Google Business Profile`,(0,$.jsx)(X,{text:`How AI answer engines and Maps surface this business: performance, search terms, and how your public listing compares to the profile you control.`})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(J,{tone:`positive`,children:`Connected`}),!Y()&&(0,$.jsx)(vs,{type:`button`,variant:`outline`,size:`sm`,disabled:D,onClick:()=>x.mutate({client:K,path:{name:e},body:{}}),children:D?`Syncing…`:`Sync`})]})]}),(0,$.jsxs)(`p`,{className:`mb-4 text-copy-13 text-muted`,children:[I?(0,$.jsxs)($.Fragment,{children:[`Account `,(0,$.jsx)(`span`,{className:`font-mono text-secondary`,children:I}),` · `]}):null,p.data?`${p.data.totalSelected} of ${p.data.totalDiscovered} locations tracked`:`Loading locations…`]}),j.length>1&&(0,$.jsxs)(`div`,{className:`mb-5 max-w-xs`,children:[(0,$.jsx)(`label`,{htmlFor:`local-presence-location`,className:`mb-1 block text-label-14-strong text-secondary`,children:`Location`}),(0,$.jsxs)(`select`,{id:`local-presence-location`,value:r??``,onChange:e=>i(e.target.value||null),className:`w-full rounded-md border border-base bg-bg px-3 py-2 text-label-14 text-strong focus:outline-none focus-visible:ring-2 focus-visible:ring-mono-500/60`,children:[(0,$.jsx)(`option`,{value:``,children:`All locations`}),j.map(e=>(0,$.jsx)(`option`,{value:e.locationName,children:e.displayName},e.id))]})]}),j.length===0?(0,$.jsxs)(`p`,{className:`text-copy-14 text-muted`,children:[`No locations are tracked yet. Open `,(0,$.jsx)(`span`,{className:`text-copy-14-strong text-neutral`,children:`Manage locations`}),` below to track the one(s) for this business.`]}):(0,$.jsxs)($.Fragment,{children:[B.length>0&&(0,$.jsxs)(`div`,{className:`mb-6 grid gap-2`,children:[(0,$.jsx)(`p`,{className:`eyebrow eyebrow-soft`,children:`Needs attention`}),B.map(e=>(0,$.jsx)(`div`,{className:[`surface-card insight-card`,Qd(e.severity),`p-3`].filter(Boolean).join(` `),children:(0,$.jsxs)(`p`,{className:`flex items-center gap-2 text-copy-14-strong text-strong`,children:[e.title,e.recommendation?.reason&&(0,$.jsx)(X,{text:e.recommendation.reason})]})},e.id))]}),k&&(0,$.jsx)(sf,{performance:k.performance,freshness:k.freshness,timeseries:k.timeseries}),k?.profileCompleteness&&(0,$.jsx)(Id,{summary:k.profileCompleteness}),R.length>0&&(0,$.jsx)(Ld,{locations:R,lodging:te,places:re,placeActions:ne,expandedLocation:a,onToggleExpanded:e=>{o(t=>t===e?null:e)}}),(0,$.jsxs)(`div`,{className:`mb-2`,children:[(0,$.jsxs)(`div`,{className:`section-head section-head-inline mb-2`,children:[(0,$.jsx)(`p`,{className:`eyebrow eyebrow-soft`,children:`Search terms`}),h.data&&h.data.total>0&&(0,$.jsxs)(`span`,{className:`text-label-12 text-faint`,children:[G(h.data.thresholdedPct,rt.percent),` privacy-thresholded`]})]}),z.length===0?(0,$.jsx)(`p`,{className:`text-copy-14 text-muted`,children:`No keyword impressions stored yet.`}):(0,$.jsxs)(`table`,{className:`data-table w-full text-label-14`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{className:`text-left`,children:`Search term`}),ae&&(0,$.jsx)(`th`,{className:`text-left`,children:`Location`}),(0,$.jsx)(`th`,{className:`text-right`,children:`Impressions`}),(0,$.jsx)(`th`,{className:`text-right`,children:`Window`})]})}),(0,$.jsx)(`tbody`,{children:z.slice(0,25).map(e=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{className:`text-neutral`,children:e.keyword}),ae&&(0,$.jsx)(`td`,{className:`text-muted`,children:A.find(t=>t.locationName===e.locationName)?.displayName??e.locationName}),(0,$.jsx)(`td`,{className:`text-right font-mono text-strong`,children:e.valueCount===null?(0,$.jsxs)(`span`,{className:`text-muted`,title:`Privacy floor — Google withheld the exact count`,children:[`<`,e.valueThreshold]}):e.valueCount.toLocaleString()}),(0,$.jsxs)(`td`,{className:`text-right text-label-12-mono text-faint`,children:[e.periodStart,`–`,e.periodEnd]})]},`${e.locationName}:${e.keyword}`))})]})]})]}),(0,$.jsxs)(`div`,{className:`mt-6 border-t border-default pt-4`,children:[(0,$.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1.5 text-button-14 text-secondary hover:text-strong`,onClick:()=>c(e=>!e),"aria-expanded":s,children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,children:s?`▾`:`▸`}),` Manage locations (`,A.length,`)`]}),s&&(0,$.jsx)(`div`,{className:`mt-3`,children:A.length===0?(0,$.jsxs)(`p`,{className:`text-copy-14 text-muted`,children:[`No locations discovered. Run `,(0,$.jsx)(`span`,{className:`font-mono`,children:`canonry gbp locations discover`}),`.`]}):(0,$.jsxs)(`table`,{className:`data-table w-full text-label-14`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{className:`text-left`,children:`Location`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Address`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Status`}),!Y()&&(0,$.jsx)(`th`,{className:`text-right`,children:`Action`})]})}),(0,$.jsx)(`tbody`,{children:A.map(t=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{className:`text-strong`,children:t.displayName}),(0,$.jsx)(`td`,{className:`text-muted`,children:t.storefrontAddress??`—`}),(0,$.jsx)(`td`,{children:(0,$.jsx)(J,{tone:t.selected?`positive`:`neutral`,children:t.selected?`Tracked`:`Not tracked`})}),!Y()&&(0,$.jsx)(`td`,{className:`text-right`,children:(0,$.jsx)(vs,{type:`button`,variant:`outline`,size:`sm`,disabled:O.isPending,onClick:()=>O.mutate({client:K,path:{name:e,locationName:t.locationName},body:{selected:!t.selected}}),children:t.selected?`Untrack`:`Track`})})]},t.id))})]})})]})]})})}function Id({summary:e}){if(e.locationCount===0)return null;let t=e.locationCount,n=[{label:`Description`,value:`${e.withDescription}/${t}`,tone:Xd(e.withDescription,t,`caution`)},{label:`Hours`,value:`${e.withHours}/${t}`,tone:Xd(e.withHours,t,`caution`)},{label:`Phone`,value:`${e.withPrimaryPhone}/${t}`,tone:Xd(e.withPrimaryPhone,t,`caution`)},{label:`Service area`,value:`${e.withServiceArea}/${t}`,tone:Xd(e.withServiceArea,t,`neutral`)},{label:`Secondary categories`,value:`${e.withSecondaryCategories}/${t}`,detail:`${e.secondaryCategoryTotal} total`,tone:Xd(e.withSecondaryCategories,t,`caution`)},{label:`Closed`,value:String(e.permanentlyClosed+e.temporarilyClosed),detail:e.permanentlyClosed||e.temporarilyClosed?`${e.permanentlyClosed} permanent, ${e.temporarilyClosed} temporary`:`reported open`,tone:e.permanentlyClosed>0?`negative`:e.temporarilyClosed>0?`caution`:`positive`}];return(0,$.jsxs)(`div`,{className:`mb-6 border-y border-default py-3`,children:[(0,$.jsxs)(`div`,{className:`mb-3 flex items-center gap-2`,children:[(0,$.jsx)(`p`,{className:`eyebrow eyebrow-soft`,children:`Owner profile · Business Information`}),(0,$.jsx)(X,{text:`Counts selected locations where Google Business Information returned the owner-authored field. A missing value means it was not returned by this API response, not that every Google surface is empty.`})]}),(0,$.jsx)(`div`,{className:`grid gap-x-5 gap-y-3 sm:grid-cols-2 lg:grid-cols-3`,children:n.map(e=>(0,$.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_auto] items-baseline gap-3`,children:[(0,$.jsx)(`span`,{className:`text-label-12 text-muted`,children:e.label}),(0,$.jsx)(`span`,{className:`text-label-14-mono tabular-nums ${Zd(e.tone)}`,children:e.value}),e.detail&&(0,$.jsx)(`span`,{className:`col-span-2 text-label-12 text-faint`,children:e.detail})]},e.label))})]})}function Ld({locations:e,lodging:t,places:n,placeActions:r,expandedLocation:i,onToggleExpanded:a}){let o=new Map(t.map(e=>[e.locationName,e])),s=new Map(n.map(e=>[e.locationName,e])),c=new Map;for(let e of r){let t=c.get(e.locationName)??[];t.push(e),c.set(e.locationName,t)}return(0,$.jsxs)(`div`,{className:`mb-6`,children:[(0,$.jsxs)(`div`,{className:`section-head section-head-inline mb-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`p`,{className:`eyebrow eyebrow-soft`,children:`Source evidence`}),(0,$.jsx)(X,{text:Y()?`Each column names the Google surface it came from. Missing or empty means that surface did not return a value in the latest sync, not that every Google product lacks the information.`:`Each column names the Google surface it came from. Missing or empty means that surface did not return a value in the latest Canonry sync, not that every Google product lacks the information.`})]}),(0,$.jsxs)(`span`,{className:`text-label-12 text-faint`,children:[e.length,` location`,e.length===1?``:`s`]})]}),(0,$.jsx)(`div`,{className:`data-table-wrapper`,children:(0,$.jsxs)(`table`,{className:`data-table`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{className:`min-w-[14rem]`,children:`Location`}),(0,$.jsx)(`th`,{className:`min-w-[15rem]`,children:`Owner profile`}),(0,$.jsx)(`th`,{className:`min-w-[11rem]`,children:`Hotel data`}),(0,$.jsx)(`th`,{className:`min-w-[11rem]`,children:`Public Maps`}),(0,$.jsx)(`th`,{className:`min-w-[10rem]`,children:`CTAs`}),(0,$.jsx)(`th`,{className:`text-right`,children:`Detail`})]})}),(0,$.jsx)(`tbody`,{children:e.map(e=>{let t=o.get(e.locationName)??null,n=s.get(e.locationName)??null,r=c.get(e.locationName)??[],l=i===e.locationName;return(0,$.jsxs)(Q.Fragment,{children:[(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{children:(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`p`,{className:`text-copy-14-strong text-strong`,children:e.displayName}),(0,$.jsx)(`p`,{className:`mt-1 text-copy-13 text-faint`,children:e.primaryCategoryDisplayName??`Primary category not returned`}),(0,$.jsxs)(`div`,{className:`mt-2 flex flex-wrap gap-1.5`,children:[(0,$.jsx)(J,{tone:e.selected?`positive`:`neutral`,children:e.selected?`Tracked`:`Not tracked`}),e.openStatus&&e.openStatus!==`OPEN`&&(0,$.jsx)(J,{tone:e.openStatus===`CLOSED_PERMANENTLY`?`negative`:`caution`,children:ef(e.openStatus)})]})]})}),(0,$.jsx)(`td`,{children:(0,$.jsx)(zd,{location:e})}),(0,$.jsx)(`td`,{children:(0,$.jsx)(Bd,{lodging:t})}),(0,$.jsx)(`td`,{children:(0,$.jsx)(Hd,{place:n,mapsUri:e.mapsUri})}),(0,$.jsx)(`td`,{children:(0,$.jsx)(Wd,{actions:r})}),(0,$.jsx)(`td`,{className:`text-right`,children:(0,$.jsx)(q,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>a(e.locationName),children:l?`Hide`:`Details`})})]}),l&&(0,$.jsx)(`tr`,{className:`bg-mono-950/35 hover:bg-mono-950/35`,children:(0,$.jsx)(`td`,{colSpan:6,className:`px-4 py-4`,children:(0,$.jsx)(qd,{location:e,lodging:t,place:n,placeActions:r})})})]},e.id)})})]})})]})}function Rd(e){return[{label:`Description`,tone:$d(e.description)?`positive`:`neutral`,value:$d(e.description)?`set`:`not returned`},{label:`Hours`,tone:e.regularHours?`positive`:`neutral`,value:e.regularHours?`set`:`not returned`},{label:`Phone`,tone:$d(e.primaryPhone)?`positive`:`neutral`,value:$d(e.primaryPhone)?`set`:`not returned`},{label:`Website`,tone:$d(e.websiteUri)?`positive`:`neutral`,value:$d(e.websiteUri)?`set`:`not returned`},{label:`Secondary`,tone:e.additionalCategories.length>0?`positive`:`neutral`,value:e.additionalCategories.length>0?String(e.additionalCategories.length):`not returned`},{label:`Service area`,tone:e.serviceArea?`positive`:`neutral`,value:e.serviceArea?`set`:`not returned`}]}function zd({location:e}){let t=Rd(e);return(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:t.map(e=>(0,$.jsxs)(J,{tone:e.tone,children:[e.label,` `,e.value]},e.label))})}function Bd({lodging:e}){return(0,$.jsx)(Kd,{...Vd(e)})}function Vd(e){return e?e.populatedGroupCount===0?{tone:`neutral`,label:`0 groups returned`,detail:`Lodging API returned no readable groups; verify Hotel details.`}:{tone:`positive`,label:`${e.populatedGroupCount} group${e.populatedGroupCount===1?``:`s`} returned`,detail:`Owner lodging attributes.`}:{tone:`neutral`,label:`No Lodging API snapshot`,detail:`Not returned for this scoped location.`}}function Hd({place:e,mapsUri:t}){return(0,$.jsx)(Kd,{...Ud(e,t)})}function Ud(e,t){if(!e)return{tone:`neutral`,label:`Public listing not checked`,detail:t?`Maps link available.`:`No Places snapshot.`};let n=e.amenities.length;return{tone:n>0?`positive`:`neutral`,label:n>0?`${n} signal${n===1?``:`s`} detected`:`0 supported signals detected`,detail:`Places tier: ${e.tier}`}}function Wd({actions:e}){return(0,$.jsx)(Kd,{...Gd(e)})}function Gd(e){if(e.length===0)return{tone:`neutral`,label:`No CTAs stored`,detail:`No placeActionLinks returned.`};let t=e.filter(e=>e.providerType===`MERCHANT`).length;return t===0?{tone:`neutral`,label:`${e.length} aggregator CTA${e.length===1?``:`s`}`,detail:`No merchant-owned CTA returned.`}:{tone:`positive`,label:`${t} merchant CTA${t===1?``:`s`}`,detail:`${e.length} total returned.`}}function Kd({tone:e,label:t,detail:n}){return(0,$.jsxs)(`div`,{children:[(0,$.jsx)(J,{tone:e,children:t}),(0,$.jsx)(`p`,{className:`mt-1.5 text-copy-13 text-faint`,children:n})]})}function qd({location:e,lodging:t,place:n,placeActions:r}){let i=t?af(t.attributes):[];return(0,$.jsxs)(`div`,{className:`grid gap-5 text-label-12 lg:grid-cols-3`,children:[(0,$.jsxs)(Jd,{title:`Owner profile · Business Information`,children:[(0,$.jsx)(Yd,{label:`Primary category`,value:e.primaryCategoryDisplayName??`Not returned`}),(0,$.jsx)(Yd,{label:`Secondary categories`,value:e.additionalCategories.length>0?e.additionalCategories.join(`, `):`Not returned`}),(0,$.jsx)(Yd,{label:`Description`,value:$d(e.description)?e.description:`Not returned`}),(0,$.jsx)(Yd,{label:`Hours`,value:e.regularHours?`Returned by Google`:`Not returned`}),(0,$.jsx)(Yd,{label:`Service area`,value:e.serviceArea?`Returned by Google`:`Not returned`}),(0,$.jsx)(Yd,{label:`Phone`,value:e.primaryPhone??`Not returned`}),(0,$.jsx)(Yd,{label:`Website`,value:e.websiteUri??`Not returned`}),(0,$.jsx)(Yd,{label:`Open status`,value:ef(e.openStatus)}),(0,$.jsx)(Yd,{label:`Opening date`,value:e.openingDate??`Not returned`})]}),(0,$.jsx)(Jd,{title:`Hotel data · Lodging API`,children:t?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Yd,{label:`Last checked`,value:rf(t.syncedAt)}),(0,$.jsx)(Yd,{label:`Groups returned`,value:String(t.populatedGroupCount)}),(0,$.jsx)(Yd,{label:`Populated groups`,value:i.length>0?i.join(`, `):`None returned`})]}):(0,$.jsx)(`p`,{className:`text-copy-13 text-secondary`,children:`No Lodging API snapshot was stored for this location.`})}),(0,$.jsxs)(Jd,{title:`Public listing + CTAs`,children:[n?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Yd,{label:`Places tier`,value:n.tier}),(0,$.jsx)(Yd,{label:`Last checked`,value:rf(n.syncedAt)}),(0,$.jsx)(Yd,{label:`Public signals`,value:n.amenities.length>0?n.amenities.join(`, `):`No supported signals detected`})]}):(0,$.jsx)(`p`,{className:`text-copy-13 text-secondary`,children:`No Places Details snapshot was stored for this location.`}),e.mapsUri&&(0,$.jsx)(`a`,{href:e.mapsUri,target:`_blank`,rel:`noopener noreferrer`,className:`inline-block text-muted hover:text-neutral`,children:`View on Google Maps →`}),(0,$.jsx)(`div`,{className:`mt-3 border-t border-default pt-3`,children:r.length===0?(0,$.jsx)(`p`,{className:`text-copy-13 text-secondary`,children:`No placeActionLinks returned.`}):(0,$.jsx)(`div`,{className:`grid gap-2`,children:r.map(e=>(0,$.jsxs)(`div`,{className:`grid gap-0.5`,children:[(0,$.jsxs)(`span`,{className:`text-label-12-strong text-neutral`,children:[tf(e.placeActionType),e.isPreferred?` · preferred`:``]}),(0,$.jsxs)(`span`,{className:`text-faint`,children:[tf(e.providerType),e.uri?` · ${nf(e.uri)}`:``]})]},e.placeActionLinkName))})})]})]})}function Jd({title:e,children:t}){return(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`mb-2 text-label-12-strong normal-case text-muted`,children:e}),(0,$.jsx)(`div`,{className:`grid gap-2`,children:t})]})}function Yd({label:e,value:t}){return(0,$.jsxs)(`div`,{className:`grid grid-cols-[7.25rem_minmax(0,1fr)] gap-3`,children:[(0,$.jsx)(`span`,{className:`text-faint`,children:e}),(0,$.jsx)(`span`,{className:`min-w-0 break-words text-secondary`,children:t})]})}function Xd(e,t,n){return e===t?`positive`:e===0?n:`caution`}function Zd(e){switch(e){case`positive`:return`text-positive`;case`caution`:return`text-caution`;case`negative`:return`text-negative`;case`neutral`:return`text-neutral`}}function Qd(e){return e===`critical`||e===`high`?`insight-card-negative`:e===`medium`?`insight-card-caution`:``}function $d(e){return typeof e==`string`&&e.trim().length>0}function ef(e){return e?tf(e):`Not returned`}function tf(e){return e?e.toLowerCase().split(`_`).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `):`Unknown`}function nf(e){try{return new URL(e).hostname.replace(/^www\./,``)}catch{return e}}function rf(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString(void 0,{month:`short`,day:`numeric`,year:`numeric`})}function af(e){return Object.entries(e).filter(([e,t])=>e!==`name`&&e!==`metadata`&&of(t)).map(([e])=>tf(e.replace(/([a-z])([A-Z])/g,`$1_$2`)))}function of(e){return e==null?!1:Array.isArray(e)?e.length>0:typeof e!=`object`||Object.keys(e).length>0}function sf({performance:e,freshness:t,timeseries:n}){let r=e.totals,i=ge.filter(e=>(r[e]??0)>0),a=De.filter(e=>(r[e]??0)>0),o=Object.keys(r).filter(e=>(r[e]??0)>0&&tn(e)===`other`).sort((e,t)=>(r[t]??0)-(r[e]??0)),s=Object.keys(r).filter(e=>(r[e]??0)===0).sort(),c=n.map(e=>{let t={date:e.date};for(let[n,r]of Object.entries(e.metrics))t[n]=r;return t}),l=n.find(e=>e.pending)?.date,u=n.length>0?n[n.length-1].date:void 0,d=c.length>0,f=t.dataThroughDate?`Data through ${_a(t.dataThroughDate)}${t.pendingDays>0?` · ${t.pendingDays}d pending`:``}`:null,p=[...i,...o];return(0,$.jsxs)(`div`,{className:`mb-6 grid gap-6`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:`mb-2 flex flex-wrap items-baseline justify-between gap-x-3 gap-y-1`,children:[(0,$.jsx)(`p`,{className:`eyebrow eyebrow-soft`,children:`Profile actions · daily`}),f&&(0,$.jsx)(`span`,{className:`text-label-12 text-muted`,children:f})]}),!d||i.length===0?(0,$.jsx)(`p`,{className:`text-copy-14 text-muted`,children:`No profile action activity yet — run a sync.`}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(cf,{data:c,metrics:i,kind:`line`,firstPending:l,lastDate:u}),(0,$.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-x-5 gap-y-1`,children:p.map(e=>(0,$.jsxs)(`span`,{className:`text-label-14 text-secondary`,children:[Ee(e),` `,(0,$.jsx)(`span`,{className:`font-mono text-heading`,children:(r[e]??0).toLocaleString()})]},e))})]})]}),d&&a.length>0&&(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`eyebrow eyebrow-soft mb-2`,children:`Reach · impressions, daily`}),(0,$.jsx)(cf,{data:c,metrics:a,kind:`area`,firstPending:l,lastDate:u})]}),s.length>0&&(0,$.jsxs)(`p`,{className:`text-copy-13 text-faint`,children:[`Not active: `,s.map(e=>Ee(e)).join(`, `)]})]})}function cf({data:e,metrics:t,kind:n,firstPending:r,lastDate:i}){return(0,$.jsx)(`div`,{className:`h-48 w-full`,children:(0,$.jsx)(I,{width:`100%`,height:`100%`,children:(0,$.jsxs)(ne,{data:e,margin:{top:8,right:8,bottom:0,left:0},children:[(0,$.jsx)(M,{stroke:xa,vertical:!1}),(0,$.jsx)(P,{dataKey:`date`,tick:va,tickLine:!1,axisLine:{stroke:Ca},tickFormatter:fa,minTickGap:24}),(0,$.jsx)(ee,{tick:va,tickLine:!1,axisLine:!1,allowDecimals:!1,width:36}),(0,$.jsx)(N,{...Sa,labelFormatter:_a,formatter:(e,t)=>[typeof e==`number`?e.toLocaleString():String(e??0),Ee(String(t??``))]}),(0,$.jsx)(R,{wrapperStyle:{fontSize:12,color:ga.text},formatter:e=>Ee(e)}),r&&i&&(0,$.jsx)(F,{x1:r,x2:i,fill:ga.surface,fillOpacity:.55,stroke:`none`,label:{value:`pending`,position:`insideTopRight`,fill:ga.textDim,fontSize:12}}),t.map((e,t)=>n===`line`?(0,$.jsx)(te,{type:`monotone`,dataKey:e,stroke:ua[t%ua.length],strokeWidth:2,dot:!1,isAnimationActive:!1},e):(0,$.jsx)(L,{type:`monotone`,dataKey:e,stackId:`reach`,stroke:ua[t%ua.length],fill:ua[t%ua.length],fillOpacity:.25,strokeWidth:1.5,isAnimationActive:!1},e))]})})})}var lf=25;function uf(e){return typeof window>`u`?e:`${window.__CANONRY_CONFIG__?.basePath?.replace(/\/$/,``)??``}${e}`}function df(e){return e.toLocaleString()}function ff(e){let t=Date.now()-new Date(e).getTime(),n=Math.floor(t/6e4);if(n<1)return`just now`;if(n<60)return`${n}m ago`;let r=Math.floor(n/60);return r<24?`${r}h ago`:`${Math.floor(r/24)}d ago`}function pf(e){let t=e.filter(e=>e.kind===Se[`backlink-extract`]&&!Ro(e.status));return t.length===0?null:t.reduce((e,t)=>e.createdAt>t.createdAt?e:t)}function mf(e,t){let n=new Date(e??t).getTime(),r=Math.max(0,Math.floor((Date.now()-n)/1e3));if(r<60)return`${r}s`;let i=Math.floor(r/60),a=r%60;return a===0?`${i}m`:`${i}m ${a}s`}function hf({projectName:e}){let t=We(),[n,r]=(0,Q.useState)(null),[s,c]=(0,Q.useState)(null),[u,d]=(0,Q.useState)(null),[f,p]=(0,Q.useState)(null),[m,h]=(0,Q.useState)(null),[g,_]=(0,Q.useState)(null),[v,y]=(0,Q.useState)(Date.now()),[x,S]=(0,Q.useState)(0),[C,w]=(0,Q.useState)(!0),[T,E]=(0,Q.useState)(!1),[D,O]=(0,Q.useState)(null),k=(0,Q.useCallback)(async()=>{w(!0),O(null);try{let[t,n,i,a,o]=await Promise.all([Ge().catch(()=>null),xe(e,{excludeCrawlers:!0}).catch(()=>null),fe(e,{limit:lf,offset:x,excludeCrawlers:!0}).catch(e=>{if(e instanceof ot&&e.code===`NOT_FOUND`)return null;throw e}),Nt(e,{surface:vt.backlinks}).catch(()=>null),he(e).catch(()=>[])]);p(t),r(n),c(i),d(a);let s=pf(o);h(s)}catch(e){O(e instanceof Error?e.message:`Failed to load backlinks`)}finally{w(!1)}},[e,x]);(0,Q.useEffect)(()=>{k()},[k]),(0,Q.useEffect)(()=>{if(!m)return;let e=m.id,t=!1,n=async()=>{try{let n=await Te(e);if(t)return;Ro(n.status)?(h(null),_(n),await k()):h(e=>e?.id===n.id?{...e,...n}:e)}catch{}},r=window.setInterval(()=>{n()},3e3);return()=>{t=!0,window.clearInterval(r)}},[m,k]),(0,Q.useEffect)(()=>{if(!m)return;let e=window.setInterval(()=>y(Date.now()),1e3);return()=>window.clearInterval(e)},[m]),(0,Q.useEffect)(()=>{if(!g||g.status===`failed`)return;let e=window.setTimeout(()=>_(null),1e4);return()=>window.clearTimeout(e)},[g]);async function A(){E(!0),O(null);try{let t=await ct(e);h(t)}catch(e){e instanceof ot&&e.code===`MISSING_DEPENDENCY`?O(`DuckDB is not installed. Visit the Backlinks admin page to install it.`):O(e instanceof Error?e.message:`Failed to trigger extract`)}finally{E(!1)}}let j=s?.rows??[],M=s?.total??0,N=n?.excludedLinkingDomains??0,P=Math.floor(x/lf)+1;return(0,Q.useEffect)(()=>{x>0&&x>=M&&S(0)},[x,M]),(0,$.jsxs)(`section`,{className:`page-section-divider`,children:[(0,$.jsx)(`div`,{className:`section-head section-head-inline`,children:(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`eyebrow eyebrow-soft`,children:`Backlinks`}),(0,$.jsx)(`h2`,{children:`Referring domains`})]})}),D&&(0,$.jsx)(Z,{className:`surface-card p-4 mb-4 bg-negative-soft`,children:(0,$.jsx)(`p`,{className:`text-copy-14 text-negative`,children:D})}),m&&(0,$.jsx)(Z,{className:`surface-card p-4 mb-4 bg-info-soft`,children:(0,$.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,$.jsx)(i,{className:`h-5 w-5 text-info-400 animate-spin shrink-0 mt-0.5`,"aria-hidden":!0}),(0,$.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,$.jsx)(`p`,{className:`text-copy-14-strong text-heading`,children:`Extract running`}),(0,$.jsx)(J,{tone:`neutral`,children:m.status}),(0,$.jsxs)(`span`,{className:`text-label-14 text-secondary tabular-nums`,children:[mf(m.startedAt??null,m.createdAt),` elapsed · refreshing every 3s`]}),(0,$.jsxs)(`span`,{className:`sr-only`,children:[`now=`,v]})]}),(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary mt-1`,children:`Refreshing this project from the current Common Crawl release.`})]})]})}),g&&!m&&(0,$.jsx)(Z,{className:`surface-card p-4 mb-4 ${g.status===`failed`?`bg-negative-soft`:`bg-positive-soft`}`,children:(0,$.jsxs)(`div`,{className:`flex items-start gap-3`,children:[g.status===`failed`?(0,$.jsx)(`span`,{className:`h-5 w-5 shrink-0 mt-0.5 text-negative-400 text-label-18`,"aria-hidden":!0,children:`!`}):(0,$.jsx)(a,{className:`h-5 w-5 text-positive-400 shrink-0 mt-0.5`,"aria-hidden":!0}),(0,$.jsxs)(`div`,{className:`flex-1`,children:[(0,$.jsx)(`p`,{className:`text-copy-14-strong ${g.status===`failed`?`text-negative`:`text-positive`}`,children:g.status===`failed`?`Extract failed`:`Extract complete`}),g.error?(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary mt-1`,children:An(g.error)}):g.status===`failed`?null:(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary mt-1`,children:`Backlinks refreshed from the cached release.`})]})]})}),F()]});function F(){return C?(0,$.jsx)(Z,{className:`surface-card p-6`,children:(0,$.jsx)(`p`,{className:`text-copy-14 text-muted`,children:`Loading backlinks…`})}):I()}function I(){let e=n!==null&&n.totalLinkingDomains>0,r=g?.status===`failed`,i=n!==null&&n.totalLinkingDomains===0&&!r,a=f?.status===`ready`,s=f?.status===`failed`,c=f&&(f.status===`downloading`||f.status===`querying`||f.status===`queued`);return e?L((0,$.jsxs)($.Fragment,{children:[!Y()&&!t&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(q,{type:`button`,variant:`outline`,size:`sm`,disabled:T||m!==null,onClick:Jn(A),children:[(0,$.jsx)(l,{className:`h-4 w-4 mr-1.5`,"aria-hidden":!0}),m?`Extract running…`:T?`Queuing…`:`Re-run extract`]}),(0,$.jsx)(Ms,{label:`About re-running`,children:`Re-queries the current release for this project without downloading it again.`})]}),!Y()&&!t&&(0,$.jsx)(q,{asChild:!0,type:`button`,variant:`outline`,size:`sm`,children:(0,$.jsx)(`a`,{href:uf(`/backlinks`),children:`Open admin`})})]})):(0,$.jsx)(Z,{className:`surface-card p-6`,children:(0,$.jsxs)(`div`,{className:`flex items-start gap-4`,children:[(0,$.jsx)(`div`,{className:`flex h-10 w-10 shrink-0 items-center justify-center rounded-md bg-bg-elevated text-secondary`,children:(0,$.jsx)(o,{className:`h-5 w-5`,"aria-hidden":!0})}),(0,$.jsxs)(`div`,{className:`flex-1`,children:[!f&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`h3`,{className:`text-heading-16 text-heading`,children:`No release sync yet`}),(0,$.jsx)(`p`,{className:`text-copy-14 text-muted mt-1`,children:`Run a workspace release sync to populate backlinks for every project in this workspace.`}),!Y()&&!t&&(0,$.jsx)(`div`,{className:`mt-4`,children:(0,$.jsx)(q,{asChild:!0,type:`button`,size:`sm`,children:(0,$.jsx)(`a`,{href:uf(`/backlinks`),children:`Set up backlinks`})})})]}),c&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`h3`,{className:`text-heading-16 text-heading`,children:`Sync in progress`}),(0,$.jsxs)(`p`,{className:`text-copy-14 text-muted mt-1`,children:[`A workspace release sync is running (`,f.status,f.phaseDetail?` — ${f.phaseDetail}`:``,`). Backlinks will appear here once it finishes.`]}),!Y()&&!t&&(0,$.jsx)(`div`,{className:`mt-4`,children:(0,$.jsx)(q,{asChild:!0,type:`button`,variant:`outline`,size:`sm`,children:(0,$.jsx)(`a`,{href:uf(`/backlinks`),children:`View sync status`})})})]}),s&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`h3`,{className:`text-heading-16 text-heading`,children:`Last sync failed`}),(0,$.jsx)(`p`,{className:`text-copy-14 text-muted mt-1`,children:f.error??`The workspace release sync failed. Retry from the Backlinks admin page.`}),!Y()&&!t&&(0,$.jsx)(`div`,{className:`mt-4`,children:(0,$.jsx)(q,{asChild:!0,type:`button`,size:`sm`,children:(0,$.jsx)(`a`,{href:uf(`/backlinks`),children:`Go to Backlinks admin`})})})]}),a&&!c&&!i&&!r&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`h3`,{className:`text-heading-16 text-heading`,children:`No backlinks yet for this project`}),(0,$.jsxs)(`p`,{className:`text-copy-14 text-secondary mt-1`,children:[`Release `,(0,$.jsx)(`code`,{className:`text-neutral`,children:f.release}),` is ready. Run an extract for this project.`]}),!Y()&&!t&&(0,$.jsxs)(`div`,{className:`mt-4 flex items-center gap-3 flex-wrap`,children:[(0,$.jsxs)(q,{type:`button`,size:`sm`,disabled:T||m!==null,onClick:Jn(A),children:[(0,$.jsx)(b,{className:`h-4 w-4 mr-1.5`,"aria-hidden":!0}),m?`Extract running…`:T?`Queuing…`:`Run extract`]}),(0,$.jsx)(Ms,{label:`About extraction`,children:`Queries the current release for this project without downloading it again.`})]})]}),r&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`h3`,{className:`text-heading-16 text-heading`,children:`Last extract failed`}),(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary mt-1`,children:`See the error above, then check the workspace source before retrying.`}),!Y()&&!t&&(0,$.jsx)(`div`,{className:`mt-4 flex items-center gap-3 flex-wrap`,children:(0,$.jsx)(q,{asChild:!0,type:`button`,size:`sm`,children:(0,$.jsx)(`a`,{href:uf(`/backlinks`),children:`Go to Backlinks admin`})})})]}),i&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`h3`,{className:`text-heading-16 text-heading`,children:`No referring domains found`}),(0,$.jsxs)(`p`,{className:`text-copy-14 text-secondary mt-1`,children:[`The latest release found no referring domains for `,n.targetDomain,`. Try a newer release or re-run this extract.`]}),!Y()&&!t&&(0,$.jsxs)(`div`,{className:`mt-4 flex items-center gap-3 flex-wrap`,children:[(0,$.jsx)(q,{asChild:!0,type:`button`,size:`sm`,children:(0,$.jsx)(`a`,{href:uf(`/backlinks`),children:`Go to Backlinks admin`})}),(0,$.jsxs)(q,{type:`button`,variant:`outline`,size:`sm`,disabled:T||m!==null,onClick:Jn(A),children:[(0,$.jsx)(b,{className:`h-4 w-4 mr-1.5`,"aria-hidden":!0}),m?`Extract running…`:T?`Queuing…`:`Re-run extract`]}),(0,$.jsxs)(Ms,{label:`What does Re-run extract do?`,children:[(0,$.jsxs)(`span`,{className:`block`,children:[`Re-queries the cached release for `,(0,$.jsx)(`span`,{className:`text-strong`,children:n.targetDomain}),`. Only useful if the cache files were incomplete last time.`]}),(0,$.jsx)(`span`,{className:`mt-2 block text-secondary`,children:`No re-download. ~5 min. If the release genuinely has no links for your domain, this won’t help — sync a different release instead.`})]})]})]})]})]})})}function L(e){if(!n)return null;let t=`release`;return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(gf,{summary:n,trend:u}),(0,$.jsxs)(`p`,{className:`text-copy-13 text-muted mt-2`,children:[(0,$.jsx)(`span`,{className:`text-secondary`,children:`Common Crawl`}),` · `,t,` `,(0,$.jsx)(`code`,{className:`text-secondary`,children:n.release}),` · queried `,ff(n.queriedAt),N>0&&(0,$.jsxs)($.Fragment,{children:[` · `,N,` excluded domain`,N===1?``:`s`]})]}),(0,$.jsxs)(`div`,{className:`mt-4`,children:[(0,$.jsx)(`p`,{className:`eyebrow eyebrow-soft mb-2`,children:`Top referring domains`}),(0,$.jsx)(Z,{className:`surface-card overflow-hidden`,children:(0,$.jsxs)(`table`,{className:`w-full text-label-14`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{className:`border-b border-base text-left text-label-12 normal-case text-faint`,children:[(0,$.jsx)(`th`,{className:`px-4 py-2 text-label-12-strong`,children:`Domain`}),(0,$.jsx)(`th`,{className:`px-4 py-2 text-right text-label-12-strong`,children:`Linking hosts`})]})}),(0,$.jsxs)(`tbody`,{children:[j.map(e=>(0,$.jsxs)(`tr`,{className:`border-b border-mono-900 last:border-0`,children:[(0,$.jsx)(`td`,{className:`px-4 py-2 text-strong`,children:e.linkingDomain}),(0,$.jsx)(`td`,{className:`px-4 py-2 text-right text-secondary tabular-nums`,children:df(e.numHosts)})]},e.linkingDomain)),j.length===0&&(0,$.jsx)(`tr`,{children:(0,$.jsx)(`td`,{className:`px-4 py-4 text-label-14 text-muted`,colSpan:2,children:N>0&&M===0?`Every referring domain in this ${t} was a crawler/proxy host (${N} hidden).`:`No referring domains in this ${t}.`})})]})]})}),(0,$.jsx)(Ts,{page:P,pageSize:lf,visibleRows:j.length,totalRows:M,onPageChange:e=>S((e-1)*lf)})]}),(0,$.jsx)(`div`,{className:`mt-4 flex items-center gap-3 flex-wrap`,children:e})]})}}function gf({summary:e,trend:t}){let[n,r]=(0,Q.useState)(`referring-domains`),i=t?.groups.find(e=>e.key===`backlinks`),a=new Map(i?.figures.map(e=>[e.key,e])),o=(e,t,n,r,i)=>{let o=a.get(e);return{key:e,label:t,help:n,value:i(r),change:o?bs(o.change,o.unit):void 0,series:o?ks(o):void 0,formatValue:i,allowDecimals:o?.unit===`fraction`}},s=[o(`referring-domains`,`Referring domains`,`Unique domains linking to ${e.targetDomain}.`,e.totalLinkingDomains,df),o(`hosts`,`Total linking hosts`,`Aggregate linking hosts across referring domains.`,e.totalHosts,df),o(`top-10-concentration`,`Top-10 concentration`,`Share of linking hosts from the 10 largest linking domains.`,Number(e.top10HostsShare),e=>G(e))],c=s.some(ws),l=a.get(`referring-domains`)?.series??[],u=l[0],d=l.at(-1);return(0,$.jsx)(Os,{name:`Backlinks figures`,groups:[{key:`backlinks`,label:`Every release`,basis:i?Es(i.figures):void 0,figures:s}],selected:c?[n]:[],onSelect:r,cadence:`release`,span:c&&u&&d?xs(u,d):void 0,emptyChartMessage:t?`One release so far. The trend starts with the next one.`:`Release history could not be loaded.`})}var _f={[U[`keyword-metrics`]]:`Search demand`,[U[`domain-intelligence`]]:`Domain comparison`,[U[`ranked-keywords`]]:`Searches you rank for`,[U[`market-rankings`]]:`Market rankings`,[U[`competitor-discovery`]]:`Organic competitors`,[U[`keyword-gaps`]]:`Search gaps`},vf={[tt.shared]:`Shared`,[tt.missing]:`Missing`,[tt.outranked]:`Competitor ahead`},yf=`Your organic position minus the competitor’s position. Positive means the competitor ranks higher; negative means you rank higher. No gap is calculated when either position is unavailable.`,bf={[cn.queued]:`Queued`,[cn.running]:`Refreshing`,[cn.completed]:`Completed`,[cn.partial]:`Partial results`,[cn.failed]:`Failed`,[cn.cancelled]:`Cancelled`,[cn[`reconciliation-required`]]:`Needs review`},xf=25,Sf=new Intl.NumberFormat(`en-US`,{maximumFractionDigits:1}),Cf=new Intl.NumberFormat(`en-US`,{style:`currency`,currency:`USD`,maximumFractionDigits:2}),wf=Intl.DateTimeFormat().resolvedOptions().timeZone,Tf=`min-h-11 w-full rounded-md border border-default bg-bg px-3 py-2 text-label-14 text-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-mono-400`,Ef=`px-4 py-3 text-right align-top tabular-nums whitespace-nowrap`,Df=`min-w-56 px-4 py-3 text-left align-top text-label-14`,Of=`Position on the page, counting maps and other blocks`;function kf(e){return e?.status===cn.queued||e?.status===cn.running}function Af({value:e,currency:t=!1}){return e===null?(0,$.jsx)(`span`,{className:`text-muted`,"aria-label":`Not supplied`,children:`—`}):(0,$.jsx)($.Fragment,{children:t?Cf.format(e):Sf.format(e)})}function jf({status:e}){let t=e===cn.completed?`positive`:e===cn.failed?`negative`:e===cn.partial||e===cn[`reconciliation-required`]?`caution`:`neutral`;return(0,$.jsx)(J,{tone:t,children:bf[e]})}function Mf(e){let t=pn(e).split(`/`).at(-1)??e,n=Zt.safeParse(t.replaceAll(`_`,`-`));return n.success?_f[n.data]:t.replaceAll(/[-_]/g,` `)}function Nf(e){return e===`mobile`?`phone results`:e===`desktop`?`computer results`:`device not specified by source`}function Pf(e){return e.capabilities.includes(U[`market-rankings`])?`Market locations`:`Location ${e.locationCode}`}function Ff(e){return e.capabilities.includes(U[`market-rankings`])?`searches`:`tasks`}function If(e){return e.capability!==U[`market-rankings`]||![cn.queued,cn.running,cn.completed].includes(e.status)}function Lf(e,t){let n=e.capabilities.includes(U[`market-rankings`]);return`${t} ${t===1?n?`search`:`task`:Ff(e)}`}function Rf(e,t){return Number.isFinite(Date.parse(e))?Ct(Ot(e,t)):null}var zf={[cn.failed]:`Latest refresh failed`,[cn.cancelled]:`Latest refresh cancelled`,[cn[`reconciliation-required`]]:`Latest refresh needs review`};function Bf(e,t){let n=e&&e.id!==t?.id?zf[e.status]:void 0;if(e&&n)return{label:n,text:`${n}. ${e.error??`Open Activity for refresh details.`}${t?` Showing the refresh before it.`:``}`};if(!t)return null;if(t.failedTasks>0){let e=`${Lf(t,t.failedTasks)} failed`,n=t.capabilities.includes(U[`market-rankings`])?`Their queries show as Failed.`:`Open Activity for details.`;return{label:e,text:`${e}: ${t.failedTasks} of ${Lf(t,t.taskCount)} in this refresh returned no results. ${n}`}}return t.status===cn.partial?{label:`Partial results`,text:`Partial results: ${t.error??`some ${Ff(t)} returned only part of their results or did not run. Open Activity for details.`}`}:null}function Vf({source:e}){return(0,$.jsxs)(`dl`,{className:`grid gap-x-8 gap-y-2 text-label-13 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`dt`,{className:`text-muted`,children:`Dataset`}),(0,$.jsx)(`dd`,{children:Mf(e.dataset)})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`dt`,{className:`text-muted`,children:`Search engine`}),(0,$.jsxs)(`dd`,{children:[`Google · `,Nf(e.device)]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`dt`,{className:`text-muted`,children:`Provider geography`}),(0,$.jsxs)(`dd`,{children:[`Location `,e.locationCode,` · `,e.languageCode]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`dt`,{className:`text-muted`,children:`Collected`}),(0,$.jsx)(`dd`,{children:ut(e.collectedAt,wf)})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`dt`,{className:`text-muted`,children:`Source updated`}),(0,$.jsx)(`dd`,{children:e.sourceUpdatedAt?en(e.sourceUpdatedAt):`Not supplied`})]})]})}function Hf({label:e,source:t,children:n}){return(0,$.jsxs)(`details`,{className:`text-left`,children:[(0,$.jsxs)(`summary`,{className:`flex min-h-11 cursor-pointer items-center text-label-13 text-secondary hover:text-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-mono-400`,children:[`Details`,(0,$.jsxs)(`span`,{className:`sr-only`,children:[` for `,e]})]}),(0,$.jsxs)(`div`,{className:`min-w-56 space-y-4 pb-3 text-label-13 text-secondary`,children:[n,t&&(0,$.jsx)(Vf,{source:t})]})]})}function Uf({error:e,retry:t}){return(0,$.jsxs)(`div`,{role:`alert`,className:`flex flex-wrap items-center justify-between gap-3 rounded-md border border-default p-4 text-label-14`,children:[(0,$.jsx)(`p`,{children:Co(e)}),(0,$.jsx)(q,{variant:`secondary`,className:`pointer-coarse:min-h-11`,onClick:t,children:`Retry`})]})}function Wf({title:e,children:t}){return(0,$.jsxs)(`div`,{className:`py-12 text-center`,children:[(0,$.jsx)(`h3`,{className:`text-heading-14 text-heading`,children:e}),(0,$.jsx)(`p`,{className:`mx-auto mt-2 max-w-lg text-copy-14 text-secondary`,children:t})]})}function Gf({projectName:e}){let t=E({strict:!1}),n=T(),i=w(ji({client:K,path:{name:e}})),a=w(qr({client:K,path:{name:e}})),o=w({...cr({client:K,path:{name:e,id:t.seoRunId??``}}),enabled:!!t.seoRunId}),[s,c]=(0,Q.useState)(null),l=(0,Q.useRef)(null),u=(0,Q.useRef)(null),d=t.seoProfileId??o.data?.profileId,f=d?a.data?.profiles.find(e=>e.id===d):t.seoRunId?void 0:a.data?.profiles[0],p=t=>{c(null),n({to:`/projects/$projectName/seo-data`,params:{projectName:e},search:e=>({...e,seoProfileId:t,seoRunId:void 0,seoRegion:void 0,seoMarket:void 0,seoShow:void 0,seoSort:void 0,seoQ:void 0})})},m=i.data?.access.canWrite===!0&&!Y()&&!We(),h=()=>{c(null),l.current?.focus()};if((0,Q.useEffect)(()=>{!t.seoProfileId&&f&&n({to:`/projects/$projectName/seo-data`,params:{projectName:e},search:e=>({...e,seoProfileId:f.id}),replace:!0})},[n,e,t.seoProfileId,f]),i.error)return(0,$.jsx)(Uf,{error:i.error,retry:()=>{i.refetch()}});if(a.error)return(0,$.jsx)(Uf,{error:a.error,retry:()=>{a.refetch()}});if(!i.data||!a.data)return(0,$.jsx)(`p`,{role:`status`,className:`py-10 text-copy-14 text-secondary`,children:`Loading SEO data…`});let g=i.data.available&&i.data.connections.some(e=>e.capabilities.length>0),_=g&&i.data.connections.some(e=>e.capabilities.some(e=>i.data.scopes.some(t=>t.capabilities?.includes(e)??!0))),v=f&&i.data.scopes.find(e=>e.kind===f.scope.kind&&e.key===(f.scope.key??null));return(0,$.jsxs)(`section`,{"aria-label":`SEO`,className:`min-w-0 space-y-5`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-end justify-between gap-3`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h2`,{className:`text-heading-20 text-heading`,children:`SEO`}),(0,$.jsx)(`p`,{className:`mt-1 text-copy-14 text-secondary`,children:`Search demand and organic rankings.`})]}),m&&_&&(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[f&&(0,$.jsx)(q,{variant:`ghost`,className:`pointer-coarse:min-h-11`,onClick:e=>{l.current=e.currentTarget,c({profile:f,id:f.id})},children:`Edit profile`}),(0,$.jsxs)(q,{variant:`secondary`,className:`pointer-coarse:min-h-11`,onClick:e=>{l.current=e.currentTarget,c({id:crypto.randomUUID()})},children:[(0,$.jsx)(r,{"aria-hidden":`true`,className:`size-4`}),`New profile`]})]})]}),a.data.profiles.length>0&&(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-5 gap-y-3 border-y border-subtle py-3`,children:[(0,$.jsxs)(`label`,{className:`flex min-w-0 flex-1 items-center gap-3 sm:flex-none`,children:[(0,$.jsx)(`span`,{className:`text-label-13 text-secondary`,children:`Profile`}),(0,$.jsxs)(`select`,{ref:u,"aria-label":`SEO profile`,value:f?.id??``,onChange:e=>p(e.target.value),className:`${Tf} min-w-0 sm:w-64`,children:[!f&&(0,$.jsx)(`option`,{value:``,disabled:!0,children:`Profile unavailable`}),a.data.profiles.map(e=>(0,$.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),f&&(0,$.jsxs)(`div`,{className:`min-w-0 text-label-13 text-secondary`,children:[(0,$.jsx)(`p`,{className:`break-words text-copy-13-strong text-primary`,children:v?.label??`${f.scope.kind}${f.scope.key?`: ${f.scope.key}`:``}`}),(0,$.jsxs)(`p`,{children:[f.rankings?`${f.rankings.locations.length} search location${f.rankings.locations.length===1?``:`s`}`:`Location ${f.locationCode}`,` · `,f.languageCode]})]})]}),s&&(0,$.jsx)(Op,{projectName:e,context:i.data,profile:s.profile,id:s.id,onClose:h,onSaved:e=>{p(e),requestAnimationFrame(()=>u.current?.focus())}},s.id),!We()&&!i.data.available&&a.data.profiles.length>0&&(0,$.jsx)(`p`,{role:`status`,className:`rounded-md border border-default px-4 py-3 text-copy-14 text-secondary`,children:i.data.reason??`Configure an SEO data provider to refresh saved profiles.`}),t.seoRunId&&o.error?(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsx)(Uf,{error:o.error,retry:()=>{o.refetch()}}),f?(0,$.jsx)(q,{variant:`secondary`,className:`pointer-coarse:min-h-11`,onClick:()=>p(f.id),children:`View latest data`}):(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:`Select a profile to view its latest data.`})]}):t.seoRunId&&o.isPending?(0,$.jsx)(`p`,{role:`status`,className:`py-10 text-copy-14 text-secondary`,children:`Loading refresh…`}):f&&o.data&&o.data.profileId!==f.id?(0,$.jsxs)(Wf,{title:`Refresh belongs to another profile`,children:[`Choose the refresh’s profile, or return to the selected profile’s latest data.`,(0,$.jsx)(q,{variant:`secondary`,className:`mt-4 pointer-coarse:min-h-11`,onClick:()=>p(f.id),children:`View latest data`})]}):f?(0,$.jsx)(Kf,{projectName:e,profile:f,context:i.data,selectedRunId:t.seoRunId,onLatest:()=>p(f.id)},`${f.id}:${f.revision}:${t.seoRunId??``}`):!_&&a.data.profiles.length===0?(0,$.jsx)(Wf,{title:g?`SEO scope unavailable`:`Configure an SEO data provider`,children:g?i.data.scopes.find(e=>e.reason)?.reason??`No datasets are available for this project’s measurement scopes.`:`Connect a provider before creating an SEO profile.`}):d?(0,$.jsx)(Wf,{title:`Profile unavailable`,children:`This saved profile is no longer available. Select another profile to view its data.`}):!s&&(0,$.jsx)(Wf,{title:`No SEO data yet`,children:m?`Create a profile to choose the scope, source, and searches to measure.`:`An SEO profile is needed before data can be collected.`})]})}function Kf({projectName:e,profile:t,context:n,selectedRunId:r,onLatest:a}){let o=S(),[s,c]=(0,Q.useState)(r?`activity`:t.capabilities.includes(U[`ranked-keywords`])?U[`ranked-keywords`]:t.capabilities.at(0)??`activity`),[l,u]=(0,Q.useState)(null),d=(0,Q.useRef)(null),f=(0,Q.useRef)(null),m={name:e},h=w({...jr({client:K,path:m,query:{profileId:t.id,runId:r}}),refetchInterval:e=>kf(e.state.data?.latestRun)?2e3:!1}),g=C({...Ai({client:K}),meta:{skipGlobalErrorToast:!0}}),_=C({...Ir({client:K}),meta:{skipGlobalErrorToast:!0}}),v=h.data?.latestRun,y=h.data?.evidenceRun,b=h.data?.evidenceRun?.capabilities??t.capabilities,x=s===`activity`||b.includes(s)?s:b.at(0)??`activity`,T=kf(v),E=g.isPending||_.isPending,D=n.access.canRun&&!Y()&&!We(),O=n.connections.find(e=>e.id===t.connectionId),k=n.scopes.find(e=>e.kind===t.scope.kind&&e.key===(t.scope.key??null)),A=w({...mr({client:K,path:m,query:{kind:At[`seo-sync`]}}),retry:!1}),j=!A.isError&&A.data?.enabled&&A.data.nextRunAt?A.data.nextRunAt:null,M=j?Rf(j,A.data?.timezone??`UTC`):null,N=y?.finishedAt&&(y.status===cn.completed||y.status===cn.partial)?Rf(y.finishedAt,wf):null,P=T?null:Bf(v,y);return(0,Q.useEffect)(()=>{v&&(kf(v)?f.current=v.id:f.current===v.id&&(f.current=null,Zn(o,`seo`,{projectName:e,profileId:t.id})))},[v,t.id,e,o]),(0,$.jsxs)(`div`,{className:`space-y-5`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-x-3 gap-y-1 text-label-14 text-secondary`,children:[(0,$.jsx)(`div`,{"aria-live":`polite`,children:T&&v?(0,$.jsxs)(`p`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(i,{className:`size-4 animate-spin`,"aria-hidden":`true`}),v.cancelRequested?`Cancellation requested`:bf[v.status],` · `,v.completedTasks,` of `,v.taskCount,` `,Ff(v),` completed`]}):(0,$.jsxs)(`p`,{children:[N&&y?.finishedAt?(0,$.jsxs)($.Fragment,{children:[`Updated `,(0,$.jsx)(`time`,{dateTime:y.finishedAt,title:ut(y.finishedAt,wf)??void 0,children:N})]}):`No completed refresh`,M&&j&&(0,$.jsxs)($.Fragment,{children:[` · Next refresh `,(0,$.jsx)(`time`,{dateTime:j,children:M})]})]})}),P&&(0,$.jsx)(X,{tone:`caution`,placement:`bottom`,label:P.label,text:P.text})]}),r?(0,$.jsx)(q,{variant:`secondary`,className:`pointer-coarse:min-h-11`,onClick:a,children:`View latest data`}):D&&(0,$.jsxs)(q,{className:`pointer-coarse:min-h-11`,disabled:E||T||!n.available||!O,onClick:Jn(async()=>{if(!(!D||r||T||E)){u(null);try{if(!d.current){let e=await g.mutateAsync({path:m,body:{profileId:t.id}});if(e.availability!==nn.ready){u(e.reason??`This profile cannot be refreshed. Review its scope and source.`);return}d.current={quoteToken:e.token,idempotencyKey:crypto.randomUUID()}}let e=await _.mutateAsync({path:m,body:d.current});d.current=null,kf(e)&&(f.current=e.id),await o.fetchQuery(jr({client:K,path:m,query:{profileId:t.id}}))}catch(e){Fo(e).code===`VALIDATION_ERROR`&&(d.current=null),u(Co(e))}}}),children:[(0,$.jsx)(p,{"aria-hidden":`true`,className:`size-4 ${E?`animate-spin`:``}`}),E?`Starting refresh…`:T?`Refresh in progress`:d.current?`Retry refresh`:`Refresh data`]})]}),l&&(0,$.jsxs)(`p`,{role:`alert`,className:`rounded-md border border-default p-4 text-copy-14 text-secondary`,children:[l,d.current&&` Retry uses the same request, so it will not start a duplicate refresh.`]}),r&&(0,$.jsxs)(`p`,{className:`break-all text-copy-13 text-secondary`,children:[`Viewing saved refresh `,r,`.`]}),h.data?.evidenceRun&&h.data.evidenceRun.profileRevision!==t.revision&&(0,$.jsxs)(`p`,{role:`status`,className:`text-copy-14 text-secondary`,children:[`Saved data uses profile revision `,h.data.evidenceRun.profileRevision,` · `,Pf(h.data.evidenceRun),` · `,h.data.evidenceRun.languageCode,`. The current profile has changed.`]}),!We()&&k&&!k.supported&&(0,$.jsx)(`p`,{role:`status`,className:`text-copy-14 text-secondary`,children:k.reason??`This scope is not supported for domain data.`}),h.error?(0,$.jsx)(Uf,{error:h.error,retry:()=>{h.refetch()}}):h.data?.summary&&(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`p`,{className:`mb-3 break-words text-copy-13 text-secondary`,children:[h.data.summary.target.value,h.data.summary.target.includeSubdomains?` · includes subdomains`:` · exact host`]}),(0,$.jsxs)(`dl`,{className:`grid grid-cols-1 gap-5 border-b border-subtle pb-5 sm:grid-cols-3`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`dt`,{className:`text-label-13 text-secondary`,children:`Searches you rank for`}),(0,$.jsx)(`dd`,{className:`mt-2 text-heading-32 tabular-nums text-heading`,children:(0,$.jsx)(Af,{value:h.data.summary.organicKeywords})})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`dt`,{className:`text-label-13 text-secondary`,children:`In the top 10`}),(0,$.jsx)(`dd`,{className:`mt-2 text-heading-32 tabular-nums text-heading`,children:(0,$.jsx)(Af,{value:h.data.summary.inTop10})})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`dt`,{className:`flex items-center gap-1.5 text-label-13 text-secondary`,children:[`Estimated organic traffic`,(0,$.jsx)(X,{text:`Modeled search traffic for this target and provider geography. This is not measured site traffic.`})]}),(0,$.jsx)(`dd`,{className:`mt-2 text-heading-32 tabular-nums text-heading`,children:(0,$.jsx)(Af,{value:h.data.summary.estimatedOrganicTraffic})})]})]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`flex flex-wrap gap-x-5 border-b border-subtle`,"aria-label":`SEO views`,children:[...b,`activity`].map(e=>(0,$.jsx)(`button`,{type:`button`,"aria-pressed":x===e,className:`min-h-11 border-b-2 text-button-14 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-mono-400 ${x===e?`border-strong text-primary`:`border-transparent text-secondary hover:text-primary`}`,onClick:()=>c(e),children:e===`activity`?`Activity`:_f[e]},e))}),x===`activity`?(0,$.jsx)(Dp,{projectName:e,profileId:t.id,canRun:D,selectedRunId:r}):h.isPending?(0,$.jsx)(`p`,{role:`status`,className:`py-8 text-copy-14 text-secondary`,children:`Loading saved data…`}):h.data&&(0,$.jsx)(qf,{projectName:e,profileId:t.id,runId:h.data.evidenceRunId,view:x,active:T,nextRefresh:M},`${t.id}:${x}:${h.data.evidenceRunId??`empty`}`)]}),(0,$.jsxs)(`details`,{className:`border-t border-subtle text-label-14 text-secondary`,children:[(0,$.jsx)(`summary`,{className:`flex min-h-11 cursor-pointer items-center text-label-14-strong focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-mono-400`,children:`Data details`}),(0,$.jsxs)(`div`,{className:`space-y-4 pb-3 text-label-13`,children:[(0,$.jsxs)(`p`,{children:[`Current profile source: `,We()?`Fictional demo data`:O?.label??`Source unavailable`,`. Google; `,Nf(t.rankings?.device??`unspecified`),`.`]}),h.data?.evidenceRun&&(0,$.jsxs)(`p`,{children:[`Saved evidence: `,h.data.evidenceRun.scope.kind,h.data.evidenceRun.scope.key?` · ${h.data.evidenceRun.scope.key}`:``,h.data.evidenceRun.scope.expectedPlanRevision===void 0?``:` · plan revision ${h.data.evidenceRun.scope.expectedPlanRevision}`,`. `,Pf(h.data.evidenceRun),` · `,h.data.evidenceRun.languageCode,` · profile revision `,h.data.evidenceRun.profileRevision,`.`]}),(0,$.jsx)(`p`,{children:`These are provider estimates and observed search rankings. Missing values are shown as a dash. Difficulty is a source score out of 100.`}),(0,$.jsx)(`p`,{children:`Current profile targets:`}),(0,$.jsx)(`ul`,{className:`space-y-1`,children:t.targets.map((e,t)=>(0,$.jsxs)(`li`,{className:`break-words`,children:[e.value,` · `,e.includeSubdomains?`includes subdomains`:`exact host`]},t))}),t.scope.expectedPlanRevision!==void 0&&(0,$.jsxs)(`p`,{children:[`Saved measurement plan revision `,t.scope.expectedPlanRevision,`.`]}),h.data?.summary&&(0,$.jsx)(Vf,{source:h.data.summary.provenance})]})]})]})}function qf({projectName:e,profileId:t,runId:n,view:r,active:i,nextRefresh:a}){return r===U[`market-rankings`]?n?(0,$.jsx)(_p,{projectName:e,profileId:t,runId:n,active:i}):(0,$.jsx)(Wf,{title:`No market rankings yet`,children:a?`First refresh ${a}`:`Refresh this profile to rank its tracked queries in each market.`}):(0,$.jsx)(Jf,{projectName:e,profileId:t,runId:n,view:r,active:i})}function Jf({projectName:e,profileId:t,runId:n,view:r,active:i}){let[a,o]=(0,Q.useState)(1),[s,c]=(0,Q.useState)(``),[l,u]=(0,Q.useState)(),[d,f]=(0,Q.useState)(),p={client:K,path:{name:e},query:{profileId:t,runId:n??void 0,limit:xf,offset:(a-1)*xf}},m=w({...ca(p),enabled:!!n&&r===U[`ranked-keywords`]}),h=w({...Ur(p),enabled:!!n&&r===U[`keyword-metrics`]}),g=w({...Pr(p),enabled:!!n&&r===U[`domain-intelligence`]}),_=w({...or({...p,query:{...p.query,sort:l}}),placeholderData:j,enabled:!!n&&r===U[`competitor-discovery`]}),v=w({...Lr({...p,query:{...p.query,kind:s||void 0,sort:d}}),placeholderData:j,enabled:!!n&&r===U[`keyword-gaps`]}),y=r===U[`ranked-keywords`]?m:r===U[`keyword-metrics`]?h:r===U[`competitor-discovery`]?_:r===U[`keyword-gaps`]?v:g;return n?(0,$.jsxs)(`div`,{className:`space-y-3 pt-4`,children:[r===U[`keyword-gaps`]&&(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsxs)(`label`,{className:`flex items-center gap-3 text-label-14`,children:[(0,$.jsx)(`span`,{children:`Show`}),(0,$.jsxs)(`select`,{"aria-label":`Show search gaps`,className:`${Tf} w-auto`,value:s,onChange:e=>{c(e.target.value),o(1)},children:[(0,$.jsx)(`option`,{value:``,children:`All comparisons`}),(0,$.jsx)(`option`,{value:tt.missing,children:`Missing`}),(0,$.jsx)(`option`,{value:tt.shared,children:`Shared`}),(0,$.jsx)(`option`,{value:tt.outranked,children:`Competitor ahead`})]})]}),(0,$.jsx)(X,{text:`Missing: the source lists the search for the competitor but not your domain. Shared includes searches where the competitor ranks higher. These are bounded observations from the source’s organic search database, not a live check of every Google result.`})]}),r===U[`competitor-discovery`]&&(0,$.jsxs)(`p`,{className:`flex items-center gap-1.5 text-label-13 text-secondary`,children:[`Domains sharing organic searches`,(0,$.jsx)(X,{text:`Discovery uses this profile’s whole domains, location and language. Suggested domains are not automatically added to tracked competitors. Counts describe the source’s database; the table is limited to this refresh’s saved results.`})]}),y.error?(0,$.jsx)(Uf,{error:y.error,retry:()=>{y.refetch()}}):y.data?y.data.items.length===0?(0,$.jsx)(Wf,{title:i?`Refresh in progress`:s?`No matching comparisons`:`No results returned`,children:i?`This profile is collecting data.`:s?`Choose another comparison filter to see the remaining saved results.`:`The source did not return records for this scope. Review the refresh in Activity before changing the profile.`}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`relative overflow-x-auto material-base`,role:`region`,"aria-label":`${_f[r]} table`,"aria-busy":y.isFetching,tabIndex:0,children:[r===U[`ranked-keywords`]&&m.data&&(0,$.jsx)($f,{rows:m.data.items}),r===U[`keyword-metrics`]&&h.data&&(0,$.jsx)(ep,{rows:h.data.items}),r===U[`domain-intelligence`]&&g.data&&(0,$.jsx)(tp,{rows:g.data.items}),r===U[`competitor-discovery`]&&_.data&&(0,$.jsx)(Zf,{rows:_.data.items,sort:l,onSort:e=>{u(e),o(1)}}),r===U[`keyword-gaps`]&&v.data&&(0,$.jsx)(Qf,{rows:v.data.items,sort:d,onSort:e=>{f(e),o(1)}})]}),(0,$.jsx)(Ts,{page:a,pageSize:xf,visibleRows:y.data.items.length,totalRows:y.data.total,onPageChange:o,disabled:y.isFetching,className:`text-label-13 [&_button]:min-h-11`})]}):(0,$.jsxs)(`p`,{role:`status`,className:`py-8 text-label-14 text-secondary`,children:[`Loading `,_f[r].toLowerCase(),`…`]})]}):(0,$.jsxs)(Wf,{title:`No saved data yet`,children:[`Refresh this profile to collect `,_f[r].toLowerCase(),` for its saved scope.`]})}function Yf({value:e}){return e===null?(0,$.jsx)(Af,{value:null}):(0,$.jsxs)($.Fragment,{children:[e>0?`+`:``,Sf.format(e)]})}function Xf({label:e,sort:t,ascending:n,descending:r,align:i=`right`,onSort:a,help:o}){return(0,$.jsx)(gp,{label:e,align:i,sorted:t===n?`ascending`:t===r?`descending`:null,onSort:()=>a(t===n?r:n),help:o,showUnsorted:!0})}function Zf({rows:e,sort:t,onSort:n}){return(0,$.jsxs)(`table`,{className:`w-full text-label-14`,children:[(0,$.jsx)(`caption`,{className:`sr-only`,children:`Organic competitors, from the selected refresh`}),(0,$.jsx)(`thead`,{className:`bg-surface text-label-13 text-secondary`,children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(Xf,{label:`Competitor`,align:`left`,sort:t,ascending:nt.domain,descending:nt[`-domain`],onSort:n}),(0,$.jsx)(Xf,{label:`Shared searches`,sort:t,ascending:nt.shared,descending:nt[`-shared`],onSort:n}),(0,$.jsx)(Xf,{label:`Avg. position`,sort:t,ascending:nt.position,descending:nt[`-position`],onSort:n}),(0,$.jsx)(Xf,{label:`Est. organic traffic`,sort:t,ascending:nt.traffic,descending:nt[`-traffic`],onSort:n}),(0,$.jsx)(`th`,{className:`px-4`,children:(0,$.jsx)(`span`,{className:`sr-only`,children:`Evidence`})})]})}),(0,$.jsx)(`tbody`,{className:`divide-y divide-subtle`,children:e.map((e,t)=>(0,$.jsxs)(`tr`,{children:[(0,$.jsxs)(`th`,{scope:`row`,className:Df,children:[(0,$.jsx)(`p`,{className:`text-primary`,children:e.domain}),(0,$.jsxs)(`p`,{className:`mt-1 text-label-13 text-secondary`,children:[`Compared with `,e.target.value]})]}),(0,$.jsx)(`td`,{className:Ef,children:(0,$.jsx)(Af,{value:e.sharedKeywords})}),(0,$.jsx)(`td`,{className:Ef,children:(0,$.jsx)(Af,{value:e.averagePosition})}),(0,$.jsx)(`td`,{className:Ef,children:(0,$.jsx)(Af,{value:e.estimatedOrganicTraffic})}),(0,$.jsx)(`td`,{className:`px-4 align-top`,children:(0,$.jsxs)(Hf,{label:e.domain,source:e.provenance,children:[(0,$.jsx)(`p`,{children:`Average position covers shared searches. Traffic covers the competitor’s whole domain.`}),(0,$.jsxs)(`p`,{children:[`Competitor’s ranked searches: `,(0,$.jsx)(Af,{value:e.organicKeywords})]}),(0,$.jsxs)(`p`,{children:[`Target: `,e.target.value,` · includes subdomains`]})]})})]},`${e.target.value}:${e.domain}:${t}`))})]})}function Qf({rows:e,sort:t,onSort:n}){return(0,$.jsxs)(`table`,{className:`w-full text-label-14`,children:[(0,$.jsx)(`caption`,{className:`sr-only`,children:`Search gaps, from the selected refresh`}),(0,$.jsx)(`thead`,{className:`bg-surface text-label-13 text-secondary`,children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(Xf,{label:`Search`,align:`left`,sort:t,ascending:it.keyword,descending:it[`-keyword`],onSort:n}),(0,$.jsx)(Xf,{label:`Comparison`,align:`left`,sort:t,ascending:it.kind,descending:it[`-kind`],onSort:n}),(0,$.jsx)(Xf,{label:`Your rank`,sort:t,ascending:it[`target-rank`],descending:it[`-target-rank`],onSort:n}),(0,$.jsx)(Xf,{label:`Competitor rank`,sort:t,ascending:it[`competitor-rank`],descending:it[`-competitor-rank`],onSort:n}),(0,$.jsx)(Xf,{label:`Rank gap`,sort:t,ascending:it[`rank-gap`],descending:it[`-rank-gap`],onSort:n,help:yf}),(0,$.jsx)(Xf,{label:`Monthly searches`,sort:t,ascending:it.volume,descending:it[`-volume`],onSort:n}),(0,$.jsx)(`th`,{className:`px-4`,children:(0,$.jsx)(`span`,{className:`sr-only`,children:`Evidence`})})]})}),(0,$.jsx)(`tbody`,{className:`divide-y divide-subtle`,children:e.map((e,t)=>(0,$.jsxs)(`tr`,{children:[(0,$.jsxs)(`th`,{scope:`row`,className:Df,children:[(0,$.jsx)(`p`,{className:`text-primary`,children:e.keyword}),(0,$.jsxs)(`p`,{className:`mt-1 text-label-13 text-secondary`,children:[e.target.value,` · `,e.competitor.value]})]}),(0,$.jsx)(`td`,{className:`px-4 py-3 align-top`,children:(0,$.jsx)(J,{tone:e.kind===tt.shared?`neutral`:`caution`,children:vf[e.kind]})}),(0,$.jsx)(`td`,{className:Ef,children:e.kind===tt.missing?(0,$.jsx)(`span`,{className:`text-secondary`,children:`Not found`}):(0,$.jsx)(Af,{value:e.targetRankOrganic})}),(0,$.jsx)(`td`,{className:Ef,children:(0,$.jsx)(Af,{value:e.competitorRankOrganic})}),(0,$.jsx)(`td`,{className:Ef,children:(0,$.jsx)(Yf,{value:e.rankGap})}),(0,$.jsx)(`td`,{className:Ef,children:(0,$.jsx)(Af,{value:e.searchVolume})}),(0,$.jsx)(`td`,{className:`px-4 align-top`,children:(0,$.jsxs)(Hf,{label:`${e.keyword} against ${e.competitor.value}`,source:e.provenance,children:[(0,$.jsxs)(`p`,{children:[`Your ranking page: `,e.targetUrl?(0,$.jsx)(os,{url:e.targetUrl}):`Not supplied`]}),(0,$.jsxs)(`p`,{children:[`Competitor’s ranking page: `,e.competitorUrl?(0,$.jsx)(os,{url:e.competitorUrl}):`Not supplied`]}),(0,$.jsxs)(`p`,{children:[`Difficulty /100: `,(0,$.jsx)(Af,{value:e.keywordDifficulty})]}),(0,$.jsxs)(`p`,{children:[`CPC: `,(0,$.jsx)(Af,{value:e.cpcUsd,currency:!0})]})]})})]},`${e.target.value}:${e.competitor.value}:${e.keyword}:${t}`))})]})}function $f({rows:e}){return(0,$.jsxs)(`table`,{className:`w-full text-label-14`,children:[(0,$.jsx)(`caption`,{className:`sr-only`,children:`Searches you rank for, from the selected refresh`}),(0,$.jsx)(`thead`,{className:`bg-surface text-label-13 text-secondary`,children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{className:`px-4 py-3 text-left text-label-13-strong`,children:`Search`}),(0,$.jsx)(`th`,{className:`${Ef} text-label-13-strong`,children:`Position`}),(0,$.jsx)(`th`,{className:`${Ef} text-label-13-strong`,children:`Monthly searches`}),(0,$.jsx)(`th`,{className:`${Ef} text-label-13-strong`,children:`Est. traffic`}),(0,$.jsx)(`th`,{className:`${Ef} text-label-13-strong`,children:`Difficulty /100`}),(0,$.jsx)(`th`,{className:`px-4`,children:(0,$.jsx)(`span`,{className:`sr-only`,children:`Evidence`})})]})}),(0,$.jsx)(`tbody`,{className:`divide-y divide-subtle`,children:e.map((e,t)=>(0,$.jsxs)(`tr`,{children:[(0,$.jsxs)(`th`,{scope:`row`,className:Df,children:[(0,$.jsx)(`p`,{className:`text-primary`,children:e.keyword}),(0,$.jsx)(`p`,{className:`mt-1 text-copy-13 text-secondary`,children:(0,$.jsx)(Ss,{value:e.url??e.target.value})})]}),(0,$.jsx)(`td`,{className:Ef,children:(0,$.jsx)(Af,{value:e.rankOrganic})}),(0,$.jsx)(`td`,{className:Ef,children:(0,$.jsx)(Af,{value:e.searchVolume})}),(0,$.jsx)(`td`,{className:Ef,children:(0,$.jsx)(Af,{value:e.estimatedTraffic})}),(0,$.jsx)(`td`,{className:Ef,children:(0,$.jsx)(Af,{value:e.keywordDifficulty})}),(0,$.jsx)(`td`,{className:`px-4 align-top`,children:(0,$.jsxs)(Hf,{label:e.keyword,source:e.provenance,children:[(0,$.jsx)(`p`,{className:`break-all`,children:e.url??`Ranking URL not supplied`}),(0,$.jsxs)(`p`,{children:[`Target: `,e.target.value,` · `,e.target.includeSubdomains?`includes subdomains`:`exact host`]}),(0,$.jsxs)(`p`,{children:[Of,`: `,(0,$.jsx)(Af,{value:e.rankAbsolute})]}),(0,$.jsxs)(`p`,{children:[`CPC: `,(0,$.jsx)(Af,{value:e.cpcUsd,currency:!0})]}),(0,$.jsxs)(`p`,{children:[`Results page features: `,e.serpFeatures.length?e.serpFeatures.map(e=>e.replaceAll(`_`,` `)).join(`, `):`Not supplied`]})]})})]},`${e.target.value}:${e.keyword}:${t}`))})]})}function ep({rows:e}){return(0,$.jsxs)(`table`,{className:`w-full text-label-14`,children:[(0,$.jsx)(`caption`,{className:`sr-only`,children:`Search demand from the selected refresh`}),(0,$.jsx)(`thead`,{className:`bg-surface text-label-13 text-secondary`,children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{className:`px-4 py-3 text-left text-label-13-strong`,children:`Search`}),(0,$.jsx)(`th`,{className:`${Ef} text-label-13-strong`,children:`Monthly searches`}),(0,$.jsx)(`th`,{className:`${Ef} text-label-13-strong`,children:`CPC`}),(0,$.jsx)(`th`,{className:`${Ef} text-label-13-strong`,children:`Difficulty /100`}),(0,$.jsx)(`th`,{className:`px-4 py-3 text-left text-label-13-strong`,children:`Intent`}),(0,$.jsx)(`th`,{className:`px-4`,children:(0,$.jsx)(`span`,{className:`sr-only`,children:`Evidence`})})]})}),(0,$.jsx)(`tbody`,{className:`divide-y divide-subtle`,children:e.map((e,t)=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{scope:`row`,className:`${Df} text-primary`,children:e.keyword}),(0,$.jsx)(`td`,{className:Ef,children:(0,$.jsx)(Af,{value:e.searchVolume})}),(0,$.jsx)(`td`,{className:Ef,children:(0,$.jsx)(Af,{value:e.cpcUsd,currency:!0})}),(0,$.jsx)(`td`,{className:Ef,children:(0,$.jsx)(Af,{value:e.keywordDifficulty})}),(0,$.jsx)(`td`,{className:`px-4 py-3 align-top`,children:e.searchIntent??`Not supplied`}),(0,$.jsx)(`td`,{className:`px-4 align-top`,children:(0,$.jsxs)(Hf,{label:e.keyword,source:e.provenance,children:[(0,$.jsxs)(`p`,{children:[`Ad competition: `,e.adCompetition===null?`Not supplied`:G(e.adCompetition,rt.fraction)]}),(0,$.jsxs)(`p`,{children:[`Core search: `,e.coreKeyword??`Not supplied`]}),e.monthlySearches.length>0&&(0,$.jsx)(`dl`,{children:e.monthlySearches.map(e=>(0,$.jsxs)(`div`,{className:`flex justify-between gap-5`,children:[(0,$.jsxs)(`dt`,{children:[e.year,`-`,String(e.month).padStart(2,`0`)]}),(0,$.jsx)(`dd`,{children:(0,$.jsx)(Af,{value:e.searchVolume})})]},`${e.year}-${e.month}`))})]})})]},`${e.keyword}:${t}`))})]})}function tp({rows:e}){return(0,$.jsxs)(`table`,{className:`w-full text-label-14`,children:[(0,$.jsx)(`caption`,{className:`sr-only`,children:`Domain comparison from the selected refresh`}),(0,$.jsx)(`thead`,{className:`bg-surface text-label-13 text-secondary`,children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{className:`px-4 py-3 text-left text-label-13-strong`,children:`Domain`}),(0,$.jsx)(`th`,{className:`${Ef} text-label-13-strong`,children:`Searches ranked for`}),(0,$.jsx)(`th`,{className:`${Ef} text-label-13-strong`,children:`Est. organic traffic`}),(0,$.jsx)(`th`,{className:`px-4`,children:(0,$.jsx)(`span`,{className:`sr-only`,children:`Evidence`})})]})}),(0,$.jsx)(`tbody`,{className:`divide-y divide-subtle`,children:e.map((e,t)=>(0,$.jsxs)(`tr`,{children:[(0,$.jsxs)(`th`,{scope:`row`,className:Df,children:[(0,$.jsx)(`p`,{className:`text-primary`,children:e.target.value}),(0,$.jsx)(`p`,{className:`mt-1 text-copy-13 text-secondary`,children:e.target.includeSubdomains?`Includes subdomains`:`Exact host`})]}),(0,$.jsx)(`td`,{className:Ef,children:(0,$.jsx)(Af,{value:e.organicKeywords})}),(0,$.jsx)(`td`,{className:Ef,children:(0,$.jsx)(Af,{value:e.estimatedOrganicTraffic})}),(0,$.jsx)(`td`,{className:`px-4 align-top`,children:(0,$.jsx)(Hf,{label:e.target.value,source:e.provenance,children:(0,$.jsxs)(`dl`,{className:`grid grid-cols-2 gap-2`,children:[(0,$.jsx)(`dt`,{children:`Position 1`}),(0,$.jsx)(`dd`,{children:(0,$.jsx)(Af,{value:e.top1})}),(0,$.jsx)(`dt`,{children:`Positions 2–3`}),(0,$.jsx)(`dd`,{children:(0,$.jsx)(Af,{value:e.top2To3})}),(0,$.jsx)(`dt`,{children:`Positions 4–10`}),(0,$.jsx)(`dd`,{children:(0,$.jsx)(Af,{value:e.top4To10})}),(0,$.jsx)(`dt`,{children:`Positions 11–20`}),(0,$.jsx)(`dd`,{children:(0,$.jsx)(Af,{value:e.top11To20})}),(0,$.jsx)(`dt`,{children:`Est. traffic value`}),(0,$.jsx)(`dd`,{children:(0,$.jsx)(Af,{value:e.estimatedOrganicTrafficValueUsd,currency:!0})})]})})})]},`${e.target.value}:${t}`))})]})}var np=5,rp=10,ip=`all`;function ap(e){return e===ip?ip:gt.safeParse(e).data??null}var op={column:`ranks11To20`,descending:!0},sp={3:`sm:grid-cols-3`,4:`sm:grid-cols-4`,5:`sm:grid-cols-5`},cp=`inline-flex min-h-11 cursor-pointer select-none items-center rounded-sm hover:text-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-mono-400`,lp=`inline-flex min-h-11 items-center rounded-sm text-secondary hover:text-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-mono-400`;function up(e,t){switch(e.count){case`page1`:return`Google rank 1 to 10.`;case`ranks11To20`:return`Google rank 11 to 20: the closest to page 1.`;case`ranks21Plus`:return t!==null&&t>21?`Google rank 21 to ${t}.`:`Google rank 21 or deeper.`;case`notRanked`:return t===null?`Searched, and the site is not in the results checked.`:`Searched, and the site is not in the top ${t} results. A search that returned only part of them counts as partly checked instead.`;default:return e.count}}function dp(e){return`Overlaps the figures beside it: queries where a tracked competitor ranks above the site, or ranks while the site is not in ${e===null?`the results`:`the top ${e}`}.`}function fp(e){let t=e.filter(e=>e.kind===z.region).length;return t===e.length?{label:`Region`,plural:`regions`}:t===0?{label:`Market`,plural:`markets`}:{label:`Region or market`,plural:`regions and markets`}}function pp(e,t){return e.counts[t]}function mp(e){let t=e.descending?-1:1,n=e.column;return n===`label`?(e,n)=>t*(Ht(e.label,n.label)||Ht(e.key,n.key)):(e,r)=>t*(pp(e,n)-pp(r,n))||Ht(e.label,r.label)||Ht(e.key,r.key)}function hp(e,t=250){let[n,r]=(0,Q.useState)(e),i=e.trim()===``;return(0,Q.useEffect)(()=>{if(i){r(``);return}let n=setTimeout(()=>r(e),t);return()=>clearTimeout(n)},[i,e,t]),i?``:n}function gp({label:e,align:t,sorted:n,onSort:r,help:i,showUnsorted:a=!1}){return(0,$.jsx)(`th`,{scope:`col`,"aria-sort":n??void 0,className:`px-4 text-label-14-strong whitespace-nowrap ${t===`right`?`text-right`:`text-left`}`,children:(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:r,className:`${cp} ${n?`text-primary`:``}`,children:[e,(n||a)&&(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`ml-0.5`,children:n===`ascending`?`↑`:n===`descending`?`↓`:`↕`})]}),i&&(0,$.jsx)(X,{text:i})]})})}function _p({projectName:e,profileId:t,runId:n,active:r}){let i=E({strict:!1}),a=T(),o=i.seoRegion,s=i.seoMarket,c=ap(i.seoShow),l=Rt.safeParse(i.seoSort).data??Gt.rank,u=t=>{a({to:`/projects/$projectName/seo-data`,params:{projectName:e},search:e=>({...e,...t}),replace:!0})},d=(0,Q.useId)(),f=w(Er({client:K,path:{name:e},query:{profileId:t,runId:n,regionKey:o,marketKey:s}}));if(f.error)return(0,$.jsx)(`div`,{className:`py-4`,children:(0,$.jsx)(Uf,{error:f.error,retry:()=>{f.refetch()}})});if(!f.data)return(0,$.jsx)(`p`,{role:`status`,className:`py-8 text-copy-14 text-secondary`,children:`Loading market rankings…`});let{totals:p,depth:m,groups:h}=f.data,g=`${o??``}\u0000${s??``}`,_=o!==void 0||s!==void 0,v=_&&(0,$.jsx)(yp,{projectName:e,regionKey:o,marketKey:s,regionLabel:f.data.regionLabel,marketLabel:f.data.marketLabel});if(p.queries===0)return(0,$.jsxs)(`div`,{className:`pt-4`,children:[v,_?(0,$.jsxs)(Wf,{title:`No rankings here`,children:[`This refresh has no rankings for this `,s===void 0?`region`:`market`,`.`]}):(0,$.jsx)(Wf,{title:r?`Refresh in progress`:`No results returned`,children:r?`This profile is collecting data.`:`The source did not return records for this scope. Review the refresh in Activity before changing the profile.`})]});let y=Oe(m,p),b=c??(p.needsWork>0?ze[`needs-work`]:ip),x=h.length>1||h.some(e=>e.kind===z.region),S=[`${Sf.format(p.queries)} ${p.queries===1?`query`:`queries`}`,...p.partlyChecked>0?[`${Sf.format(p.partlyChecked)} partly checked`]:[],...p.failed>0?[`${Sf.format(p.failed)} failed`]:[],...p.cancelled>0?[`${Sf.format(p.cancelled)} not searched`]:[]].join(` · `);return(0,$.jsxs)(`div`,{className:`space-y-6 pt-4`,children:[v,(0,$.jsxs)(`section`,{"aria-labelledby":d,className:`space-y-3`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-baseline justify-between gap-3`,children:[(0,$.jsx)(`h3`,{id:d,className:`text-heading-16 text-heading`,children:`Google rank`}),(0,$.jsx)(`p`,{className:`text-copy-13 tabular-nums text-secondary`,children:S})]}),(0,$.jsxs)(`dl`,{className:`grid grid-cols-2 gap-5 border-b border-subtle pb-5 ${sp[y.length+1]??`sm:grid-cols-5`}`,children:[y.map(e=>(0,$.jsx)(vp,{label:e.label,help:up(e,m),value:p[e.count]},e.count)),(0,$.jsx)(vp,{label:`Rival ahead`,help:dp(m),value:p.rivalAhead,className:`sm:border-l sm:border-subtle sm:pl-5`})]})]}),x&&(0,$.jsx)(bp,{projectName:e,groups:h,bands:y},`groups\u0000${g}`),(0,$.jsx)(xp,{projectName:e,profileId:t,runId:n,regionKey:o,marketKey:s,totals:p,bands:y,depth:m,show:b,onShow:e=>u({seoShow:e}),sort:l,onSort:e=>u({seoSort:e===Gt.rank?void 0:e}),urlQ:i.seoQ??``,onQ:e=>u({seoQ:e||void 0}),onClear:()=>u({seoShow:ip,seoQ:void 0})},`queries\u0000${g}`)]})}function vp({label:e,help:t,value:n,className:r}){return(0,$.jsxs)(`div`,{className:r,children:[(0,$.jsxs)(`dt`,{className:`flex items-center gap-1.5 text-label-13 text-secondary`,children:[e,(0,$.jsx)(X,{text:t,placement:`bottom`})]}),(0,$.jsx)(`dd`,{className:`mt-2 text-heading-32 tabular-nums text-heading`,children:Sf.format(n)})]})}function yp({projectName:e,regionKey:t,marketKey:n,regionLabel:r,marketLabel:i}){let a=r??`Region not in this refresh`;return(0,$.jsxs)(`nav`,{"aria-label":`Market rankings scope`,className:`flex flex-wrap items-center gap-x-2 text-label-14`,children:[(0,$.jsx)(A,{to:`/projects/$projectName/seo-data`,params:{projectName:e},search:e=>({...e,seoRegion:void 0,seoMarket:void 0}),className:lp,children:`All markets`}),t!==void 0&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`text-muted`,children:`/`}),n===void 0?(0,$.jsx)(`span`,{"aria-current":`page`,className:`text-label-14-strong text-primary`,children:a}):(0,$.jsx)(A,{to:`/projects/$projectName/seo-data`,params:{projectName:e},search:e=>({...e,seoMarket:void 0}),className:lp,children:a})]}),n!==void 0&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`text-muted`,children:`/`}),(0,$.jsx)(`span`,{"aria-current":`page`,className:`text-label-14-strong text-primary`,children:i??`Market not in this refresh`})]})]})}function bp({projectName:e,groups:t,bands:n}){let r=T(),[i,a]=(0,Q.useState)(null),[o,s]=(0,Q.useState)(1),c=fp(t),l=(i===null?t:[...t].sort(mp(i))).slice((o-1)*np,o*np),d=i??(n.some(e=>e.count===op.column)?op:null),f=[{column:`queries`,label:`Queries`},...n.map(e=>({column:e.count,label:e.label})),{column:`rivalAhead`,label:`Rival ahead`}],p=e=>{let t=i??op;a(t.column===e?{column:e,descending:!t.descending}:{column:e,descending:e!==`label`}),s(1)},m=e=>d?.column===e?d.descending?`descending`:`ascending`:null,h=e=>e.kind===z.region?t=>({...t,seoRegion:e.key,seoMarket:void 0}):t=>({...t,seoMarket:e.key}),g=`Google rank by ${c.label.toLowerCase()}`;return(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsxs)(`h3`,{className:`text-heading-16 text-heading`,children:[`By `,c.label.toLowerCase()]}),(0,$.jsx)(`div`,{className:`relative overflow-x-auto rounded-md border border-default`,role:`region`,"aria-label":g,tabIndex:0,children:(0,$.jsxs)(`table`,{className:`w-full text-label-14`,children:[(0,$.jsx)(`caption`,{className:`sr-only`,children:g}),(0,$.jsx)(`thead`,{className:`bg-surface text-label-13 text-secondary`,children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(gp,{label:c.label,align:`left`,sorted:m(`label`),onSort:()=>p(`label`)}),f.map(e=>(0,$.jsx)(gp,{label:e.label,align:`right`,sorted:m(e.column),onSort:()=>p(e.column)},e.column)),(0,$.jsx)(`th`,{className:`px-4`,children:(0,$.jsx)(`span`,{className:`sr-only`,children:`Open`})})]})}),(0,$.jsx)(`tbody`,{className:`divide-y divide-subtle`,children:l.map(t=>(0,$.jsxs)(`tr`,{className:`cursor-pointer hover:bg-surface-hover`,onClick:n=>{n.target.closest(`a, button`)||r({to:`/projects/$projectName/seo-data`,params:{projectName:e},search:h(t)})},children:[(0,$.jsx)(`th`,{scope:`row`,className:`min-w-36 px-4 py-3 text-left align-top text-label-14`,children:(0,$.jsx)(A,{to:`/projects/$projectName/seo-data`,params:{projectName:e},search:h(t),className:`rounded-sm text-primary hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-mono-400`,children:t.label})}),f.map(e=>(0,$.jsx)(`td`,{className:Ef,children:Sf.format(t.counts[e.column])},e.column)),(0,$.jsx)(`td`,{className:`px-4 py-3 text-right align-top`,children:(0,$.jsx)(u,{"aria-hidden":`true`,className:`ml-auto size-4 text-muted`})})]},`${t.kind}:${t.key}`))})]})}),(0,$.jsx)(Ts,{page:o,pageSize:np,visibleRows:l.length,totalRows:t.length,onPageChange:s,itemLabel:c.plural,className:`text-label-13 [&_button]:min-h-11`})]})}function xp({projectName:e,profileId:t,runId:n,regionKey:r,marketKey:i,totals:a,bands:o,depth:s,show:c,onShow:l,sort:u,onSort:d,urlQ:f,onQ:p,onClear:m}){let h=(0,Q.useId)(),[g,_]=(0,Q.useState)(f),v=hp(g).trim().slice(0,200),y=(0,Q.useRef)(f);(0,Q.useEffect)(()=>{v!==y.current&&(y.current=v,p(v))},[v]);let b=`${c}\u0000${u}\u0000${v}`,[x,S]=(0,Q.useState)({filterKey:b,page:1});x.filterKey!==b&&S({filterKey:b,page:1});let C=x.filterKey===b?x.page:1,T=w({...br({client:K,path:{name:e},query:{profileId:t,runId:n,regionKey:r,marketKey:i,outcome:c===ip?void 0:c,q:v||void 0,sort:u,limit:rp,offset:(C-1)*rp}}),placeholderData:j}),E=[{value:ze[`needs-work`],label:`Needs work`,count:a.needsWork},...o.map(e=>({value:e.filter,label:e.label,count:a[e.count]})),{value:ze[`rival-ahead`],label:`Rival ahead`,count:a.rivalAhead},{value:ze[`partly-checked`],label:`Partly checked`,count:a.partlyChecked},{value:ze.failed,label:`Failed`,count:a.failed},{value:ze.cancelled,label:`Not searched`,count:a.cancelled},{value:ip,label:`All`,count:a.queries}],D=[ze[`partly-checked`],ze.failed,ze.cancelled],O=E.filter(e=>e.value===c||e.count>0||!D.includes(e.value)),k=O.find(e=>e.value===c)?.label??`All`,A=u===Gt.rank?`ascending`:u===Gt[`-rank`]?`descending`:null,M=u===Gt.query?`ascending`:u===Gt[`-query`]?`descending`:null,N=T.data?.items??[],P=s===null?`not ranked`:`not in the top ${s}`,F=!T.data||T.isPlaceholderData?null:T.data.total===0?`No queries match`:`${Sf.format(T.data.total)} ${T.data.total===1?`query`:`queries`}: ${k}`;return(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`h3`,{className:`text-heading-16 text-heading`,id:h,children:`Queries`}),(0,$.jsx)(X,{placement:`bottom`,text:`Needs work: queries ranking 11 or deeper, ${P}, or partly checked. Rival ahead: a tracked competitor ranks above the site.`})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,$.jsxs)(`label`,{className:`flex min-w-0 items-center gap-3`,children:[(0,$.jsx)(`span`,{className:`text-label-13 text-secondary`,children:`Show`}),(0,$.jsx)(`select`,{"aria-label":`Show queries`,value:c,onChange:e=>l(e.target.value),className:`${Tf} min-w-0 sm:w-56`,children:O.map(e=>(0,$.jsxs)(`option`,{value:e.value,children:[e.label,` (`,Sf.format(e.count),`)`]},e.value))})]}),(0,$.jsx)(js,{value:g,onChange:_,label:`Find a query`,placeholder:`Find a query`,className:`min-w-48 flex-1 sm:max-w-xs [&_input]:h-11`})]}),(0,$.jsx)(`p`,{role:`status`,className:`sr-only`,children:F}),T.error?(0,$.jsx)(Uf,{error:T.error,retry:()=>{T.refetch()}}):T.data?T.data.total===0?(0,$.jsxs)(`div`,{className:`py-12 text-center`,children:[(0,$.jsx)(`h4`,{className:`text-heading-14 text-heading`,children:`No queries match`}),(0,$.jsx)(q,{variant:`secondary`,className:`mt-4 pointer-coarse:min-h-11`,onClick:()=>{y.current=``,_(``),m()},children:`Clear filters`})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`relative overflow-x-auto rounded-md border border-default ${T.isPlaceholderData?`opacity-60`:``}`,role:`region`,"aria-label":`Queries`,"aria-busy":T.isPlaceholderData,tabIndex:0,children:(0,$.jsxs)(`table`,{className:`w-full text-label-14`,children:[(0,$.jsxs)(`caption`,{className:`sr-only`,children:[`Queries: `,k]}),(0,$.jsx)(`thead`,{className:`bg-surface text-label-13 text-secondary`,children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(gp,{label:`Query`,align:`left`,sorted:M,onSort:()=>d(u===Gt.query?Gt[`-query`]:Gt.query)}),(0,$.jsx)(gp,{label:`Google rank`,align:`right`,sorted:A,onSort:()=>d(u===Gt.rank?Gt[`-rank`]:Gt.rank)}),(0,$.jsx)(`th`,{className:`px-4 py-3 text-left text-label-13-strong whitespace-nowrap`,children:`Top rival`}),(0,$.jsx)(`th`,{className:`${Ef} text-label-13-strong`,children:`Rival rank`}),(0,$.jsx)(`th`,{className:`${Ef} text-label-13-strong`,children:(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[`Rank gap`,(0,$.jsx)(X,{text:yf,placement:`bottom`})]})}),(0,$.jsx)(`th`,{className:`px-4`,children:(0,$.jsx)(`span`,{className:`sr-only`,children:`Evidence`})})]})}),(0,$.jsx)(`tbody`,{className:`divide-y divide-subtle`,children:N.map((e,t)=>(0,$.jsx)(Sp,{row:e,requested:s},`${e.marketKey}\u0000${e.queryId??e.queryText}\u0000${t}`))})]})}),(0,$.jsx)(Ts,{page:C,pageSize:rp,visibleRows:N.length,totalRows:T.data.total,onPageChange:e=>S({filterKey:b,page:e}),disabled:T.isFetching,itemLabel:`queries`,className:`text-label-13 [&_button]:min-h-11`})]}):(0,$.jsx)(`p`,{className:`py-8 text-copy-14 text-secondary`,children:`Loading queries…`})]})}function Sp({row:e,requested:t}){let[n,r]=(0,Q.useState)(!1),i=(0,Q.useId)();return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`tr`,{className:n?`border-b-0`:void 0,children:[(0,$.jsxs)(`th`,{scope:`row`,className:Df,children:[(0,$.jsx)(`p`,{className:`text-primary`,children:e.queryText}),(0,$.jsx)(`p`,{className:`mt-1 text-copy-13 text-secondary`,children:e.marketLabel})]}),(0,$.jsx)(`td`,{className:Ef,children:(0,$.jsx)(wp,{row:e,requested:t})}),(0,$.jsx)(`td`,{className:`px-4 py-3 align-top text-label-13`,children:(0,$.jsx)(Tp,{row:e})}),(0,$.jsx)(`td`,{className:Ef,children:(0,$.jsx)(Af,{value:e.topCompetitor?.rankOrganic??null})}),(0,$.jsx)(`td`,{className:Ef,children:(0,$.jsx)(Yf,{value:e.rankGap})}),(0,$.jsx)(`td`,{className:`px-4 text-right align-top`,children:(0,$.jsxs)(`button`,{type:`button`,"aria-expanded":n,"aria-controls":i,onClick:()=>r(e=>!e),className:`inline-flex min-h-11 items-center whitespace-nowrap rounded-sm text-button-14 text-secondary hover:text-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-mono-400`,children:[n?`Hide details`:`Details`,(0,$.jsxs)(`span`,{className:`sr-only`,children:[` for `,e.queryText,` in `,e.marketLabel]})]})})]}),(0,$.jsx)(`tr`,{id:i,hidden:!n,children:(0,$.jsx)(`td`,{colSpan:6,className:`bg-surface-subtle px-4 pb-4 pt-3`,children:(0,$.jsx)(Ep,{row:e,requested:t})})})]})}function Cp(e){return e.outcome===xt.failed||e.outcome===xt.cancelled}function wp({row:e,requested:t}){return e.outcome===xt.failed?(0,$.jsx)(X,{tone:`caution`,label:`Failed`,placement:`bottom`,text:`Failed: the source returned no results for this search in this refresh.`}):e.outcome===xt.cancelled?(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-secondary`,children:[`Not searched`,(0,$.jsx)(X,{placement:`bottom`,text:`The refresh was cancelled, or reached a spending limit, before this search ran.`})]}):e.rankOrganic===null?e.outcome===xt[`partly-checked`]?(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-secondary`,children:[`Not in top `,e.depth,(0,$.jsx)(X,{placement:`bottom`,text:`Only the top ${e.depth}${t===null?``:` of ${t}`} results came back for this search, so ranks past ${e.depth} are unknown.`})]}):(0,$.jsxs)(`span`,{className:`text-secondary`,children:[`Not in top `,e.depth]}):(0,$.jsx)($.Fragment,{children:e.rankOrganic})}function Tp({row:e}){if(Cp(e))return(0,$.jsxs)(`span`,{className:`text-muted`,children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,children:`—`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`No result`})]});let t=e.topCompetitor;return t?(0,$.jsxs)(`span`,{className:`inline-flex flex-wrap items-center gap-x-1.5 gap-y-1`,children:[(0,$.jsx)(`span`,{className:`text-primary`,children:t.domain}),e.rivalAhead&&(0,$.jsx)(J,{tone:`caution`,children:`Ahead`})]}):(0,$.jsxs)(`span`,{className:`text-secondary`,children:[`None in top `,e.depth]})}function Ep({row:e,requested:t}){let n=`text-muted`,r=`mt-0.5 text-primary`,i=e.outcome===xt.failed?`No result: the search failed`:e.outcome===xt.cancelled?`No result: not searched`:`Not in the top ${e.depth}`;return(0,$.jsxs)(`div`,{className:`grid gap-x-8 gap-y-3 text-label-13 text-secondary sm:grid-cols-2 lg:grid-cols-4`,children:[(0,$.jsxs)(`div`,{className:`sm:col-span-2 lg:col-span-4`,children:[(0,$.jsx)(`p`,{className:n,children:`Ranking page`}),e.url?(0,$.jsx)(os,{url:e.url}):(0,$.jsx)(`p`,{className:r,children:i})]}),(0,$.jsxs)(`div`,{className:`lg:col-span-2`,children:[(0,$.jsx)(`p`,{className:n,children:`Searched as`}),(0,$.jsxs)(`p`,{className:r,children:[`“`,e.searchText,`” from `,e.locationLabel]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:n,children:`Target`}),(0,$.jsxs)(`p`,{className:`${r} break-words`,children:[e.target.value,` · `,e.target.includeSubdomains?`includes subdomains`:`exact host`]})]}),e.rankOrganic!==null&&(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:n,children:Of}),(0,$.jsx)(`p`,{className:`${r} tabular-nums`,children:(0,$.jsx)(Af,{value:e.rankAbsolute})})]}),e.searchStatus===mn.partial&&(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:n,children:`Results checked`}),(0,$.jsxs)(`p`,{className:`${r} tabular-nums`,children:[`Top `,e.depth,t===null?``:` of ${t}`]})]}),!Cp(e)&&(0,$.jsxs)(`div`,{className:`sm:col-span-2 lg:col-span-2`,children:[(0,$.jsx)(`p`,{className:n,children:`Tracked competitors in these results`}),e.competitors.length?(0,$.jsx)(`dl`,{className:`mt-0.5 grid grid-cols-[minmax(0,1fr)_auto] gap-x-6 gap-y-1`,children:e.competitors.map(e=>(0,$.jsxs)(Q.Fragment,{children:[(0,$.jsx)(`dt`,{className:`break-all text-primary`,children:e.domain}),(0,$.jsxs)(`dd`,{className:`text-right tabular-nums text-primary`,children:[`#`,e.rankOrganic]})]},e.domain))}):(0,$.jsxs)(`p`,{className:r,children:[`None in the top `,e.depth]})]}),e.provenance&&(0,$.jsx)(`div`,{className:`sm:col-span-2 lg:col-span-4`,children:(0,$.jsx)(Vf,{source:e.provenance})})]})}function Dp({projectName:e,profileId:t,canRun:n,selectedRunId:r}){let[i,a]=(0,Q.useState)(r??null),[o,s]=(0,Q.useState)(null),c=w({...ri({client:K,path:{name:e},query:{profileId:t}}),refetchInterval:e=>e.state.data?.runs.some(kf)?2e3:!1}),l=w({...cr({client:K,path:{name:e,id:i??``}}),enabled:!!i,refetchInterval:e=>kf(e.state.data)?2e3:!1}),u=C({...Nr({client:K}),meta:{skipGlobalErrorToast:!0}}),d=async t=>{if(n&&!u.isPending){s(null);try{await u.mutateAsync({path:{name:e,id:t}})}catch(e){s(Co(e))}}};if(c.error)return(0,$.jsx)(`div`,{className:`py-4`,children:(0,$.jsx)(Uf,{error:c.error,retry:()=>{c.refetch()}})});if(!c.data)return(0,$.jsx)(`p`,{role:`status`,className:`py-8 text-copy-14 text-secondary`,children:`Loading activity…`});let f=l.data&&!c.data.runs.some(e=>e.id===l.data.id)?[l.data,...c.data.runs]:c.data.runs;return f.length?(0,$.jsxs)(`div`,{className:`divide-y divide-subtle`,children:[o&&(0,$.jsx)(`p`,{role:`alert`,className:`py-3 text-copy-14`,children:o}),f.map(e=>(0,$.jsxs)(`div`,{className:`py-4`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,$.jsx)(jf,{status:e.status}),(0,$.jsx)(`span`,{className:`text-label-14`,children:ut(e.createdAt,wf)})]}),(0,$.jsxs)(`p`,{className:`text-copy-13 text-secondary`,children:[e.completedTasks,` of `,e.taskCount,` `,Ff(e),` completed`,e.failedTasks>0?` · ${e.failedTasks} failed`:``]})]}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsxs)(q,{variant:`ghost`,className:`pointer-coarse:min-h-11`,"aria-expanded":i===e.id,"aria-controls":`seo-run-${e.id}`,onClick:()=>a(i===e.id?null:e.id),children:[`Details`,(0,$.jsxs)(`span`,{className:`sr-only`,children:[` for refresh `,e.id]})]}),n&&kf(e)&&(0,$.jsx)(q,{variant:`secondary`,className:`pointer-coarse:min-h-11`,disabled:u.isPending||e.cancelRequested,onClick:Jn(()=>d(e.id)),children:e.cancelRequested?`Cancellation requested`:`Cancel refresh`})]})]}),i===e.id&&(0,$.jsxs)(`div`,{id:`seo-run-${e.id}`,className:`mt-4 space-y-3 rounded-md bg-surface p-4 text-label-13 text-secondary`,children:[(0,$.jsxs)(`p`,{className:`break-all`,children:[`Refresh `,e.id]}),(0,$.jsxs)(`p`,{children:[`Profile revision `,e.profileRevision,` · `,Pf(e),` · `,e.languageCode]}),(0,$.jsxs)(`p`,{children:[`Scope: `,e.scope.kind,e.scope.key?` · ${e.scope.key}`:``,e.scope.expectedPlanRevision===void 0?``:` · plan revision ${e.scope.expectedPlanRevision}`]}),e.error&&(0,$.jsx)(`p`,{children:e.error}),l.error?(0,$.jsx)(Uf,{error:l.error,retry:()=>{l.refetch()}}):l.data?l.data.tasks.some(If)&&(0,$.jsx)(`ul`,{className:`space-y-3`,children:l.data.tasks.filter(If).map(e=>(0,$.jsxs)(`li`,{children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,$.jsxs)(`span`,{children:[_f[e.capability],e.searchText===null?e.target?` · ${e.target.value}`:``:` · “${e.searchText}” from ${e.locationLabel??`its market`}`,e.comparison?` · ${e.comparison.competitor.value} · ${vf[e.comparison.mode]} searches`:``,e.retried?` · retried once`:``]}),(0,$.jsx)(jf,{status:e.status})]}),e.error&&(0,$.jsx)(`p`,{className:`mt-1`,children:e.error})]},e.id))}):(0,$.jsx)(`p`,{role:`status`,children:`Loading refresh details…`})]})]},e.id))]}):(0,$.jsx)(Wf,{title:`No refreshes yet`,children:`Refresh this profile to collect its first saved results.`})}function Op({projectName:e,context:t,profile:n,id:r,onClose:i,onSaved:a}){let o=S(),[s,c]=(0,Q.useState)(n?.name??``),[l,u]=(0,Q.useState)(n?.connectionId??t.connections.at(0)?.id??``),[d,f]=(0,Q.useState)(n?.capabilities??[U[`ranked-keywords`]]),[p,m]=(0,Q.useState)(n?.targets??[{kind:lt.domain,value:``,includeSubdomains:!0}]),[h,g]=(0,Q.useState)(n?.competitors?.map(e=>e.value).join(`
1
+ import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{A as t,B as n,C as r,I as i,J as a,L as o,Q as s,T as c,U as l,Y as u,Z as d,a as f,b as p,c as m,i as h,lt as g,n as _,s as v,t as y,w as b}from"./vendor-lucide-DuOM7wVi.js";import{r as x}from"./vendor-markdown-BDQ1GKGP.js";import{E as S,_ as C,b as w,d as T,f as E,g as D,p as O,r as k,u as A,w as j}from"./vendor-tanstack-BNuZ37rE.js";import{c as M,f as N,i as P,l as F,m as I,o as L,p as R,r as ee,s as te,t as ne,u as re}from"./vendor-recharts-DhEHcK3G.js";import{$i as ie,$n as z,A as ae,An as B,Bi as V,Br as oe,Cr as se,Ct as ce,Dr as le,Dt as ue,Er as de,F as fe,Fi as pe,Fr as H,Ft as me,G as he,Gi as ge,Gr as _e,Hi as ve,Hr as ye,Ht as be,I as xe,Ii as Se,Ir as Ce,It as we,J as Te,Ji as Ee,Jn as U,Ki as De,Kn as Oe,Kr as W,Kt as ke,Li as Ae,Lr as je,Lt as Me,M as Ne,Nr as Pe,Nt as Fe,Or as Ie,P as Le,Pt as Re,Qn as ze,Rr as Be,Rt as Ve,Sr as He,Tr as Ue,Tt as We,U as Ge,Ur as Ke,Ut as qe,V as Je,Vi as Ye,Vr as Xe,Vt as Ze,Wi as Qe,Wr as $e,Wt as et,Xn as tt,Yn as nt,Zi as rt,Zn as it,_i as G,_t as at,a as ot,ai as st,an as ct,ar as lt,bi as ut,br as dt,c as ft,ca as pt,ci as mt,cn as ht,cr as gt,di as _t,dr as vt,dt as yt,ea as bt,er as xt,f as St,fi as Ct,g as wt,gi as Tt,gt as Et,h as Dt,hi as Ot,ht as kt,ia as At,ii as jt,ir as Mt,it as Nt,j as Pt,kn as Ft,l as It,ln as Lt,lr as Rt,lt as zt,m as Bt,mi as Vt,mt as K,na as Ht,nc as Ut,nn as Wt,nr as Gt,nt as Kt,o as qt,oa as Jt,oi as Yt,on as Xt,or as Zt,ot as Qt,p as $t,pi as en,qi as tn,qn as nn,qr as rn,r as q,ra as an,rc as on,ri as sn,rr as cn,rt as ln,s as un,sa as dn,sn as fn,sr as pn,t as J,tr as mn,u as hn,ua as gn,ui as _n,ur as vn,ut as yn,vi as bn,vn as xn,wr as Sn,wt as Y,x as Cn,xr as wn,yi as Tn,yr as En,yt as Dn,zi as On,zr as kn}from"./ToneBadge-BhjTBHi-.js";import{_ as An,a as jn,b as Mn,d as Nn,g as Pn,h as Fn,i as In,l as Ln,m as Rn,n as zn,p as Bn,r as Vn,s as Hn,t as Un,u as Wn,v as Gn,y as Kn}from"./format-helpers-BPugHeIX.js";import{r as qn}from"./account-context-j3asaevn.js";import{t as Jn}from"./async-handler-Bj3TnIRw.js";import{a as Yn,d as Xn,l as Zn,n as Qn,o as $n,s as er,t as tr,u as nr}from"./query-client-CwZpfiiD.js";import{$ as rr,A as ir,An as ar,At as or,B as sr,Bt as cr,C as lr,Cn as ur,Ct as dr,D as fr,Dn as pr,Dt as mr,E as hr,En as gr,Et as _r,F as vr,Fn as yr,Ft as br,G as xr,H as Sr,Ht as Cr,I as wr,In as Tr,It as Er,J as Dr,K as Or,L as kr,Ln as Ar,Lt as jr,M as Mr,Mn as Nr,Mt as Pr,N as Fr,Nn as Ir,Nt as Lr,O as Rr,On as zr,Ot as Br,P as Vr,Pn as Hr,Pt as Ur,Q as Wr,R as Gr,Rn as Kr,Rt as qr,S as Jr,Sn as Yr,St as Xr,T as Zr,Tn as Qr,Tt as $r,U as ei,Ut as ti,V as ni,Vt as ri,W as ii,X as ai,Y as oi,Z as si,_ as ci,_n as li,_t as ui,an as di,at as fi,b as pi,bt as mi,c as hi,d as gi,dn as _i,et as vi,f as yi,fn as bi,ft as xi,g as Si,gn as Ci,gt as wi,h as Ti,ht as Ei,in as Di,it as Oi,j as ki,jn as Ai,jt as ji,k as Mi,kn as Ni,kt as Pi,l as Fi,lt as Ii,m as Li,n as Ri,o as zi,ot as Bi,p as Vi,pt as Hi,q as Ui,r as Wi,rt as Gi,s as Ki,t as qi,tn as Ji,tt as Yi,u as Xi,un as Zi,v as Qi,vt as $i,w as ea,wn as ta,wt as na,x as ra,xn as ia,xt as aa,y as oa,z as sa,zt as ca}from"./react-query-CBpNFR4t.js";import{_ as la,a as ua,c as da,d as fa,f as pa,g as ma,h as ha,i as ga,l as _a,n as va,o as ya,p as ba,r as xa,s as Sa,t as Ca,u as wa}from"./ChartPrimitives-CvK6CQrj.js";import{t as X}from"./InfoTooltip-Drnst4ML.js";import{t as Z}from"./card-CQAQ-c3g.js";import{$ as Ta,$t as Ea,A as Da,At as Oa,B as ka,Bt as Aa,C as ja,Ct as Ma,D as Na,Dt as Pa,E as Fa,Et as Ia,F as La,Ft as Ra,G as za,Gt as Ba,Ht as Va,I as Ha,It as Ua,J as Wa,Jt as Ga,K as Ka,Kt as qa,L as Ja,Lt as Ya,M as Xa,Mt as Za,N as Qa,Nt as $a,O as eo,Ot as to,P as no,Pt as ro,Q as io,Qt as ao,Rt as oo,St as so,Tt as co,U as lo,Ut as uo,V as fo,Vt as po,W as mo,Wt as ho,X as go,Xt as _o,Y as vo,Yt as yo,Z as bo,Zt as xo,_ as So,_t as Co,a as wo,an as To,b as Eo,bt as Do,c as Oo,cn as ko,ct as Ao,dt as jo,en as Mo,fn as No,ft as Po,gt as Fo,hn as Io,i as Lo,in as Ro,it as zo,j as Bo,jt as Vo,k as Ho,kt as Uo,l as Wo,ln as Go,mn as Ko,mt as qo,nn as Jo,nt as Yo,o as Xo,on as Zo,ot as Qo,pn as $o,pt as es,q as ts,qt as ns,r as rs,rn as is,s as as,st as os,tn as ss,tt as cs,u as ls,un as us,ut as ds,vt as fs,wt as ps,x as ms,xt as hs,y as gs,yt as _s,z as vs,zt as ys}from"./index-xlDLvgRC.js";import{a as bs,c as xs,d as Ss,f as Cs,i as ws,l as Ts,o as Es,p as Ds,r as Os,s as ks,t as As,u as js}from"./SiteHealthSection-DxQPaR--.js";import{t as Ms}from"./Hint-c4a4W87X.js";import{t as Ns}from"./AuditHistoryPanel-CiTzFgbw.js";import{a as Ps,i as Fs,l as Is,n as Ls,o as Rs,r as zs,t as Bs}from"./service-DFumlmXt.js";import{a as Vs,c as Hs,s as Us,t as Ws}from"./server-traffic-jKXLZyeC.js";import{i as Gs,n as Ks,r as qs}from"./agent-trust-copy--U_DFYQE.js";function Js(e){return e.split(/[?#]/)[0]||`/`}var Ys=1e6;function Xs(e,t=`USD`,n={}){let r=new Intl.NumberFormat(`en-US`,{style:`currency`,currency:t,...n.fractionDigits===void 0?{}:{minimumFractionDigits:n.fractionDigits,maximumFractionDigits:n.fractionDigits}}),i=r.format(e/Ys);if(n.showTinyAsLessThan&&e>0&&i===r.format(0)){let e=10**-(r.resolvedOptions().maximumFractionDigits??0);return`<${r.format(e)}`}return i}var Q=e(g(),1),Zs={projectWide:`Project-wide`,projectWideHelp:`This tab covers the whole project. Your measurement scope stays selected for AI Visibility and Queries.`,savedScopeUnavailable:`Saved scope unavailable`};function Qs(e,t){return e!==`viewer`||t!==null}function $s(e,t){return e===`research`&&!t?`tracked`:e}function ec(e,t){return t.measurementScope===`project`?!1:!t.measurementScopeKey||!(t.measurementScope===`group`?e.groups:t.measurementScope===`property`?e.targets:e.markets).some(e=>e.stableKey===t.measurementScopeKey)}function tc(e,t){return e.find(e=>e.kind===t.measurementScope&&(e.kind===`project`||e.id===t.measurementScopeKey))}function nc(e){return e.measurementScope!==`project`||e.marketKey!==void 0}function rc(e){if(e.embedded)return{kind:`none`};let{tab:t}=e;switch(t){case`overview`:return e.surface===`advanced-overview`?{kind:`report-picker`}:{kind:`none`};case`queries`:case`discovery`:{let{tracking:t}=e;return e.queryWorkspace!==`tracked`||t.state!==`ready`||t.mode!==`advanced`?{kind:`none`}:t.scopeUnavailable?{kind:`scope-unavailable`}:{kind:`tracking-picker`}}case`search-console`:case`activity`:case`technical-aeo`:case`conversions`:case`local`:case`backlinks`:case`history`:return e.scoped&&e.surface===`advanced-overview`?{kind:`project-wide`}:{kind:`none`};case`client-queries`:case`settings`:case`portfolio`:case`seo-data`:case`journeys`:return{kind:`none`};default:return t}}var $=x();function ic({state:e,label:t,className:n}){return(0,$.jsx)(J,{tone:us(e),className:n,children:t??Gn(e)})}var ac=[{value:`non-brand`,label:`Non-brand`},{value:`branded`,label:`Branded`}],oc={"non-brand":`Non-brand`,branded:`Branded`,pooled:`All queries`},sc={"non-brand":`On queries that do not contain your name: of the brand names written into the answer text, the share that were yours. Branded queries are scored separately because you are named on nearly all of them and a competitor cannot be.`,branded:`On queries that contain your name: of the brand names written into the answer text, the share that were yours. This is recognition, not competitive placement, and it is never pooled with the non-brand figure.`,pooled:`This project has no brand name or domain to match on, so branded and non-brand queries could not be separated. This figure pools both and is not a competitive read. Set a display name or aliases to split them.`},cc=`Mentioned = brand in the answer. Cited = domain in the sources. Neither implies the other.`;function lc(e,t){return t.unavailable?{headline:`No data`,numeric:!1,detail:`could not load, refresh to retry`,showRows:!1}:t.noRun?{headline:`No data`,numeric:!1,detail:`no check has run yet`,showRows:!1}:e.snapshotsTotal===0?t.otherClassHasData?{headline:`No non-brand queries`,numeric:!1,detail:`every tracked query names your brand`,showRows:!1}:{headline:`No queries`,numeric:!1,detail:`none tracked`,showRows:!1}:e.snapshotsWithAnswerText===0?{headline:`No answers`,numeric:!1,detail:`no answer text in this run`,showRows:!1}:t.hasCompetitors?e.combinedMentionSnapshots===0||e.score===null?{headline:`No mentions`,numeric:!1,detail:`no brand named in ${e.snapshotsWithAnswerText} answers`,showRows:!1}:{headline:G(e.score,rt.percent),numeric:!0,detail:`${e.projectMentionSnapshots} of ${e.combinedMentionSnapshots} brand mentions`,showRows:!0}:{headline:`Add competitors`,numeric:!1,detail:`you were named in ${e.projectMentionSnapshots} of ${e.snapshotsWithAnswerText} answers`,showRows:!1}}function uc({breakdown:e,projectLabel:t}){if(e.ranking.length===0)return null;let n=e.ranking.map(e=>({label:e.kind===`project`?`${t} (you)`:e.domain??``,mentions:e.mentionSnapshots,share:e.share,isYou:e.kind===`project`}));return(0,$.jsxs)(`table`,{className:`mention-share-table`,children:[(0,$.jsx)(`caption`,{className:`sr-only`,children:`Brand mentions by domain, most mentioned first`}),(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{className:`mention-share-row mention-share-row-head`,children:[(0,$.jsx)(`th`,{scope:`col`,className:`mention-share-row-label`,children:`Domain`}),(0,$.jsx)(`th`,{"aria-hidden":`true`}),(0,$.jsxs)(`th`,{scope:`col`,className:`mention-share-count`,children:[`Mentions`,(0,$.jsx)(X,{text:cc})]}),(0,$.jsx)(`th`,{scope:`col`,className:`mention-share-share`,children:`Share`})]})}),(0,$.jsx)(`tbody`,{className:`mention-share-rows`,children:n.map(e=>(0,$.jsxs)(`tr`,{className:`mention-share-row`,children:[(0,$.jsx)(`th`,{scope:`row`,className:`mention-share-row-label ${e.isYou?`text-heading text-label-14-strong`:`text-secondary`}`,children:e.label}),(0,$.jsx)(`td`,{"aria-hidden":`true`,children:(0,$.jsx)(`div`,{className:`mention-share-bar`,children:(0,$.jsx)(`div`,{className:`mention-share-bar-fill ${e.isYou?`bg-positive-500/70`:`bg-mono-500/60`}`,style:{width:`${e.share>0?Math.max(e.share*100,1.5):0}%`}})})}),(0,$.jsx)(`td`,{className:`mention-share-count`,children:e.mentions}),(0,$.jsx)(`td`,{className:`mention-share-share`,children:G(e.share)})]},e.label))})]})}function dc({summary:e,projectLabel:t,competitorDomains:n}){let[r,i]=(0,Q.useState)(`non-brand`),a=(0,Q.useId)(),o=e.scope===`pooled`,s=!o&&e.branded.snapshotsTotal>0,c=s?r:`non-brand`,l=o?`pooled`:c,u=c===`branded`?e.branded:e.breakdown,d=c===`branded`?e.breakdown:e.branded,f=lc(u,{hasCompetitors:n.length>0,unavailable:e.unavailable===!0,noRun:e.breakdown.snapshotsTotal===0&&e.branded.snapshotsTotal===0,otherClassHasData:d.snapshotsTotal>0}),p=Pn(f.headline),m=l===`non-brand`?ko[e.tone]:`text-secondary`;function h(e){let t=ac.findIndex(e=>e.value===c),n=null;e.key===`ArrowRight`||e.key===`ArrowDown`?n=(t+1)%ac.length:e.key===`ArrowLeft`||e.key===`ArrowUp`?n=(t-1+ac.length)%ac.length:e.key===`Home`?n=0:e.key===`End`&&(n=ac.length-1),n!==null&&(e.preventDefault(),i(ac[n].value),e.currentTarget.querySelectorAll(`[role="radio"]`)[n]?.focus())}return(0,$.jsxs)(`div`,{className:`mention-share`,children:[(0,$.jsxs)(`div`,{className:`mention-share-head`,children:[(0,$.jsxs)(`div`,{className:`mention-share-label`,children:[(0,$.jsx)(`h3`,{id:a,className:`mention-share-label-text`,children:`Mention share`}),(0,$.jsx)(X,{text:sc[l]})]}),s?(0,$.jsx)(`div`,{role:`radiogroup`,"aria-labelledby":a,className:`segmented flex-wrap`,onKeyDown:h,children:ac.map(e=>{let t=e.value===c;return(0,$.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":t,tabIndex:t?0:-1,onClick:()=>i(e.value),className:`segmented-option min-h-11 ${t?`segmented-option-active`:``}`,children:e.label},e.value)})}):(0,$.jsx)(`span`,{className:`mention-share-class`,children:oc[l]})]}),f.numeric?(0,$.jsxs)(`p`,{className:`mention-share-value ${m}`,children:[p.figure,p.sign?(0,$.jsx)(`span`,{className:`text-faint`,children:p.sign}):null]}):(0,$.jsx)(`p`,{className:`mention-share-value-text`,children:f.headline}),(0,$.jsxs)(`p`,{className:`mention-share-caption`,children:[(0,$.jsx)(`span`,{className:`mention-share-caption-scope`,children:oc[l]}),` · ${f.detail}`]}),o&&(0,$.jsx)(`p`,{className:`mention-share-note`,children:`Set a brand name to split branded from non-brand.`}),f.showRows&&(0,$.jsx)(uc,{breakdown:u,projectLabel:t})]})}function fc({items:e,label:t=`Details`}){return e.length===0?null:(0,$.jsxs)(`details`,{className:`av-details`,children:[(0,$.jsx)(`summary`,{children:t}),(0,$.jsx)(`ul`,{className:`av-details-list`,children:e.map((e,t)=>(0,$.jsx)(`li`,{children:e},t))})]})}var pc=[{value:`7d`,label:`7 days`},{value:`30d`,label:`30 days`},{value:`90d`,label:`90 days`},{value:`all`,label:`All`}],mc={"7d":`last 7 days`,"30d":`last 30 days`,"90d":`last 90 days`,all:`all checks`},hc={"non-brand":`Non-brand`,branded:`Branded`,all:`All queries`},gc={"non-brand":`Counts queries that do not name your brand.`,branded:`Counts queries that name your brand.`,all:`Counts every tracked query, so mention share is not shown.`},_c={"select-query-class":`no query type selected`,"answer-selection":`answers selected by the brands they named`,"no-competitors":`no competitors configured`,"insufficient-observed":`needs 3 observed competitors, each named in 3 or more answers`,"no-answers":`no answer text`,"no-mentions":`no brands named`,unavailable:`competitor data unavailable`},vc=`Mention share: your share of the brand mentions in these answers, each brand counted at most once per answer. Named: answers that name the brand. Cited: answers whose sources link to its site. Company names in answers are observations. Only competitor sites count toward mention share.`,yc=100;function bc(e){return e?e.evidence.answeredResults>0||e.evidence.sourceResults>0?`measured`:`not-measured`:`unavailable`}function xc(e){return e===`unavailable`?`Unavailable`:`Not measured`}function Sc(e){switch(e){case`own`:return`Your domain`;case`direct-competitor`:return`Competitor`;case`ota-aggregator`:return`Aggregator`;case`editorial-media`:return`Editorial`;case`other`:return`Other`;default:return`Unclassified`}}function Cc(e,t,n){return e===1?t:n}function wc(e){let t=e.label.trim(),n=ie(e.domain);return t&&t.toLowerCase()!==e.domain.toLowerCase()&&t.toLowerCase()!==n.toLowerCase()?t:null}function Tc({row:e,aliases:t=[],autoAliases:n=[]}){let r=wc(e),i=[...t.map(e=>({alias:e,auto:!1})),...n.map(e=>({alias:e,auto:!0}))],a=i.length>0?(0,$.jsxs)(`span`,{className:`av-of block`,children:[`Also named`,` `,i.map(({alias:e,auto:t},n)=>(0,$.jsxs)(`span`,{children:[n>0?`, `:``,e,t?(0,$.jsx)(`span`,{className:`av-alias-auto`,title:`Detected automatically from this project's stored answers`,children:` (auto)`}):null]},`${t?`auto`:`curated`}:${e}`))]}):null;return r?(0,$.jsxs)($.Fragment,{children:[r,` `,(0,$.jsx)(`span`,{className:`av-of`,children:e.domain}),a]}):(0,$.jsxs)($.Fragment,{children:[e.domain,a]})}function Ec(e){let t=wc(e);return t?`${t} (${e.domain})`:e.domain}function Dc(e,t){return t&&e>=yc?(0,$.jsxs)($.Fragment,{children:[`top `,(0,$.jsx)(`strong`,{children:e})]}):(0,$.jsx)(`strong`,{children:e})}function Oc({action:e,domain:t,mutation:n}){let[r,i]=(0,Q.useState)(!1),[a,o]=(0,Q.useState)(null);async function s(){if(!r){i(!0),o(null);try{await n(t)===!1&&o(`Could not ${e} competitor. Try again.`)}catch{o(`Could not ${e} competitor. Try again.`)}finally{i(!1)}}}return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(q,{type:`button`,size:`sm`,variant:`outline`,disabled:r,onClick:()=>{s()},children:[e===`pin`?`Pin`:`Unpin`,` `,(0,$.jsx)(`span`,{className:`sr-only`,children:t})]}),a?(0,$.jsx)(`span`,{role:`alert`,className:`sr-only`,children:a}):null]})}function kc({urls:e}){return(0,$.jsxs)(`details`,{className:`inline-disclosure text-left text-label-12 text-secondary`,children:[(0,$.jsx)(`summary`,{children:`Source URLs`}),(0,$.jsx)(`ul`,{className:`mt-2 max-w-72 space-y-1 text-label-12-mono`,children:e.map(e=>(0,$.jsx)(`li`,{className:`break-all`,children:e},e))})]})}function Ac({count:e,of:t,state:n,toneClass:r}){return n===`measured`?(0,$.jsxs)(`span`,{className:`whitespace-nowrap`,children:[(0,$.jsx)(`span`,{className:`av-n-sm ${r}`,children:e}),` `,(0,$.jsxs)(`span`,{className:`av-of`,children:[`of `,t]})]}):(0,$.jsx)(`span`,{className:`text-label-13 text-secondary`,children:xc(n)})}function jc({percent:e,state:t,toneClass:n}){if(t!==`measured`||e===null)return(0,$.jsx)(`span`,{className:`text-label-13 text-secondary`,children:t===`measured`?`Not measured`:xc(t)});let{figure:r,sign:i}=Pn(G(e,rt.percent));return(0,$.jsxs)(`span`,{className:`av-n-sm ${n}`,children:[r,i?(0,$.jsx)(`span`,{className:`text-faint`,children:i}):null]})}function Mc({rows:e,state:t,named:n,cited:r,onPin:i}){return(0,$.jsx)(`div`,{className:`overflow-x-auto`,children:(0,$.jsxs)(`table`,{className:`av-grid av-grid-dense`,"aria-label":`Other competitors seen`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{scope:`col`,children:`Competitor`}),(0,$.jsx)(`th`,{scope:`col`,children:`Type`}),(0,$.jsx)(`th`,{scope:`col`,children:`Named`}),(0,$.jsx)(`th`,{scope:`col`,children:`Cited`}),(0,$.jsx)(`th`,{scope:`col`,children:(0,$.jsx)(`span`,{className:`sr-only`,children:`Actions`})})]})}),(0,$.jsx)(`tbody`,{children:e.map(e=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{scope:`row`,className:`av-row-label`,children:(0,$.jsx)(Tc,{row:e})}),(0,$.jsx)(`td`,{className:`text-label-13 text-secondary`,children:Sc(e.surfaceClass)}),(0,$.jsx)(`td`,{children:(0,$.jsx)(Ac,{count:e.mentionCount,of:n,state:t,toneClass:`text-primary`})}),(0,$.jsx)(`td`,{children:(0,$.jsx)(Ac,{count:e.citationCount,of:r,state:t,toneClass:`text-primary`})}),(0,$.jsx)(`td`,{children:(0,$.jsxs)(`div`,{className:`flex min-w-max items-start gap-2`,children:[t===`measured`&&e.sampleUrls.length>0?(0,$.jsx)(kc,{urls:e.sampleUrls}):null,i?(0,$.jsx)(Oc,{action:`pin`,domain:e.domain,mutation:i}):null]})})]},e.domain))})]})})}function Nc({onAddCompetitor:e}){let t=(0,Q.useId)(),[n,r]=(0,Q.useState)(``),[i,a]=(0,Q.useState)(!1),[o,s]=(0,Q.useState)(null);async function c(){let t=n.trim();if(t&&!i){a(!0),s(null);try{if(await e(t)===!1){s(`Could not add competitor. Try again.`);return}r(``)}catch{s(`Could not add competitor. Try again.`)}finally{a(!1)}}}return(0,$.jsxs)(`details`,{className:`inline-disclosure`,children:[(0,$.jsx)(`summary`,{children:`Manage competitors`}),(0,$.jsxs)(`form`,{className:`mt-3 flex flex-wrap items-end gap-2`,onSubmit:e=>{e.preventDefault(),c()},"aria-busy":i,children:[(0,$.jsxs)(`label`,{htmlFor:t,className:`min-w-56 flex-1 text-label-14-strong text-heading`,children:[`Competitor domain`,(0,$.jsx)(`input`,{id:t,type:`text`,value:n,onChange:e=>r(e.target.value),placeholder:`competitor.com`,className:`mt-1 h-10 w-full rounded-md border border-default bg-surface px-3 text-label-14 text-primary placeholder-mono-400 focus:outline-none focus:ring-2 focus:ring-mono-400`})]}),(0,$.jsx)(q,{type:`submit`,size:`sm`,className:`min-h-10`,disabled:i||!n.trim(),children:i?`Adding…`:`Add competitor`}),o?(0,$.jsx)(`p`,{role:`alert`,className:`w-full text-copy-14 text-negative`,children:o}):null]})]})}function Pc({window:e,landscape:t,pinnedFallback:n=[],competitorAliases:r={},competitorAutoAliases:i={},canWrite:a,isEmbed:o,onWindowChange:s,onPin:c,onUnpin:l,onAddCompetitor:u,error:d,onRetry:f,isLoading:p=!1,scopeLabel:m,advancedPortfolio:h=!1}){let g=(0,Q.useId)(),_=a&&!o,v=t?.pinned??n,y=t?.observed??[],b=t?.otherSources??[],x=t?.evidence,S=bc(t),C=t?.basis===`observed`,w=C?y.filter(e=>e.shareOfVoice!==null):v,T=C?y.filter(e=>e.shareOfVoice===null):y,E=t?.filters.queryClass,D=t?.marketState?.draft?.pendingCompetitorDomains.length??0,O=t?.truncated===!0,k=x?.answeredResults??0,A=x?x.answeredResults+x.missingAnswerTextResults:0,j=E===`non-brand`&&t?.project.shareOfVoice!=null?ko[Go(t.project.shareOfVoice)]:`text-primary`,M=e=>_?e.pinned?l?(0,$.jsx)(Oc,{action:`unpin`,domain:e.domain,mutation:l}):null:c?(0,$.jsx)(Oc,{action:`pin`,domain:e.domain,mutation:c}):null:null,N=w.some(e=>M(e)!==null),P=[m,E?hc[E]:null,mc[e],t?.basis?C?`observed competitors only`:`tracked competitors only`:null].filter(Boolean).join(` · `),F=[];if(t&&!C&&w.length===0&&F.push({key:`no-pins`,text:`No pinned competitors.`}),t?.reason&&F.push({key:`reason`,text:`Mention share: ${_c[t.reason]}`}),t&&T.length>0){let e=T.length;F.push({key:`others`,text:O&&e>=yc?`${yc} or more other competitors seen`:`${e} other ${Cc(e,`competitor`,`competitors`)} seen`})}D>0&&F.push({key:`pending`,text:`${t?.scope.kind===`all-markets`?`Pending publication across markets`:`Pending publication`}: ${D} ${Cc(D,`competitor`,`competitors`)}`});let I=[x&&x.missingAnswerTextResults>0?`Answer data incomplete`:null,x&&x.incompleteSourceResults>0?`Citation data incomplete`:null].filter(Boolean);I.length>0&&F.push({key:`incomplete`,text:I.join(` · `),className:ko.caution});let L=[];if(t&&x){L.push(t.runCount===void 0?(0,$.jsxs)($.Fragment,{children:[`Base: `,(0,$.jsx)(`strong`,{children:x.answeredResults}),` `,Cc(x.answeredResults,`answer`,`answers`)]}):(0,$.jsxs)($.Fragment,{children:[`Base: `,(0,$.jsx)(`strong`,{children:t.runCount}),` `,Cc(t.runCount,`check`,`checks`),`, `,(0,$.jsx)(`strong`,{children:x.answeredResults}),` `,Cc(x.answeredResults,`answer`,`answers`)]})),!t.reason&&S===`measured`&&t.project.shareOfVoice!==null&&L.push((0,$.jsxs)($.Fragment,{children:[`Mention share: you `,(0,$.jsx)(`strong`,{children:t.project.mentionCount}),w.map(e=>(0,$.jsxs)(Q.Fragment,{children:[`, `,e.domain,` `,(0,$.jsx)(`strong`,{children:e.mentionCount})]},e.domain)),` `,`of `,(0,$.jsx)(`strong`,{children:x.mentionCredits}),` `,C?`brand mentions`:`tracked-brand mentions`]})),L.push((0,$.jsxs)($.Fragment,{children:[`Answers with source links: `,(0,$.jsx)(`strong`,{children:x.sourceResults})]})),T.length===0&&L.push(`Other competitors seen: none`),x.missingAnswerTextResults>0&&L.push((0,$.jsxs)($.Fragment,{children:[`No answer text: `,(0,$.jsx)(`strong`,{children:x.missingAnswerTextResults}),` `,Cc(x.missingAnswerTextResults,`answer`,`answers`),`, left out of mention share`]})),x.incompleteSourceResults>0&&L.push((0,$.jsxs)($.Fragment,{children:[`Incomplete source lists: `,(0,$.jsx)(`strong`,{children:x.incompleteSourceResults}),` `,Cc(x.incompleteSourceResults,`answer`,`answers`),`, not counted as misses`]}));let e=x.excludedProbeResults+x.excludedNonCompletedResults;e>0&&L.push((0,$.jsxs)($.Fragment,{children:[`Left out: `,(0,$.jsx)(`strong`,{children:e}),` `,Cc(e,`answer`,`answers`),` from spot checks or unfinished checks`]}))}let R=[...t?[{name:`You`,row:t.project}]:[],...w.map(e=>({name:e.domain,row:e}))].filter(e=>e.row.sampleUrls.length>0);S===`measured`&&R.length>0&&L.push((0,$.jsxs)(`details`,{className:`av-subdetails`,children:[(0,$.jsx)(`summary`,{children:`Sample pages cited`}),(0,$.jsx)(`div`,{className:`av-subdetails-body`,children:R.map(({name:e,row:t})=>(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{children:e}),(0,$.jsx)(`ul`,{className:`space-y-1 text-label-12-mono text-muted`,children:t.sampleUrls.map(e=>(0,$.jsx)(`li`,{className:`break-all`,children:e},e))})]},t.domain))})]})),t&&T.length>0&&L.push((0,$.jsxs)(`details`,{className:`av-subdetails`,children:[(0,$.jsxs)(`summary`,{children:[`Other competitors seen: `,Dc(T.length,O)]}),(0,$.jsx)(`div`,{className:`av-subdetails-body`,children:(0,$.jsx)(Mc,{rows:T,state:S,named:k,cited:A,onPin:_?c:void 0})})]}));let ee=t?.observedNames??[];if(ee.length>0){let e=t?.observedNamesTotal??ee.length;L.push((0,$.jsxs)(`details`,{className:`av-subdetails`,children:[(0,$.jsxs)(`summary`,{children:[`Company names in answers: `,e>ee.length?(0,$.jsxs)($.Fragment,{children:[`top `,(0,$.jsx)(`strong`,{children:ee.length}),` of `,(0,$.jsx)(`strong`,{children:e})]}):(0,$.jsx)(`strong`,{children:ee.length})]}),(0,$.jsx)(`ul`,{className:`av-subdetails-body`,children:ee.map(e=>(0,$.jsxs)(`li`,{children:[e.name,` · `,e.answerCount,` `,Cc(e.answerCount,`answer`,`answers`)]},e.name))})]}))}return b.length>0&&L.push((0,$.jsxs)(`details`,{className:`av-subdetails`,children:[(0,$.jsxs)(`summary`,{children:[`Other sites cited: `,Dc(b.length,O)]}),(0,$.jsx)(`ul`,{className:`av-subdetails-body`,children:b.map(e=>(0,$.jsxs)(`li`,{children:[(0,$.jsxs)(`span`,{children:[Ec(e),` · `,Sc(e.surfaceClass),` · `,e.citationCount,` `,Cc(e.citationCount,`citation`,`citations`)]}),e.sampleUrls.length>0?(0,$.jsx)(`ul`,{className:`mt-1 space-y-1 text-label-12-mono text-muted`,children:e.sampleUrls.map(e=>(0,$.jsx)(`li`,{className:`break-all`,children:e},e))}):null]},e.domain))})]})),(0,$.jsxs)(`section`,{"aria-labelledby":g,"aria-busy":p,className:`overview-brief`,children:[(0,$.jsxs)(`div`,{className:`av-card-head`,children:[(0,$.jsxs)(`div`,{className:`inline-flex items-center`,children:[(0,$.jsx)(`h2`,{id:g,className:`av-card-title`,children:`Competitors over time`}),(0,$.jsx)(X,{text:E?`${gc[E]} ${vc}`:vc})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[(0,$.jsx)(`p`,{className:`av-card-meta`,children:P}),(0,$.jsx)(fs,{label:`Competitors over time window`,className:`flex-wrap`,options:pc,value:e,onChange:s})]})]}),(0,$.jsxs)(`div`,{className:`av-card-body space-y-3`,children:[d?(0,$.jsxs)(`div`,{role:`alert`,className:`flex flex-wrap items-center gap-3 border-y border-negative-800/40 bg-negative-950/20 py-3 text-label-14 text-negative`,children:[(0,$.jsx)(`span`,{children:d}),f?(0,$.jsx)(q,{type:`button`,size:`sm`,variant:`outline`,onClick:f,children:`Retry competitors over time`}):null]}):null,p&&!t&&v.length===0?(0,$.jsx)(`div`,{role:`status`,"aria-live":`polite`,className:`h-24 animate-pulse rounded-md bg-surface`,children:(0,$.jsx)(`span`,{className:`sr-only`,children:`Loading competitors over time`})}):t||w.length>0?(0,$.jsxs)(`table`,{className:`av-grid av-grid-brands`,"aria-label":`Competitors over time`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{scope:`col`,children:(0,$.jsx)(`span`,{className:`sr-only`,children:`Brand`})}),(0,$.jsx)(`th`,{scope:`col`,className:`av-brand-type`,children:`Type`}),(0,$.jsx)(`th`,{scope:`col`,children:`Mention share`}),(0,$.jsx)(`th`,{scope:`col`,children:`Named`}),(0,$.jsx)(`th`,{scope:`col`,children:`Cited`}),N?(0,$.jsx)(`th`,{scope:`col`,className:`av-brand-actions`,children:(0,$.jsx)(`span`,{className:`sr-only`,children:`Actions`})}):null]})}),(0,$.jsxs)(`tbody`,{children:[t?(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{scope:`row`,className:`av-row-label`,children:t.project.label.trim()?(0,$.jsxs)($.Fragment,{children:[t.project.label.trim(),` `,(0,$.jsx)(`span`,{className:`av-of`,children:`(you)`})]}):`You`}),(0,$.jsx)(`td`,{className:`av-brand-type text-label-13 text-secondary`,children:`Your brand`}),(0,$.jsx)(`td`,{children:(0,$.jsx)(jc,{percent:t.project.shareOfVoice,state:S,toneClass:j})}),(0,$.jsx)(`td`,{children:(0,$.jsx)(Ac,{count:t.project.mentionCount,of:k,state:S,toneClass:j})}),(0,$.jsxs)(`td`,{children:[(0,$.jsx)(Ac,{count:t.project.citationCount,of:A,state:S,toneClass:j}),h&&S===`measured`?(0,$.jsx)(`span`,{className:`block text-label-13 text-secondary`,children:Fn(t.project.domain,`cited`)}):null]}),N?(0,$.jsx)(`td`,{className:`av-brand-actions`}):null]}):null,w.map(e=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{scope:`row`,className:`av-row-label`,children:(0,$.jsx)(Tc,{row:e,aliases:e.pinned?r[e.domain]:void 0,autoAliases:e.pinned?i[e.domain]:void 0})}),(0,$.jsx)(`td`,{className:`av-brand-type text-label-13 text-secondary`,children:Sc(e.surfaceClass)}),(0,$.jsx)(`td`,{children:(0,$.jsx)(jc,{percent:e.shareOfVoice,state:S,toneClass:`text-primary`})}),(0,$.jsx)(`td`,{children:(0,$.jsx)(Ac,{count:e.mentionCount,of:k,state:S,toneClass:`text-primary`})}),(0,$.jsx)(`td`,{children:(0,$.jsx)(Ac,{count:e.citationCount,of:A,state:S,toneClass:`text-primary`})}),N?(0,$.jsx)(`td`,{className:`av-brand-actions`,children:M(e)}):null]},e.domain))]})]}):null,F.length>0?(0,$.jsx)(`div`,{className:`space-y-1 text-label-13 text-secondary`,children:F.map(e=>(0,$.jsx)(`p`,{className:e.className,children:e.text},e.key))}):null]}),(0,$.jsx)(fc,{items:L}),_&&u?(0,$.jsx)(`div`,{className:`border-t border-subtle px-5 py-3`,children:(0,$.jsx)(Nc,{onAddCompetitor:u})}):null]})}function Fc({history:e,maxDots:t=12,signal:n=`citations`}){let r=e.slice(-t);if(r.length===0)return(0,$.jsx)(`span`,{className:`text-label-13 text-secondary`,children:`No data`});let i=n===`mentions`?`Mention`:`Citation`,a=n===`mentions`?{cited:`mentioned`,"not-cited":`not mentioned`,lost:`mention lost`,emerging:`new mention`,pending:`mention pending`}:{cited:`cited`,"not-cited":`not cited`,lost:`citation lost`,emerging:`new citation`,pending:`citation pending`},o={cited:`bg-positive-400`,"not-cited":`bg-mono-600`,lost:`bg-negative-400`,emerging:`bg-caution-400 ring-1 ring-caution-300/60`},s={cited:`rounded-full`,"not-cited":`rounded-sm`,lost:`rotate-45 rounded-[1px]`,emerging:`rounded-full`},c=r.length-1,l=new Date(r[0].createdAt).toLocaleDateString(void 0,{month:`short`,day:`numeric`}),u=new Date(r[c].createdAt).toLocaleDateString(void 0,{month:`short`,day:`numeric`}),d=`${r.length} ${r.length===1?`run`:`runs`}`,f=r.map((e,t)=>{let n=new Date(e.createdAt).toLocaleDateString();return`${t===c?`Latest run, `:``}${n}: ${a[e.citationState]??e.citationState}${e.model?`, model ${e.model}`:``}`}).join(`; `);return(0,$.jsxs)(`div`,{className:`inline-flex w-max items-center gap-2 whitespace-nowrap`,role:`img`,"aria-label":`${i} history across ${d}. ${f}`,children:[r.length>1?(0,$.jsx)(`span`,{className:`text-label-12 text-secondary shrink-0`,"aria-hidden":`true`,children:l}):null,(0,$.jsx)(`div`,{className:`flex shrink-0 items-center gap-[3px]`,title:d,"aria-hidden":`true`,children:r.map((e,t)=>{let n=!!(e.model&&t>0&&r[t-1]?.model&&r[t-1].model!==e.model),i=t===c;return(0,$.jsx)(`span`,{className:`h-2.5 w-2.5 shrink-0 ${s[e.citationState]??`rounded-sm`} ${o[e.citationState]??`bg-mono-700`} ${n?`ring-1 ring-caution-300/80 ring-offset-1 ring-offset-bg`:``} ${i?`outline outline-1 outline-offset-2 outline-mono-400`:``}`,title:[a[e.citationState]??e.citationState,new Date(e.createdAt).toLocaleDateString(),e.model?`model ${e.model}`:null,n?`model changed`:null,i?`latest run`:null].filter(Boolean).join(` · `)},`${e.runId}:${e.createdAt}`)})}),(0,$.jsxs)(`span`,{className:`text-label-12 shrink-0 text-secondary`,"aria-hidden":`true`,children:[u,` `,(0,$.jsx)(`span`,{children:`latest`})]})]})}function Ic(e){let t=new Map;for(let n of e)for(let e of n.runHistory){let n=t.get(e.createdAt);n?n.states.push(e.citationState):t.set(e.createdAt,{states:[e.citationState],runId:e.runId})}return[...t.entries()].sort(([e],[t])=>e.localeCompare(t)).map(([e,{states:t,runId:n}])=>({runId:n,createdAt:e,citationState:t.includes(`cited`)?`cited`:t.includes(`emerging`)?`emerging`:`not-cited`}))}var Lc=320;function Rc(e){return e===`branded`?`Branded`:e===`non-brand`?`Non-brand`:`Unclassified`}function zc(e){return e===`non-brand`?0:e===`branded`?1:2}function Bc(e){let t=[];for(let n of e){let e=t.at(-1);e&&e.queryClass===n.queryClass?e.rows.push(n):t.push({queryClass:n.queryClass,rows:[n]})}return t}function Vc(e){return e.phrase}function Hc(e,t){return t===`citations`?e.citationState:e.visibilityState===`pending`||e.answerMentioned==null&&e.visibilityState==null?`pending`:e.visibilityState===`visible`||e.answerMentioned===!0?`cited`:`not-cited`}function Uc(e,t){if(t===`mentions`)switch(e){case`cited`:return`Mentioned`;case`not-cited`:return`Not Mentioned`;case`pending`:return`Pending`;case`emerging`:return`Newly Mentioned`;case`lost`:return`No Longer Mentioned`}switch(e){case`cited`:return`Cited`;case`not-cited`:return`Not Cited`;case`lost`:return`Lost`;case`emerging`:return`Emerging`;case`pending`:return`Pending`}}function Wc(e,t){return e.map(e=>Gc(e,t))}function Gc(e,t){return t===`citations`?e:{...e,citationState:Hc(e,t),runHistory:e.runHistory.map(e=>({...e,citationState:Hc(e,t)}))}}function Kc(e,t){let n=t===`mentions`?`mention`:`citation`,r=t===`mentions`?`Mention`:`Citation`;if(e.length===0)return{key:t,label:`${r} pending`,tone:`pending`};let i=e[e.length-1].citationState,a=e.length>=2?e[e.length-2].citationState:null,o=i===`cited`||i===`emerging`,s=a===`cited`||a===`emerging`;return i===`lost`||a!==null&&s&&!o?{key:t,label:`Lost ${n}`,tone:`negative`}:i===`emerging`||a!==null&&!s&&o?{key:t,label:`New ${n}`,tone:`positive`}:a===null&&o?{key:t,label:`First ${n}`,tone:`positive`}:o?{key:t,label:t===`mentions`?`Still mentioned`:`Still cited`,tone:`neutral`}:{key:t,label:`No ${n}`,tone:`neutral`}}function qc(e){let t=Ic(Wc(e,`mentions`)),n=Ic(e);return[Kc(t,`mentions`),Kc(n,`citations`)]}function Jc({signal:e}){let t=e.tone===`positive`?`text-positive`:e.tone===`negative`?`text-negative`:e.tone===`pending`?`text-caution`:`text-secondary`;return(0,$.jsx)(`span`,{className:t,children:e.label})}function Yc({items:e}){return(0,$.jsx)(`div`,{className:`query-evidence-signals`,"aria-label":`Latest run mention and citation signals`,children:qc(e).map(e=>(0,$.jsx)(Jc,{signal:e},e.key))})}function Xc({queryClass:e,actions:t}){return(0,$.jsxs)($.Fragment,{children:[t?(0,$.jsx)(`div`,{className:`query-evidence-toolbar`,children:(0,$.jsxs)(`div`,{className:`query-evidence-actions`,children:[!e&&(0,$.jsx)(eo,{}),t]})}):null,e?(0,$.jsx)(Ho,{queryClass:e,manage:!!t}):null]})}function Zc({evidence:e,compareLocations:t=!1,defaultDensity:n=`detailed`,providerSelection:r,onProviderSelectionChange:i,addedQueries:a=[],actions:o,actionPanel:s}){let{openEvidence:c}=Ta(),l=(0,Q.useId)(),[d,f]=(0,Q.useState)(new Set),p=Xa(),[m,h]=(0,Q.useState)(`mentions`),[g,_]=(0,Q.useState)(n),[v,y]=(0,Q.useState)(`all`),[b,x]=(0,Q.useState)(``),S=r??b,C=e=>{x(e),i?.(e)},w=(0,Q.useMemo)(()=>[...new Set([...e.map(e=>e.provider).filter(Boolean),...S?[S]:[]])].sort(),[e,S]),T=(0,Q.useMemo)(()=>{let n=new Map;for(let r of e){if(S&&r.provider!==S)continue;let e=r.query,i=r.queryClass??null,a=t?r.location??null:null,o=JSON.stringify([e,i,a]),s=n.get(o)??{key:o,phrase:e,queryClass:i,location:a,items:[],rawItems:[]};s.items.push(Gc(r,m)),s.rawItems.push(r),n.set(o,s)}return[...n.values()].sort((e,t)=>zc(e.queryClass)-zc(t.queryClass))},[e,m,t,S]),E=(0,Q.useMemo)(()=>T.filter(e=>v===`all`||(v===`unclassified`?e.queryClass===null:e.queryClass===v)),[T,v]),D=Ds({rows:E,getSearchText:Vc}),O=(0,Q.useMemo)(()=>{let e=new Map;for(let t of D.filteredRows){let n=e.get(t.queryClass)??new Set;n.add(t.phrase),e.set(t.queryClass,n)}return e},[D.filteredRows]),k=(0,Q.useMemo)(()=>new Set(a.map(Pe)),[a]),A=p?6:5,j=D.rows.map(e=>e.key),M=j.length>0&&j.every(e=>d.has(e)),N=e=>{f(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},P=m===`mentions`?`mentioned`:`cited`,F=m===`mentions`?`Mention History`:`Citation History`,I=m===`mentions`?`mentioned`:`cited`;return(0,$.jsxs)(`div`,{className:`query-evidence`,children:[(0,$.jsx)(Xc,{queryClass:v,actions:o}),s,(0,$.jsxs)(`div`,{className:`query-evidence-view-row`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(`div`,{className:`query-evidence-tabs`,role:`tablist`,"aria-label":`Citation tracking view`,children:[`mentions`,`citations`].map(e=>(0,$.jsx)(`button`,{id:`${l}-${e}`,type:`button`,role:`tab`,"aria-controls":l,"aria-selected":m===e,tabIndex:m===e?0:-1,onClick:()=>h(e),onKeyDown:t=>{if(![`ArrowLeft`,`ArrowRight`,`Home`,`End`].includes(t.key))return;t.preventDefault();let n=t.key===`Home`?`mentions`:t.key===`End`||e===`mentions`?`citations`:`mentions`;h(n),document.getElementById(`${l}-${n}`)?.focus()},children:e===`mentions`?`Mentions`:`Citations`},e))}),(0,$.jsx)(X,{text:`Mentions track your brand or domain in answer text. Citations track your domain in source links. Each signal is measured independently.`})]}),(0,$.jsxs)(`div`,{className:`query-evidence-display-controls`,children:[(0,$.jsxs)(`label`,{className:`query-evidence-preview-toggle`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:g===`detailed`,onChange:e=>_(e.target.checked?`detailed`:`compact`)}),`Show answer previews`]}),(0,$.jsx)(q,{type:`button`,variant:`ghost`,className:`pointer-coarse:min-h-11`,disabled:j.length===0,onClick:()=>{f(e=>{let t=new Set(e);for(let e of j)M?t.delete(e):t.add(e);return t})},children:M?`Collapse page`:`Expand page`})]})]}),e.length>0||S?(0,$.jsxs)(`div`,{className:`query-evidence-filters`,children:[(0,$.jsx)(js,{value:D.query,onChange:D.setQuery,label:`Find a query`,placeholder:`Find a query`,className:`query-evidence-search`}),(0,$.jsxs)(`label`,{className:`query-evidence-filter`,children:[(0,$.jsx)(`span`,{className:`sr-only`,children:`Answer engine`}),(0,$.jsxs)(`select`,{value:S,onChange:e=>{C(e.target.value),D.setPage(1)},children:[(0,$.jsx)(`option`,{value:``,children:`All engines`}),w.map(e=>(0,$.jsx)(`option`,{value:e,children:po(e)},e))]})]}),(0,$.jsxs)(`label`,{className:`query-evidence-filter`,children:[(0,$.jsx)(`span`,{className:`sr-only`,children:`Query class`}),(0,$.jsxs)(`select`,{value:v,onChange:e=>{y(e.target.value),D.setPage(1)},children:[(0,$.jsx)(`option`,{value:`all`,children:`All queries`}),(0,$.jsx)(`option`,{value:`branded`,children:`Branded`}),(0,$.jsx)(`option`,{value:`non-brand`,children:`Non-brand`}),(0,$.jsx)(`option`,{value:`unclassified`,children:`Unclassified`})]})]})]}):null,(0,$.jsxs)(`div`,{id:l,role:`tabpanel`,"aria-labelledby":`${l}-${m}`,children:[(0,$.jsx)(`div`,{className:`query-evidence-table-wrap`,children:(0,$.jsxs)(`table`,{className:`evidence-table query-evidence-table`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{scope:`col`,children:`Query`}),(0,$.jsx)(`th`,{scope:`col`,children:`Status`}),p&&(0,$.jsx)(`th`,{scope:`col`,"aria-label":`Sentiment`,children:(0,$.jsxs)(`span`,{className:`inline-flex items-center`,children:[`Sentiment`,(0,$.jsx)(X,{text:`Branded query rows show the favorable share of judged answers. Non-brand rows show only their unfavorable and mixed answers. Expanded engine rows show each stored answer’s sentiment; factual and unmentioned answers are not judgments.`})]})}),(0,$.jsx)(`th`,{scope:`col`,children:F}),(0,$.jsx)(`th`,{scope:`col`,children:`Latest run`}),(0,$.jsx)(`th`,{children:(0,$.jsx)(`span`,{className:`sr-only`,children:`Answer`})})]})}),Bc(D.rows).map(e=>(0,$.jsxs)(`tbody`,{children:[(0,$.jsx)(`tr`,{className:`query-evidence-group`,children:(0,$.jsxs)(`th`,{scope:`rowgroup`,colSpan:A,children:[Rc(e.queryClass),` (`,O.get(e.queryClass)?.size??0,`)`]})}),e.rows.map(({key:e,phrase:n,queryClass:r,location:i,items:a,rawItems:o})=>{let s=d.has(e),f=j.indexOf(e),h=`${l}-query-${f}`,_=k.has(Pe(n)),v=a.map(e=>e.citationState),y=v.includes(`cited`)?`cited`:v.includes(`emerging`)?`emerging`:v.includes(`lost`)?`lost`:v.every(e=>e===`pending`)?`pending`:`not-cited`,b=[...new Set(o.map(e=>e.queryId).filter(e=>!!e))],x=o.map(e=>e.sourceSnapshotId).filter(e=>!!e),S=Ic(a),C=a.filter(e=>e.citationState===pe.cited||e.citationState===`emerging`).length;return(0,$.jsxs)(Q.Fragment,{children:[(0,$.jsxs)(`tr`,{className:`query-evidence-row`,onClick:()=>N(e),children:[(0,$.jsx)(`td`,{className:`evidence-query-cell`,children:(0,$.jsxs)(`button`,{type:`button`,className:`query-evidence-query`,"aria-label":n,"aria-describedby":h,"aria-expanded":s,onClick:t=>{t.stopPropagation(),N(e)},children:[(0,$.jsx)(u,{size:16,"aria-hidden":`true`,className:s?`rotate-90`:``}),(0,$.jsxs)(`span`,{className:`min-w-0`,children:[(0,$.jsx)(`span`,{children:n}),(0,$.jsxs)(`span`,{id:h,className:`query-evidence-meta`,children:[(0,$.jsx)(`span`,{children:Rc(r)}),t&&(0,$.jsx)(`span`,{children:i??`No location`}),a.filter(e=>e.provider).map(e=>(0,$.jsx)(`span`,{children:po(e.provider)},e.id))]})]})]})}),(0,$.jsx)(`td`,{children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(ic,{state:y,label:Uc(y,m),className:`rounded-none border-0 bg-transparent p-0 text-label-14`}),(0,$.jsxs)(`span`,{className:`text-label-14 text-secondary tabular-nums`,"aria-label":`${C} of ${a.length} engines ${I}`,title:`${C} of ${a.length} engines ${I}`,children:[C,`/`,a.length]})]})}),p&&(0,$.jsx)(`td`,{children:(0,$.jsx)(Da,{queryId:b.length===1?b[0]:null,sourceSnapshotIds:b.length>1?[]:x,queryClass:r,location:t?i:void 0})}),(0,$.jsx)(`td`,{children:(0,$.jsx)(Fc,{history:S,signal:m})}),(0,$.jsx)(`td`,{className:`evidence-change-cell`,children:_?(0,$.jsx)(`span`,{className:`query-evidence-new`,children:`new query`}):(0,$.jsx)(Yc,{items:o})}),(0,$.jsx)(`td`,{})]}),s&&a.map((e,t)=>(0,$.jsxs)(Q.Fragment,{children:[(0,$.jsxs)(`tr`,{className:`query-evidence-engine-row`,children:[(0,$.jsx)(`td`,{className:`evidence-query-cell`,children:(0,$.jsx)(`span`,{className:`text-label-14 text-secondary`,children:e.provider?po(e.provider):`Awaiting engine`})}),(0,$.jsx)(`td`,{children:(0,$.jsx)(ic,{state:e.citationState,className:`rounded-none border-0 bg-transparent p-0 text-label-14`,label:Uc(e.citationState,m)})}),p&&(0,$.jsx)(`td`,{children:(0,$.jsx)(Na,{queryId:e.queryId,sourceSnapshotIds:e.sourceSnapshotId?[e.sourceSnapshotId]:[],queryClass:e.queryClass,provider:e.provider,location:e.location??null})}),(0,$.jsx)(`td`,{children:(0,$.jsx)(Fc,{history:e.runHistory,signal:m})}),(0,$.jsx)(`td`,{className:`evidence-change-cell`,children:_?null:(0,$.jsx)(Yc,{items:[o[t]??e]})}),(0,$.jsx)(`td`,{children:(0,$.jsx)(q,{variant:`ghost`,className:`pointer-coarse:min-h-11`,type:`button`,title:`View ${e.provider?po(e.provider):`saved`} answer for ${e.query}`,onClick:t=>{t.stopPropagation(),c(e.id)},children:`View`})})]}),g===`detailed`&&(0,$.jsx)(`tr`,{className:`query-evidence-preview-row`,children:(0,$.jsx)(`td`,{colSpan:A,children:(0,$.jsx)(el,{item:e,mode:m,onViewFull:()=>c(e.id)},m)})})]},e.id))]},e)})]},e.queryClass??`unclassified`))]})}),D.totalRows===0&&(D.hasQuery||v!==`all`||S)?(0,$.jsx)(`p`,{className:`supporting-copy mt-3`,children:`No tracked queries match this filter.`}):null,(0,$.jsx)(Ts,{page:D.page,pageSize:D.pageSize,visibleRows:D.rows.length,totalRows:D.totalRows,onPageChange:D.setPage,itemLabel:D.hasQuery||v!==`all`||S?`matches`:`queries`})]}),(0,$.jsxs)(`p`,{className:`sr-only`,"aria-live":`polite`,children:[`Showing `,P===`cited`?`citations (sources)`:`mentions (answer text)`,`.`]})]})}function Qc(e){let t=(e.matchedTerms??[]).filter(e=>e.trim().length>2),n=Qo(e),r=[];return t.length>0&&r.push({terms:t,className:`answer-highlight-brand`}),n.length>0&&r.push({terms:n,className:`answer-highlight-competitor`}),r}function $c(e,t){let n=t.toLowerCase().replace(/^www\./,``);return(e.citedCompetitorDomains??[]).some(e=>e.toLowerCase().replace(/^www\./,``)===n)}function el({item:e,mode:t,onViewFull:n}){let[r,i]=(0,Q.useState)(!1),[a,o]=(0,Q.useState)(!1);if(t===`mentions`)return(0,$.jsx)(tl,{item:e,onViewFull:n});let s=e.evidenceUrls.length>0?e.evidenceUrls.map(t=>({uri:t,title:e.groundingSources.find(e=>e.uri===t)?.title})):e.groundingSources;return(0,$.jsxs)(`div`,{className:`query-evidence-preview space-y-3`,children:[(0,$.jsx)(`p`,{className:`text-copy-13-strong text-secondary`,children:e.evidenceUrls.length>0?`Cited sources`:s.length>0?`Grounding sources`:`Cited domains`}),s.length>0?(0,$.jsx)(`ul`,{className:`space-y-4`,children:s.slice(0,a?void 0:6).map((t,n)=>(0,$.jsxs)(`li`,{className:`min-w-0`,children:[(0,$.jsx)(os,{url:t.uri,title:t.title}),$c(e,bt(t.uri)??``)&&(0,$.jsx)(`p`,{className:`mt-1 text-copy-13 text-secondary`,children:`Competitor source`})]},`${n}-${t.uri}`))}):e.citedDomains.length>0?(0,$.jsx)(`ul`,{className:`space-y-1 text-label-14 text-secondary`,children:e.citedDomains.slice(0,a?void 0:6).map(t=>(0,$.jsxs)(`li`,{className:`[overflow-wrap:anywhere]`,children:[t,$c(e,t)?` · competitor source`:``]},t))}):(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:`No cited sources captured for this run.`}),(s.length>6||s.length===0&&e.citedDomains.length>6)&&(0,$.jsx)(q,{type:`button`,variant:`ghost`,className:`pointer-coarse:min-h-11`,"aria-expanded":a,onClick:()=>o(e=>!e),children:a?`Show fewer sources`:`View all sources`}),e.answerSnippet.trim()?(0,$.jsxs)(`details`,{open:r,className:`border-t border-subtle pt-1`,children:[(0,$.jsx)(`summary`,{className:`min-h-11 cursor-pointer py-3 text-label-14 text-secondary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-mono-400`,onClick:e=>{e.preventDefault(),i(e=>!e)},children:`Answer text`}),r&&(0,$.jsx)(tl,{item:e,onViewFull:n,contextOnly:!0})]}):(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:`No answer text captured for this run.`})]})}function tl({item:e,onViewFull:t,contextOnly:n=!1}){let{matchedTerms:r,mentionedCompetitorDomains:i,mentionedCompetitorTerms:a,recommendedCompetitors:o}=e,s=(0,Q.useMemo)(()=>Qc({matchedTerms:r,mentionedCompetitorDomains:i,mentionedCompetitorTerms:a,recommendedCompetitors:o}),[r,i,a,o]);if(!(e.answerSnippet.trim().length>0))return(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:`No answer text captured for this run.`});let c=e.answerSnippet.length>Lc;return(0,$.jsxs)(`div`,{className:`query-evidence-preview space-y-3`,children:[!n&&(0,$.jsx)(`p`,{className:`text-copy-13-strong text-secondary`,children:`Answer text`}),(0,$.jsx)(Ja,{headingLevel:4,highlightGroups:s,previewLength:Lc,children:e.answerSnippet}),(!n&&e.citedDomains.length>0||(e.mentionedCompetitorDomains?.length??0)>0)&&(0,$.jsxs)(`dl`,{className:`space-y-2 text-label-13 text-secondary`,children:[!n&&e.citedDomains.length>0&&(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`dt`,{className:`text-label-13-strong`,children:`Cited domains`}),(0,$.jsxs)(`dd`,{className:`flex flex-wrap gap-x-3 gap-y-1`,children:[e.citedDomains.slice(0,6).map(t=>(0,$.jsxs)(`span`,{className:`[overflow-wrap:anywhere]`,children:[t,$c(e,t)?` · competitor source`:``]},`c-${t}`)),e.citedDomains.length>6&&(0,$.jsxs)(`span`,{children:[`+`,e.citedDomains.length-6,` more`]})]})]}),(e.mentionedCompetitorDomains?.length??0)>0&&(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`dt`,{className:`text-label-13-strong`,children:`Competitors in answer`}),(0,$.jsxs)(`dd`,{className:`flex flex-wrap gap-x-3 gap-y-1`,children:[e.mentionedCompetitorDomains.slice(0,4).map(e=>(0,$.jsx)(`span`,{className:`[overflow-wrap:anywhere]`,children:e},`co-${e}`)),e.mentionedCompetitorDomains.length>4&&(0,$.jsxs)(`span`,{children:[`+`,e.mentionedCompetitorDomains.length-4,` more`]})]})]})]}),c&&(0,$.jsx)(q,{type:`button`,variant:`ghost`,className:`pointer-coarse:min-h-11`,onClick:e=>{e.stopPropagation(),t()},children:`View full answer`})]})}function nl({windows:e,value:t,onChange:n,label:r,formatOption:i,disabled:a=!1}){return(0,$.jsx)(`div`,{className:`segmented`,role:`group`,"aria-label":r,children:e.map(e=>(0,$.jsx)(`button`,{type:`button`,"aria-pressed":t===e,disabled:a,className:`segmented-option ${t===e?`segmented-option-active`:``}`,onClick:()=>{e!==t&&B(`window`),n(e)},children:i?i(e):e},e))})}var rl=`baseline`;function il(e,t=[]){let n=(e?.series??[]).map((e,t)=>({dataKey:`s${t}`,key:e.key,label:e.label})),r=new Map;for(let t of e?.days??[])r.set(t.date,t.values);let i=new Map(t.map(e=>[e.date,e.value]));return{rows:[...new Set([...r.keys(),...i.keys()])].sort().map(e=>{let t=r.get(e),a={date:e,[rl]:i.get(e)??null};for(let e of n)a[e.dataKey]=t?.[e.key]??0;return a}),series:n}}var al=`text-label-12-strong normal-case text-muted`;function ol({id:e,title:t,tooltip:n,meta:r,actions:i}){return(0,$.jsxs)(`div`,{className:`mb-4 flex flex-wrap items-start justify-between gap-3`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`h2`,{id:e,className:`text-heading-16 text-primary`,children:t}),n&&(0,$.jsx)(X,{text:n})]}),r&&(0,$.jsx)(`p`,{className:`mt-1 text-copy-13 text-secondary`,children:r})]}),i]})}function sl({children:e}){return(0,$.jsx)(`div`,{className:`[&>details:first-child]:border-t-0`,children:e})}function cl({label:e,meta:t,children:n}){let[r,i]=(0,Q.useState)(!1);return(0,$.jsxs)(`details`,{className:`visibility-disclosure`,"aria-label":e,onToggle:e=>i(e.currentTarget.open),children:[(0,$.jsxs)(`summary`,{className:`visibility-disclosure-summary`,children:[(0,$.jsx)(`span`,{className:`visibility-disclosure-label`,children:e}),(0,$.jsx)(`span`,{className:`visibility-disclosure-meta`,children:t})]}),r&&(0,$.jsx)(`div`,{className:`visibility-disclosure-panel`,children:n})]})}var ll={3:`lg:grid-cols-3`,4:`lg:grid-cols-4`,5:`lg:grid-cols-5`};function ul({items:e,label:t}){return(0,$.jsx)(`div`,{role:`group`,"aria-label":t,children:(0,$.jsx)(`dl`,{className:`grid grid-cols-2 gap-x-6 gap-y-4 border-y border-default py-4 sm:grid-cols-3 ${ll[e.length]??`lg:grid-cols-4`}`,children:e.map(e=>(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsxs)(`dt`,{className:`flex items-center gap-1 text-label-13 text-secondary`,children:[e.label,e.tooltip&&(0,$.jsx)(X,{text:e.tooltip})]}),(0,$.jsx)(`dd`,{className:`mt-1 truncate text-label-20-strong text-primary tabular-nums`,title:e.value,children:e.value}),e.detail&&(0,$.jsx)(`dd`,{className:`mt-0.5 text-label-13 text-secondary tabular-nums`,children:e.detail})]},e.label))})})}function dl({label:e,sortKey:t,current:n,dir:r,onSort:i,align:a}){let o=n===t;return(0,$.jsx)(`th`,{className:`py-2 ${a===`right`?`pl-4 text-right`:`text-left`}`,"aria-sort":o?r===`asc`?`ascending`:`descending`:void 0,children:(0,$.jsxs)(`button`,{type:`button`,className:`${al} cursor-pointer select-none rounded transition-colors hover:text-neutral focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-mono-400`,onClick:()=>i(t),children:[e,o&&(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`ml-0.5`,children:r===`asc`?`↑`:`↓`})]})})}function fl({label:e,align:t}){return(0,$.jsx)(`th`,{className:`py-2 ${t===`right`?`pl-4 text-right`:`text-left`}`,children:(0,$.jsx)(`span`,{className:al,children:e})})}function pl(e,t,n=`desc`){return e.key===t?{key:t,dir:e.dir===`desc`?`asc`:`desc`}:{key:t,dir:n}}function ml(e,t){return(n,r)=>{let i=n[e],a=r[e],o=typeof i==`string`&&typeof a==`string`?i.localeCompare(a):Number(i)-Number(a);return t===`asc`?o:-o}}function hl({groups:e,groupLabel:t,caption:n,childColumns:r,childRowKey:i,renderChildCells:a,pinLast:o}){let s=(0,Q.useId)(),[c,l]=(0,Q.useState)(new Set),[f,p]=(0,Q.useState)({key:`sessions`,dir:`desc`}),m=(0,Q.useMemo)(()=>{let t=ml(f.key,f.dir);return[...e].sort((e,n)=>Number(o?.(e)??!1)-Number(o?.(n)??!1)||t(e,n))},[e,f,o]),h=e=>p(t=>pl(t,e,e===`label`?`asc`:`desc`)),g=e=>l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n});return(0,$.jsx)(`div`,{className:`overflow-x-auto`,children:(0,$.jsxs)(`table`,{className:`w-full min-w-[36rem] text-label-14`,children:[(0,$.jsx)(`caption`,{className:`sr-only`,children:n}),(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{className:`border-b border-default`,children:[(0,$.jsx)(dl,{label:t,sortKey:`label`,current:f.key,dir:f.dir,onSort:h,align:`left`}),(0,$.jsx)(dl,{label:`Sessions`,sortKey:`sessions`,current:f.key,dir:f.dir,onSort:h,align:`right`}),(0,$.jsx)(dl,{label:`Organic`,sortKey:`organicSessions`,current:f.key,dir:f.dir,onSort:h,align:`right`}),(0,$.jsx)(dl,{label:`Paid`,sortKey:`paidSessions`,current:f.key,dir:f.dir,onSort:h,align:`right`}),(0,$.jsx)(fl,{label:`Share`,align:`right`})]})}),(0,$.jsx)(`tbody`,{children:m.map((e,t)=>{let n=c.has(e.label),o=`${s}-group-${t}`,l=e.sources.length;return(0,$.jsxs)(Q.Fragment,{children:[(0,$.jsxs)(`tr`,{className:`border-t border-subtle`,children:[(0,$.jsx)(`td`,{className:`py-2 pr-3`,children:(0,$.jsxs)(`button`,{type:`button`,"aria-expanded":n,"aria-controls":n?o:void 0,onClick:()=>g(e.label),className:`inline-flex min-h-8 max-w-full items-center gap-2 rounded text-left text-strong hover:text-primary focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-mono-400`,children:[n?(0,$.jsx)(d,{"aria-hidden":`true`,className:`size-3.5 shrink-0 text-secondary`}):(0,$.jsx)(u,{"aria-hidden":`true`,className:`size-3.5 shrink-0 text-muted`}),(0,$.jsx)(`span`,{className:`truncate`,title:e.label,children:e.label}),(0,$.jsxs)(`span`,{className:`shrink-0 text-label-12 text-secondary tabular-nums`,children:[l,` `,l===1?`source`:`sources`]})]})}),(0,$.jsx)(`td`,{className:`py-2 pl-4 text-right text-primary tabular-nums`,children:e.sessions.toLocaleString()}),(0,$.jsx)(`td`,{className:`py-2 pl-4 text-right text-secondary tabular-nums`,children:e.organicSessions.toLocaleString()}),(0,$.jsx)(`td`,{className:`py-2 pl-4 text-right text-secondary tabular-nums`,children:e.paidSessions.toLocaleString()}),(0,$.jsx)(`td`,{className:`py-2 pl-4 text-right text-secondary tabular-nums`,children:G(e.share)})]}),n&&(0,$.jsx)(`tr`,{id:o,children:(0,$.jsx)(`td`,{colSpan:5,className:`pb-3 pl-6`,children:(0,$.jsx)(`div`,{className:`overflow-x-auto material-base px-3 pb-1`,children:(0,$.jsxs)(`table`,{className:`w-full min-w-[32rem] text-label-13`,children:[(0,$.jsx)(`caption`,{className:`sr-only`,children:`${e.label} sources`}),(0,$.jsx)(`thead`,{children:(0,$.jsx)(`tr`,{children:r.map(e=>(0,$.jsx)(fl,{label:e.label,align:e.align},e.label))})}),(0,$.jsx)(`tbody`,{children:e.sources.map(e=>(0,$.jsx)(`tr`,{className:`border-t border-subtle`,children:a(e)},i(e)))})]})})})})]},e.label)})})]})})}function gl(e,t){return e===`other`?ga.textDim:ua[t%ua.length]}function _l({input:e,baseline:t,baselineLabel:n,label:r,height:i=224}){let{rows:a,series:o}=(0,Q.useMemo)(()=>il(e,t),[e,t]),[s,c]=(0,Q.useState)(new Set),[l,u]=(0,Q.useState)(!1);if(a.length===0)return null;let d=o.filter(e=>!s.has(e.key)),f=new Map(o.map(e=>[e.dataKey,e.label])),p=e=>c(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n});return(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{role:`img`,"aria-label":r,style:{height:i},children:(0,$.jsx)(I,{width:`100%`,height:`100%`,children:(0,$.jsxs)(ne,{data:a,margin:{top:4,right:4,bottom:0,left:0},children:[(0,$.jsx)(M,{stroke:xa,vertical:!1}),(0,$.jsx)(P,{dataKey:`date`,tick:va,tickLine:!1,axisLine:{stroke:Ca},tickFormatter:fa,minTickGap:24}),(0,$.jsx)(ee,{tick:va,tickLine:!1,axisLine:!1,allowDecimals:!1,width:36}),(0,$.jsx)(N,{...Sa,labelFormatter:_a,formatter:(e,t)=>[typeof e==`number`?e.toLocaleString():String(e??0),t===`baseline`?n??`Total`:f.get(String(t))??String(t)]}),d.map(e=>{let t=gl(e.key,o.indexOf(e));return(0,$.jsx)(L,{type:`monotone`,dataKey:e.dataKey,name:e.dataKey,stackId:`stack`,stroke:t,fill:t,fillOpacity:.35,strokeWidth:1.5},e.dataKey)}),l&&n&&(0,$.jsx)(te,{type:`monotone`,dataKey:`baseline`,name:`baseline`,stroke:ga.textFaint,strokeWidth:1.5,strokeDasharray:`5 4`,dot:!1,connectNulls:!1})]})})}),(0,$.jsxs)(`fieldset`,{className:`mt-2 flex flex-wrap gap-x-5 text-label-13 text-secondary`,children:[(0,$.jsx)(`legend`,{className:`sr-only`,children:`${r} series`}),o.map((e,t)=>(0,$.jsxs)(`label`,{className:`flex min-h-9 items-center gap-2`,children:[(0,$.jsx)(`input`,{type:`checkbox`,className:`size-4 accent-mono-200 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-mono-400`,checked:!s.has(e.key),onChange:()=>p(e.key)}),(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`inline-block size-2.5 shrink-0 rounded-sm`,style:{backgroundColor:gl(e.key,t)}}),e.label]},e.key)),n&&(0,$.jsxs)(`label`,{className:`flex min-h-9 items-center gap-2`,children:[(0,$.jsx)(`input`,{type:`checkbox`,className:`size-4 accent-mono-200 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-mono-400`,checked:l,onChange:()=>u(e=>!e)}),(0,$.jsx)(`svg`,{"aria-hidden":`true`,width:`18`,height:`10`,viewBox:`0 0 18 10`,className:`shrink-0`,children:(0,$.jsx)(`line`,{x1:`0`,y1:`5`,x2:`18`,y2:`5`,stroke:ga.textFaint,strokeWidth:`2`,strokeDasharray:`5 3`})}),n]})]})]})}var vl=[`sessions`,`activeUsers`,`organicSessions`,`engagementRate`,`keyEvents`],yl=`canonry.siteTraffic.slots`;function bl(e){return typeof e==`string`&&Ce.some(t=>t===e)}function xl(){try{let e=JSON.parse(window.localStorage.getItem(yl)??`null`);if(Array.isArray(e)&&e.length===vl.length&&e.every(bl))return[...e]}catch{}return[...vl]}function Sl(e){try{window.localStorage.setItem(yl,JSON.stringify(e))}catch{}}function Cl(e,t,n){let r=$e(e,t);return r===null||t===null?{kind:`note`,text:`No earlier data`}:{kind:`delta`,amount:G(Math.abs(t),rt.percent),direction:t>0?`up`:t<0?`down`:`flat`,tone:r===Xe.better?`better`:r===Xe.worse?`worse`:`neutral`,basis:n}}function wl({overview:e,refreshing:t=!1}){let[n,r]=(0,Q.useState)(xl),[i,a]=(0,Q.useState)(0),o=rn(e.window)?Be[e.window]:null,s=o===null?`This period`:`Last ${o} days`,c=o===null?`vs the previous period`:`vs prior ${o} days`,l=(e,t)=>r(n=>{let r=[...n],i=r.indexOf(t);return i!==-1&&i!==e&&(r[i]=r[e]),r[e]=t,Sl(r),r}),u=n.map((t,n)=>({key:t,slot:`slot-${n}`,label:H[t].label,value:Ke(t,e.totals[t],{compact:!0}),exactValue:Ke(t,e.totals[t]),change:Cl(t,e.changePct[t],c),series:e.days.map(e=>({date:e.date,previousDate:e.previousDate,current:e.values[t],previous:e.previousValues[t]})),interactive:!0,picker:{ariaLabel:`Figure ${n+1}`,value:t,options:Ce.map(e=>({value:e,label:H[e].label})),onChange:e=>{bl(e)&&l(n,e)}},formatValue:e=>Ke(t,e,{compact:!0}),formatExact:e=>Ke(t,e),allowDecimals:H[t].unit!==ye.count})),d=n[i]??vl[0],f=e.current.startDate&&e.current.endDate&&e.previous.startDate&&e.previous.endDate?`${Tl(e.current.startDate,e.current.endDate,!0)} vs ${Tl(e.previous.startDate,e.previous.endDate,!1)}`:void 0;return(0,$.jsx)(Os,{name:`Site traffic figures`,groups:[{key:`site-traffic`,figures:u}],selected:[d],onSelect:e=>{let t=n.indexOf(e);t!==-1&&a(t)},span:f,currentLabel:s,previous:{label:`Previous period`,available:!0},notice:e.syncedAt===null?`These figures fill in after the next GA4 sync.`:void 0,emptyChartMessage:`No daily ${H[d].label.toLowerCase()} yet.`,refreshing:t})}function Tl(e,t,n){let r=(e,t)=>new Date(`${e}T00:00:00Z`).toLocaleDateString(`en-US`,{month:`short`,day:`numeric`,...t?{year:`numeric`}:{},timeZone:`UTC`});return`${r(e,!1)} to ${r(t,n)}`}function El(e){return e?_a(e.slice(0,10)):`—`}function Dl({children:e,onClick:t,disabled:n,title:r}){return(0,$.jsx)(`button`,{type:`button`,title:r,disabled:n,onClick:t,className:`rounded px-1.5 py-0.5 text-button-14 text-secondary hover:bg-surface-hover hover:text-strong focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-mono-400 disabled:cursor-not-allowed disabled:opacity-50`,children:e})}function Ol({rows:e,expanded:t,loading:n,onToggle:r,actions:i,lastReadLabel:a,empty:o}){let s=i?6:5,c=(e,a)=>{let o=t.has(e.url),s=n?.has(e.url)??!1;return(0,$.jsxs)(`tr`,{className:`group`,children:[(0,$.jsx)(`td`,{className:`max-w-md ${a?`pl-9`:``}`,children:(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-0.5`,children:[e.isIndex&&!a&&(0,$.jsx)(`button`,{type:`button`,"aria-expanded":o,"aria-label":`${o?`Hide`:`Show`} the sitemaps in ${e.label}`,className:`rounded p-0.5 text-secondary hover:text-strong focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-mono-400`,onClick:()=>r(e.url),children:o?(0,$.jsx)(d,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}):(0,$.jsx)(u,{className:`h-3.5 w-3.5`,"aria-hidden":`true`})}),(0,$.jsx)(Ss,{value:e.label,title:e.url,className:`font-mono text-label-13 text-neutral`}),e.isIndex&&(0,$.jsx)(`span`,{className:`shrink-0 text-label-12 text-secondary`,children:s?`Loading…`:e.files?`Index · ${e.files.length} ${e.files.length===1?`sitemap`:`sitemaps`}`:`Index`}),e.kind&&(0,$.jsx)(`span`,{className:`shrink-0 text-label-12 text-secondary`,children:e.kind}),e.isDefault&&(0,$.jsxs)(`span`,{className:`flex shrink-0 items-center gap-1 text-label-12 text-secondary`,children:[`Default`,(0,$.jsx)(X,{text:`Canonry uses this sitemap when a command names none.`})]})]})}),(0,$.jsx)(`td`,{children:(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 whitespace-nowrap`,children:[(0,$.jsx)(J,{tone:e.status.tone,children:e.status.label}),e.status.detail&&(0,$.jsx)(`span`,{className:`text-label-12 text-secondary`,children:e.status.detail})]})}),(0,$.jsx)(`td`,{className:`text-right tabular-nums text-secondary`,children:e.urls===null?`—`:e.urls.toLocaleString()}),(0,$.jsx)(`td`,{className:`whitespace-nowrap tabular-nums text-secondary`,children:e.missing?`—`:e.submittedAt?El(e.submittedAt):a?(0,$.jsx)(`span`,{title:`Submitted through its sitemap index.`,children:`Via index`}):(0,$.jsx)(`span`,{title:`Nobody submitted it: the engine found it on its own.`,children:`Not submitted`})}),(0,$.jsx)(`td`,{className:`whitespace-nowrap tabular-nums text-secondary`,children:e.missing?`—`:e.lastReadAt?El(e.lastReadAt):`Not yet`}),i&&(0,$.jsx)(`td`,{className:`text-right`,children:(0,$.jsx)(`div`,{className:`flex justify-end gap-0.5 whitespace-nowrap ${e.missing?``:`opacity-0 transition-opacity group-hover:opacity-100 group-focus-within:opacity-100 pointer-coarse:opacity-100`}`,children:i(e,a)})})]},`${a?.url??``}|${e.url}`)};return(0,$.jsx)(`div`,{className:`overflow-x-auto`,children:(0,$.jsxs)(`table`,{className:`data-table w-full text-label-14`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{className:`text-left`,children:`Sitemap`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Status`}),(0,$.jsx)(`th`,{className:`text-right`,children:`URLs`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Submitted`}),(0,$.jsx)(`th`,{className:`text-left`,children:a}),i&&(0,$.jsx)(`th`,{className:`text-right`,children:(0,$.jsx)(`span`,{className:`sr-only`,children:`Actions`})})]})}),(0,$.jsxs)(`tbody`,{children:[e.length===0&&(0,$.jsx)(`tr`,{children:(0,$.jsx)(`td`,{colSpan:s,className:`py-6 text-center text-secondary`,children:o})}),e.map(e=>(0,$.jsxs)(Q.Fragment,{children:[c(e,null),e.isIndex&&t.has(e.url)&&(e.files??[]).map(t=>c(t,e))]},e.url))]})]})})}var kl=10,Al={ok:`positive`,pending:`neutral`,warnings:`caution`,errors:`negative`,other:`neutral`},jl={site:`on your site`,google:`in Google`,bing:`in Bing`};function Ml(e){return e.map(e=>jl[e]).join(` and `)}function Nl(e){let t=[e.errors?`${e.errors} error${e.errors===1?``:`s`}`:``,e.warnings?`${e.warnings} warning${e.warnings===1?``:`s`}`:``].filter(Boolean);return t.length>0?t.join(` · `):void 0}function Pl(e){let{engine:t,data:n,label:r}=e,[i,a]=(0,Q.useState)(!1),[o,s]=(0,Q.useState)(``),[c,l]=(0,Q.useState)(new Set),[u,d]=(0,Q.useState)(new Set),[f,p]=(0,Q.useState)(``),m=n?.sitemaps??[],h=t=>({url:t.url,label:r(t.url),isIndex:t.isIndex,kind:!t.isIndex&&t.type&&!/^sitemap$/i.test(t.type)?t.type:void 0,status:{label:t.statusLabel,tone:Al[t.state],detail:Nl(t)},urls:t.urlCount,submittedAt:t.submittedAt,lastReadAt:t.lastReadAt,isDefault:e.defaultUrl===t.url}),g=(n?.missing??[]).map(e=>({url:e.url,label:r(e.url),isIndex:!1,status:u.has(e.url)?{label:`Sent`,tone:`neutral`,detail:`shows after the next sync`}:{label:`Missing`,tone:`caution`,detail:Ml(e.foundIn)},urls:null,submittedAt:null,lastReadAt:null,missing:!0})),_=m.filter(e=>e.parentUrl===null).map(e=>({...h(e),files:e.isIndex?m.filter(t=>t.parentUrl===e.url).map(h):void 0})),v=Ds({rows:[...g,..._],getSearchText:e=>`${e.url} ${e.files?.map(e=>e.url).join(` `)??``}`,pageSize:kl});async function y(t){let n=await e.onSubmit(t);return n.length>0&&d(e=>new Set([...e,...n])),n}let b=g.filter(e=>!u.has(e.url)).length,x=_.filter(e=>e.isIndex).length;return(0,$.jsxs)(Z,{className:`surface-card`,children:[(0,$.jsxs)(`div`,{className:`section-head section-head-inline`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`h3`,{children:`Sitemaps`}),(0,$.jsx)(X,{text:`Canonry compares the sitemaps your site lists (from the latest Site Health scan) with what ${t} and the other engine have, and shows what ${t} is missing. Submitting asks ${t} to read a sitemap; it does not guarantee indexing.`})]}),b>0&&(0,$.jsx)(X,{tone:`caution`,label:`${b} missing`,text:`${b===1?`One sitemap your site or the other engine has is`:`${b} sitemaps your site or the other engine has are`} not in ${t}. Add ${b===1?`it`:`them`} from the list.`})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[n&&(0,$.jsxs)(`span`,{className:`text-label-13 text-secondary`,children:[`As of `,Nn(n.syncedAt)]}),!e.readOnly&&(e.canSubmit?(0,$.jsx)(q,{type:`button`,variant:`ghost`,size:`sm`,disabled:i||e.submitting,onClick:()=>a(!0),children:`Add another`}):e.submitBlocked)]})]}),i&&e.canSubmit&&!e.readOnly&&(0,$.jsxs)(`form`,{className:`mb-3 flex flex-col gap-2 sm:flex-row`,onSubmit:e=>{e.preventDefault();let t=o.trim();t&&y([t]).then(e=>{e.includes(t)&&(s(``),a(!1))})},children:[(0,$.jsx)(`input`,{"aria-label":`Sitemap URL`,className:`flex-1 rounded border border-strong bg-transparent px-2 py-1.5 font-mono text-label-13 text-strong placeholder-mono-400 focus:border-mono-500 focus:outline-none`,type:`url`,autoFocus:!0,placeholder:`https://example.com/sitemap.xml`,value:o,onChange:e=>s(e.target.value)}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(q,{type:`submit`,size:`sm`,disabled:e.submitting||!o.trim(),children:e.submitting?`Submitting…`:`Submit to ${t}`}),(0,$.jsx)(q,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>{a(!1),s(``)},children:`Cancel`})]})]}),e.loadError?(0,$.jsxs)(`p`,{className:`text-copy-14 text-negative`,children:[`Could not load sitemaps: `,e.loadError]}):n===void 0?(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:`Loading sitemaps…`}):n===null?e.notRead:(0,$.jsxs)($.Fragment,{children:[(_.length>0||g.length>0)&&(0,$.jsxs)(`div`,{className:`mb-2 flex flex-wrap items-center justify-between gap-2`,children:[(0,$.jsx)(js,{className:`w-full sm:w-64`,value:f,onChange:e=>{p(e),v.setQuery(e)},label:`Filter sitemaps`,placeholder:`Filter sitemaps…`}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,$.jsxs)(`span`,{className:`text-label-13 text-secondary`,children:[_.length,` in `,t,x>0?`, ${x} ${x===1?`index`:`indexes`}`:``]}),e.bulk]})]}),(0,$.jsx)(Ol,{rows:v.rows,expanded:c,onToggle:e=>l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),lastReadLabel:`Last read`,empty:`${t} lists no sitemaps for this site, and Canonry found none to add.`,actions:e.readOnly?void 0:n=>n.missing?(0,$.jsx)(Dl,{disabled:!e.canSubmit||e.submitting||u.has(n.url),onClick:()=>void y([n.url]),children:u.has(n.url)?`Sent`:`Add to ${t}`}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Dl,{disabled:!e.canSubmit||e.submitting,onClick:()=>void y([n.url]),children:n.submittedAt?`Resubmit`:`Submit`}),e.onInspect&&(0,$.jsx)(Dl,{disabled:e.inspecting,onClick:()=>e.onInspect(n.url),children:`Inspect URLs`}),e.onSetDefault&&!n.isDefault&&(0,$.jsx)(Dl,{disabled:e.settingDefault,title:`Canonry uses this sitemap when a command names none.`,onClick:()=>e.onSetDefault(n.url),children:`Set as default`})]})}),v.totalRows>kl&&(0,$.jsx)(Ts,{page:v.page,pageSize:kl,visibleRows:v.rows.length,totalRows:v.totalRows,onPageChange:v.setPage,itemLabel:`sitemaps`})]})]})}function Fl({label:e,items:t,disabled:n=!1,menuLabel:r}){let[i,a]=(0,Q.useState)(!1),o=(0,Q.useRef)(null),s=(0,Q.useRef)(null),c=(0,Q.useId)();return(0,Q.useEffect)(()=>{if(!i)return;o.current?.querySelector(`[role="menuitem"]:not([disabled])`)?.focus();let e=e=>{o.current&&!o.current.contains(e.target)&&a(!1)},t=e=>{e.key===`Escape`&&(a(!1),s.current?.focus())};return document.addEventListener(`pointerdown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`pointerdown`,e),document.removeEventListener(`keydown`,t)}},[i]),(0,$.jsxs)(`div`,{className:`relative inline-flex`,ref:o,children:[(0,$.jsxs)(q,{ref:s,type:`button`,variant:`outline`,size:`sm`,disabled:n,"aria-haspopup":`menu`,"aria-expanded":i,"aria-controls":i?c:void 0,onClick:()=>a(e=>!e),children:[e,(0,$.jsx)(d,{className:`h-3.5 w-3.5`,"aria-hidden":`true`})]}),i&&(0,$.jsx)(`div`,{id:c,role:`menu`,"aria-label":r,className:`project-subnav-menu min-w-[16rem]`,onKeyDown:e=>{let t=[...e.currentTarget.querySelectorAll(`[role="menuitem"]:not([disabled])`)],n=t.indexOf(document.activeElement),r=e.key===`ArrowDown`?(n+1)%t.length:e.key===`ArrowUp`?(n-1+t.length)%t.length:null;r!==null&&(e.preventDefault(),t[r]?.focus())},onBlur:e=>{o.current?.contains(e.relatedTarget)||a(!1)},children:t.map(e=>(0,$.jsxs)(`button`,{type:`button`,role:`menuitem`,tabIndex:-1,disabled:e.disabled,className:`project-subnav-menu-item flex flex-col items-start gap-0.5 text-left disabled:cursor-not-allowed disabled:opacity-50`,onClick:()=>{a(!1),e.onSelect()},children:[(0,$.jsx)(`span`,{children:e.label}),e.description&&(0,$.jsx)(`span`,{className:`text-label-13 text-secondary`,children:e.description})]},e.key))})]})}function Il(e){let t=e.details;if(e.code!==`FORBIDDEN`||!t||t.reason!==`gsc-api-disabled`)return null;let n=typeof t.projectNumber==`string`?t.projectNumber:void 0;return{title:`Enable the Search Console API`,message:`Your Google Cloud project${n?` (${n})`:``} hasn't enabled the Search Console API. Enable the Search Console API and the Indexing API, wait ~2–5 minutes, then retry.`,enableUrl:typeof t.enableUrl==`string`?t.enableUrl:void 0,indexingApiUrl:typeof t.indexingApiUrl==`string`?t.indexingApiUrl:void 0,projectNumber:n}}var Ll=`Search Console is not connected yet. Your Canonry team can set this up.`,Rl=[`7d`,`30d`,`90d`,`all`],zl=500,Bl=[{key:`clicks`,label:`Clicks`,color:ua[1],format:e=>e.toLocaleString()},{key:`impressions`,label:`Impressions`,color:ua[4],format:e=>e.toLocaleString()},{key:`ctr`,label:`CTR`,color:ya.caution,format:e=>G(e)},{key:`position`,label:`Avg position`,color:ua[2],inverted:!0,format:e=>e.toFixed(1)}],Vl=25,Hl=`canonry:google-oauth-complete`;function Ul(e,t,n){if(!e)return{kind:`note`,text:`No comparison period`};if(!e.comparable)return{kind:`note`,text:`Property-level comparison unavailable`};let r=`${e.days} ${e.days===1?`day`:`days`}`,i=`vs prior ${r}`,a=e=>e===!!n?`worse`:`better`,o=t===`ctr`||t===`position`?e.difference?.[t]:void 0;if(o!=null&&Number.isFinite(o))return o===0?{kind:`delta`,amount:t===`ctr`?`0 pts`:`0`,direction:`flat`,tone:`neutral`,basis:i}:{kind:`delta`,amount:t===`ctr`?`${bn(Math.abs(o)).magnitude} pts`:Tn(o),direction:o>0?`up`:`down`,tone:a(o>0),basis:i};let s=e.change[t];if(s===null||!Number.isFinite(s)){let n=e.prior[t],i=e.trailing[t];return n!==null&&i!==null&&n<=0&&i>0?{kind:`note`,text:`New in the last ${r}`}:n===null||n<=0?{kind:`note`,text:`No prior ${r} to compare`}:i===null?{kind:`note`,text:`No value in the last ${r}`}:{kind:`note`,text:`Comparison unavailable`}}return s===0?{kind:`delta`,amount:`0%`,direction:`flat`,tone:`neutral`,basis:i}:{kind:`delta`,amount:G(Math.abs(s)),direction:s>0?`up`:`down`,tone:a(s>0),basis:i}}var Wl=[{key:`google-indexed`,engine:`google`,color:ua[0]},{key:`bing-indexed`,engine:`bing`,color:ua[6]}];function Gl(e){if(!e)return`Tile percentages compare the selected window with the equal-length period before it.`;let{days:t,basis:n,prior:r,trailing:i}=e,a=t===1?`day`:`days`,o=`${r.startDate} to ${r.endDate}`,s=`Tile percentages compare these ${t} ${a} (${`${i.startDate} to ${i.endDate}`}) with the ${t} ${a} before them (${o}).`;return n===`split-window`?`${s} That is the trailing half of the selected window against its own earlier half: there is no equal-length period before the window with synced data to compare it against.`:s}function Kl(e,t){let n;try{n=new URL(e)}catch{return e}let r=`${n.pathname}${n.search}`;if(t?.startsWith(`sc-domain:`)){if(n.hostname===t.slice(10))return r}else if(t&&e.startsWith(t.replace(/\/?$/,`/`)))return`/${e.slice(t.replace(/\/?$/,`/`).length)}`;return`${n.host}${r}`}function ql({projectName:e,refreshNonce:t}){let n=S(),{isAdmin:r}=qn(),i=We(),[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)([]),[l,u]=(0,Q.useState)([]),[d,f]=(0,Q.useState)([]),[p,m]=(0,Q.useState)(null),[h,g]=(0,Q.useState)([]),[_,v]=(0,Q.useState)([]),[y,b]=(0,Q.useState)(null),[x,C]=(0,Q.useState)(``),[T,E]=(0,Q.useState)(``),[D,O]=(0,Q.useState)(`30`),[k,M]=(0,Q.useState)(!1),[N,P]=(0,Q.useState)(`30d`),[F,I]=(0,Q.useState)(null),L=w({...Zi({client:K,path:{name:e},query:F?{surface:`index-coverage`,...F}:{surface:`index-coverage`,window:N}}),staleTime:Qn,placeholderData:j}),[R,ee]=(0,Q.useState)([`clicks`,`impressions`]),[te,ne]=(0,Q.useState)(!0),[re,ie]=(0,Q.useState)(null),[z,ae]=(0,Q.useState)(0),[B,V]=(0,Q.useState)({startDate:``,endDate:``,query:``,page:``}),[oe,se]=(0,Q.useState)(0),[ce,le]=(0,Q.useState)(!1),[ue,de]=(0,Q.useState)(0),[fe,pe]=(0,Q.useState)(!1),[H,me]=(0,Q.useState)(``),[he,ge]=(0,Q.useState)(!0),[_e,ve]=(0,Q.useState)(!1),[ye,be]=(0,Q.useState)(!1),[xe,Ce]=(0,Q.useState)(!1),[we,Te]=(0,Q.useState)(!1),[Ee,U]=(0,Q.useState)(!1),[De,Oe]=(0,Q.useState)(!1),[W,ke]=(0,Q.useState)(null),[je,Me]=(0,Q.useState)(!1),[Ne,Pe]=(0,Q.useState)(null),[Fe,Ie]=(0,Q.useState)(!1),[Le,Re]=(0,Q.useState)(!1),[ze,Be]=(0,Q.useState)(!1),[He,Ue]=(0,Q.useState)(!1),[Ge,Ke]=(0,Q.useState)(`indexed`),[Je,Ye]=(0,Q.useState)(null),Xe=!!(B.query.trim()||B.page.trim()||Je),Qe=Je!==null,$e=(0,Q.useMemo)(()=>{if(!Je)return d;let{key:e,dir:t}=Je;return[...d].sort((n,r)=>{let i=e===zn.CTR?Number.isFinite(n.ctr)?n.ctr:0:n[e],a=e===zn.CTR?Number.isFinite(r.ctr)?r.ctr:0:r[e];return t===`asc`?i-a:a-i})},[d,Je]),et=Ds({rows:$e,pageSize:25}),tt=fe?et.rows:$e,[nt,rt]=(0,Q.useState)([]),[it,ot]=(0,Q.useState)(null),[st,ct]=(0,Q.useState)(1),lt=(0,Q.useMemo)(()=>{if(nt.length<2)return null;let e=nt[nt.length-1],t=nt[nt.length-2];return{indexed:e.indexed-t.indexed,notIndexed:e.notIndexed-t.notIndexed}},[nt]);(0,Q.useEffect)(()=>{ct(1)},[W,Ge,it]);let ut=(0,Q.useMemo)(()=>it?(W?.reasonGroups??[]).find(e=>e.reason===it):void 0,[W,it]),dt=(0,Q.useMemo)(()=>W?Ge===`indexed`?W.indexed:Ge===`deindexed`?W.deindexed:Ge===`notIndexed`?it?ut?.urls??[]:(W.reasonGroups??[]).length===0?W.notIndexed:[]:[]:[],[W,Ge,it,ut]),ft=Math.max(1,Math.ceil(dt.length/Vl)),pt=Math.min(Math.max(1,st),ft),mt=(pt-1)*Vl,ht=(0,Q.useMemo)(()=>W?.indexed.slice(mt,mt+Vl)??[],[W,mt]),gt=(0,Q.useMemo)(()=>W?.notIndexed.slice(mt,mt+Vl)??[],[W,mt]),vt=(0,Q.useMemo)(()=>W?.deindexed.slice(mt,mt+Vl)??[],[W,mt]),bt=(0,Q.useMemo)(()=>(ut?.urls??[]).slice(mt,mt+Vl),[ut,mt]),[xt,St]=(0,Q.useState)(!1),[Ct,wt]=(0,Q.useState)(null),[Tt,Et]=(0,Q.useState)(null),[Dt,Ot]=(0,Q.useState)(null),[kt,At]=(0,Q.useState)(null);function jt(e,t){let n=Fo(e),r=Il(n);r?(Et(r),wt(null)):(Et(null),wt(n.message||t))}let Mt=s.find(e=>e.connectionType===`gsc`),Nt=(Mt?.scopes??[]).includes(`https://www.googleapis.com/auth/webmasters`),Pt=w({...Cr({client:K,path:{name:e}}),staleTime:Qn,enabled:!!Mt?.propertyId&&!i}),Ft=Pt.data?.google?.sitemaps??[],It=Ft.filter(e=>e.parentUrl===null),Lt=It.filter(e=>e.isIndex).map(e=>e.url),Rt=Lt.length>0?Lt:It.map(e=>e.url),zt=Lt.length,Bt=zt===1?`Resubmit sitemap index`:zt>1?`Resubmit sitemap indexes`:`Resubmit all sitemaps`,Vt=d.length>0||h.length>0||_.length>0,Ht=gs(),Ut=Eo();async function Gt(t,r=!1){if(i)u([]);else if(!t)u([]),C(``);else{be(!0);try{let{sites:i}=await n.fetchQuery({...oi({client:K,path:{name:e}}),staleTime:r?0:Qn});u(i),C(t.propertyId??i[0]?.siteUrl??``),Et(null)}catch(e){u([]),jt(e,`Failed to load Search Console properties`)}finally{be(!1)}}}async function qt(t){Te(!0);let r=t??oe;try{let t=Xe?zl:25,i=Xe?0:r,a={limit:String(t)};B.startDate&&(a.startDate=B.startDate),B.endDate&&(a.endDate=B.endDate),B.query&&(a.query=B.query),B.page&&(a.page=B.page),i>0&&(a.offset=String(i)),N&&N!==`all`&&!B.startDate&&(a.window=N);let o=await n.fetchQuery({...Dr({client:K,path:{name:e},query:a}),staleTime:Qn}),s=o.rows;Xe?(le(!1),f(s),de(s.length),pe(!0)):(le(i+s.length<o.totalMatching),f(s),de(0),pe(!1))}catch(e){f([]),le(!1),de(0),wt(e instanceof Error?e.message:`Failed to load GSC performance data`)}finally{Te(!1)}}async function Jt(){try{let t={};B.startDate&&(t.startDate=B.startDate),B.endDate&&(t.endDate=B.endDate),N&&N!==`all`&&!B.startDate&&(t.window=N);let r=await n.fetchQuery({...Ui({client:K,path:{name:e},query:t}),staleTime:Qn});m(r),I(t.startDate||t.endDate?{...t.startDate?{startDate:t.startDate}:{},...t.endDate?{endDate:t.endDate}:{}}:null)}catch{m(null)}}async function Yt(t=!1){U(!0);try{let r=H.trim()||void 0,i={limit:`20`};r&&(i.url=r);let[a,o]=await Promise.all([n.fetchQuery({...Or({client:K,path:{name:e},query:i}),staleTime:t?0:Qn}),n.fetchQuery({...xr({client:K,path:{name:e}}),staleTime:t?0:Qn})]);g(a),v(o)}catch(e){g([]),v([]),wt(e instanceof Error?e.message:`Failed to load GSC inspection history`)}finally{U(!1)}}async function Xt(t=!1){Me(!0);try{let[r,i]=await Promise.all([n.fetchQuery({...ii({client:K,path:{name:e}}),staleTime:t?0:Qn}),n.fetchQuery({...ei({client:K,path:{name:e}}),staleTime:t?0:Qn}).catch(()=>[])]);ke(r),rt(i)}catch(e){ke(null),rt([]),wt(e instanceof Error?e.message:`Failed to load coverage data`)}finally{Me(!1)}}async function Zt(t){St(!0),wt(null);try{let{succeeded:n,failed:r,total:i}=(await Ve(e,{urls:t})).summary;Xn({title:`Indexing requested`,detail:r===0?`${n} URL${n===1?``:`s`} submitted for indexing.`:`${n}/${i} submitted successfully, ${r} failed.`,tone:r===0?`positive`:`caution`,dedupeKey:`gsc:indexing:${e}`,dedupeMode:`replace`})}catch(e){wt(e instanceof Error?e.message:`Failed to request indexing`)}finally{St(!1)}}async function Qt(){St(!0),wt(null);try{let{succeeded:t,failed:n,total:r}=(await Ve(e,{urls:[],allUnindexed:!0})).summary;Xn({title:`Indexing requested`,detail:n===0?`${t} unindexed URL${t===1?``:`s`} submitted for indexing.`:`${t}/${r} submitted successfully, ${n} failed.`,tone:n===0?`positive`:`caution`,dedupeKey:`gsc:indexing-all:${e}`,dedupeMode:`replace`})}catch(e){wt(e instanceof Error?e.message:`Failed to request indexing`)}finally{St(!1)}}async function $t(t){let n=[];if(!Nt||t.length===0)return n;let r=[...new Set(t)];Re(!0),wt(null),Pe({completed:0,total:r.length});let i=0,a=0,o=0,s=null;try{for(let t=0;t<r.length;t+=50){let c=r.slice(t,t+50);try{let t=await Wt(e,c);n.push(...t.results.filter(e=>e.status===`accepted`).map(e=>e.sitemapUrl)),i+=t.summary.accepted,a+=t.summary.failed,o+=c.length,Pe({completed:o,total:r.length})}catch(t){o+=c.length;let l=c.length,u=r.length-o,d=t instanceof Error?t.message:`The batch request failed`,f=`${i} accepted, ${a} failed, ${l} unconfirmed, ${u} not attempted. Google may still process accepted sitemaps; indexing is not guaranteed.`;return s=`Sitemap submission stopped after a batch request failed. ${f} ${d}`,wt(s),Xn({title:`Sitemap resubmission partially completed`,detail:f,tone:`caution`,dedupeKey:`gsc:sitemap-submit:${e}`,dedupeMode:`replace`}),n}}let t=r.length;Xn({title:a===0?`Sitemap submitted to Google`:`Some sitemap submissions need attention`,detail:a===0?`Google accepted the sitemap submission/refetch request; indexing is not guaranteed.`:`Google accepted ${i}/${t} sitemap submissions; ${a} failed. Indexing is not guaranteed.`,tone:a===0?`positive`:`caution`,dedupeKey:`gsc:sitemap-submit:${e}`,dedupeMode:`replace`})}catch(e){wt(e instanceof Error?e.message:`Failed to submit sitemap to Google`)}finally{Re(!1),Pe(null),s&&wt(s)}return n}async function en(){let e=Ft.filter(e=>!e.isIndex).map(e=>e.url),t=Lt.filter(e=>!Ft.some(t=>t.parentUrl===e));await $t([...e,...t])}async function tn(t){Ie(!0),wt(null);try{await qe(e,`gsc`,t),await Zn(n,`google`),c(e=>e.map(e=>e.connectionType===`gsc`?{...e,sitemapUrl:t}:e)),Xn({title:`Default sitemap updated`,detail:t,tone:`positive`,dedupeKey:`gsc:sitemap-default:${e}`,dedupeMode:`replace`})}catch(e){wt(e instanceof Error?e.message:`Failed to set the default sitemap`)}finally{Ie(!1)}}async function nn(t){try{await Ut.mutateAsync({projectName:e,projectLabel:e,opts:t?{sitemapUrl:t}:void 0})}catch{}}async function rn(){try{let t=(await n.fetchQuery({..._r({client:K,path:{name:e},query:{kind:Se[`gsc-sync`],limit:1}}),staleTime:Qn}))[0];At(t?.status===Ae.failed&&t.error?`Last saved Search Console sync failed: ${On(t.error)}`:null)}catch{At(`Saved Search Console sync status is unavailable.`)}}async function on(){ge(!0),wt(null);try{let[t,a]=await Promise.all([i||!r?Promise.resolve(null):Kt().catch(()=>null),n.fetchQuery({...Sr({client:K,path:{name:e}}),staleTime:Qn}).catch(()=>[])]);o(!!t?.google?.configured),c(a);let s=a.find(e=>e.connectionType===`gsc`);C(s?.propertyId??``),await Promise.all([!i&&s&&!s.propertyId?Gt(s):Promise.resolve(),!i&&s?rn():Promise.resolve(),qt(),Jt(),Yt(),Xt()])}finally{ge(!1)}}(0,Q.useEffect)(()=>{u([]),Be(!1),At(null),Et(null),Ot(null)},[e]);let sn=(0,Q.useRef)(t);(0,Q.useEffect)(()=>{on(),sn.current!==t&&(sn.current=t,L.refetch())},[e,t,r]),(0,Q.useEffect)(()=>{se(0),ie(null),V(e=>e.startDate||e.endDate?{...e,startDate:``,endDate:``}:e),ae(e=>e+1),Jt()},[N]);let cn=(0,Q.useRef)(!1);(0,Q.useEffect)(()=>{cn.current?(se(0),et.setPage(1),qt(0)):cn.current=!0},[z]);function ln(e){let t=re===e?null:e;ie(t),V(e=>({...e,startDate:t??``,endDate:t??``})),ae(e=>e+1)}let un=(0,Q.useRef)(!1);(0,Q.useEffect)(()=>{un.current?(se(0),qt(0)):un.current=!0},[Qe]);async function dn(){if(!a)wt(`Google OAuth app credentials are not configured yet. Set them on the Settings page first.`);else{ve(!0),wt(null),Ot(null);try{let{authUrl:t,redirectUri:r}=await yn(e,`gsc`);if(!t.startsWith(`https://accounts.google.com/`)){wt(`Unexpected OAuth redirect URL. Please try again.`);return}let i=window.open(t,`_blank`,`width=600,height=700`);if(!i){window.location.assign(t);return}let a=r?new URL(r).origin:window.location.origin,o=!1,s=null,c=()=>{s!==null&&window.clearInterval(s),window.removeEventListener(`message`,u)},l=async e=>{if(!o){o=!0,c(),Ot(e?`Google connected. Refreshing access…`:`Refreshing Google connection…`);try{await Zn(n,`google`),await on()}finally{Ot(null)}}};function u(e){if(e.source!==i||e.origin!==a||!e.data||typeof e.data!=`object`)return;let t=e.data;t.type===Hl&&t.connectionType===`gsc`&&l(!0)}window.addEventListener(`message`,u),Ot(`Finish the Google consent flow in the popup. This page will refresh automatically.`),s=window.setInterval(()=>{i.closed&&l(!1)},1e3)}catch(e){wt(e instanceof Error?e.message:`Failed to start OAuth flow`)}finally{ve(!1)}}}async function fn(){wt(null),Ot(null);try{await yt(e,`gsc`),await Zn(n,`google`),c(e=>e.filter(e=>e.connectionType!==`gsc`)),u([]),C(``)}catch(e){wt(e instanceof Error?e.message:`Failed to disconnect`)}}async function pn(){if(x){Ce(!0),wt(null);try{await Ze(e,`gsc`,x),await Zn(n,`google`),c(e=>e.map(e=>e.connectionType===`gsc`?{...e,propertyId:x}:e)),Xn({title:`GSC property updated`,detail:`${e} is now linked to ${x}.`,tone:`positive`,dedupeKey:`gsc:property:${e}`,dedupeMode:`drop`})}catch(e){wt(e instanceof Error?e.message:`Failed to save GSC property`)}finally{Ce(!1)}}}async function mn(){wt(null),Ot(null);try{await Ht.mutateAsync({projectName:e,projectLabel:e,opts:{days:parseInt(D,10)||void 0,full:k||void 0}}),await Zn(n,`gsc`)}catch{}}async function hn(){if(T.trim()){Oe(!0),wt(null),Ot(null);try{let t=await at(e,T.trim());await Zn(n,`gsc`),b(t),E(``),await Yt()}catch(e){wt(e instanceof Error?e.message:`Failed to inspect URL`)}finally{Oe(!1)}}}return(0,$.jsxs)(`section`,{className:`page-section-divider`,children:[(0,$.jsx)(`div`,{className:`section-head section-head-inline`,children:(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`eyebrow eyebrow-soft`,children:`Search Console`}),(0,$.jsx)(`h2`,{children:`Google Search Console`})]})}),kt&&(0,$.jsx)(`p`,{role:`status`,className:`mb-3 text-copy-14 text-caution`,children:kt}),Tt&&(0,$.jsx)(`div`,{className:`mb-3 rounded-md border border-caution-800/40 bg-caution-950/20 px-3 py-2.5 text-label-14 text-caution-200`,children:(0,$.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`text-copy-14-strong text-caution-100`,children:Tt.title}),(0,$.jsx)(`p`,{className:`mt-0.5 text-caution-200/90`,children:Tt.message}),(Ao(Tt.enableUrl)||Ao(Tt.indexingApiUrl))&&(0,$.jsxs)(`div`,{className:`mt-2 flex flex-wrap gap-3`,children:[Ao(Tt.enableUrl)&&(0,$.jsx)(`a`,{href:Ao(Tt.enableUrl),target:`_blank`,rel:`noopener noreferrer`,className:`text-label-14-strong text-caution-100 underline decoration-caution-500/50 underline-offset-2 hover:text-caution-50`,children:`Enable Search Console API ↗`}),Ao(Tt.indexingApiUrl)&&(0,$.jsx)(`a`,{href:Ao(Tt.indexingApiUrl),target:`_blank`,rel:`noopener noreferrer`,className:`text-label-14-strong text-caution-100 underline decoration-caution-500/50 underline-offset-2 hover:text-caution-50`,children:`Enable Indexing API ↗`})]})]}),(0,$.jsx)(`button`,{type:`button`,className:`text-caution-400 hover:text-caution-200`,onClick:()=>Et(null),children:`×`})]})}),Ct&&(0,$.jsxs)(`div`,{className:`mb-3 rounded-md border border-negative-800/40 bg-negative-950/20 px-3 py-2 text-label-14 text-negative`,children:[Ct,(0,$.jsx)(`button`,{type:`button`,className:`ml-2 text-negative-400 hover:text-negative-200`,onClick:()=>wt(null),children:`×`})]}),Dt&&(0,$.jsxs)(`div`,{className:`mb-3 rounded-md border border-positive-800/40 bg-positive-950/20 px-3 py-2 text-label-14 text-positive`,children:[Dt,(0,$.jsx)(`button`,{type:`button`,className:`ml-2 text-positive-400 hover:text-positive-200`,onClick:()=>Ot(null),children:`×`})]}),he?(0,$.jsx)(`p`,{className:`text-copy-14 text-muted`,children:`Loading…`}):(0,$.jsxs)(`div`,{className:`space-y-3`,children:[Mt?(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 px-1 text-label-12 text-muted`,children:[(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full bg-positive-500`}),(0,$.jsx)(`span`,{className:`text-neutral`,children:`Authorized`})]}),(0,$.jsx)(`span`,{className:`text-mono-700`,children:`·`}),(0,$.jsx)(`code`,{className:`text-secondary`,children:Mt.domain}),(0,$.jsx)(`span`,{className:`text-mono-700`,children:`·`}),(0,$.jsxs)(`span`,{children:[`Coverage measured`,` `,W?.lastInspectedAt?Nn(W.lastInspectedAt):`never`]}),!i&&(0,$.jsx)(`button`,{type:`button`,className:`ml-auto text-muted transition-colors hover:text-negative-400`,onClick:Jn(fn),children:`Disconnect`})]}):r?(0,$.jsxs)(Z,{className:`surface-card`,children:[(0,$.jsxs)(`div`,{className:`section-head section-head-inline`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`eyebrow eyebrow-soft`,children:`Connection`}),(0,$.jsx)(`h3`,{children:`Domain authorization`})]}),(0,$.jsx)(J,{tone:a?`caution`:`negative`,children:a?`Ready to connect`:`App credentials missing`})]}),(0,$.jsxs)(`div`,{className:`mt-3 material-base px-4 py-5`,children:[(0,$.jsx)(`p`,{className:`text-copy-14 text-neutral`,children:a?`Generate a Google OAuth link for this project and have the client sign in with a Google account that already has access to the correct Search Console property.`:`Set Google OAuth client credentials first. Once configured, you can generate a consent link for this project domain.`}),(0,$.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-2`,children:[a?(0,$.jsx)(q,{type:`button`,variant:`outline`,size:`sm`,disabled:_e,onClick:Jn(dn),children:_e?`Opening…`:`Connect Google Search Console`}):(0,$.jsx)(q,{type:`button`,variant:`outline`,size:`sm`,asChild:!0,children:(0,$.jsx)(A,{to:`/settings`,children:`Open Settings`})}),!a&&(0,$.jsx)(`p`,{className:`text-copy-13 text-muted`,children:`The same Google OAuth app credentials are shared across all projects.`})]})]})]}):(0,$.jsx)(Z,{className:`surface-card`,children:(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:Ll})}),(Mt||Vt)&&(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsxs)(Z,{className:`surface-card`,children:[(0,$.jsxs)(`div`,{className:`section-head section-head-inline`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`eyebrow eyebrow-soft`,children:`Performance`}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`h3`,{children:`Search performance`}),(0,$.jsx)(X,{text:`${Gl(p?.periodComparison)} The optional trend line shows the fitted direction. Click any day to filter the table below to that date. Query and page filters match case-insensitive substrings and run on Apply filters. Filtering and sorting examine up to ${zl.toLocaleString()} matching rows while the table shows 25 per page.`})]}),p?.window?.startDate&&p.window.endDate&&(0,$.jsxs)(`p`,{className:`text-copy-13 text-muted`,children:[p.window.startDate,` to `,p.window.endDate,(p.window.daysSinceLatestData??0)>0&&` · latest data ${p.window.daysSinceLatestData} day${p.window.daysSinceLatestData===1?``:`s`} ago`]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(nl,{windows:Rl,value:N,onChange:e=>{P(e),se(0),et.setPage(1)},label:`Search Console time period`,formatOption:e=>e===`all`?`All`:e}),(0,$.jsx)(q,{type:`button`,variant:`outline`,size:`sm`,disabled:we,onClick:()=>{se(0),et.setPage(1),qt(0),Jt()},children:we?`Loading…`:`Apply filters`})]})]}),p&&p.daily.length>0&&(()=>{let{totals:e,daily:t,trends:n,periodComparison:r}=p,i=t=>e[t]??null,a=Wl.flatMap(e=>{let t=L.data?.groups.find(t=>t.key===e.engine),n=t?.figures.find(e=>e.key===`indexed`);return t&&n?[{...e,label:t.label,figure:n}]:[]}),o=new Map(t.map(e=>[e.date,e])),s=new Map(a.map(e=>[e.key,new Map(e.figure.series.map(e=>[e.date,e.value]))])),c=t[t.length-1].date,l=a.filter(e=>R.includes(e.key)).map(e=>e.figure.series.at(-1)?.date).filter(e=>!!e).sort().at(-1),u=l&&l>c?l:c,d=_t(t[0].date,u).map(e=>{let t={...o.get(e)??{date:e}};for(let n of a)t[n.key]=s.get(n.key)?.get(e)??null;return t}),f=[...Bl.filter(e=>R.includes(e.key)).map(e=>({dataKey:e.key,label:e.label,color:e.color,axisId:e.key,inverted:e.inverted,formatValue:e.format,trend:te?n?.[e.key]??null:null})),...a.filter(e=>R.includes(e.key)).map(e=>({dataKey:e.key,label:`${e.label} indexed pages`,color:e.color,axisId:e.key,formatValue:e=>e.toLocaleString(),connectNulls:!0}))],m={key:`performance`,label:`Google search`,basis:r?.comparable?`vs prior ${r.days} ${r.days===1?`day`:`days`}`:void 0,figures:Bl.map(e=>{let t=i(e.key);return{key:e.key,label:e.label,color:e.color,value:t===null?`—`:e.format(t),change:Ul(r,e.key,e.inverted),interactive:!0,disabled:t===null}})},h=a.length===0?null:{key:`indexed`,label:`Indexed pages`,basis:Es(a.map(e=>e.figure)),figures:a.map(e=>({key:e.key,label:e.label,color:e.color,value:e.figure.value===null?`—`:e.figure.value.toLocaleString(),change:bs(e.figure.change,e.figure.unit),interactive:!0,disabled:e.figure.value===null}))};return(0,$.jsxs)(`div`,{className:`mt-3`,children:[(0,$.jsx)(Os,{name:`Search performance figures`,frame:`none`,mode:`compare`,groups:h?[m,h]:[m],selected:R,onSelect:e=>ee(t=>t.includes(e)?t.length===1?t:t.filter(t=>t!==e):[...t,e]),chart:(0,$.jsx)(da,{data:d,xKey:`date`,series:f,xTickFormatter:fa,labelFormatter:_a,onSelectX:ln,selectedX:re}),legendExtra:(0,$.jsxs)(`label`,{className:`flex min-h-9 cursor-pointer items-center gap-2 pointer-coarse:min-h-11`,children:[(0,$.jsx)(`input`,{type:`checkbox`,className:`size-4 accent-mono-200 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-mono-400`,checked:te,onChange:e=>ne(e.target.checked)}),`Trend line`]})}),(0,$.jsx)(`div`,{role:`group`,"aria-label":`Filter the table to a single day`,children:t.map(e=>(0,$.jsxs)(`button`,{type:`button`,className:`sr-only focus:not-sr-only focus:inline-block focus:rounded focus:border focus:border-strong focus:bg-surface-active focus:px-2 focus:py-1 focus:text-button-14 focus:text-strong`,"aria-pressed":re===e.date,onClick:()=>ln(e.date),children:[_a(e.date),`: `,e.clicks,` clicks, `,e.impressions,` impressions`]},e.date))}),re&&(0,$.jsxs)(`div`,{className:`mt-1 flex items-center gap-2 text-label-12`,children:[(0,$.jsxs)(`span`,{className:`text-secondary`,children:[`Table showing `,_a(re)]}),(0,$.jsxs)(`button`,{type:`button`,className:`text-link hover:underline`,onClick:()=>ln(re),children:[`Show all `,e.days,` days`]})]}),e.position!==null&&(e.positionDays??e.days)<e.days&&(0,$.jsxs)(`p`,{className:`mt-1 text-copy-13 text-muted`,children:[`Average position covers `,e.positionDays,` of `,e.days,` days. The rest have no property-level position recorded.`]}),(e.position===null||e.position===void 0)&&(0,$.jsxs)(`p`,{className:`mt-1 text-copy-13 text-muted`,children:[`Average position needs a property-level sync. Run `,(0,$.jsx)(`code`,{children:`canonry google sync`}),` to record it.`]})]})})(),(0,$.jsxs)(`div`,{className:`mt-3 grid gap-2 lg:grid-cols-4`,children:[(0,$.jsx)(`input`,{className:`rounded border border-strong bg-transparent px-2 py-1.5 text-label-14 text-strong placeholder-mono-400 focus:border-mono-500 focus:outline-none`,type:`date`,"aria-label":`Start date`,title:`Start date (inclusive). Leave blank to use the window above.`,value:B.startDate,onChange:e=>V(t=>({...t,startDate:e.target.value}))}),(0,$.jsx)(`input`,{className:`rounded border border-strong bg-transparent px-2 py-1.5 text-label-14 text-strong placeholder-mono-400 focus:border-mono-500 focus:outline-none`,type:`date`,"aria-label":`End date`,title:`End date (inclusive).`,value:B.endDate,onChange:e=>V(t=>({...t,endDate:e.target.value}))}),(0,$.jsx)(js,{value:B.query,onChange:e=>V(t=>({...t,query:e})),label:`Filter search queries`,placeholder:`Contains query…`}),(0,$.jsx)(js,{value:B.page,onChange:e=>V(t=>({...t,page:e})),label:`Filter page URLs`,placeholder:`Contains page URL…`})]}),d.length>0?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`mt-3 overflow-x-auto`,children:(0,$.jsxs)(`table`,{className:`data-table w-full text-label-14`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{className:`text-left`,children:`Date`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Query`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Page`}),Object.values(zn).map(e=>(0,$.jsx)(`th`,{className:`text-right`,"aria-sort":Je?.key===e?Je.dir===`asc`?`ascending`:`descending`:`none`,children:(0,$.jsxs)(`button`,{type:`button`,className:`w-full cursor-pointer select-none text-right hover:text-strong focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-mono-400 rounded px-1 -mx-1`,onClick:()=>{et.setPage(1),Ye(t=>t?.key===e?t.dir===`desc`?{key:e,dir:`asc`}:null:{key:e,dir:`desc`})},children:[Un[e],Je?.key===e?Je.dir===`desc`?` ↓`:` ↑`:``]})},e))]})}),(0,$.jsx)(`tbody`,{children:tt.map((e,t)=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{className:`text-secondary`,children:e.date}),(0,$.jsx)(`td`,{className:`max-w-xs truncate text-strong`,children:e.query}),(0,$.jsx)(`td`,{className:`max-w-xs text-secondary`,children:(0,$.jsx)(Ss,{value:e.page})}),(0,$.jsx)(`td`,{className:`text-right tabular-nums text-neutral`,children:e.clicks.toLocaleString()}),(0,$.jsx)(`td`,{className:`text-right tabular-nums text-secondary`,children:e.impressions.toLocaleString()}),(0,$.jsx)(`td`,{className:`text-right tabular-nums text-secondary`,children:G(e.ctr)}),(0,$.jsx)(`td`,{className:`text-right tabular-nums text-secondary`,children:e.position.toFixed(1)})]},`${e.date}:${e.query}:${e.page}:${t}`))})]})}),(0,$.jsx)(Ts,{page:fe?et.page:Math.floor(oe/25)+1,pageSize:25,visibleRows:tt.length,totalRows:fe?ue:void 0,hasNextPage:fe?void 0:ce,disabled:we,itemLabel:fe?`matches`:`rows`,onPageChange:e=>{if(fe){et.setPage(e);return}let t=(e-1)*25;se(t),qt(t)}}),fe&&ue>=zl?(0,$.jsxs)(`p`,{className:`mt-2 text-copy-13 text-muted`,children:[`Results are capped at `,zl.toLocaleString(),`; narrow the filters to search beyond this set.`]}):null]}):(0,$.jsx)(`p`,{className:`mt-3 text-copy-14 text-muted`,children:`No performance rows match the current filters yet.`})]}),(0,$.jsxs)(Z,{className:`surface-card`,children:[(0,$.jsxs)(`div`,{className:`section-head section-head-inline`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`eyebrow eyebrow-soft`,children:`Coverage`}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`h3`,{children:`Index coverage`}),(0,$.jsx)(X,{text:`Google's Indexing API is intended for eligible JobPosting and BroadcastEvent pages. Sitemap resubmission is the general-site bulk path.`})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[W&&W.notIndexed.length>0&&(0,$.jsx)(q,{type:`button`,variant:`outline`,size:`sm`,disabled:xt,onClick:()=>void Qt(),children:xt?`Requesting…`:`Request indexing (${W.notIndexed.length})`}),(0,$.jsx)(q,{type:`button`,variant:`outline`,size:`sm`,disabled:je,onClick:()=>void Xt(!0),children:je?`Loading…`:`Reload saved coverage`})]})]}),W&&W.summary.total>0?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`mt-6 flex flex-col items-center`,children:(()=>{let e=W.summary.indexedShare??0,t=W.summary.notIndexedShare??0,n=2*Math.PI*54,r=n*(1-e),i=n*t,a=n*e;return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`relative h-48 w-48`,children:[(0,$.jsxs)(`svg`,{viewBox:`0 0 128 128`,className:`h-full w-full`,"aria-hidden":`true`,children:[(0,$.jsx)(`circle`,{cx:`64`,cy:`64`,r:54,fill:`none`,stroke:ga.trackSubtle,strokeWidth:`14`}),(0,$.jsx)(`circle`,{cx:`64`,cy:`64`,r:54,fill:`none`,stroke:ya.positiveDeep,strokeWidth:`14`,strokeDasharray:n,strokeDashoffset:r,strokeLinecap:`round`,transform:`rotate(-90 64 64)`,style:{transition:`stroke-dashoffset 0.6s ease`}}),W.summary.notIndexed>0&&(0,$.jsx)(`circle`,{cx:`64`,cy:`64`,r:54,fill:`none`,stroke:ga.textFaint,strokeWidth:`14`,strokeDasharray:`${i} ${n-i}`,strokeDashoffset:-a,transform:`rotate(-90 64 64)`,style:{transition:`stroke-dasharray 0.6s ease, stroke-dashoffset 0.6s ease`}})]}),(0,$.jsxs)(`div`,{className:`absolute inset-0 flex flex-col items-center justify-center`,children:[(0,$.jsx)(`span`,{className:`text-heading-32 tabular-nums text-primary`,children:G(W.summary.indexedShare)}),(0,$.jsx)(`span`,{className:`text-label-12 normal-case text-muted mt-0.5`,children:`Indexed`})]})]}),(0,$.jsxs)(`div`,{className:`mt-4 flex items-center justify-center gap-8`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`inline-block h-2.5 w-2.5 rounded-full bg-positive-500`}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`text-copy-24-strong tabular-nums text-primary`,children:W.summary.indexed.toLocaleString()}),(0,$.jsx)(`p`,{className:`text-label-12 normal-case text-muted`,children:`Indexed`})]})]}),(0,$.jsx)(`div`,{className:`h-8 w-px bg-mono-800`}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`inline-block h-2.5 w-2.5 rounded-full bg-mono-500`}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`text-copy-24-strong tabular-nums text-primary`,children:W.summary.notIndexed.toLocaleString()}),(0,$.jsxs)(`p`,{className:`text-label-12 normal-case text-muted`,children:[`Not indexed`,(W.reasonGroups??[]).length>0&&(0,$.jsxs)(`span`,{className:`ml-1 text-faint`,children:[`· `,(W.reasonGroups??[]).length,` `,(W.reasonGroups??[]).length===1?`reason`:`reasons`]})]})]})]}),W.summary.deindexed>0&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`h-8 w-px bg-mono-800`}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`inline-block h-2.5 w-2.5 rounded-full bg-negative-500`}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`text-copy-24-strong tabular-nums text-primary`,children:W.summary.deindexed.toLocaleString()}),(0,$.jsx)(`p`,{className:`text-label-12 normal-case text-muted`,children:`Deindexed`})]})]})]})]})]})})()}),(0,$.jsx)(`div`,{className:`mt-3 flex border-b border-default`,role:`tablist`,"aria-label":`Coverage status`,children:[`indexed`,`notIndexed`,`deindexed`].map(e=>{let t=e===`indexed`?W.indexed.length:e===`notIndexed`?W.notIndexed.length:W.deindexed.length;return(0,$.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":Ge===e,className:`border-b-2 px-3 py-2 text-button-14 transition-colors ${Ge===e?`border-accent text-heading`:`border-transparent text-secondary hover:border-mono-600 hover:text-strong`}`,onClick:()=>{Ke(e),ot(null)},children:[e===`indexed`?`Indexed`:e===`notIndexed`?`Not Indexed`:`Deindexed`,` (`,t,`)`]},e)})}),(0,$.jsxs)(`div`,{className:`mt-3 overflow-x-auto`,children:[Ge===`indexed`&&W.indexed.length>0&&(0,$.jsxs)(`table`,{className:`data-table w-full text-label-14`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{className:`text-left`,children:`URL`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Verdict`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Last Crawl`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Mobile`})]})}),(0,$.jsx)(`tbody`,{children:ht.map(e=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{className:`max-w-sm truncate text-strong`,children:e.url}),(0,$.jsx)(`td`,{className:`text-secondary`,children:e.verdict??`Unknown`}),(0,$.jsx)(`td`,{className:`text-secondary`,children:e.crawlTime?e.crawlTime.split(`T`)[0]:`—`}),(0,$.jsx)(`td`,{className:`text-secondary`,children:e.isMobileFriendly===!0?`Yes`:e.isMobileFriendly===!1?`No`:`—`})]},e.id))})]}),Ge===`notIndexed`&&!it&&(W.reasonGroups??[]).length>0&&(0,$.jsxs)(`table`,{className:`data-table w-full text-label-14`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{className:`text-left`,children:`Reason`}),(0,$.jsx)(`th`,{className:`text-right`,children:`Pages`})]})}),(0,$.jsx)(`tbody`,{children:(W.reasonGroups??[]).map(e=>(0,$.jsxs)(`tr`,{className:`cursor-pointer hover:bg-surface-inset-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-mono-400`,onClick:()=>ot(e.reason),onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),ot(e.reason))},tabIndex:0,role:`button`,"aria-label":`View ${e.reason} pages`,children:[(0,$.jsx)(`td`,{className:`text-strong`,children:e.reason}),(0,$.jsx)(`td`,{className:`text-right tabular-nums text-secondary`,children:e.count})]},e.reason))})]}),Ge===`notIndexed`&&!it&&(W.reasonGroups??[]).length===0&&W.notIndexed.length>0&&(0,$.jsxs)(`table`,{className:`data-table w-full text-label-14`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{className:`text-left`,children:`URL`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Indexing State`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Coverage`})]})}),(0,$.jsx)(`tbody`,{children:gt.map(e=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{className:`max-w-sm truncate text-strong`,children:e.url}),(0,$.jsx)(`td`,{className:`text-secondary`,children:e.indexingState??`Unknown`}),(0,$.jsx)(`td`,{className:`text-secondary`,children:e.coverageState??`Unknown`})]},e.id))})]}),Ge===`notIndexed`&&it&&(()=>{let e=(W.reasonGroups??[]).find(e=>e.reason===it);return e?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`flex items-center gap-2 mb-3`,children:(0,$.jsxs)(`button`,{type:`button`,className:`text-button-14 text-secondary hover:text-strong transition-colors`,onClick:()=>ot(null),children:[`←`,` Back to reasons`]})}),(0,$.jsxs)(`div`,{className:`mb-3 flex items-center justify-between material-base p-3`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`text-copy-14-strong text-strong`,children:e.reason}),(0,$.jsxs)(`p`,{className:`mt-1 text-copy-13 text-muted`,children:[e.count,` affected page`,e.count===1?``:`s`]})]}),(0,$.jsx)(q,{type:`button`,variant:`outline`,size:`sm`,disabled:xt,onClick:()=>void Zt(e.urls.map(e=>e.url)),children:xt?`Requesting…`:`Request indexing (${e.count})`})]}),(0,$.jsxs)(`table`,{className:`data-table w-full text-label-14`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{className:`text-left`,children:`URL`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Last Crawl`}),(0,$.jsx)(`th`,{className:`w-8`})]})}),(0,$.jsx)(`tbody`,{children:bt.map(e=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{className:`max-w-sm truncate text-strong`,children:e.url}),(0,$.jsx)(`td`,{className:`text-secondary`,children:e.crawlTime?e.crawlTime.split(`T`)[0]:`—`}),(0,$.jsx)(`td`,{children:(0,$.jsx)(`button`,{type:`button`,className:`text-button-14 text-muted hover:text-strong transition-colors`,disabled:xt,onClick:()=>void Zt([e.url]),title:`Request indexing`,children:`Index`})})]},e.id))})]})]}):null})(),Ge===`deindexed`&&W.deindexed.length>0&&(0,$.jsxs)(`table`,{className:`data-table w-full text-label-14`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{className:`text-left`,children:`URL`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Previous`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Current`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Detected`})]})}),(0,$.jsx)(`tbody`,{children:vt.map((e,t)=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{className:`max-w-sm truncate text-strong`,children:e.url}),(0,$.jsx)(`td`,{className:`text-secondary`,children:e.previousState}),(0,$.jsx)(`td`,{className:`text-secondary`,children:e.currentState}),(0,$.jsx)(`td`,{className:`text-secondary`,children:e.transitionDate.split(`T`)[0]})]},`${e.url}-${t}`))})]}),(Ge===`indexed`&&W.indexed.length===0||Ge===`notIndexed`&&!it&&W.notIndexed.length===0||Ge===`deindexed`&&W.deindexed.length===0)&&(0,$.jsx)(`p`,{className:`text-copy-14 text-muted`,children:`No URLs in this category.`}),(0,$.jsx)(Ts,{page:pt,pageSize:Vl,visibleRows:Math.min(Vl,dt.length-mt),totalRows:dt.length,onPageChange:ct,itemLabel:`URLs`})]}),(0,$.jsxs)(`div`,{className:`mt-4 border-t border-default pt-3`,children:[(0,$.jsxs)(`button`,{type:`button`,className:`flex w-full items-center justify-between text-left text-button-14 text-secondary hover:text-strong focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-mono-400`,"aria-expanded":He,onClick:()=>Ue(e=>!e),children:[(0,$.jsx)(`span`,{children:`Coverage history`}),(0,$.jsx)(`span`,{children:He?`Hide snapshots`:nt.length>0?`View ${nt.length} snapshots`:`View history`})]}),(0,$.jsxs)(`p`,{className:`mt-1 text-copy-13 text-muted`,children:[`Current: `,W.summary.indexed.toLocaleString(),` indexed, `,W.summary.notIndexed.toLocaleString(),` not indexed.`,lt&&(0,$.jsxs)($.Fragment,{children:[` Since the last snapshot: `,lt.indexed>=0?`+`:``,lt.indexed.toLocaleString(),` indexed, `,lt.notIndexed>=0?`+`:``,lt.notIndexed.toLocaleString(),` not indexed.`]})]}),He&&(0,$.jsx)(`div`,{className:`mt-3 overflow-x-auto`,children:nt.length>0?(0,$.jsxs)(`table`,{className:`data-table w-full text-label-14`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{className:`text-left`,children:`Date`}),(0,$.jsx)(`th`,{className:`text-right`,children:`Indexed`}),(0,$.jsx)(`th`,{className:`text-right`,children:`Not indexed`})]})}),(0,$.jsx)(`tbody`,{children:nt.map(e=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{className:`text-secondary`,children:e.date}),(0,$.jsx)(`td`,{className:`text-right tabular-nums text-neutral`,children:e.indexed.toLocaleString()}),(0,$.jsx)(`td`,{className:`text-right tabular-nums text-secondary`,children:e.notIndexed.toLocaleString()})]},e.date))})]}):(0,$.jsx)(`p`,{className:`text-copy-14 text-muted`,children:`No saved coverage snapshots yet.`})})]})]}):(0,$.jsx)(`p`,{className:`mt-3 text-copy-14 text-muted`,children:je?`Loading coverage data…`:`No coverage data yet. Inspect your sitemap to populate this view.`})]}),!i&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Pl,{engine:`Google`,data:Pt.isError?null:Pt.isPending&&Pt.fetchStatus!==`idle`?void 0:Pt.data?.google??null,loadError:Pt.isError?an(Pt.error):null,label:e=>Kl(e,Mt?.propertyId),canSubmit:Nt,submitBlocked:Mt?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{tone:`caution`,label:`Read-only access`,text:`Canonry's Google access can read Search Console but not submit sitemaps. Reconnect to allow submitting.`}),(0,$.jsx)(q,{type:`button`,variant:`outline`,size:`sm`,onClick:Jn(dn),children:`Reconnect`})]}):void 0,onSubmit:$t,submitting:Le,defaultUrl:Mt?.sitemapUrl??null,onSetDefault:e=>void tn(e),settingDefault:Fe,onInspect:e=>void nn(e),inspecting:Ut.isPending,notRead:(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:`Google's sitemap list arrives with the next Google sync. Refresh search data to read it now.`}),bulk:It.length>0?(0,$.jsx)(Fl,{label:Ne?`Submitting ${Ne.completed} of ${Ne.total}`:`Resubmit all`,menuLabel:`Resubmit sitemaps to Google`,disabled:!Nt||Le,items:[{key:`primary`,label:Bt,description:zt>0?`Google rereads every sitemap the index lists.`:`Each sitemap in the list, once.`,disabled:Rt.length===0,onSelect:()=>void $t(Rt)},{key:`files`,label:`Resubmit all files`,description:`Every file inside each index, one by one.`,onSelect:()=>void en()}]}):void 0}),(0,$.jsxs)(Z,{className:`surface-card`,children:[(0,$.jsx)(`div`,{className:`section-head`,children:(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`eyebrow eyebrow-soft`,children:`Inspection`}),(0,$.jsx)(`h3`,{children:`Inspect a URL`})]})}),(0,$.jsxs)(`div`,{className:`mt-3 flex flex-col gap-2 lg:flex-row`,children:[(0,$.jsx)(`input`,{className:`flex-1 rounded border border-strong bg-transparent px-2 py-1.5 text-label-14 text-strong placeholder-mono-400 focus:border-mono-500 focus:outline-none`,type:`url`,placeholder:`https://example.com/page`,value:T,onChange:e=>E(e.target.value),onKeyDown:e=>e.key===`Enter`&&void hn()}),(0,$.jsx)(q,{type:`button`,size:`sm`,disabled:De||!Mt?.propertyId||!T.trim(),onClick:Jn(hn),children:De?`Inspecting…`:`Inspect URL`})]}),y&&(0,$.jsxs)(`div`,{className:`mt-3 grid gap-3 md:grid-cols-2 xl:grid-cols-4`,children:[(0,$.jsxs)(`div`,{className:`material-base p-3`,children:[(0,$.jsx)(`p`,{className:`text-label-12 normal-case text-muted`,children:`Indexing state`}),(0,$.jsx)(`p`,{className:`mt-1 text-copy-14 text-strong`,children:y.indexingState??`Unknown`})]}),(0,$.jsxs)(`div`,{className:`material-base p-3`,children:[(0,$.jsx)(`p`,{className:`text-label-12 normal-case text-muted`,children:`Verdict`}),(0,$.jsx)(`p`,{className:`mt-1 text-copy-14 text-strong`,children:y.verdict??`Unknown`})]}),(0,$.jsxs)(`div`,{className:`material-base p-3`,children:[(0,$.jsx)(`p`,{className:`text-label-12 normal-case text-muted`,children:`Mobile friendly`}),(0,$.jsx)(`p`,{className:`mt-1 text-copy-14 text-strong`,children:jn(y.isMobileFriendly??null)})]}),(0,$.jsxs)(`div`,{className:`material-base p-3`,children:[(0,$.jsx)(`p`,{className:`text-label-12 normal-case text-muted`,children:`Last crawl`}),(0,$.jsx)(`p`,{className:`mt-1 text-copy-14 text-strong`,children:Nn(y.crawlTime)})]})]})]})]}),(0,$.jsxs)(Z,{className:`surface-card`,children:[(0,$.jsxs)(`div`,{className:`section-head section-head-inline`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`eyebrow eyebrow-soft`,children:`History`}),(0,$.jsx)(`h3`,{children:`Inspection log`})]}),(0,$.jsx)(q,{type:`button`,variant:`outline`,size:`sm`,disabled:Ee,onClick:()=>void Yt(!0),children:Ee?`Loading…`:`Refresh history`})]}),(0,$.jsxs)(`div`,{className:`mt-3 flex flex-col gap-2 lg:flex-row`,children:[(0,$.jsx)(`input`,{className:`flex-1 rounded border border-strong bg-transparent px-2 py-1.5 text-label-14 text-strong placeholder-mono-400 focus:border-mono-500 focus:outline-none`,type:`text`,placeholder:`Filter exact URL`,value:H,onChange:e=>me(e.target.value)}),(0,$.jsx)(q,{type:`button`,size:`sm`,variant:`outline`,disabled:Ee,onClick:()=>void Yt(!0),children:`Apply filter`})]}),h.length>0?(0,$.jsx)(`div`,{className:`mt-3 overflow-x-auto`,children:(0,$.jsxs)(`table`,{className:`data-table w-full text-label-14`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{className:`text-left`,children:`URL`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Indexing`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Verdict`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Coverage`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Mobile`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Inspected`})]})}),(0,$.jsx)(`tbody`,{children:h.map(e=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{className:`max-w-sm truncate text-strong`,children:e.url}),(0,$.jsx)(`td`,{className:`text-neutral`,children:e.indexingState??`Unknown`}),(0,$.jsx)(`td`,{className:`text-secondary`,children:e.verdict??`Unknown`}),(0,$.jsx)(`td`,{className:`text-secondary`,children:e.coverageState??`Unknown`}),(0,$.jsx)(`td`,{className:`text-secondary`,children:jn(e.isMobileFriendly??null)}),(0,$.jsx)(`td`,{className:`text-secondary`,children:Nn(e.inspectedAt)})]},e.id))})]})}):(0,$.jsx)(`p`,{className:`mt-3 text-copy-14 text-muted`,children:`No inspection history yet.`})]}),(0,$.jsxs)(Z,{className:`surface-card`,children:[(0,$.jsx)(`div`,{className:`section-head`,children:(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`eyebrow eyebrow-soft`,children:`Deindexed`}),(0,$.jsx)(`h3`,{children:`Recent indexing losses`})]})}),_.length>0?(0,$.jsx)(`div`,{className:`mt-3 overflow-x-auto`,children:(0,$.jsxs)(`table`,{className:`data-table w-full text-label-14`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{className:`text-left`,children:`URL`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Previous`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Current`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Changed at`})]})}),(0,$.jsx)(`tbody`,{children:_.map(e=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{className:`max-w-sm truncate text-strong`,children:e.url}),(0,$.jsx)(`td`,{className:`text-secondary`,children:e.previousState??`Unknown`}),(0,$.jsx)(`td`,{className:`text-neutral`,children:e.currentState??`Unknown`}),(0,$.jsx)(`td`,{className:`text-secondary`,children:Nn(e.transitionDate)})]},`${e.url}:${e.transitionDate}`))})]})}):(0,$.jsx)(`p`,{className:`mt-3 text-copy-14 text-muted`,children:`No deindexed transitions recorded.`})]})]}),Mt&&!i&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`border-t border-default pt-3`,children:(0,$.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-2 text-left`,onClick:()=>{ze||Gt(Mt),Be(e=>!e)},children:[(0,$.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 20 20`,fill:`currentColor`,className:`h-4 w-4 text-muted transition-transform ${ze?`rotate-90`:``}`,"aria-hidden":`true`,children:(0,$.jsx)(`path`,{fillRule:`evenodd`,d:`M7.21 14.77a.75.75 0 01.02-1.06L11.168 10 7.23 6.29a.75.75 0 111.04-1.08l4.5 4.25a.75.75 0 010 1.08l-4.5 4.25a.75.75 0 01-1.06-.02z`,clipRule:`evenodd`})}),(0,$.jsx)(`span`,{className:`text-label-12 normal-case text-muted`,children:`Setup & Configuration`})]})}),ze&&(0,$.jsx)(`div`,{className:`space-y-3`,children:(0,$.jsxs)(`div`,{className:`grid gap-3 xl:grid-cols-2`,children:[(0,$.jsxs)(Z,{className:`surface-card`,children:[(0,$.jsx)(`div`,{className:`section-head`,children:(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`eyebrow eyebrow-soft`,children:`Property`}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`h3`,{children:`Pick the Search Console property`}),(0,$.jsx)(X,{text:`The selected property is used for future syncs and URL inspections for this project.`})]})]})}),(0,$.jsxs)(`div`,{className:`mt-3 space-y-2`,children:[(0,$.jsx)(`label`,{className:`text-label-12 text-muted`,htmlFor:`gsc-property-${e}`,children:`Property URL`}),(0,$.jsx)(`select`,{id:`gsc-property-${e}`,className:`w-full rounded border border-strong bg-transparent px-2 py-1.5 text-label-14 text-strong focus:border-mono-500 focus:outline-none`,value:x,disabled:ye||l.length===0,onChange:e=>C(e.target.value),children:l.length===0?(0,$.jsx)(`option`,{value:``,children:ye?`Loading properties…`:`No properties available`}):l.map(e=>(0,$.jsxs)(`option`,{value:e.siteUrl,children:[e.siteUrl,` · `,e.permissionLevel]},e.siteUrl))}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(q,{type:`button`,size:`sm`,variant:`outline`,disabled:ye,onClick:()=>void Gt(Mt,!0),children:ye?`Refreshing…`:`Refresh properties`}),(0,$.jsx)(q,{type:`button`,size:`sm`,disabled:!x||xe,onClick:Jn(pn),children:xe?`Saving…`:`Save property`})]})]})]}),(0,$.jsxs)(Z,{className:`surface-card`,children:[(0,$.jsx)(`div`,{className:`section-head`,children:(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`eyebrow eyebrow-soft`,children:`Sync`}),(0,$.jsx)(`h3`,{children:`Import GSC performance data`})]})}),(0,$.jsxs)(`div`,{className:`mt-3 space-y-3`,children:[(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-[160px_1fr]`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`text-label-12 text-muted`,htmlFor:`gsc-sync-days-${e}`,children:`Days`}),(0,$.jsx)(`input`,{id:`gsc-sync-days-${e}`,type:`number`,min:`1`,className:`mt-0.5 w-full rounded border border-strong bg-transparent px-2 py-1.5 text-label-14 text-strong placeholder-mono-400 focus:border-mono-500 focus:outline-none`,value:D,onChange:e=>O(e.target.value)})]}),(0,$.jsxs)(`label`,{className:`flex items-center gap-2 rounded-md border border-default bg-surface-subtle px-3 py-2 text-label-14 text-neutral`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:k,onChange:e=>M(e.target.checked)}),`Replace existing imported rows for the requested range`]})]}),(0,$.jsx)(q,{type:`button`,size:`sm`,disabled:Ht.isPending||!Mt.propertyId,onClick:Jn(mn),children:Ht.isPending?`Queueing…`:`Queue sync`}),!Mt.propertyId&&(0,$.jsx)(`p`,{className:`text-copy-13 text-caution-400`,children:`Select a Search Console property before queueing a sync.`})]})]})]})})]})]})]})}var Jl=[`7d`,`30d`,`90d`,`all`],Yl=10,Xl=[{key:`clicks`,label:`Clicks`,color:ua[1],format:e=>e.toLocaleString()},{key:`impressions`,label:`Impressions`,color:ua[4],format:e=>e.toLocaleString()},{key:`ctr`,label:`CTR`,color:ya.caution,format:e=>G(e)},{key:`position`,label:`Avg position`,color:ua[2],inverted:!0,format:e=>e.toFixed(1)}],Zl=`bing-indexed`,Ql=`Impression-weighted across the queries Bing names. Bing reports these per week, so the line moves weekly.`,$l=`Asks Bing directly. Counts against the shared Bing request limit for this key.`;function eu(e){if(!e)return{kind:`note`,text:`No comparison period`};let t=e.difference.avgImpressionPosition,n=`vs prior ${e.days} ${e.days===1?`day`:`days`}`;return t===null?{kind:`note`,text:`No position in the prior ${e.days} days`}:t===0?{kind:`delta`,amount:`0`,direction:`flat`,tone:`neutral`,basis:n}:{kind:`delta`,amount:Tn(t),direction:t>0?`up`:`down`,tone:t>0?`worse`:`better`,basis:n}}function tu(e){return e==null?`—`:e.toFixed(1)}function nu(e){return e==null?`—`:Math.round(e).toLocaleString()}function ru(e){return e.replace(/^https?:\/\//,``).replace(/\/+$/,``)}function iu(e,t){let n=t.replace(/\/+$/,``);return e.startsWith(n)?e.slice(n.length)||`/`:e}function au(e,t){return e?.find(e=>e.kind===t)}function ou(e){let t=e?.payload;return t&&typeof t.dailyQuota==`number`&&typeof t.monthlyQuota==`number`?{dailyQuota:t.dailyQuota,monthlyQuota:t.monthlyQuota}:null}function su(e){let t=e?.payload;return t&&typeof t.crawlBoostAvailable==`boolean`?{crawlBoostAvailable:t.crawlBoostAvailable,crawlBoostEnabled:t.crawlBoostEnabled===!0,crawlRate:Array.isArray(t.crawlRate)?t.crawlRate:[]}:null}function cu(e){return Array.isArray(e?.payload)?e.payload.filter(e=>typeof e==`object`&&!!e):null}var lu=new Set([`entityType`,`requestType`,`type`,`role`]);function uu(e,t){return e==null||e===``?`—`:typeof e==`boolean`?e?`Yes`:`No`:typeof e==`number`?e.toLocaleString():typeof e==`string`?/^\d{4}-\d{2}-\d{2}(?:T00:00:00(?:\.000)?Z)?$/.test(e)?_a(e.slice(0,10)):lu.has(t)&&/^[a-z]+(?:-[a-z]+)*$/.test(e)?e.charAt(0).toUpperCase()+e.slice(1).replaceAll(`-`,` `):e:JSON.stringify(e)}function du({status:e,right:t,children:n}){return(0,$.jsxs)(`section`,{className:`page-section-divider`,children:[(0,$.jsxs)(`div`,{className:`section-head section-head-inline`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h2`,{children:`Bing Webmaster Tools`}),e]}),t]}),n]})}function fu({projectName:e,refreshNonce:t}){let n=S(),r=w({...Qi({client:K,path:{name:e}}),staleTime:Qn}),i=r.data??null,a=w({...ci({client:K,path:{name:e}}),staleTime:Qn,enabled:!(!i?.connected||i.siteUrl)}),[o,s]=(0,Q.useState)(``),[c,l]=(0,Q.useState)(``),[u,d]=(0,Q.useState)(null);(0,Q.useEffect)(()=>{t>0&&r.refetch()},[t]);async function f(){if(o.trim()){d(null);try{await St(e,o.trim()),s(``),await Zn(n,`bing`)}catch(e){d(an(e))}}}async function p(){d(null);try{await $t(e),l(``),await Zn(n,`bing`)}catch(e){d(an(e))}}async function m(){if(c){d(null);try{await Dt(e,c),await Zn(n,`bing`)}catch(e){d(an(e))}}}if(r.isPending)return(0,$.jsx)(du,{children:(0,$.jsx)(Z,{className:`surface-card`,children:(0,$.jsx)(`div`,{className:`text-label-14 text-secondary`,children:`Loading Bing data…`})})});if(r.isError)return(0,$.jsx)(du,{children:(0,$.jsxs)(Z,{className:`surface-card`,children:[(0,$.jsxs)(`p`,{className:`text-copy-14 text-negative`,children:[`Could not load the Bing connection: `,an(r.error)]}),(0,$.jsx)(q,{type:`button`,variant:`outline`,size:`sm`,className:`mt-3`,onClick:()=>void r.refetch(),children:`Retry`})]})});if(!i?.connected)return(0,$.jsx)(du,{children:(0,$.jsxs)(Z,{className:`surface-card`,children:[(0,$.jsxs)(`div`,{className:`section-head section-head-inline`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`eyebrow eyebrow-soft`,children:`Connection`}),(0,$.jsx)(`h3`,{children:`Domain authorization`})]}),(0,$.jsx)(J,{tone:`caution`,children:`Not connected`})]}),Y()?(0,$.jsx)(`p`,{className:`text-copy-14 text-neutral`,children:`Bing Webmaster Tools is not connected for this project.`}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`p`,{className:`text-copy-14 text-neutral`,children:`Connect Bing Webmaster Tools to inspect URLs, monitor index coverage, and submit pages for indexing.`}),(0,$.jsxs)(`div`,{className:`mt-3`,children:[(0,$.jsx)(`label`,{className:`text-label-12 text-muted`,htmlFor:`bing-api-key`,children:`API Key`}),(0,$.jsxs)(`div`,{className:`mt-1 flex items-center gap-2`,children:[(0,$.jsx)(`input`,{id:`bing-api-key`,type:`password`,className:`flex-1 rounded border border-strong bg-transparent px-2 py-1.5 text-label-14 text-strong placeholder-mono-400 focus:border-mono-500 focus:outline-none`,placeholder:`Bing Webmaster Tools API key`,value:o,onChange:e=>s(e.target.value),onKeyDown:e=>{e.key===`Enter`&&f()}}),(0,$.jsx)(vs,{size:`sm`,disabled:!o.trim(),onClick:Jn(f),children:`Connect`})]}),(0,$.jsxs)(`p`,{className:`mt-1 text-copy-14 text-secondary`,children:[`Get your API key from`,` `,(0,$.jsx)(`a`,{href:`https://www.bing.com/webmasters/`,target:`_blank`,rel:`noopener noreferrer`,className:`text-secondary underline underline-offset-2 hover:text-neutral`,children:`Bing Webmaster Tools`})]})]})]}),u&&(0,$.jsx)(`p`,{className:`mt-3 text-copy-13 text-negative`,children:u})]})});if(!i.siteUrl){let e=a.data?.sites??[];return(0,$.jsx)(du,{children:(0,$.jsxs)(Z,{className:`surface-card`,children:[(0,$.jsxs)(`div`,{className:`section-head section-head-inline`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`eyebrow eyebrow-soft`,children:`Connection`}),(0,$.jsx)(`h3`,{children:`Domain authorization`})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(J,{tone:`positive`,children:`Connected`}),!Y()&&(0,$.jsx)(vs,{size:`sm`,variant:`ghost`,onClick:Jn(p),children:`Disconnect`})]})]}),(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsxs)(`div`,{className:`material-base px-4 py-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(`span`,{className:`h-2 w-2 rounded-full bg-positive-500`}),(0,$.jsx)(`span`,{className:`text-label-14 text-strong`,children:`Authorized for this project domain`}),(0,$.jsx)(`span`,{className:`text-label-12 text-muted`,children:i.domain})]}),(0,$.jsx)(`p`,{className:`mt-2 text-copy-13 text-muted`,children:`The API key is connected, but no Bing site is selected yet. Pick the verified site that should receive inspections and indexing requests.`})]}),(0,$.jsxs)(`div`,{className:`grid gap-3 lg:grid-cols-2`,children:[(0,$.jsxs)(`div`,{className:`material-base p-3`,children:[(0,$.jsx)(`p`,{className:`text-label-12 normal-case text-muted`,children:`Registered domain`}),(0,$.jsx)(`p`,{className:`mt-1 text-copy-14 text-strong`,children:i.domain})]}),(0,$.jsxs)(`div`,{className:`material-base p-3`,children:[(0,$.jsx)(`p`,{className:`text-label-12 normal-case text-muted`,children:`Last auth update`}),(0,$.jsx)(`p`,{className:`mt-1 text-copy-14 text-strong`,children:i.updatedAt?Nn(i.updatedAt):`—`})]})]}),(0,$.jsxs)(`div`,{className:`material-base p-3`,children:[(0,$.jsx)(`p`,{className:`text-label-12 normal-case text-muted`,children:`Select site`}),e.length>0?(0,$.jsxs)(`div`,{className:`mt-3 flex flex-col gap-2 lg:flex-row`,children:[(0,$.jsxs)(`select`,{"aria-label":`Bing site`,className:`flex-1 rounded border border-strong bg-bg-elevated px-2 py-1.5 text-label-14 text-strong focus:border-mono-500 focus:outline-none`,value:c,onChange:e=>l(e.target.value),children:[(0,$.jsx)(`option`,{value:``,children:`Select a site...`}),e.map(e=>(0,$.jsxs)(`option`,{value:e.url,children:[e.url,e.verified?` (verified)`:``]},e.url))]}),!Y()&&(0,$.jsx)(vs,{size:`sm`,disabled:!c,onClick:Jn(m),children:`Set Site`})]}):(0,$.jsx)(`p`,{className:`mt-3 text-copy-13 text-muted`,children:a.isPending?`Loading sites…`:`No verified Bing sites are available yet. Verify the domain in Bing Webmaster Tools, then use the page-level refresh to reload everything.`})]})]}),u&&(0,$.jsx)(`p`,{className:`mt-3 text-copy-13 text-negative`,children:u})]})})}return(0,$.jsx)(pu,{projectName:e,connection:i,siteUrl:i.siteUrl,onDisconnect:p,error:u})}function pu({projectName:e,connection:t,siteUrl:n,onDisconnect:r,error:i}){let[a,o]=(0,Q.useState)(`30d`),s={name:e},c=w({...oa({client:K,path:s,query:{window:a}}),staleTime:Qn,placeholderData:j}),l=w({...Ti({client:K,path:s}),staleTime:Qn}),u=w({...Si({client:K,path:s}),staleTime:Qn}),f=!!(c.data?.latestAvailableDate||l.data?.syncedAt||u.data?.syncedAt),p=!c.isPending&&!l.isPending&&!u.isPending,m=[c,l,u].find(e=>e.isError)?.error??null,h=cu(au(l.data?.snapshots,`blocked-urls`))?.length??0;return(0,$.jsx)(du,{status:(0,$.jsxs)(`p`,{className:`mt-1 flex flex-wrap items-center gap-x-1.5 gap-y-1 text-label-13 text-secondary`,children:[(0,$.jsx)(`span`,{className:`h-2 w-2 rounded-full bg-positive-500`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{children:`Connected`}),(0,$.jsx)(`span`,{"aria-hidden":`true`,children:`·`}),(0,$.jsx)(`span`,{className:`font-mono`,title:n,children:ru(n)}),c.data?.latestAvailableDate&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,children:`·`}),(0,$.jsxs)(`span`,{children:[`Data through `,_a(c.data.latestAvailableDate)]})]}),l.data?.syncedAt&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,children:`·`}),(0,$.jsxs)(`span`,{children:[`Synced `,Nn(l.data.syncedAt)]})]}),h>0&&(0,$.jsx)(`span`,{className:`ml-1.5`,children:(0,$.jsx)(X,{tone:`caution`,label:`${h} blocked URL${h===1?``:`s`}`,text:`Bing is keeping ${h===1?`one URL`:`${h} URLs`} out of its results, which also keeps ${h===1?`it`:`them`} out of Copilot answers. See Site settings.`})})]}),right:(0,$.jsxs)(`details`,{className:`group`,children:[(0,$.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center gap-1 rounded px-2 py-1 text-button-14 text-secondary hover:text-strong focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-mono-400 [&::-webkit-details-marker]:hidden`,children:[`Connection `,(0,$.jsx)(d,{className:`h-3.5 w-3.5 transition-transform group-open:rotate-180`,"aria-hidden":`true`})]}),(0,$.jsxs)(`div`,{className:`material-base mt-2 space-y-2 p-3 text-copy-13`,children:[(0,$.jsxs)(`p`,{children:[(0,$.jsx)(`span`,{className:`text-secondary`,children:`Domain`}),` `,(0,$.jsx)(`span`,{className:`text-strong`,children:t.domain})]}),(0,$.jsxs)(`p`,{children:[(0,$.jsx)(`span`,{className:`text-secondary`,children:`Site`}),` `,(0,$.jsx)(`span`,{className:`font-mono text-strong`,children:n})]}),(0,$.jsxs)(`p`,{children:[(0,$.jsx)(`span`,{className:`text-secondary`,children:`Last auth update`}),` `,(0,$.jsx)(`span`,{className:`text-strong`,children:t.updatedAt?Nn(t.updatedAt):`—`})]}),!Y()&&(0,$.jsx)(vs,{size:`sm`,variant:`ghost`,onClick:Jn(r),children:`Disconnect`})]})]}),children:(0,$.jsxs)(`div`,{className:`space-y-3`,children:[i&&(0,$.jsx)(`p`,{className:`text-copy-13 text-negative`,children:i}),p&&!f&&m?(0,$.jsxs)(Z,{className:`surface-card`,children:[(0,$.jsxs)(`p`,{className:`text-copy-14 text-negative`,children:[`Could not load Bing data: `,an(m)]}),(0,$.jsx)(q,{type:`button`,variant:`outline`,size:`sm`,className:`mt-3`,onClick:()=>{c.refetch(),l.refetch(),u.refetch()},children:`Retry`})]}):p&&!f?(0,$.jsx)(gu,{projectName:e,loadedAt:l.dataUpdatedAt}):(0,$.jsx)(_u,{projectName:e,siteUrl:n,range:a,onRangeChange:o}),(0,$.jsx)(Su,{projectName:e,siteUrl:n,snapshots:l.data?.snapshots}),f&&(0,$.jsx)(Cu,{projectName:e,siteUrl:n}),f&&(0,$.jsx)(bu,{projectName:e}),f&&(0,$.jsx)(Tu,{siteUrl:n,snapshots:l.data?.snapshots??[]})]})})}var mu=5e3;function hu(e){return e?.status===Ae.queued||e?.status===Ae.running}function gu({projectName:e,loadedAt:t}){let n=S(),r=w({..._r({client:K,path:{name:e},query:{kind:Se[`bing-sync`],limit:1}}),refetchInterval:e=>hu(e.state.data?.[0])?mu:!1,enabled:!Y()}),i=r.data?.[0],a=hu(i),[o,s]=(0,Q.useState)(!1),c=i&&!a&&i.finishedAt?Date.parse(i.finishedAt):0;(0,Q.useEffect)(()=>{c>t&&ka(n,Se[`bing-sync`],e)},[c,t,n,e]);async function l(){s(!0);try{let t=await Xt(e);Zo({id:t.id,projectId:t.projectId,kind:Se[`bing-sync`],projectLabel:e,sourceAction:`bing-sync`}),await r.refetch(),Xn({title:`Bing sync started`,detail:`Search data appears here when it finishes.`,tone:`neutral`,dedupeKey:`bing:sync:${e}`,dedupeMode:`replace`})}catch(t){Xn({title:`Bing sync could not start`,detail:an(t),tone:`negative`,dedupeKey:`bing:sync:${e}`,dedupeMode:`replace`})}finally{s(!1)}}let u=!a&&i?.status===Ae.failed;return(0,$.jsxs)(Z,{className:`surface-card`,children:[(0,$.jsx)(`h3`,{className:`text-heading-16 text-strong`,children:`No Bing search data yet`}),(0,$.jsx)(`p`,{className:`mt-1 text-copy-14 text-secondary`,children:a?`Bing sync ${i?.status===Ae.queued?`queued`:`running`}. Search data appears here when it finishes.`:`It arrives with the daily refresh.`}),u&&(0,$.jsxs)(`p`,{className:`mt-1 text-copy-13 text-negative`,children:[`Last sync failed`,i?.error?`: ${On(i.error)}`:`.`]}),!Y()&&(0,$.jsx)(vs,{className:`mt-3`,size:`sm`,disabled:a||o,onClick:Jn(l),children:a||o?`Sync running…`:u?`Try the sync again`:`Sync Bing data now`})]})}function _u({projectName:e,siteUrl:t,range:n,onRangeChange:r}){let i={name:e},a=w({...oa({client:K,path:i,query:{window:n}}),staleTime:Qn,placeholderData:j}),o=w({...Vi({client:K,path:i,query:{window:n,groupBy:`week`}}),staleTime:Qn,placeholderData:j}),s=w({...Zi({client:K,path:i,query:{surface:`index-coverage`,window:n}}),staleTime:Qn,placeholderData:j}),[c,l]=(0,Q.useState)([`clicks`,`impressions`]),[u,d]=(0,Q.useState)(!0),f=a.data,p=s.data?.groups.find(e=>e.key===`bing`)?.figures.find(e=>e.key===`indexed`)??null,m=f?.periodComparison??null,h;if(a.isPending)h=(0,$.jsx)(`p`,{className:`mt-3 text-copy-14 text-secondary`,children:`Loading Bing search data…`});else if(a.isError||!f)h=(0,$.jsxs)(`p`,{className:`mt-3 text-copy-14 text-negative`,children:[`Could not load Bing search data: `,an(a.error)]});else{let r=o.data?.totals?.avgImpressionPosition??null,i=eu(o.data?.comparison),s=m?.comparable?`vs prior ${m.days} ${m.days===1?`day`:`days`}`:void 0,g={key:`performance`,label:`Bing search`,basis:s!==void 0&&(i.kind!==`delta`||i.basis===s)?s:void 0,figures:Xl.map(e=>{if(e.key===`position`)return{key:e.key,label:e.label,help:Ql,color:e.color,value:r===null?`—`:e.format(r),change:i,interactive:!0,disabled:r===null};let t=f.totals[e.key];return{key:e.key,label:e.label,color:e.color,value:e.format(t),change:Ul(m,e.key,!1),interactive:!0,disabled:f.rows.length===0}})},_=p?{key:`indexed`,label:`Indexed pages`,basis:Es([p]),figures:[{key:Zl,label:`Bing`,color:ua[6],value:p.value===null?`—`:p.value.toLocaleString(),change:bs(p.change,p.unit),interactive:!0,disabled:p.value===null}]}:null,v=f.rows[0]?.date,y=f.rows.at(-1)?.date,b=f.earliestAvailableDate,x=f.window.startDate&&b&&f.window.startDate>b?f.window.startDate:b??f.window.startDate??v,S=f.window.endDate??y,C=new Map(f.rows.map(e=>[e.date,e])),w=new Map((o.data?.weekly??[]).map(e=>[e.date,e.avgImpressionPosition])),T=new Map((p?.series??[]).map(e=>[e.date,e.value])),E=x&&S?_t(x,S).map(e=>{let t=C.get(e);return{date:e,clicks:t?.clicks??0,impressions:t?.impressions??0,ctr:t&&t.impressions>0?t.ctr:null,position:w.get(e)??null,[Zl]:T.get(e)??null}}):[],D=[...Xl.filter(e=>c.includes(e.key)).map(e=>({dataKey:e.key,label:e.label,color:e.color,axisId:e.key,inverted:`inverted`in e?e.inverted:void 0,formatValue:e.format,trend:u&&e.key!==`position`?f.trends[e.key]:null,connectNulls:e.key===`position`})),...c.includes(Zl)&&p?[{dataKey:Zl,label:`Bing indexed pages`,color:ua[6],axisId:Zl,formatValue:e=>e.toLocaleString(),connectNulls:!0}]:[]];h=(0,$.jsxs)(`div`,{className:`mt-3`,children:[(0,$.jsx)(Os,{name:`Bing search figures`,frame:`none`,mode:`compare`,groups:_?[g,_]:[g],selected:c,refreshing:a.isFetching&&a.isPlaceholderData,onSelect:e=>l(t=>t.includes(e)?t.length===1?t:t.filter(t=>t!==e):[...t,e]),chart:E.length>0?(0,$.jsx)(da,{data:E,xKey:`date`,series:D,xTickFormatter:fa,labelFormatter:_a,ariaLabel:`Daily Bing search figures`}):void 0,emptyChartMessage:`Bing reported no search traffic in this window.`,legendExtra:(0,$.jsxs)(`label`,{className:`flex min-h-9 cursor-pointer items-center gap-2 pointer-coarse:min-h-11`,children:[(0,$.jsx)(`input`,{type:`checkbox`,className:`size-4 accent-mono-200 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-mono-400`,checked:u,onChange:e=>d(e.target.checked)}),`Trend line`]})}),(0,$.jsx)(vu,{projectName:e,siteUrl:t,range:n})]})}return(0,$.jsxs)(Z,{className:`surface-card`,children:[(0,$.jsxs)(`div`,{className:`section-head section-head-inline`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`h3`,{children:`Search performance`}),(0,$.jsx)(X,{text:`${Gl(m)} Clicks, impressions and CTR are Bing's daily totals for the whole site. The queries and pages below are the ones Bing names, reported per week, so they do not add up to the site total.`})]}),f?.window.startDate&&f.window.endDate&&(0,$.jsxs)(`p`,{className:`text-copy-13 text-muted`,children:[_a(f.window.startDate),` to `,_a(f.window.endDate)]})]}),(0,$.jsx)(nl,{windows:Jl,value:n,onChange:r,label:`Bing time period`,formatOption:e=>e===`all`?`All`:e})]}),h]})}function vu({projectName:e,siteUrl:t,range:n}){let[r,i]=(0,Q.useState)(`queries`),[a,o]=(0,Q.useState)(``),[s,c]=(0,Q.useState)(void 0),[l,f]=(0,Q.useState)(1),[p,m]=(0,Q.useState)(null),h={name:e},g=(l-1)*Yl;(0,Q.useEffect)(()=>{let e=a.trim()||void 0;if(e===void 0){c(void 0);return}let t=setTimeout(()=>c(e),300);return()=>clearTimeout(t)},[a]);let _=w({...Vi({client:K,path:h,query:{window:n,query:s,limit:Yl,offset:g}}),staleTime:Qn,placeholderData:j,enabled:r===`queries`}),v=w({...yi({client:K,path:h,query:{window:n,page:s,limit:Yl,offset:g}}),staleTime:Qn,placeholderData:j,enabled:r===`pages`}),y=r===`queries`?_:v,b=r===`queries`?(_.data?.rows??[]).map(e=>({key:e.query,...e})):(v.data?.rows??[]).map(e=>({key:e.page,...e})),x=y.data?.totalMatching??0,S=r===`queries`?`Query`:`Page`;return(0,Q.useEffect)(()=>{f(1),m(null)},[r,n,s]),(0,$.jsxs)(`div`,{className:`mt-4`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-end justify-between gap-3 border-b border-base`,children:[(0,$.jsx)(`div`,{className:`flex gap-1`,role:`tablist`,"aria-label":`Bing search rows`,children:[`queries`,`pages`].map(e=>(0,$.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":r===e,className:`border-b-2 px-3 py-1.5 text-button-14 transition-colors ${r===e?`border-mono-200 text-strong`:`border-transparent text-muted hover:text-neutral`}`,onClick:()=>i(e),children:e===`queries`?`Queries`:`Pages`},e))}),(0,$.jsx)(js,{className:`mb-1.5 w-full sm:w-64`,value:a,onChange:o,label:r===`queries`?`Filter Bing queries`:`Filter Bing pages`,placeholder:r===`queries`?`Contains query…`:`Contains page URL…`})]}),y.isError?(0,$.jsxs)(`p`,{className:`mt-3 text-copy-14 text-negative`,children:[`Could not load Bing `,r,`: `,an(y.error)]}):(0,$.jsx)(`div`,{className:`mt-2 overflow-x-auto`,children:(0,$.jsxs)(`table`,{className:`data-table w-full text-label-14`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{className:`w-7`,children:(0,$.jsx)(`span`,{className:`sr-only`,children:`Expand`})}),(0,$.jsx)(`th`,{className:`text-left`,children:S}),(0,$.jsx)(`th`,{className:`text-right`,children:`Clicks`}),(0,$.jsx)(`th`,{className:`text-right`,children:`Impressions`}),(0,$.jsx)(`th`,{className:`text-right`,children:`CTR`}),(0,$.jsx)(`th`,{className:`text-right`,children:`Position`})]})}),(0,$.jsxs)(`tbody`,{children:[b.length===0&&(0,$.jsx)(`tr`,{children:(0,$.jsx)(`td`,{colSpan:6,className:`py-6 text-center text-secondary`,children:y.isPending?`Loading…`:s?`No ${r} match "${s}" in this window.`:`Bing named no ${r} in this window.`})}),b.map(i=>{let a=p===i.key;return(0,$.jsxs)(Q.Fragment,{children:[(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{children:(0,$.jsx)(`button`,{type:`button`,"aria-expanded":a,"aria-label":`${a?`Hide`:`Show`} details for ${i.key}`,className:`rounded p-0.5 text-secondary hover:text-strong focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-mono-400`,onClick:()=>m(a?null:i.key),children:a?(0,$.jsx)(d,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}):(0,$.jsx)(u,{className:`h-3.5 w-3.5`,"aria-hidden":`true`})})}),(0,$.jsx)(`td`,{className:`max-w-md text-strong`,children:r===`pages`?(0,$.jsx)(Ss,{value:iu(i.key,t),title:i.key,className:`font-mono text-label-13`}):(0,$.jsx)(`span`,{className:`block truncate`,title:i.key,children:i.key})}),(0,$.jsx)(`td`,{className:`text-right tabular-nums text-neutral`,children:i.clicks.toLocaleString()}),(0,$.jsx)(`td`,{className:`text-right tabular-nums text-secondary`,children:i.impressions.toLocaleString()}),(0,$.jsx)(`td`,{className:`text-right tabular-nums text-secondary`,children:G(i.ctr)}),(0,$.jsx)(`td`,{className:`text-right tabular-nums text-secondary`,children:tu(i.avgImpressionPosition)})]}),a&&(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{}),(0,$.jsx)(`td`,{colSpan:5,className:`pb-4`,children:(0,$.jsx)(yu,{projectName:e,siteUrl:t,range:n,tab:r,rowKey:i.key})})]})]},i.key)})]})]})}),(0,$.jsx)(`div`,{className:`mt-2 flex justify-end`,children:(0,$.jsx)(Ts,{page:l,pageSize:Yl,visibleRows:b.length,totalRows:x,disabled:y.isFetching,itemLabel:r,onPageChange:f})})]})}function yu({projectName:e,siteUrl:t,range:n,tab:r,rowKey:i}){let a={name:e},[o,s]=(0,Q.useState)(!1),c=w({...Vi({client:K,path:a,query:{window:n,query:i,match:`exact`,groupBy:`week`}}),staleTime:Qn,enabled:r===`queries`}),l=w({...yi({client:K,path:a,query:{window:n,page:i,match:`exact`,groupBy:`week`}}),staleTime:Qn,enabled:r===`pages`}),u=w({...Li({client:K,path:a,query:{query:i}}),staleTime:Qn,retry:!1,enabled:o&&r===`queries`}),d=w({...gi({client:K,path:a,query:{page:i}}),staleTime:Qn,retry:!1,enabled:o&&r===`pages`}),f=(r===`queries`?c.data?.weekly:l.data?.weekly)??[],m=r===`queries`?u:d,h=m.data?.rows??[],g=r===`queries`?`Pages`:`Queries`;return(0,$.jsxs)(`div`,{className:`grid gap-6 lg:grid-cols-[minmax(260px,1fr)_minmax(280px,1.4fr)]`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`mb-1.5 text-label-13-strong text-strong`,children:`By week`}),(0,$.jsxs)(`table`,{className:`data-table w-full text-label-13`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{className:`text-left`,children:`Week`}),(0,$.jsx)(`th`,{className:`text-right`,children:`Clicks`}),(0,$.jsx)(`th`,{className:`text-right`,children:`Impr.`}),(0,$.jsx)(`th`,{className:`text-right`,children:`Pos.`})]})}),(0,$.jsxs)(`tbody`,{children:[f.length===0&&(0,$.jsx)(`tr`,{children:(0,$.jsx)(`td`,{colSpan:4,className:`py-3 text-secondary`,children:(r===`queries`?c:l).isPending?`Loading…`:`No weeks in this window.`})}),f.map(e=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{className:`tabular-nums`,children:_a(e.date)}),(0,$.jsx)(`td`,{className:`text-right tabular-nums`,children:e.clicks.toLocaleString()}),(0,$.jsx)(`td`,{className:`text-right tabular-nums text-secondary`,children:e.impressions.toLocaleString()}),(0,$.jsx)(`td`,{className:`text-right tabular-nums text-secondary`,children:tu(e.avgImpressionPosition)})]},e.date))]})]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`p`,{className:`mb-1.5 flex items-baseline gap-2 text-label-13-strong text-strong`,children:[g,` for this `,r===`queries`?`query`:`page`,m.isSuccess&&(0,$.jsx)(`span`,{className:`text-label-12 text-secondary`,children:`from Bing, by week`})]}),!o&&(Y()?(0,$.jsx)(`p`,{className:`text-copy-13 text-secondary`,children:`Not available here.`}):(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsxs)(q,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>s(!0),children:[(0,$.jsx)(y,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),`Load `,g.toLowerCase(),` from Bing`]}),(0,$.jsx)(X,{label:`Live`,text:$l})]})),o&&m.isPending&&(0,$.jsx)(`p`,{className:`text-copy-13 text-secondary`,children:`Asking Bing…`}),o&&m.isError&&(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(X,{tone:`caution`,label:`Bing refused this read`,text:`${an(m.error)} Nothing was stored.`}),(0,$.jsxs)(q,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>void m.refetch(),children:[(0,$.jsx)(p,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),`Retry`]})]}),o&&m.isSuccess&&(h.length===0?(0,$.jsxs)(`p`,{className:`text-copy-13 text-secondary`,children:[`Bing named no `,g.toLowerCase(),` for this `,r===`queries`?`query`:`page`,`.`]}):(0,$.jsxs)(`table`,{className:`data-table w-full text-label-13`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{className:`text-left`,children:`Week`}),(0,$.jsx)(`th`,{className:`text-left`,children:r===`queries`?`Page`:`Query`}),(0,$.jsx)(`th`,{className:`text-right`,children:`Clicks`}),(0,$.jsx)(`th`,{className:`text-right`,children:`Impr.`}),(0,$.jsx)(`th`,{className:`text-right`,children:`Pos.`})]})}),(0,$.jsx)(`tbody`,{children:h.map((e,n)=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{className:`tabular-nums text-secondary`,children:e.date?_a(e.date):`—`}),(0,$.jsx)(`td`,{className:`max-w-xs`,children:r===`queries`?(0,$.jsx)(Ss,{value:iu(e.key,t),title:e.key,className:`font-mono`}):(0,$.jsx)(`span`,{className:`block truncate`,title:e.key,children:e.key})}),(0,$.jsx)(`td`,{className:`text-right tabular-nums`,children:e.clicks.toLocaleString()}),(0,$.jsx)(`td`,{className:`text-right tabular-nums text-secondary`,children:e.impressions.toLocaleString()}),(0,$.jsx)(`td`,{className:`text-right tabular-nums text-secondary`,children:tu(e.avgImpressionPosition)})]},`${e.date}:${e.key}:${n}`))})]}))]})]})}function bu({projectName:e}){let t=w({...Xi({client:K,path:{name:e}}),staleTime:Qn}),[n,r]=(0,Q.useState)(null),i=t.data?.market,a=t.data?.rows??[];return(0,$.jsxs)(Z,{className:`surface-card`,children:[(0,$.jsxs)(`div`,{className:`section-head section-head-inline`,children:[(0,$.jsx)(`h3`,{children:`Search demand`}),i&&(0,$.jsx)(X,{label:`${i.country.toUpperCase()} · ${i.language}`,text:`Exact-match Bing searches per week for your tracked queries, averaged over the weeks stored. This is demand, not your traffic. Refreshed weekly.`})]}),t.isError?(0,$.jsxs)(`p`,{className:`text-copy-14 text-negative`,children:[`Could not load search demand: `,an(t.error)]}):(0,$.jsx)(`div`,{className:`overflow-x-auto`,children:(0,$.jsxs)(`table`,{className:`data-table w-full text-label-14`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{className:`w-7`,children:(0,$.jsx)(`span`,{className:`sr-only`,children:`Expand`})}),(0,$.jsx)(`th`,{className:`text-left`,children:`Tracked query`}),(0,$.jsx)(`th`,{className:`text-right`,children:`Searches / week`}),(0,$.jsx)(`th`,{className:`text-right`,children:`Latest week`})]})}),(0,$.jsxs)(`tbody`,{children:[a.length===0&&(0,$.jsx)(`tr`,{children:(0,$.jsx)(`td`,{colSpan:4,className:`py-6 text-center text-secondary`,children:t.isPending?`Loading…`:`No search demand stored yet. It is read weekly for tracked queries.`})}),a.map(t=>{let i=n===t.query;return(0,$.jsxs)(Q.Fragment,{children:[(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{children:(0,$.jsx)(`button`,{type:`button`,"aria-expanded":i,"aria-label":`${i?`Hide`:`Show`} weekly searches for ${t.query}`,className:`rounded p-0.5 text-secondary hover:text-strong focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-mono-400`,onClick:()=>r(i?null:t.query),children:i?(0,$.jsx)(d,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}):(0,$.jsx)(u,{className:`h-3.5 w-3.5`,"aria-hidden":`true`})})}),(0,$.jsx)(`td`,{className:`text-strong`,children:t.query}),(0,$.jsx)(`td`,{className:`text-right tabular-nums text-neutral`,children:nu(t.avgWeeklyImpressions)}),(0,$.jsx)(`td`,{className:`text-right tabular-nums text-secondary`,children:nu(t.latestImpressions)})]}),i&&(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{}),(0,$.jsx)(`td`,{colSpan:3,className:`pb-4`,children:(0,$.jsx)(xu,{projectName:e,query:t.query})})]})]},t.query)})]})]})})]})}function xu({projectName:e,query:t}){let n=w({...Xi({client:K,path:{name:e},query:{query:t}}),staleTime:Qn}),r=n.data?.history??[];return n.isPending?(0,$.jsx)(`p`,{className:`text-copy-13 text-secondary`,children:`Loading…`}):r.length===0?(0,$.jsx)(`p`,{className:`text-copy-13 text-secondary`,children:`No weeks stored.`}):(0,$.jsxs)(`table`,{className:`data-table w-full max-w-md text-label-13`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{className:`text-left`,children:`Week`}),(0,$.jsx)(`th`,{className:`text-right`,children:`Exact`}),(0,$.jsx)(`th`,{className:`text-right`,children:`Broad`})]})}),(0,$.jsx)(`tbody`,{children:r.map(e=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{className:`tabular-nums`,children:_a(e.date)}),(0,$.jsx)(`td`,{className:`text-right tabular-nums`,children:e.impressions.toLocaleString()}),(0,$.jsx)(`td`,{className:`text-right tabular-nums text-secondary`,children:e.broadImpressions.toLocaleString()})]},e.date))})]})}function Su({projectName:e,siteUrl:t,snapshots:n}){let r=S(),i={name:e},a=w({...Ki({client:K,path:i}),staleTime:Qn}),o=w({...Fi({client:K,path:i}),staleTime:Qn}),s=w({...hi({client:K,path:i,query:{days:`30`}}),staleTime:Qn}),[c,l]=(0,Q.useState)(`not-indexed`),[u,d]=(0,Q.useState)(!1),[f,p]=(0,Q.useState)(``),[m,h]=(0,Q.useState)(null),[g,_]=(0,Q.useState)(null),v=ou(au(n,`url-submission-quota`)),y=a.data?.summary,b=s.data?.rows[0],x=a.data?.notIndexed??[],C=a.data?.unknown??[],T=a.data?.indexed??[],E=o.data??[];async function D(t,n){d(!0),_(null);try{let{succeeded:i,failed:a,total:o}=(await Bt(e,t)).summary;Xn({title:a===0?`Sent to Bing`:`Some URLs were not sent`,detail:a===0?`${i} of ${o} URL${o===1?``:`s`} submitted.`:`${i} of ${o} submitted, ${a} not sent.`,tone:a===0?`positive`:`caution`,dedupeKey:`bing:indexing:${e}:${n}`,dedupeMode:`replace`}),await Zn(r,`bing`)}catch(t){let r=an(t);_(r),Xn({title:`Bing submission failed`,detail:r,tone:`negative`,dedupeKey:`bing:indexing:${e}:${n}`,dedupeMode:`replace`})}finally{d(!1)}}async function O(){if(f.trim()){_(null);try{let t=await Et(e,f.trim());h(t),await Zn(r,`bing`)}catch(e){_(an(e))}}}let k=y?[{label:`Indexed`,value:y.indexed.toLocaleString()},{label:`Not in index`,value:(y.notIndexed+(y.unknown??0)).toLocaleString(),tooltip:`Pages Bing has not confirmed in its index, including those with an unknown status.`},{label:`Status unknown`,value:(y.unknown??0).toLocaleString()},{label:`Coverage`,value:G(y.percentage,rt.percent)}]:[],A=Ds({rows:c===`not-indexed`?x:c===`unknown`?C:c===`indexed`?T:[],pageSize:Yl}),j=Ds({rows:E,pageSize:Yl}),M=Ds({rows:s.data?.rows??[],pageSize:Yl}),N=[{key:`not-indexed`,label:`Not indexed (${x.length})`},{key:`unknown`,label:`Status unknown (${C.length})`},{key:`indexed`,label:`Indexed (${T.length})`},{key:`inspections`,label:`Inspections (${E.length})`},{key:`crawl`,label:`Crawl by day`}],P=!Y()&&(c===`not-indexed`||c===`unknown`)&&(c===`not-indexed`?x.length:C.length)>0;return(0,$.jsxs)(Z,{className:`surface-card`,children:[(0,$.jsxs)(`div`,{className:`section-head section-head-inline`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1`,children:[(0,$.jsx)(`h3`,{children:`Index and crawl`}),b&&b.crawlErrors>0&&(0,$.jsx)(X,{tone:`caution`,label:`${b.crawlErrors.toLocaleString()} crawl error${b.crawlErrors===1?``:`s`}`,text:`Bingbot got errors from ${b.crawlErrors===1?`one URL`:`${b.crawlErrors.toLocaleString()} URLs`} on ${_a(b.date)}. Crawl by day has the codes.`})]}),(0,$.jsx)(`p`,{className:`text-copy-13 text-muted`,children:a.data?.lastInspectedAt?`Last inspected ${Nn(a.data.lastInspectedAt)}`:`No inspection history yet`})]}),(0,$.jsx)(`div`,{className:`space-y-4`,children:k.length>0?(0,$.jsx)(ul,{label:`Bing index coverage`,items:k}):(0,$.jsx)(`p`,{className:`text-copy-13 text-muted`,children:`No coverage data yet. Inspect URLs to build coverage data.`})}),(0,$.jsxs)(`div`,{className:`mt-4 flex flex-wrap items-end justify-between gap-3 border-b border-base`,children:[(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1`,role:`tablist`,"aria-label":`Bing index and crawl lists`,children:N.map(e=>(0,$.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":c===e.key,className:`border-b-2 px-3 py-1.5 text-button-14 transition-colors ${c===e.key?`border-mono-200 text-strong`:`border-transparent text-muted hover:text-neutral`}`,onClick:()=>{l(e.key),A.setPage(1)},children:e.label},e.key))}),P&&(0,$.jsxs)(`div`,{className:`mb-1.5 flex flex-wrap items-center gap-2`,children:[v&&(0,$.jsxs)(`span`,{className:`text-label-13 text-secondary`,children:[v.dailyQuota.toLocaleString(),` submissions left today`]}),(0,$.jsx)(vs,{size:`sm`,variant:`outline`,disabled:u,onClick:Jn(()=>D({allUnindexed:!0},`all`)),children:u?`Submitting…`:`Submit all to Bing`})]})]}),g&&(0,$.jsx)(`p`,{className:`mt-2 text-copy-13 text-negative`,children:g}),(0,$.jsxs)(`div`,{className:`mt-2 overflow-x-auto`,children:[(c===`not-indexed`||c===`unknown`||c===`indexed`)&&(()=>{let e=c!==`indexed`&&!Y();return(0,$.jsxs)(`table`,{className:`data-table w-full text-label-14`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{className:`text-left`,children:`URL`}),(0,$.jsx)(`th`,{className:`text-right`,children:c===`not-indexed`?`HTTP`:`Last crawled`}),e&&(0,$.jsx)(`th`,{className:`text-right`,children:(0,$.jsx)(`span`,{className:`sr-only`,children:`Action`})})]})}),(0,$.jsxs)(`tbody`,{children:[A.totalRows===0&&(0,$.jsx)(`tr`,{children:(0,$.jsx)(`td`,{colSpan:e?3:2,className:`py-6 text-center text-secondary`,children:a.isPending?`Loading…`:`None.`})}),A.rows.map(n=>(0,$.jsxs)(`tr`,{className:`group`,children:[(0,$.jsx)(`td`,{className:`max-w-lg`,children:(0,$.jsx)(Ss,{value:iu(n.url,t),title:n.url,className:`font-mono text-label-13 text-neutral`})}),(0,$.jsx)(`td`,{className:`text-right tabular-nums text-secondary`,children:c===`not-indexed`?n.httpCode??`—`:n.lastCrawledDate?Nn(n.lastCrawledDate):`—`}),e&&(0,$.jsx)(`td`,{className:`text-right`,children:(0,$.jsx)(`div`,{className:`opacity-0 transition-opacity group-hover:opacity-100 group-focus-within:opacity-100 pointer-coarse:opacity-100`,children:(0,$.jsx)(vs,{size:`sm`,variant:`ghost`,disabled:u,onClick:Jn(()=>D({urls:[n.url]},n.url)),children:`Submit`})})})]},n.id))]})]})})(),(c===`not-indexed`||c===`unknown`||c===`indexed`)&&(0,$.jsx)(Ts,{page:A.page,pageSize:Yl,visibleRows:A.rows.length,totalRows:A.totalRows,onPageChange:A.setPage,itemLabel:`URLs`}),c===`inspections`&&(0,$.jsxs)(`div`,{className:`space-y-3 pt-2`,children:[!Y()&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 lg:flex-row`,children:[(0,$.jsx)(`input`,{type:`text`,"aria-label":`URL to inspect`,className:`flex-1 rounded border border-strong bg-transparent px-2 py-1.5 text-label-14 text-strong placeholder-mono-400 focus:border-mono-500 focus:outline-none`,placeholder:`URL to inspect`,value:f,onChange:e=>p(e.target.value),onKeyDown:e=>{e.key===`Enter`&&O()}}),(0,$.jsx)(vs,{size:`sm`,disabled:!f.trim(),onClick:Jn(O),children:`Inspect`})]}),m&&(0,$.jsxs)(`div`,{className:`material-base space-y-1 p-3 text-label-13`,children:[(0,$.jsx)(`div`,{className:`text-label-13-strong text-strong`,children:m.url}),(0,$.jsxs)(`div`,{className:`text-secondary`,children:[`In index: `,(0,$.jsx)(`span`,{className:m.inIndex?`text-positive`:`text-negative`,children:m.inIndex?`Yes`:`No`}),` · `,`HTTP: `,m.httpCode??`—`,` · `,`Crawled: `,m.lastCrawledDate??`—`]})]}),(0,$.jsxs)(`table`,{className:`data-table w-full text-label-14`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{className:`text-left`,children:`URL`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Index`}),(0,$.jsx)(`th`,{className:`text-right`,children:`HTTP`}),(0,$.jsx)(`th`,{className:`text-right`,children:`Inspected`})]})}),(0,$.jsxs)(`tbody`,{children:[E.length===0&&(0,$.jsx)(`tr`,{children:(0,$.jsx)(`td`,{colSpan:4,className:`py-6 text-center text-secondary`,children:o.isPending?`Loading…`:`No inspections yet.`})}),j.rows.map(e=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{className:`max-w-lg`,children:(0,$.jsx)(Ss,{value:iu(e.url,t),title:e.url,className:`font-mono text-label-13 text-neutral`})}),(0,$.jsx)(`td`,{children:(0,$.jsx)(J,{tone:e.inIndex?`positive`:`negative`,children:e.inIndex?`Yes`:`No`})}),(0,$.jsx)(`td`,{className:`text-right tabular-nums text-secondary`,children:e.httpCode??`—`}),(0,$.jsx)(`td`,{className:`text-right tabular-nums text-secondary`,children:Nn(e.inspectedAt)})]},e.id))]})]}),(0,$.jsx)(Ts,{page:j.page,pageSize:Yl,visibleRows:j.rows.length,totalRows:j.totalRows,onPageChange:j.setPage,itemLabel:`inspections`})]}),c===`crawl`&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`table`,{className:`data-table w-full text-label-13`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{className:`text-left`,children:`Day`}),(0,$.jsx)(`th`,{className:`text-right`,children:`Crawled`}),(0,$.jsx)(`th`,{className:`text-right`,children:`Errors`}),(0,$.jsx)(`th`,{className:`text-right`,children:`In index`}),(0,$.jsx)(`th`,{className:`text-right`,children:`2xx`}),(0,$.jsx)(`th`,{className:`text-right`,children:`301`}),(0,$.jsx)(`th`,{className:`text-right`,children:`302`}),(0,$.jsx)(`th`,{className:`text-right`,children:`4xx`}),(0,$.jsx)(`th`,{className:`text-right`,children:`5xx`}),(0,$.jsx)(`th`,{className:`text-right`,children:`Other`}),(0,$.jsx)(`th`,{className:`text-right`,children:`Robots.txt`}),(0,$.jsx)(`th`,{className:`text-right`,children:`Timeouts`}),(0,$.jsx)(`th`,{className:`text-right`,children:`DNS`}),(0,$.jsx)(`th`,{className:`text-right`,children:`Malware`}),(0,$.jsx)(`th`,{className:`text-right`,children:`Inbound links`})]})}),(0,$.jsxs)(`tbody`,{children:[(s.data?.rows??[]).length===0&&(0,$.jsx)(`tr`,{children:(0,$.jsx)(`td`,{colSpan:15,className:`py-6 text-center text-secondary`,children:s.isPending?`Loading…`:`No crawl stats stored yet.`})}),M.rows.map(e=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{className:`tabular-nums`,children:_a(e.date)}),[e.crawledPages,e.crawlErrors,e.inIndex,e.code2xx,e.code301,e.code302,e.code4xx,e.code5xx,e.allOtherCodes,e.blockedByRobotsTxt,e.connectionTimeout,e.dnsFailures,e.containsMalware,e.inLinks].map((e,t)=>(0,$.jsx)(`td`,{className:`text-right tabular-nums text-secondary`,children:e.toLocaleString()},t))]},e.date))]})]}),(0,$.jsx)(Ts,{page:M.page,pageSize:Yl,visibleRows:M.rows.length,totalRows:M.totalRows,onPageChange:M.setPage,itemLabel:`days`})]})]})]})}function Cu({projectName:e,siteUrl:t}){let{canWrite:n}=qn(),r=w({...Cr({client:K,path:{name:e}}),staleTime:Qn}),[i,a]=(0,Q.useState)(!1),[o,s]=(0,Q.useState)(!1);async function c(t){a(!0);let n=[];try{for(let r of t)await wt(e,r),n.push(r);let r=n.length;Xn({title:r===1?`Sent to Bing`:`${r} sitemaps sent to Bing`,detail:`Bing reads it soon. A new sitemap shows in the list after the next Bing sync.`,tone:`positive`,dedupeKey:`bing:submit-sitemap:${e}`,dedupeMode:`replace`})}catch(r){Xn({title:n.length>0?`Bing took ${n.length} of ${t.length}`:`Bing did not take the sitemap`,detail:an(r),tone:`negative`,dedupeKey:`bing:submit-sitemap:${e}`,dedupeMode:`replace`})}finally{a(!1)}return n}async function l(t){s(!0);try{await kt(e,{sitemapUrl:t}),Xn({title:`Checking sitemap URLs in Bing`,detail:`Coverage updates when the check finishes.`,tone:`neutral`,dedupeKey:`bing:inspect-sitemap:${e}`,dedupeMode:`replace`})}catch(t){Xn({title:`Sitemap check could not start`,detail:an(t),tone:`negative`,dedupeKey:`bing:inspect-sitemap:${e}`,dedupeMode:`replace`})}finally{s(!1)}}return(0,$.jsx)(Pl,{engine:`Bing`,data:r.isError?null:r.isPending?void 0:r.data.bing,loadError:r.isError?an(r.error):null,label:e=>iu(e,t),canSubmit:n,onSubmit:c,submitting:i,onInspect:e=>void l(e),inspecting:o,notRead:(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:`Bing's sitemap list arrives with the next Bing sync.`}),readOnly:Y()})}var wu=`Bing shows this only to the site owner key. Not a failure.`;function Tu({siteUrl:e,snapshots:t}){let n=ou(au(t,`url-submission-quota`)),r=ou(au(t,`content-submission-quota`)),i=su(au(t,`crawl-settings`)),a=[{kind:`blocked-urls`,label:`Blocked URLs`,columns:[{key:`url`,label:`URL`},{key:`entityType`,label:`Type`},{key:`requestType`,label:`Removal`},{key:`daysToExpire`,label:`Days left`},{key:`date`,label:`Added`}]},{kind:`page-preview-blocks`,label:`Preview blocks`,columns:[]},{kind:`deep-link-blocks`,label:`Sitelink blocks`,columns:[]},{kind:`query-parameters`,label:`URL parameters`,columns:[{key:`parameter`,label:`Parameter`},{key:`isEnabled`,label:`Enabled`},{key:`source`,label:`Source`},{key:`date`,label:`Added`}]},{kind:`country-region-settings`,label:`Geo-targeting`,columns:[{key:`url`,label:`URL`},{key:`countryCode`,label:`Country`},{key:`type`,label:`Applies to`},{key:`date`,label:`Added`}]},{kind:`crawl-issues`,label:`Crawl issues`,columns:[{key:`url`,label:`URL`},{key:`httpCode`,label:`HTTP`},{key:`issues`,label:`Issues`},{key:`inLinks`,label:`Inbound links`}]},{kind:`fetched-urls`,label:`Fetch as Bingbot`,columns:[{key:`url`,label:`URL`},{key:`fetched`,label:`Fetched`},{key:`expired`,label:`Expired`},{key:`date`,label:`Requested`}]},{kind:`connected-pages`,label:`Connected pages`,columns:[]},{kind:`site-roles`,label:`Users and roles`,columns:[{key:`email`,label:`User`},{key:`role`,label:`Role`},{key:`expired`,label:`Expired`},{key:`date`,label:`Added`}]}];function o(e,t){if(!e)return{value:`—`,help:`Not read yet.`};if(e.status===`unauthorized`)return{value:`Owner key needed`,help:wu};if(e.status===`failed`&&t===null)return{value:`—`,help:`The last read failed: ${e.error??`no detail`}`};let n=t?.length??0;return{value:n===0?`None`:n.toLocaleString()}}let s=a.map(({kind:n,label:r,columns:i})=>{let a=au(t,n),s=cu(a),{value:c,help:l}=o(a,s),u=a?.status===`failed`&&s!==null,d=i.length>0||!s?i:[...new Set(s.flatMap(e=>Object.keys(e)))].filter(e=>e!==`__type`).map(e=>({key:e,label:e}));return(0,$.jsx)(Eu,{label:r,value:c,help:l,note:u?`from an earlier sync`:void 0,children:s&&s.length>0?(0,$.jsxs)(`div`,{className:`overflow-x-auto`,children:[u&&(0,$.jsxs)(`p`,{className:`mb-2 text-copy-13 text-caution`,children:[`The last read failed, so these rows are from an earlier sync: `,a?.error??`no detail`]}),(0,$.jsxs)(`table`,{className:`data-table w-full text-label-13`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsx)(`tr`,{children:d.map(e=>(0,$.jsx)(`th`,{className:`text-left`,children:e.label},e.key))})}),(0,$.jsx)(`tbody`,{children:s.map((t,n)=>(0,$.jsx)(`tr`,{children:d.map(n=>{let r=t[n.key]??t[n.key.charAt(0).toUpperCase()+n.key.slice(1)];return(0,$.jsx)(`td`,{className:n.key.toLowerCase()===`url`?`max-w-md`:`text-secondary`,children:n.key.toLowerCase()===`url`&&typeof r==`string`?(0,$.jsx)(Ss,{value:iu(r,e),title:r,className:`font-mono text-neutral`}):uu(r,n.key)},n.key)})},n))})]})]}):void 0},n)}),c=e=>s[a.findIndex(t=>t.kind===e)],l=e=>e?`${e.dailyQuota.toLocaleString()} today \u00b7 ${e.monthlyQuota.toLocaleString()} this month`:`—`;return(0,$.jsxs)(Z,{className:`surface-card`,children:[(0,$.jsx)(`div`,{className:`section-head section-head-inline`,children:(0,$.jsx)(`h3`,{children:`Site settings`})}),(0,$.jsxs)(`div`,{role:`list`,"aria-label":`Bing site settings`,children:[c(`blocked-urls`),c(`crawl-issues`),(0,$.jsx)(Eu,{label:`URL submissions left`,value:l(n),help:`URL submissions Bing will still accept, as of the last sync.`}),(0,$.jsx)(Eu,{label:`Content submissions left`,value:l(r)}),(0,$.jsx)(Eu,{label:`Crawl boost`,value:i?i.crawlBoostEnabled?`On`:i.crawlBoostAvailable?`Off`:`Not offered`:`—`}),i&&i.crawlRate.length===24&&(0,$.jsx)(Eu,{label:`Crawl rate by hour`,value:`24 hours`,children:(0,$.jsx)(`div`,{className:`overflow-x-auto`,children:(0,$.jsxs)(`table`,{className:`data-table text-label-13`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsx)(`tr`,{children:i.crawlRate.map((e,t)=>(0,$.jsx)(`th`,{className:`text-right`,children:t},t))})}),(0,$.jsx)(`tbody`,{children:(0,$.jsx)(`tr`,{children:i.crawlRate.map((e,t)=>(0,$.jsx)(`td`,{className:`text-right tabular-nums text-secondary`,children:e},t))})})]})})}),c(`fetched-urls`),c(`query-parameters`),c(`country-region-settings`),c(`page-preview-blocks`),c(`deep-link-blocks`),c(`connected-pages`),c(`site-roles`)]})]})}function Eu({label:e,value:t,help:n,note:r,children:i}){let[a,o]=(0,Q.useState)(!1),s=(0,$.jsx)(`span`,{className:`flex-1 text-label-14 text-strong`,children:e}),c=(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5 text-label-14 tabular-nums text-secondary`,children:[r&&(0,$.jsx)(`span`,{className:`text-label-12 text-caution`,children:r}),t]});return i?(0,$.jsx)(`div`,{role:`listitem`,className:`border-t border-default first:border-t-0`,children:(0,$.jsxs)(`details`,{className:`group`,onToggle:e=>o(e.currentTarget.open),children:[(0,$.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center gap-2 py-2.5 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-mono-400 [&::-webkit-details-marker]:hidden`,children:[(0,$.jsx)(u,{className:`h-3.5 w-3.5 shrink-0 text-secondary transition-transform group-open:rotate-90`,"aria-hidden":`true`}),s,c]}),a&&(0,$.jsx)(`div`,{className:`pb-4 pl-5.5`,children:i})]})}):(0,$.jsxs)(`div`,{role:`listitem`,className:`flex items-center gap-2 border-t border-default py-2.5 first:border-t-0`,children:[(0,$.jsx)(`span`,{className:`w-3.5 shrink-0`,"aria-hidden":`true`}),s,c,n&&(0,$.jsx)(X,{text:n})]})}var Du=ua[0],Ou=ua[1],ku=ua[2],Au=ua[3],ju=ua[4],Mu=[`both`,`server`,`ga4`],Nu=[`days`,`months`],Pu={serverLoading:`Loading monthly server visits…`,gaLoading:`Loading monthly GA4 visits…`,gaStatusLoading:`Checking the GA4 connection…`,serverError:`Could not load monthly server visits.`,gaError:`Could not load monthly GA4 visits.`,gaStatusError:`Could not check the GA4 connection.`,retryServer:`Retry monthly server visits`,retryGa:`Retry monthly GA4 visits`,retryGaStatus:`Retry GA4 connection check`,connectGa:`Connect Google Analytics 4 to see monthly visits.`,emptyMonths:`No monthly visits recorded yet.`},Fu=e=>new Date(`${e}-01T00:00:00.000Z`),Iu=e=>Fu(e).toLocaleDateString(void 0,{month:`short`,timeZone:`UTC`}),Lu=e=>Fu(String(e)).toLocaleDateString(void 0,{month:`long`,year:`numeric`,timeZone:`UTC`}),Ru=e=>Number(e.slice(0,4))*12+Number(e.slice(5,7)),zu={fontSize:12,paddingTop:6},Bu=e=>typeof e==`number`?Tt(Math.round(e)):String(e),Vu=`Visits, server`,Hu=`${Vu} (older count)`,Uu=`${Vu} (part month)`,Wu=`Visits, GA4 (part month)`,Gu=e=>typeof e==`number`&&Number.isFinite(e)?e:0;function Ku(e,t){if(!e||t<2)return Array(t).fill(null);let n=e.endIndex-e.startIndex;if(n<=0)return Array(t).fill(null);let r=(e.end-e.start)/n;return Array.from({length:t},(t,n)=>n<e.startIndex||n>e.endIndex?null:e.start+(n-e.startIndex)*r)}function qu(e,t){if(!e||t<e.startMonth||t>e.endMonth)return null;let n=Ru(e.endMonth)-Ru(e.startMonth);return n<=0?null:e.start+(e.end-e.start)*((Ru(t)-Ru(e.startMonth))/n)}function Ju(e,t){if(!e||t<e.startDate||t>e.endDate)return null;let n=Date.parse(`${e.startDate}T00:00:00.000Z`),r=Date.parse(`${e.endDate}T00:00:00.000Z`)-n;return r<=0?null:e.start+(e.end-e.start)*((Date.parse(`${t}T00:00:00.000Z`)-n)/r)}function Yu(e){let t=e=>e.measured!==!1;if(e.length===0||t(e[0]))return null;let n=e.findIndex(t)-1;return n<0?{from:e[0].bucket,to:e[e.length-1].bucket}:{from:e[0].bucket,to:e[n].bucket}}function Xu(e,t){if(!t)return null;let n=e.find(e=>e.measured!==!1),r=e[e.length-1]?.bucket;return!n||!r||t<n.bucket?null:{from:n.bucket,to:t<r?t:r}}function Zu(e,t,n=!1){return r=>{let{cx:i,cy:a,index:o,key:s}=r,c=o??-1,l=e[c]!=null&&e[c-1]==null&&e[c+1]==null;return e[c]==null||!n&&!l||i===void 0||a===void 0?(0,$.jsx)(`g`,{},s):n?(0,$.jsx)(`circle`,{cx:i,cy:a,r:3.2,fill:`none`,stroke:t,strokeWidth:1.6},s):(0,$.jsx)(`circle`,{cx:i,cy:a,r:2.6,fill:t,stroke:`none`},s)}}function Qu({projectName:e,sinceMinutes:t}){let[n,r]=(0,Q.useState)(!0),[i,a]=(0,Q.useState)(!0),[o,s]=(0,Q.useState)(`both`),[c,l]=(0,Q.useState)(`days`),u=c===`months`,d=(0,Q.useMemo)(()=>{let e=new Date;return{since:new Date(Date.UTC(e.getUTCFullYear(),e.getUTCMonth()-11,1)).toISOString(),until:e.toISOString()}},[]),f=Vs(e,{range:d,granularity:`month`,limit:1},{enabled:u}),p=Vs(e,{sinceMinutes:t,granularity:`day`,limit:1}),m=Us(e),h=w({...ir({client:K,path:{name:e}}),enabled:!!e,staleTime:er}),g=h.data?.connected===!0,_=w({...hr({client:K,path:{name:e},query:{window:t>=259200?`180d`:t>=129600?`90d`:t>=43200?`30d`:`7d`}}),enabled:!!e&&g,staleTime:er}),v=w({...hr({client:K,path:{name:e},query:{startDate:d.since.slice(0,10)}}),enabled:!!e&&g&&u,staleTime:er}),y=(0,Q.useMemo)(()=>p.data?.series?.points??[],[p.data]),b=(0,Q.useMemo)(()=>{let e=_.data;return new Map((e?.days??[]).map(e=>[e.date,e.sessions]))},[_.data]),x=_.data?.trend??null,S=(0,Q.useMemo)(()=>Yu(y),[y]),C=p.data?.series?.coverageStart??null,T=p.data?.series?.aiReferralCountingChangedAt??null,E=(0,Q.useMemo)(()=>Xu(y,T?.slice(0,10)),[T,y]),D=p.data?.series?.trends,O=(0,Q.useMemo)(()=>{let e=Ku(D?.crawlerContentHits,y.length),t=Ku(D?.aiUserFetchHits,y.length),n=Ku(D?.aiReferralLandedHits,y.length);return y.map((r,i)=>({...r,crawlerContentHits:r.measured===!1?null:Gu(r.crawlerContentHits),aiUserFetchHits:r.measured===!1?null:Gu(r.aiUserFetchHits),aiReferralLandedHits:r.measured===!1?null:Gu(r.aiReferralLandedHits),ga4Visits:b.get(r.bucket)??null,ga4Trend:Ju(x,r.bucket),crawlTrend:e[i],fetchTrend:t[i],visitTrend:n[i]}))},[y,b,x,D]),k=f.data?.series,A=v.data,j=(0,Q.useMemo)(()=>k?.points??[],[k]),ie=(0,Q.useMemo)(()=>{let e=new Set(k?.partialBuckets??[]),t=new Map((A?.months??[]).map(e=>[e.month,e])),n=Ku(k?.trends?.aiReferralLandedHits,j.length),r=new Map(j.map((e,t)=>[e.bucket,{point:e,trend:n[t]}])),i=[...new Set([...r.keys(),...t.keys()])].sort().map(n=>{let i=r.get(n),a=i?.point,o=a&&a.measured!==!1?Gu(a.aiReferralLandedHits):null,s=t.get(n);return{bucket:n,aiReferralLandedHits:e.has(n)?null:o,serverPartial:e.has(n)?o:null,ga4Visits:s?.complete?s.sessions:null,ga4Partial:s&&!s.complete?s.sessions:null,visitTrend:i?.trend??null,ga4Trend:qu(A?.monthlyTrend,n),recorded:o!==null||(s?.sessions??null)!==null}}),a=i.findIndex(e=>e.recorded);return a>0?i.slice(a):i},[j,k,A]),z=u?ie:O,ae=(0,Q.useMemo)(()=>{if(o===`ga4`)return null;if(!u)return S;let e=new Set(ie.map(e=>e.bucket));return Yu(j.filter(t=>e.has(t.bucket)))},[o,u,j,ie,S]),B=(0,Q.useMemo)(()=>u?Xu(j,k?.aiReferralCountingChangedAt?.slice(0,7)):E,[u,j,k,E]),V=B!==null&&o!==`ga4`,oe=(e,t,n)=>{let r=n.payload?.bucket;return B&&t===Vu&&r!==void 0&&r<=B.to?[Bu(e),Hu]:Bu(e)},se=(A?.months??[]).filter(e=>e.complete&&e.sessions!==null).at(-1)??null,ce=ie.filter(e=>e.aiReferralLandedHits!==null).at(-1)??null,le=o===`server`?ce?.bucket??null:o===`ga4`?se?.month??null:se?.month??ce?.bucket??null,ue=le?ie.find(e=>e.bucket===le)?.aiReferralLandedHits??null:null,de=A?.monthlyTrend??null,fe=u&&o!==`ga4`,pe=u&&o!==`server`,H=pe&&g,me=fe&&f.isSuccess||H&&v.isSuccess,he=(!fe||f.isSuccess)&&(!pe||h.isSuccess&&(!g||v.isSuccess)),ge=ie.some(e=>fe&&(e.aiReferralLandedHits!==null||e.serverPartial!==null)||H&&(e.ga4Visits!==null||e.ga4Partial!==null)),_e=ie.find(e=>e.bucket===d.until.slice(0,7)),ve=H?_e?.ga4Partial??null:null,ye=fe?_e?.serverPartial??null:null,be=ve!==null||ye!==null,xe=p.data?.totals,Se=xe&&{crawlers:Gu(xe.crawlerContentHits),fetches:Gu(xe.aiUserFetchHits),visits:Gu(xe.aiReferralLandedHits)},Ce=(0,Q.useMemo)(()=>y.reduce((e,t)=>({crawlers:e.crawlers+Gu(t.crawlerContentHits),fetches:e.fetches+Gu(t.aiUserFetchHits),visits:e.visits+Gu(t.aiReferralLandedHits)}),{crawlers:0,fetches:0,visits:0}),[y]),we=Se??Ce,Te=we.crawlers>0||we.fetches>0||we.visits>0,Ee=null;if(p.isLoading)Ee=(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:`Loading AI traffic history…`});else if(p.isError)Ee=(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`p`,{role:`alert`,className:`text-copy-14 text-negative`,children:`Could not load AI traffic history.`}),(0,$.jsx)(X,{text:`The request failed, so this is not a reading of zero activity. Retry, or check the traffic source.`})]});else if(!Te){let e=m.data?.sources,t=e!==void 0&&e.length===0,n=!t&&C===null;Ee=(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:t?`No server-side traffic source connected yet.`:n?`No AI activity recorded yet.`:`No AI activity recorded in this period.`}),(0,$.jsx)(X,{text:t?`Connect a traffic source to see how AI engines read this site over time.`:n?`The source is connected but has not reported anything yet. A new source can take a few hours to appear.`:`The window was measured and nothing was recorded. Try a longer range.`})]})}return(0,$.jsxs)(`div`,{children:[Ee??(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`mb-5`,children:(0,$.jsx)(ul,{label:`AI traffic totals`,items:[{label:`AI crawlers`,value:Tt(we.crawlers),detail:`pages crawled`,tooltip:`Requests from AI crawlers for a real content page. Robots.txt and sitemap re-fetches are excluded, because they are not a page an engine read.`},{label:`AI page fetches`,value:Tt(we.fetches),detail:`reading a page to answer`,tooltip:`An AI engine fetching a page live while answering someone, rather than crawling it for an index.`},{label:`AI visitors`,value:Tt(we.visits),detail:E?`older days may read high`:`arrived from an AI answer`,tooltip:`Visits your server answered that came from an AI engine. Requests answered with a redirect are excluded: a redirect is a hop, not an arrival.`+(E?` Days through ${_a(E.to)} were counted by an older rule that also counted a visitor's later pages, so they can read high and cannot be recounted.`:``)}]})}),y.length>0&&(0,$.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-5 gap-y-1 pb-3 mb-4 border-b border-default text-label-12 text-muted`,children:[(0,$.jsx)(`span`,{className:`text-secondary text-label-12-strong`,children:`Latest day (UTC)`}),(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`span`,{className:`text-heading text-label-12-strong tabular-nums mr-1`,children:Gu(y[y.length-1].crawlerContentHits).toLocaleString()}),`pages crawled`]}),(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`span`,{className:`text-heading text-label-12-strong tabular-nums mr-1`,children:Gu(y[y.length-1].aiUserFetchHits).toLocaleString()}),`page fetches`]}),(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`span`,{className:`text-heading text-label-12-strong tabular-nums mr-1`,children:Gu(y[y.length-1].aiReferralLandedHits).toLocaleString()}),`visits, server`]}),(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`span`,{className:`text-heading text-label-12-strong tabular-nums mr-1`,children:b.get(y[y.length-1].bucket)?.toLocaleString()??`—`}),`visits, GA4`]}),(0,$.jsx)(`span`,{className:`text-faint`,children:`still filling`})]}),(0,$.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`h3`,{className:`text-heading-14 text-heading`,children:`Machines reading your site`}),(0,$.jsx)(X,{text:`Crawlers index pages for later. Page fetches happen while an engine is answering someone. Both are machines, not people.`})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,$.jsxs)(`label`,{className:`flex items-center gap-1.5 text-label-12 text-secondary cursor-pointer`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:n,onChange:e=>r(e.target.checked),className:`accent-current`}),`Page fetches`]}),(0,$.jsxs)(`label`,{className:`flex items-center gap-1.5 text-label-12 text-secondary cursor-pointer`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:i,onChange:e=>a(e.target.checked),className:`accent-current`}),`Trend line`]})]})]}),(0,$.jsx)(I,{width:`100%`,height:206,children:(0,$.jsxs)(ne,{data:O,margin:{top:4,right:8,left:-18,bottom:0},children:[(0,$.jsx)(M,{stroke:`var(--chart-grid, #2e2e2e)`,vertical:!1}),(0,$.jsx)(P,{dataKey:`bucket`,tick:va,stroke:`var(--chart-axis, #2e2e2e)`,tickFormatter:fa,minTickGap:28}),(0,$.jsx)(ee,{tick:va,stroke:`var(--chart-axis, #2e2e2e)`,width:48,allowDecimals:!1}),(0,$.jsx)(N,{contentStyle:Sa.contentStyle,labelStyle:Sa.labelStyle,itemStyle:Sa.itemStyle,labelFormatter:_a,formatter:Bu}),S&&(0,$.jsx)(F,{x1:S.from,x2:S.to,fill:`var(--color-overlay-hover)`,fillOpacity:.5,stroke:`none`,label:{value:`not measured`,position:`insideTop`,fontSize:12,fill:`var(--chart-neutral-text-dim, #a1a1a1)`}}),(0,$.jsx)(R,{wrapperStyle:zu,iconType:`plainline`,iconSize:14}),(0,$.jsx)(L,{type:`monotone`,dataKey:`crawlerContentHits`,name:`Pages crawled`,stroke:Du,fill:Du,fillOpacity:.22,strokeWidth:1.8}),n&&(0,$.jsx)(L,{type:`monotone`,dataKey:`aiUserFetchHits`,name:`Page fetches`,stroke:Ou,fill:Ou,fillOpacity:.18,strokeWidth:1.6}),i&&(0,$.jsx)(te,{type:`linear`,dataKey:`crawlTrend`,legendType:`none`,name:`Pages crawled trend`,dot:!1,tooltipType:`none`,stroke:Du,strokeWidth:1.4,strokeDasharray:`5 4`,connectNulls:!0}),i&&n&&(0,$.jsx)(te,{type:`linear`,dataKey:`fetchTrend`,legendType:`none`,name:`Page fetches trend`,dot:!1,tooltipType:`none`,stroke:Ou,strokeWidth:1.3,strokeDasharray:`5 4`,connectNulls:!0})]})})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3 mt-5 mb-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`h3`,{className:`text-heading-14 text-heading`,children:`People arriving from AI`}),(0,$.jsx)(X,{text:`Two independent counts of the same thing. Server reads your own logs and misses nothing a browser blocks, but cannot see a page served from cache. GA4 needs the browser to run a tag. They rarely match, and neither is the correction of the other.`})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[(0,$.jsx)(nl,{windows:Nu,value:c,onChange:l,label:`Visits by day or month`,formatOption:e=>e===`months`?`Months`:`Days`}),(0,$.jsx)(nl,{windows:Mu,value:o,onChange:s,label:`Visit measurement source`,formatOption:e=>e===`ga4`?`GA4`:e===`both`?`Both`:`Server`})]})]}),fe&&f.isLoading&&(0,$.jsx)(`p`,{role:`status`,className:`text-copy-14 text-secondary`,children:Pu.serverLoading}),H&&v.isLoading&&(0,$.jsx)(`p`,{role:`status`,className:`text-copy-14 text-secondary`,children:Pu.gaLoading}),pe&&h.isLoading&&(0,$.jsx)(`p`,{role:`status`,className:`text-copy-14 text-secondary`,children:Pu.gaStatusLoading}),pe&&h.isError&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`p`,{role:`alert`,className:`text-copy-14 text-negative`,children:Pu.gaStatusError}),(0,$.jsx)(q,{variant:`outline`,size:`sm`,"aria-label":Pu.retryGaStatus,disabled:h.isFetching,onClick:()=>{h.refetch()},children:`Retry`})]}),fe&&f.isError&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`p`,{role:`alert`,className:`text-copy-14 text-negative`,children:Pu.serverError}),(0,$.jsx)(q,{variant:`outline`,size:`sm`,"aria-label":Pu.retryServer,disabled:f.isFetching,onClick:()=>{f.refetch()},children:`Retry`})]}),H&&v.isError&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`p`,{role:`alert`,className:`text-copy-14 text-negative`,children:Pu.gaError}),(0,$.jsx)(q,{variant:`outline`,size:`sm`,"aria-label":Pu.retryGa,disabled:v.isFetching,onClick:()=>{v.refetch()},children:`Retry`})]}),u&&o===`ga4`&&h.isSuccess&&!g&&(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:Pu.connectGa}),me&&he&&!ge&&(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:Pu.emptyMonths}),u&&le&&(0,$.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-5 gap-y-1 pb-3 mb-3 text-label-12 text-muted`,children:[(0,$.jsx)(`span`,{className:`text-secondary text-label-12-strong`,children:Lu(le)}),o!==`server`&&se?.month===le&&(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`span`,{className:`text-heading text-label-12-strong tabular-nums mr-1`,children:Tt(se.sessions??0)}),`visits, GA4`]}),o!==`ga4`&&ue!==null&&(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`span`,{className:`text-heading text-label-12-strong tabular-nums mr-1`,children:Tt(ue)}),`visits, server`]}),o!==`server`&&de?.changePct!=null&&(0,$.jsxs)(`span`,{children:[(0,$.jsxs)(`span`,{className:`text-heading text-label-12-strong tabular-nums mr-1`,children:[de.changePct>0?`▲`:de.changePct<0?`▼`:``,G(Math.abs(de.changePct),rt.percent)]}),`trend since `,Iu(de.startMonth)]}),o!==`server`&&se?.month===le&&se.engines[0]&&(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`span`,{className:`text-heading text-label-12-strong tabular-nums mr-1`,children:Tt(se.engines[0].sessions)}),`from `,se.engines[0].label]})]}),be&&_e&&(0,$.jsxs)(`div`,{role:`group`,"aria-label":`Month so far`,className:`flex flex-wrap items-center gap-x-5 gap-y-1 mb-3 text-label-13 text-secondary`,children:[(0,$.jsxs)(`span`,{className:`text-label-13-strong`,children:[Lu(_e.bucket),` so far`]}),ve!==null&&(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`span`,{className:`text-heading text-label-13-strong tabular-nums mr-1`,children:Tt(ve)}),`visits, GA4`]}),ye!==null&&(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`span`,{className:`text-heading text-label-13-strong tabular-nums mr-1`,children:Tt(ye)}),`visits, server`]}),(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[`Hollow dots: partial months`,(0,$.jsx)(X,{text:`Hollow dots show part-month totals. The current month is still filling; earlier partial months have incomplete coverage. Partial months are kept off the connecting line and out of the trend.`})]})]}),(u?me&&ge:!Ee)&&(0,$.jsx)(I,{width:`100%`,height:176,children:(0,$.jsxs)(ne,{data:z,margin:{top:4,right:8,left:-18,bottom:0},children:[(0,$.jsx)(M,{stroke:`var(--chart-grid, #2e2e2e)`,vertical:!1}),(0,$.jsx)(P,{dataKey:`bucket`,tick:va,stroke:`var(--chart-axis, #2e2e2e)`,tickFormatter:u?Iu:fa,minTickGap:u?8:28}),(0,$.jsx)(ee,{tick:va,stroke:`var(--chart-axis, #2e2e2e)`,width:48,allowDecimals:!1}),(0,$.jsx)(N,{contentStyle:Sa.contentStyle,labelStyle:Sa.labelStyle,itemStyle:Sa.itemStyle,labelFormatter:u?Lu:_a,formatter:oe}),ae&&ae.from!==ae.to&&(0,$.jsx)(F,{x1:ae.from,x2:ae.to,fill:`var(--color-overlay-hover)`,fillOpacity:.5,stroke:`none`,label:{value:`not measured`,position:`insideTop`,fontSize:12,fill:`var(--chart-neutral-text-dim, #a1a1a1)`}}),B&&V&&(0,$.jsx)(F,{x1:B.from,x2:B.to,fill:`var(--color-overlay-hover)`,fillOpacity:.3,stroke:`none`}),B&&V&&(0,$.jsx)(re,{x:B.to,stroke:ju,strokeDasharray:`4 4`,strokeWidth:1.5}),(0,$.jsx)(R,{wrapperStyle:zu,iconType:`plainline`,iconSize:14}),o!==`ga4`&&(0,$.jsx)(te,{type:`monotone`,dataKey:`aiReferralLandedHits`,name:Vu,stroke:ku,strokeWidth:2,connectNulls:!1,dot:u?Zu(z.map(e=>e.aiReferralLandedHits??null),ku):!1}),u&&o!==`ga4`&&(0,$.jsx)(te,{type:`monotone`,dataKey:`serverPartial`,name:Uu,legendType:`none`,connectNulls:!1,stroke:ku,strokeWidth:0,activeDot:!1,dot:Zu(z.map(e=>e.serverPartial??null),ku,!0)}),o!==`server`&&(0,$.jsx)(te,{type:`monotone`,dataKey:`ga4Visits`,name:`Visits, GA4`,connectNulls:!1,stroke:Au,strokeWidth:1.8,strokeDasharray:`5 3`,dot:Zu(z.map(e=>e.ga4Visits??null),Au)}),u&&o!==`server`&&(0,$.jsx)(te,{type:`monotone`,dataKey:`ga4Partial`,name:Wu,legendType:`none`,connectNulls:!1,stroke:Au,strokeWidth:0,activeDot:!1,dot:Zu(z.map(e=>e.ga4Partial??null),Au,!0)}),i&&o!==`ga4`&&(0,$.jsx)(te,{type:`linear`,dataKey:`visitTrend`,legendType:`none`,name:`Visits trend`,dot:!1,tooltipType:`none`,stroke:ku,strokeWidth:1.3,strokeDasharray:`5 4`,connectNulls:!0}),i&&o!==`server`&&(0,$.jsx)(te,{type:`linear`,dataKey:`ga4Trend`,legendType:`none`,name:`GA4 visits trend`,dot:!1,tooltipType:`none`,stroke:Au,strokeWidth:1.6,strokeDasharray:`1 4`,strokeLinecap:`round`,connectNulls:!0})]})})]})}function $u(e){return e.replace(/\+/g,` `)}var ed=je,td={"7d":10080,"30d":43200,"90d":129600,"180d":259200};function nd(e){return Cs(e.landingPage)}var rd=25,id=10,ad={days:[],sources:[],totalSessions:0,totalPaidSessions:0,totalOrganicSessions:0,byEngine:{series:[],otherCount:0,days:[]}},od={siteTrafficTooltip:`GA4's own figures for the complete days ending yesterday, as GA4 counts them, each against the period of the same length before it. Pick a figure in any slot to chart it by day.`,siteTrafficFallbackTooltip:`Sessions, Google organic search sessions and distinct users from GA4. Distinct users are unavailable when the selected range has no stored GA4 aggregate.`,channelTooltip:`GA4 sessions split into five channels that do not overlap. AI sessions are taken out of the channel GA4 filed them under before the rest is counted.`,organicTooltip:`Sessions from Google organic search, after AI sessions are taken out.`,socialTooltip:`Organic Social and Paid Social sessions, after AI sessions are taken out.`,directTooltip:`Sessions with no source: bookmarks, typed URLs, untagged email and in-app browsers. AI visits that send no referrer land here too.`,aiTooltip:`Sessions in GA4's AI Assistant channel or from a known AI source. Paid AI comes from paid UTM values or a GA4 paid channel group. AI visits that send no referrer count as Direct, so this is a floor.`,otherTooltip:`Every other GA4 channel, such as Referral, Email, Paid Search, Display and Video.`,aiEnginesTooltip:`AI referral sessions by engine. Open an engine to see the sources GA4 reported. Unattributed AI is AI traffic whose source names no engine.`,aiChartLabel:`AI sessions by engine`,socialTooltip2:`Sessions GA4 classifies as Organic Social or Paid Social, grouped by platform. Open a platform to see the sources GA4 reported for it.`,platformsTooltip:`Platforms with sessions in this period. A source no platform matches counts as its own platform.`,paidSocialTooltip:`Sessions in GA4's Paid Social channel.`,socialChartLabel:`Social sessions by platform`,noAiReferrals:`No AI referrals in this period.`,noAiLandingPages:`No AI landing pages in this period.`,noSocial:`No social sessions in this period.`,noneInPeriod:`None in this period`,aiHistoryTooltip:`Daily AI crawls, page fetches and visits from connected traffic sources, with GA4 visits beside server visits.`};function sd(e){let t=Date.now()-new Date(e).getTime(),n=Math.floor(t/6e4);if(n<1)return`just now`;if(n<60)return`${n}m ago`;let r=Math.floor(n/60);return r<24?`${r}h ago`:`${Math.floor(r/24)}d ago`}function cd(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toLocaleString()}function ld(e,t){return!e||!t?null:`${new Date(`${e}T00:00:00`).toLocaleDateString(void 0,{month:`short`,day:`numeric`})} to ${new Date(`${t}T00:00:00`).toLocaleDateString(void 0,{month:`short`,day:`numeric`,year:`numeric`})}`}function ud({projectName:e}){let{data:t,isLoading:n,isError:r}=Hs(e),i=t?.sources??[];return(0,$.jsxs)(`section`,{"aria-labelledby":`server-activity-heading`,children:[(0,$.jsx)(ol,{id:`server-activity-heading`,title:`Server activity`,tooltip:`Crawler, AI fetch and AI referral activity from connected traffic sources over the last 24 hours.`,meta:`Last 24 hours`,actions:!Y()&&i.length>0?(0,$.jsx)(A,{to:`/traffic`,className:`text-label-14 text-link hover:underline`,children:`Manage sources`}):void 0}),n?(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:`Loading server activity…`}):r?(0,$.jsx)(`p`,{role:`alert`,className:`text-copy-14 text-negative`,children:`Could not load server activity.`}):i.length===0?(0,$.jsxs)(`p`,{className:`text-copy-14 text-secondary`,children:[`No traffic source connected.`,` `,!Y()&&(0,$.jsx)(A,{to:`/traffic`,className:`text-link hover:underline`,children:`Connect a source`})]}):(0,$.jsx)(`div`,{className:`overflow-x-auto`,children:(0,$.jsxs)(`table`,{className:`w-full min-w-[36rem] text-label-14`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{className:`border-b border-default`,children:[(0,$.jsx)(fl,{label:`Source`,align:`left`}),(0,$.jsx)(fl,{label:`Status`,align:`left`}),(0,$.jsx)(fl,{label:`Crawler hits`,align:`right`}),(0,$.jsx)(fl,{label:`AI hits`,align:`right`}),(0,$.jsx)(fl,{label:`AI sessions`,align:`right`}),(0,$.jsx)(fl,{label:`Last sync`,align:`right`}),(0,$.jsx)(`th`,{className:`py-2`,"aria-label":`Detail`})]})}),(0,$.jsx)(`tbody`,{children:i.map(t=>(0,$.jsxs)(`tr`,{className:`border-t border-subtle`,children:[(0,$.jsx)(`td`,{className:`py-2 pr-3 text-strong`,children:t.displayName}),(0,$.jsx)(`td`,{className:`py-2 pr-3`,children:(0,$.jsx)(J,{tone:Ws(t.status),children:t.status})}),(0,$.jsx)(`td`,{className:`py-2 pl-4 text-right tabular-nums text-primary`,children:t.totals24h.crawlerHits.toLocaleString(`en-US`)}),(0,$.jsx)(`td`,{className:`py-2 pl-4 text-right tabular-nums text-primary`,children:(0,$.jsxs)(`span`,{className:`inline-flex items-center justify-end gap-1`,children:[t.totals24h.aiUserFetchHits.toLocaleString(`en-US`),t.totals24h.aiUserFetchLikelyFakeHits>0&&(0,$.jsx)(X,{text:qs(t.totals24h.aiUserFetchLikelyFakeHits)})]})}),(0,$.jsx)(`td`,{className:`py-2 pl-4 text-right tabular-nums text-primary`,children:t.totals24h.aiReferralLandedHits.toLocaleString(`en-US`)}),(0,$.jsx)(`td`,{className:`py-2 pl-4 text-right text-secondary`,children:t.lastSyncedAt?sd(t.lastSyncedAt):`never`}),(0,$.jsx)(`td`,{className:`py-2 pl-3 text-right`,children:!Y()&&(0,$.jsx)(A,{to:`/traffic/$projectName/$sourceId`,params:{projectName:e,sourceId:t.id},className:`text-link hover:underline`,"aria-label":`${t.displayName} detail`,children:`Detail`})})]},t.id))})]})})]})}function dd({projectName:e}){let[t,n]=(0,Q.useState)(`30d`);return(0,$.jsxs)(`div`,{children:[(0,$.jsx)(ud,{projectName:e}),(0,$.jsx)(`div`,{className:`page-section-divider`}),(0,$.jsx)(bd,{projectName:e,window:t,periodControl:(0,$.jsx)(nl,{windows:ed,value:t,onChange:n,label:`Traffic time period`}),between:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`page-section-divider`}),(0,$.jsxs)(`section`,{"aria-labelledby":`ai-traffic-history-heading`,children:[(0,$.jsx)(ol,{id:`ai-traffic-history-heading`,title:`AI traffic history`,tooltip:od.aiHistoryTooltip}),(0,$.jsx)(Qu,{projectName:e,sinceMinutes:td[t]})]})]})})]})}var fd={session:`Session`,first_user:`First visit`,manual_utm:`UTM`},pd={session:`Detected via GA4 sessionSource (referrer or utm_source for this session)`,first_user:`Detected via GA4 firstUserSource (referrer from the user's first-ever visit)`,manual_utm:`Detected via GA4 sessionManualSource (explicit utm_source parameter for the session)`},md=[{label:`Source`,align:`left`},{label:`Medium`,align:`left`},{label:`Class`,align:`left`},{label:`Attribution`,align:`left`},{label:`Sessions`,align:`right`},{label:`Share`,align:`right`}],hd=[{label:`Source`,align:`left`},{label:`Medium`,align:`left`},{label:`Channel`,align:`left`},{label:`Sessions`,align:`right`},{label:`Share`,align:`right`}];function gd(e){return e.engine===null}function _d({row:e}){return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`td`,{className:`max-w-[220px] truncate py-1.5 pr-3 text-strong`,title:e.source,children:e.source}),(0,$.jsx)(`td`,{className:`max-w-[160px] truncate py-1.5 pr-3 text-secondary`,title:e.medium,children:e.medium}),(0,$.jsx)(`td`,{className:`py-1.5 pr-3 text-secondary`,title:e.trafficClass===`paid`?`Paid AI traffic, from paid UTM values or a GA4 paid channel group`:`AI traffic without a paid attribution signal`,children:e.trafficClass===`paid`?`Paid`:`Organic`}),(0,$.jsx)(`td`,{className:`py-1.5 pr-3 text-secondary`,title:pd[e.sourceDimension]??``,children:fd[e.sourceDimension]??e.sourceDimension}),(0,$.jsx)(`td`,{className:`py-1.5 pl-4 text-right text-primary tabular-nums`,children:e.sessions.toLocaleString()}),(0,$.jsx)(`td`,{className:`py-1.5 pl-4 text-right text-secondary tabular-nums`,children:G(e.share)})]})}function vd({row:e}){return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`td`,{className:`max-w-[240px] truncate py-1.5 pr-3 text-strong`,title:e.source,children:$u(e.source)}),(0,$.jsx)(`td`,{className:`max-w-[160px] truncate py-1.5 pr-3 text-secondary`,title:e.medium,children:$u(e.medium)}),(0,$.jsx)(`td`,{className:`py-1.5 pr-3 text-secondary`,title:`GA4 channel group: ${e.channelGroup}`,children:e.channelGroup===`Paid Social`?`Paid social`:`Organic social`}),(0,$.jsx)(`td`,{className:`py-1.5 pl-4 text-right text-primary tabular-nums`,children:e.sessions.toLocaleString()}),(0,$.jsx)(`td`,{className:`py-1.5 pl-4 text-right text-secondary tabular-nums`,children:G(e.share)})]})}function yd(e,t){let n=S(),[r,i]=(0,Q.useState)(null),[a,o]=(0,Q.useState)(null),[s,c]=(0,Q.useState)(!0),[l,u]=(0,Q.useState)(!1),[d,f]=(0,Q.useState)(!1),[p,m]=(0,Q.useState)(null),[h,g]=(0,Q.useState)(null),[_,v]=(0,Q.useState)(ad),[y,b]=(0,Q.useState)([]),[x,C]=(0,Q.useState)(null);async function w(r){c(!0),m(null);try{let a=await n.fetchQuery({...ir({client:K,path:{name:e}}),staleTime:er});if(r.current)return;if(i(a),!a.connected){o(null),v(ad),b([]),C(null),c(!1);return}let s=t===`all`?void 0:t,[l,u,d,f]=await Promise.all([n.fetchQuery({...ki({client:K,path:{name:e},query:s?{window:s}:void 0}),staleTime:er}),n.fetchQuery({...hr({client:K,path:{name:e},query:s?{window:s}:void 0}),staleTime:er}).catch(()=>ad),n.fetchQuery({...Mi({client:K,path:{name:e},query:s?{window:s}:void 0}),staleTime:er}).catch(()=>[]),n.fetchQuery({...fr({client:K,path:{name:e},query:{window:rn(t)?t:`30d`}}),staleTime:er}).catch(()=>null)]);if(r.current)return;o(l),v(u),b(d),C(f),c(!1)}catch(e){if(r.current)return;m(e instanceof Error?e.message:`Failed to load GA4 data`),c(!1)}}(0,Q.useEffect)(()=>{let e={current:!1};return w(e),()=>{e.current=!0}},[e,t,n]);async function T(){u(!0),m(null),g(null);try{let r=await ht(e,rn(t)?Be[t]:void 0);g(`Synced ${r.rowCount.toLocaleString()} page rows, ${r.aiReferralCount.toLocaleString()} AI and ${r.socialReferralCount.toLocaleString()} social referral rows (${r.days} days)`),await Zn(n,`ga`),await w({current:!1})}catch(e){m(e instanceof Error?e.message:`Sync failed`)}finally{u(!1)}}async function E(){f(!0),m(null),g(null);try{await Pt(e),await Zn(n,`ga`),i({connected:!1,propertyId:null,clientEmail:null,lastSyncedAt:null,createdAt:null,updatedAt:null}),o(null),C(null),g(`GA4 disconnected`)}catch(e){m(e instanceof Error?e.message:`Disconnect failed`)}finally{f(!1)}}async function D(){await Zn(n,`ga`),await w({current:!1})}return{status:r,traffic:a,loading:s,syncing:l,disconnecting:d,error:p,notice:h,aiDaily:_,sessionHistory:y,overview:x,handleSync:T,handleDisconnect:E,handleConnected:D}}function bd({projectName:e,window:t,periodControl:n,between:r}){let i=yd(e,t??`30d`);return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(xd,{ga:i,projectName:e,periodControl:n}),r,(0,$.jsx)(Sd,{ga:i,projectName:e})]})}function xd({ga:e,projectName:t,periodControl:n}){let{status:r,traffic:i,syncing:a,disconnecting:o,handleSync:s,handleDisconnect:c}=e,l=r?.connected===!0,u=l&&!Y()&&!We(),d=i?ld(i.windowStart,i.windowEnd):null,m;return m=e.loading&&!r?(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:`Loading traffic data…`}):l?i&&e.overview?(0,$.jsx)(wl,{overview:e.overview,refreshing:e.loading}):i?(0,$.jsx)($.Fragment,{children:(0,$.jsx)(ul,{label:`Site traffic`,items:[{label:`Total sessions`,value:cd(i.totalSessions),detail:i.totalSessions.toLocaleString()},{label:`Organic sessions`,value:cd(i.totalOrganicSessions),detail:`${i.organicSharePctDisplay} of total`},{label:`Total users`,value:i.totalUsers===null?`n/a`:cd(i.totalUsers),detail:i.totalUsers===null?`Unavailable for this range`:i.totalUsers.toLocaleString()}]})}):(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 border-y border-default py-4`,children:[(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:`No traffic data yet.`}),!Y()&&!We()&&(0,$.jsxs)(q,{variant:`outline`,size:`sm`,disabled:a,onClick:Jn(s),children:[(0,$.jsx)(p,{className:`mr-1.5 size-3.5 ${a?`animate-spin`:``}`}),`Sync from GA4`]})]}):Y()||We()?(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:`No Google Analytics 4 property connected.`}):(0,$.jsx)(jd,{projectName:t,onConnected:()=>{e.handleConnected()}}),(0,$.jsxs)(`section`,{"aria-labelledby":`site-traffic-heading`,children:[(0,$.jsx)(ol,{id:`site-traffic-heading`,title:`Site traffic`,tooltip:e.overview?od.siteTrafficTooltip:d?`${od.siteTrafficFallbackTooltip} Data covers ${d}.`:od.siteTrafficFallbackTooltip,meta:l?(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`inline-block size-2 rounded-full bg-positive-500`}),`GA4 property `,(0,$.jsx)(`span`,{className:`text-strong`,children:r.propertyId}),r.clientEmail&&(0,$.jsxs)(`span`,{className:`text-muted`,children:[`· `,r.clientEmail]})]}):void 0,actions:n||u?(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[n,u&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(q,{variant:`outline`,size:`sm`,disabled:a,onClick:Jn(s),children:[(0,$.jsx)(p,{className:`mr-1.5 size-3.5 ${a?`animate-spin`:``}`}),a?`Syncing…`:`Sync`]}),(0,$.jsxs)(q,{variant:`ghost`,size:`sm`,className:`text-negative-400 hover:text-negative`,disabled:o,onClick:Jn(c),children:[(0,$.jsx)(f,{className:`mr-1.5 size-3.5`}),`Disconnect`]})]})]}):void 0}),e.error&&(0,$.jsx)(`div`,{role:`alert`,className:`mb-4 rounded-md border border-negative-800/60 bg-negative-900/20 px-4 py-2 text-label-14 text-negative`,children:e.error}),e.notice&&(0,$.jsx)(`div`,{role:`status`,className:`mb-4 rounded-md border border-positive-800/60 bg-positive-900/20 px-4 py-2 text-label-14 text-positive`,children:e.notice}),m]})}function Sd({ga:e,projectName:t}){let{traffic:n,aiDaily:r,sessionHistory:i}=e,[a,o]=(0,Q.useState)({key:`sessions`,dir:`desc`}),[s,c]=(0,Q.useState)({key:`sessions`,dir:`desc`}),l=(0,Q.useMemo)(()=>{if(!n?.topPages)return[];let{key:e,dir:t}=a;return[...n.topPages].sort((n,r)=>{let i=n[e],a=r[e],o=typeof i==`string`&&typeof a==`string`?i.localeCompare(a):Number(i)-Number(a);return t===`asc`?o:-o})},[n?.topPages,a]),u=Ds({rows:l,getSearchText:e=>Cs(e.landingPage),pageSize:id}),d=(0,Q.useMemo)(()=>{if(!n?.aiReferralLandingPages)return[];let{key:e,dir:t}=s;return[...n.aiReferralLandingPages].sort((n,r)=>{let i=n[e],a=r[e],o=typeof i==`string`&&typeof a==`string`?i.localeCompare(a):Number(i)-Number(a);return t===`asc`?o:-o})},[n?.aiReferralLandingPages,s]),f=Ds({rows:d,getSearchText:nd,pageSize:rd}),p=(0,Q.useMemo)(()=>i.map(e=>({date:e.date,value:e.sessions})),[i]);function m(e){u.setPage(1),o(t=>t.key===e?{key:e,dir:t.dir===`desc`?`asc`:`desc`}:{key:e,dir:`desc`})}function h(e){f.setPage(1),c(t=>t.key===e?{key:e,dir:t.dir===`desc`?`asc`:`desc`}:{key:e,dir:`desc`})}if(!e.status?.connected)return null;let g=n?ld(n.windowStart,n.windowEnd):null,_=n?.channelBreakdown,v=n?.paidAiSessionsBySession??0,y=n?.aiEngines??[],b=n?.socialPlatforms??[],x=b[0]??null,S=f.totalRows>0?`${f.totalRows.toLocaleString()} ${f.hasQuery?f.totalRows===1?`match`:`matches`:f.totalRows===1?`row`:`rows`}`:f.hasQuery&&(n?.aiReferralLandingPages.length??0)>0?`0 matches`:null;return(0,$.jsxs)($.Fragment,{children:[n&&_&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`page-section-divider`}),(0,$.jsxs)(`section`,{"aria-labelledby":`traffic-by-channel-heading`,children:[(0,$.jsx)(ol,{id:`traffic-by-channel-heading`,title:`Traffic by channel`,tooltip:od.channelTooltip,meta:g}),(0,$.jsx)(ul,{label:`Sessions by channel`,items:[{label:`Organic search`,value:_.organic.sharePctDisplay,detail:`${_.organic.sessions.toLocaleString()} sessions`,tooltip:od.organicTooltip},{label:`Social`,value:_.social.sharePctDisplay,detail:`${_.social.sessions.toLocaleString()} sessions`,tooltip:od.socialTooltip},{label:`Direct`,value:_.direct.sharePctDisplay,detail:`${_.direct.sessions.toLocaleString()} sessions`,tooltip:od.directTooltip},{label:`AI (at least)`,value:_.ai.sharePctDisplay,detail:v>0?`${_.ai.sessions.toLocaleString()} sessions · ${v.toLocaleString()} paid`:`${_.ai.sessions.toLocaleString()} sessions`,tooltip:od.aiTooltip},{label:`Other channels`,value:_.other.sharePctDisplay,detail:`${_.other.sessions.toLocaleString()} sessions`,tooltip:od.otherTooltip}]}),(0,$.jsxs)(sl,{children:[(0,$.jsx)(cl,{label:od.aiChartLabel,meta:r.days.length>0?Cd(r.totalSessions,`session`):od.noneInPeriod,children:r.days.length>0?(0,$.jsx)(_l,{input:r.byEngine,baseline:p,baselineLabel:`Total sessions`,label:od.aiChartLabel}):(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:od.noAiReferrals})}),(0,$.jsx)(cl,{label:`Where AI visitors came from`,meta:y.length>0?`${Cd(y.filter(e=>e.engine!==null).length,`engine`)} · ${Cd(n.aiReferrals.length,`source`)}`:od.noneInPeriod,children:y.length>0?(0,$.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,$.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,$.jsx)(hl,{groups:y,groupLabel:`Engine`,caption:`AI referral sessions by engine`,childColumns:md,childRowKey:e=>`${e.source}:${e.medium}:${e.sourceDimension}:${e.trafficClass}`,renderChildCells:e=>(0,$.jsx)(_d,{row:e}),pinLast:gd})}),(0,$.jsx)(X,{text:od.aiEnginesTooltip})]}):(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:od.noAiReferrals})}),(0,$.jsx)(cl,{label:`Pages AI visitors landed on`,meta:S??od.noneInPeriod,children:n.aiReferralLandingPages.length>0?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(js,{value:f.query,onChange:f.setQuery,label:`Filter landing page URLs or query parameters`,placeholder:`Filter URL or query parameters`,className:`mb-4 max-w-md`}),f.totalRows>0?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`overflow-x-auto`,children:(0,$.jsxs)(`table`,{className:`w-full min-w-[36rem] text-label-14`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{className:`border-b border-default`,children:[(0,$.jsx)(dl,{label:`Landing page`,sortKey:`landingPage`,current:s.key,dir:s.dir,onSort:h,align:`left`}),(0,$.jsx)(dl,{label:`Source`,sortKey:`source`,current:s.key,dir:s.dir,onSort:h,align:`left`}),(0,$.jsx)(fl,{label:`Attribution`,align:`left`}),(0,$.jsx)(dl,{label:`Sessions`,sortKey:`sessions`,current:s.key,dir:s.dir,onSort:h,align:`right`})]})}),(0,$.jsx)(`tbody`,{children:f.rows.map(e=>(0,$.jsx)(Nd,{row:e},`${e.landingPage}:${e.source}:${e.medium}:${e.sourceDimension}`))})]})}),(0,$.jsx)(Ts,{page:f.page,pageSize:f.pageSize,visibleRows:f.rows.length,totalRows:f.totalRows,onPageChange:f.setPage,itemLabel:f.hasQuery?`matches`:`rows`})]}):(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 py-4`,children:[(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:`No landing pages match this filter`}),(0,$.jsx)(q,{variant:`outline`,size:`sm`,onClick:()=>f.setQuery(``),children:`Clear filter`})]})]}):(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:od.noAiLandingPages})})]})]}),(0,$.jsx)(`div`,{className:`page-section-divider`}),(0,$.jsxs)(`section`,{"aria-labelledby":`social-heading`,children:[(0,$.jsx)(ol,{id:`social-heading`,title:`Social`,tooltip:od.socialTooltip2,meta:g}),(0,$.jsx)(ul,{label:`Social sessions`,items:[{label:`Social sessions`,value:n.socialSessions.toLocaleString(),detail:`${n.socialSharePctDisplay} of all sessions`},{label:`Platforms`,value:String(b.length),detail:`${n.socialReferrals.length} sources`,tooltip:od.platformsTooltip},{label:`Paid social`,value:(n.paidSocialSessions??0).toLocaleString(),detail:`${G(n.paidSocialShare??0)} of social`,tooltip:od.paidSocialTooltip},{label:`Top platform`,value:x?.label??`None`,detail:x?`${x.sessions.toLocaleString()} sessions`:void 0}]}),(0,$.jsxs)(sl,{children:[(0,$.jsx)(cl,{label:od.socialChartLabel,meta:b.length>0?Cd(n.socialSessions,`session`):od.noneInPeriod,children:b.length>0?(0,$.jsx)(_l,{input:n.socialPlatformDaily,label:od.socialChartLabel}):(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:od.noSocial})}),(0,$.jsx)(cl,{label:`Social platforms`,meta:b.length>0?`${Cd(b.length,`platform`)} · ${Cd(n.socialReferrals.length,`source`)}`:od.noneInPeriod,children:b.length>0?(0,$.jsx)(hl,{groups:b,groupLabel:`Platform`,caption:`Social sessions by platform`,childColumns:hd,childRowKey:e=>`${e.source}:${e.medium}:${e.channelGroup}`,renderChildCells:e=>(0,$.jsx)(vd,{row:e})}):(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:od.noSocial})})]})]})]}),n&&n.topPages.length>0&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`page-section-divider`}),(0,$.jsxs)(`section`,{"aria-labelledby":`top-landing-pages-heading`,children:[(0,$.jsx)(ol,{id:`top-landing-pages-heading`,title:`Top landing pages`,tooltip:`Landing pages by sessions. Organic share is the share of a page's sessions that came from Google organic search.`}),(0,$.jsx)(js,{value:u.query,onChange:u.setQuery,label:`Filter landing page URLs`,placeholder:`Filter landing pages`,className:`mb-4 max-w-md`}),(0,$.jsx)(`div`,{className:`overflow-x-auto`,children:(0,$.jsxs)(`table`,{className:`w-full min-w-[36rem] text-label-14`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{className:`border-b border-default`,children:[(0,$.jsx)(dl,{label:`Landing page`,sortKey:`landingPage`,current:a.key,dir:a.dir,onSort:m,align:`left`}),(0,$.jsx)(dl,{label:`Sessions`,sortKey:`sessions`,current:a.key,dir:a.dir,onSort:m,align:`right`}),(0,$.jsx)(dl,{label:`Organic`,sortKey:`organicSessions`,current:a.key,dir:a.dir,onSort:m,align:`right`}),(0,$.jsx)(fl,{label:`Organic share`,align:`right`})]})}),(0,$.jsx)(`tbody`,{children:u.rows.map(e=>(0,$.jsx)(Md,{page:e},e.landingPage))})]})}),u.totalRows===0&&u.hasQuery&&(0,$.jsx)(`p`,{className:`mt-3 text-copy-14 text-secondary`,children:`No landing pages match this filter`}),(0,$.jsx)(Ts,{page:u.page,pageSize:u.pageSize,visibleRows:u.rows.length,totalRows:u.totalRows,onPageChange:u.setPage,itemLabel:u.hasQuery?`matches`:`pages`})]})]}),(0,$.jsx)(Ad,{projectName:t}),(0,$.jsx)(`p`,{className:`mt-6 text-copy-13 text-secondary`,children:n?.lastSyncedAt?`Last synced ${sd(n.lastSyncedAt)}`:`Never synced`})]})}function Cd(e,t){return`${e.toLocaleString()} ${e===1?t:`${t}s`}`}var wd=25,Td=`n/a`,Ed={heading:`Google organic search traffic`,tooltip:`GA4's "Google organic search traffic: Landing page + query string" report, from the property's Search Console link. Each window ends yesterday in the property time zone, as GA4's own date ranges do. The Total row is GA4's own total for all pages, not a sum of the rows, and it does not change with the filter. Search Console data arrives about two days late.`,windowLabel:`Google organic search time period`,loading:`Loading Google organic search pages…`,loadError:`Could not load Google organic search pages.`,neverSynced:`No Google organic search data has been synced yet.`,neverSyncedAction:`Sync GA4 to load the Search Console landing-page report.`,unavailable:`GA4 did not return Search Console data for this property.`,unavailableAction:`Link Search Console to this GA4 property (Admin, Product links, Search Console links), then sync GA4 again.`,refreshFailed:`The last refresh failed.`,noSearchTraffic:`No landing pages had Google organic search traffic in this window.`,noSearchTrafficAction:`If this property should have some, check its Search Console link in GA4 (Admin, Product links, Search Console links).`,noSearchTrafficConfirmed:`Search Console also recorded no impressions for these days.`,notLinkedBadge:`Search Console not linked`,notLinked:e=>`GA4 has no Search Console data for this site, but Search Console recorded ${e.toLocaleString()} impressions in this window. Link the site's Search Console property in GA4 (Admin, Product links, Search Console links).`,thresholded:`GA4 applied thresholding to this report, so it may withhold some rows.`,retry:`Retry`,refreshFailedBadge:`Last refresh failed`,unavailableBadge:`Search Console unavailable`,thresholdedBadge:`Thresholded`,previousSnapshot:`Showing the last good snapshot, synced`,totalLabel:`Total`,totalScope:`all pages`,noFilterMatch:`No landing pages match this filter`,noFilterMatchInLoaded:e=>`No landing pages in the top ${e.toLocaleString()} by clicks match this filter. The filter searches only the pages loaded here.`};function Dd(e,t){switch(t){case`landingPage`:return e.landingPage;case`clicks`:return e.organicGoogleSearchClicks;case`impressions`:return e.organicGoogleSearchImpressions;case`ctr`:return e.organicGoogleSearchClickThroughRate;case`position`:return e.organicGoogleSearchAveragePosition;case`activeUsers`:return e.activeUsers}}function Od(e){return e===null?Td:e.toFixed(1)}function kd(e){return e===null?Td:G(e)}function Ad({projectName:e}){let[t,n]=(0,Q.useState)(`28d`),[r,i]=(0,Q.useState)(`clicks`),[a,o]=(0,Q.useState)(`desc`),s=w({...Rr({client:K,path:{name:e},query:{window:t,limit:kn}}),staleTime:er}),c=s.data,l=(0,Q.useMemo)(()=>[...c?.rows??[]].sort((e,t)=>{let n=Dd(e,r),i=Dd(t,r);return n===null||i===null?n===i?0:n===null?1:-1:typeof n==`string`&&typeof i==`string`?a===`asc`?n.localeCompare(i):i.localeCompare(n):a===`asc`?n-i:i-n}),[c?.rows,r,a]),u=Ds({rows:l,getSearchText:e=>Cs(W(e.landingPage)),pageSize:wd});function d(e){u.setPage(1),r===e?o(e=>e===`desc`?`asc`:`desc`):(i(e),o(e===`landingPage`?`asc`:`desc`))}let f=c?.total??null,p=c?.searchConsoleLink?.state===`not-linked`,m=!Y()&&!We();return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`page-section-divider`}),(0,$.jsxs)(`section`,{"aria-labelledby":`ga-search-landing-heading`,children:[(0,$.jsxs)(`div`,{className:`mb-4 flex flex-wrap items-start justify-between gap-3`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`h2`,{id:`ga-search-landing-heading`,className:`text-heading-16 text-primary`,children:Ed.heading}),(0,$.jsx)(X,{text:Ed.tooltip})]}),c?.windowStart&&c.windowEnd&&(0,$.jsxs)(`p`,{className:`text-copy-14 text-secondary mt-1`,children:[en(c.windowStart),` to `,en(c.windowEnd),c.timeZone?` (${c.timeZone})`:``]})]}),(0,$.jsx)(nl,{windows:oe,value:t,onChange:e=>{u.setPage(1),n(e)},label:Ed.windowLabel})]}),s.isPending?(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary py-6 text-center`,children:Ed.loading}):s.isError||!c?(0,$.jsxs)(`div`,{role:`alert`,className:`flex flex-wrap items-center gap-3 px-4 py-2 rounded-md bg-negative-900/20 border border-negative-800/60 text-label-14 text-negative`,children:[(0,$.jsx)(`span`,{children:Ed.loadError}),(0,$.jsx)(q,{variant:`outline`,size:`sm`,onClick:()=>{s.refetch()},children:Ed.retry})]}):(0,$.jsxs)($.Fragment,{children:[(c.status===`error`||c.status===`unavailable`||c.subjectToThresholding||p)&&(0,$.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-center gap-2`,"data-testid":`ga-search-landing-status`,children:[p&&(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1`,"data-testid":`ga-search-landing-not-linked`,children:[(0,$.jsx)(J,{tone:`caution`,children:Ed.notLinkedBadge}),(0,$.jsx)(X,{text:Ed.notLinked(c.searchConsoleLink?.searchConsoleImpressions??0)})]}),c.status===`error`&&(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,$.jsx)(J,{tone:`negative`,children:Ed.refreshFailedBadge}),c.error&&(0,$.jsx)(X,{text:c.error})]}),c.status===`unavailable`&&(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,$.jsx)(J,{tone:`caution`,children:Ed.unavailableBadge}),c.error&&(0,$.jsx)(X,{text:c.error})]}),c.subjectToThresholding&&(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,$.jsx)(J,{tone:`caution`,children:Ed.thresholdedBadge}),(0,$.jsx)(X,{text:Ed.thresholded})]}),c.status!==`ready`&&f&&c.syncedAt&&(0,$.jsxs)(`span`,{className:`text-label-14 text-secondary`,children:[Ed.previousSnapshot,` `,sd(c.syncedAt),`.`]}),c.status===`unavailable`&&f&&(0,$.jsx)(`p`,{className:`w-full text-copy-14 text-secondary`,children:Ed.unavailableAction})]}),f?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(js,{value:u.query,onChange:u.setQuery,label:`Filter Google organic search landing pages`,placeholder:`Filter landing pages`,className:`mb-4 max-w-md`}),(0,$.jsx)(`div`,{className:`overflow-x-auto`,children:(0,$.jsxs)(`table`,{className:`w-full min-w-[40rem] text-label-14`,"aria-labelledby":`ga-search-landing-heading`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{className:`border-b border-default`,children:[(0,$.jsx)(dl,{label:`Landing page`,sortKey:`landingPage`,current:r,dir:a,onSort:d,align:`left`}),(0,$.jsx)(dl,{label:`Clicks`,sortKey:`clicks`,current:r,dir:a,onSort:d,align:`right`}),(0,$.jsx)(dl,{label:`Impressions`,sortKey:`impressions`,current:r,dir:a,onSort:d,align:`right`}),(0,$.jsx)(dl,{label:`CTR`,sortKey:`ctr`,current:r,dir:a,onSort:d,align:`right`}),(0,$.jsx)(dl,{label:`Avg. position`,sortKey:`position`,current:r,dir:a,onSort:d,align:`right`}),(0,$.jsx)(dl,{label:`Active users`,sortKey:`activeUsers`,current:r,dir:a,onSort:d,align:`right`})]})}),(0,$.jsxs)(`tbody`,{children:[(0,$.jsxs)(`tr`,{className:`border-t border-subtle text-label-14-strong`,"data-testid":`ga-search-landing-total`,children:[(0,$.jsxs)(`td`,{className:`py-1.5 text-primary`,children:[Ed.totalLabel,` `,(0,$.jsx)(`span`,{className:`text-label-14 text-secondary`,children:Ed.totalScope})]}),(0,$.jsx)(`td`,{className:`py-1.5 pl-4 text-right text-primary tabular-nums`,children:f.organicGoogleSearchClicks.toLocaleString()}),(0,$.jsx)(`td`,{className:`py-1.5 pl-4 text-right text-primary tabular-nums`,children:f.organicGoogleSearchImpressions.toLocaleString()}),(0,$.jsx)(`td`,{className:`py-1.5 pl-4 text-right text-primary tabular-nums`,children:kd(f.organicGoogleSearchClickThroughRate)}),(0,$.jsx)(`td`,{className:`py-1.5 pl-4 text-right text-primary tabular-nums`,children:Od(f.organicGoogleSearchAveragePosition)}),(0,$.jsx)(`td`,{className:`py-1.5 pl-4 text-right text-primary tabular-nums`,children:f.activeUsers.toLocaleString()})]}),u.rows.map(e=>(0,$.jsxs)(`tr`,{className:`border-t border-subtle`,children:[(0,$.jsx)(`td`,{className:`py-1.5 text-neutral max-w-[400px] truncate`,title:W(e.landingPage),children:W(e.landingPage)}),(0,$.jsx)(`td`,{className:`py-1.5 pl-4 text-right text-strong tabular-nums`,children:e.organicGoogleSearchClicks.toLocaleString()}),(0,$.jsx)(`td`,{className:`py-1.5 pl-4 text-right text-secondary tabular-nums`,children:e.organicGoogleSearchImpressions.toLocaleString()}),(0,$.jsx)(`td`,{className:`py-1.5 pl-4 text-right text-secondary tabular-nums`,children:kd(e.organicGoogleSearchClickThroughRate)}),(0,$.jsx)(`td`,{className:`py-1.5 pl-4 text-right text-secondary tabular-nums`,children:Od(e.organicGoogleSearchAveragePosition)}),(0,$.jsx)(`td`,{className:`py-1.5 pl-4 text-right text-secondary tabular-nums`,children:e.activeUsers.toLocaleString()})]},e.landingPage))]})]})}),!_e(f)&&!p&&(0,$.jsxs)(`div`,{className:`text-label-14 text-secondary mt-3 space-y-1`,children:[(0,$.jsx)(`p`,{children:Ed.noSearchTraffic}),(0,$.jsx)(`p`,{children:c.searchConsoleLink?.state===`no-search-data`?Ed.noSearchTrafficConfirmed:Ed.noSearchTrafficAction})]}),u.totalRows===0&&u.hasQuery&&(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary mt-3`,children:c.totalRows>c.rows.length?Ed.noFilterMatchInLoaded(c.rows.length):Ed.noFilterMatch}),(0,$.jsx)(Ts,{page:u.page,pageSize:u.pageSize,visibleRows:u.rows.length,totalRows:u.totalRows,onPageChange:u.setPage,itemLabel:u.hasQuery?`matches`:`pages`}),(c.totalRows>c.rows.length||c.rowsCapped)&&(0,$.jsxs)(`p`,{className:`text-copy-14 text-secondary mt-3`,children:[c.totalRows>c.rows.length?`Showing the top ${c.rows.length.toLocaleString()} of ${c.totalRows.toLocaleString()} stored pages by clicks.`:``,c.totalRows>c.rows.length&&c.rowsCapped?` `:``,c.rowsCapped&&c.reportRowCount!==null?`GA4 reported ${c.reportRowCount.toLocaleString()} pages; the ${c.totalRows.toLocaleString()} with the most clicks are stored.`:``]}),c.syncedAt&&(0,$.jsxs)(`p`,{className:`mt-2 text-copy-13 text-muted`,children:[`Synced `,sd(c.syncedAt)]})]}):(0,$.jsx)(Z,{className:`p-5`,children:c.status===`unavailable`?(0,$.jsxs)(`div`,{className:`text-label-14 text-secondary space-y-1`,children:[(0,$.jsx)(`p`,{className:`text-neutral`,children:Ed.unavailable}),(0,$.jsx)(`p`,{children:Ed.unavailableAction})]}):c.status===`error`?(0,$.jsxs)(`div`,{className:`text-label-14 text-secondary space-y-1`,children:[(0,$.jsx)(`p`,{className:`text-neutral`,children:Ed.refreshFailed}),c.error&&(0,$.jsx)(`p`,{children:c.error})]}):(0,$.jsxs)(`div`,{className:`text-label-14 text-secondary space-y-1`,children:[(0,$.jsx)(`p`,{className:`text-neutral`,children:Ed.neverSynced}),m&&(0,$.jsx)(`p`,{children:Ed.neverSyncedAction})]})})]})]})]})}function jd({projectName:e,onConnected:t}){let[n,r]=(0,Q.useState)(``),[i,a]=(0,Q.useState)(null),[o,s]=(0,Q.useState)(null),[c,l]=(0,Q.useState)(!1),[u,d]=(0,Q.useState)(null),f=(0,Q.useRef)(null),p=(0,Q.useCallback)(e=>{let t=e.target.files?.[0];if(!t)return;d(null),a(t.name);let n=new FileReader;n.onload=()=>{let e=n.result;try{let t=JSON.parse(e);if(!t.client_email||!t.private_key){d(`JSON file is missing required fields: client_email and private_key. Make sure you downloaded a service account key (not an OAuth client).`),s(null);return}s(e)}catch{d(`File is not valid JSON. Please upload a service account key file (.json) downloaded from Google Cloud Console.`),s(null)}},n.onerror=()=>{d(`Failed to read file.`),s(null)},n.readAsText(t)},[]);async function m(){if(d(null),!n.trim())d(`Property ID is required.`);else if(!o)d(`Please upload a service account key file.`);else{l(!0);try{await Cn(e,{propertyId:n.trim(),keyJson:o});try{await ht(e)}catch{}t()}catch(e){d(e instanceof Error?e.message:`Failed to connect GA4`)}finally{l(!1)}}}return(0,$.jsxs)(Z,{className:`surface-card p-6`,children:[(0,$.jsx)(`h3`,{className:`text-heading-16 text-primary mb-1`,children:`Connect Google Analytics 4`}),(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary mb-5`,children:`Connect a GA4 property to see traffic data for this project. You'll need a service account key file from Google Cloud Console.`}),u&&(0,$.jsx)(`div`,{className:`mb-4 px-4 py-2 rounded-md bg-negative-900/20 border border-negative-800/60 text-label-14 text-negative`,children:u}),(0,$.jsxs)(`div`,{className:`mb-4`,children:[(0,$.jsx)(`label`,{htmlFor:`ga4-property-id`,className:`block text-label-12-strong text-secondary mb-1.5`,children:`GA4 Property ID`}),(0,$.jsx)(`input`,{id:`ga4-property-id`,type:`text`,placeholder:`e.g. 123456789`,value:n,onChange:e=>r(e.target.value),className:`w-full rounded-md bg-bg-elevated/60 border border-default px-3 py-2 text-label-14 text-strong placeholder-mono-400 focus:outline-none focus:ring-1 focus:ring-mono-600`}),(0,$.jsx)(`p`,{className:`mt-1 text-copy-13 text-muted`,children:`Find this in GA4 → Admin → Property Settings. It's a numeric ID, not the Measurement ID (G-XXXXXX).`})]}),(0,$.jsxs)(`div`,{className:`mb-5`,children:[(0,$.jsx)(`label`,{className:`block text-label-12-strong text-secondary mb-1.5`,children:`Service Account Key File`}),(0,$.jsx)(`input`,{ref:f,type:`file`,accept:`.json,application/json`,onChange:p,className:`hidden`}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>f.current?.click(),className:`flex items-center gap-2 w-full rounded-md bg-bg-elevated/60 border border-default border-dashed px-4 py-3 text-button-14 text-secondary hover:border-mono-600 hover:text-neutral transition-colors cursor-pointer`,children:[(0,$.jsx)(h,{className:`w-4 h-4 shrink-0`}),i?(0,$.jsx)(`span`,{className:`text-strong truncate`,children:i}):(0,$.jsx)(`span`,{children:`Upload .json key file`})]}),(0,$.jsxs)(`p`,{className:`mt-1 text-copy-13 text-muted`,children:[`Download from Google Cloud Console → IAM & Admin → Service Accounts → Keys → Add Key → JSON. The service account must have `,(0,$.jsx)(`span`,{className:`text-secondary`,children:`Viewer`}),` access on the GA4 property.`]})]}),(0,$.jsx)(q,{variant:`default`,size:`sm`,disabled:c||!n.trim()||!o,onClick:Jn(m),children:c?`Connecting & syncing…`:`Connect GA4`})]})}function Md({page:e}){return(0,$.jsxs)(`tr`,{className:`border-t border-subtle`,children:[(0,$.jsx)(`td`,{className:`max-w-[400px] truncate py-1.5 pr-3 text-strong`,title:e.landingPage,children:e.landingPage}),(0,$.jsx)(`td`,{className:`py-1.5 pl-4 text-right text-primary tabular-nums`,children:e.sessions.toLocaleString()}),(0,$.jsx)(`td`,{className:`py-1.5 pl-4 text-right text-secondary tabular-nums`,children:e.organicSessions.toLocaleString()}),(0,$.jsx)(`td`,{className:`py-1.5 pl-4 text-right text-secondary tabular-nums`,children:G(e.organicShare)})]})}function Nd({row:e}){return(0,$.jsxs)(`tr`,{className:`border-t border-subtle`,children:[(0,$.jsx)(`td`,{className:`max-w-[400px] py-1.5 pr-3 text-strong`,children:(0,$.jsx)(Ss,{value:e.landingPage,className:`whitespace-nowrap`})}),(0,$.jsx)(`td`,{className:`max-w-[220px] truncate py-1.5 pr-3 text-secondary`,title:e.source,children:e.source}),(0,$.jsx)(`td`,{className:`py-1.5 pr-3 text-secondary`,title:pd[e.sourceDimension]??``,children:fd[e.sourceDimension]??e.sourceDimension}),(0,$.jsx)(`td`,{className:`py-1.5 pl-4 text-right text-primary tabular-nums`,children:e.sessions.toLocaleString()})]})}var Pd=new Set([`gbp-listing-discrepancy`,`gbp-lodging-gap`,`gbp-cta-gap`,`gbp-metric-drop`,`gbp-keyword-drop`]);function Fd({projectName:e,projectId:t}){let n=S(),[r,i]=(0,Q.useState)(null),[a,o]=(0,Q.useState)(null),[s,c]=(0,Q.useState)(!1),l=w(Sr({client:K,path:{name:e}})),u=l.data?.find(e=>e.connectionType===`gbp`),d=!!u,f=r?{locationName:r}:void 0,p=w({...Fr({client:K,path:{name:e}}),enabled:d}),m=w({...kr({client:K,path:{name:e},query:f}),enabled:d}),h=w({...Mr({client:K,path:{name:e},query:f}),enabled:d}),g=w({...Vr({client:K,path:{name:e},query:f}),enabled:d}),_=w({...vr({client:K,path:{name:e},query:f}),enabled:d}),v=w({...wr({client:K,path:{name:e},query:f}),enabled:d}),y=w({queryKey:[`gbp-section-insights`,e],queryFn:()=>Je(e),enabled:d});function b(){Zn(n,`gbp`)}let x=C({...Yr(),onSuccess:n=>{Zo({id:n.runId,projectId:t,kind:Se[`gbp-sync`],projectLabel:e,sourceAction:`gbp-sync`}),Xn({title:`Business Profile sync started`,detail:`${e} will refresh when the sync completes.`,tone:`neutral`,dedupeKey:`gbp-sync:${e}`,dedupeMode:`replace`})}}),T=(0,Q.useSyncExternalStore)(To,is,is),E=Object.values(T.runs).some(e=>e.kind===Se[`gbp-sync`]&&e.projectId===t),D=x.isPending||E,O=C({...Hr(),onSuccess:()=>b()});if((0,Q.useEffect)(()=>{if(!r||!p.data)return;let e=p.data.locations.filter(e=>e.selected);(e.length<=1||!e.some(e=>e.locationName===r))&&i(null)},[r,p.data]),(0,Q.useEffect)(()=>{a&&p.data&&((r?[r]:p.data.locations.filter(e=>e.selected).map(e=>e.locationName)).includes(a)||o(null))},[a,p.data,r]),l.isLoading)return null;if(!u){let t=[{title:`Connect your Google account`,command:`canonry gbp connect ${e}`,note:`Opens Google OAuth. Grant Business Profile (business.manage) access.`},{title:`Choose the account`,command:`canonry gbp accounts ${e}`,note:`Pick which Business Profile account this project tracks.`},{title:`Select locations`,command:`canonry gbp locations discover ${e}`,note:(0,$.jsxs)($.Fragment,{children:[`Then adopt the ones to sync: `,(0,$.jsxs)(`code`,{className:`rounded bg-bg-elevated/80 px-1 py-0.5 text-label-12-mono text-secondary`,children:[`canonry gbp locations select `,e,` <location>`]})]})},{title:`Sync, and keep it fresh`,command:`canonry gbp sync ${e}`,note:(0,$.jsxs)($.Fragment,{children:[`Schedule it: `,(0,$.jsxs)(`code`,{className:`rounded bg-bg-elevated/80 px-1 py-0.5 text-label-12-mono text-secondary`,children:[`canonry schedule set `,e,` --kind gbp-sync --preset daily`]})]})}];return(0,$.jsx)(`section`,{className:`page-section-divider`,children:(0,$.jsxs)(Z,{className:`surface-card`,children:[(0,$.jsx)(`p`,{className:`eyebrow eyebrow-soft`,children:`Local presence`}),(0,$.jsx)(`h2`,{children:`Connect Google Business Profile`}),(0,$.jsx)(`p`,{className:`mt-2 max-w-2xl text-copy-14 text-muted`,children:`Track local performance, search terms, place-action CTAs, and how your public Maps listing compares to the profile you control. Four steps from the CLI:`}),(0,$.jsx)(`ol`,{className:`mt-5 space-y-4`,children:t.map((e,t)=>(0,$.jsxs)(`li`,{className:`grid grid-cols-[1.5rem_1fr] gap-x-3`,children:[(0,$.jsx)(`span`,{className:`mt-0.5 inline-flex h-6 w-6 items-center justify-center rounded-full bg-mono-800 text-label-12-strong tabular-nums text-neutral`,"aria-hidden":`true`,children:t+1}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`p`,{className:`text-copy-14-strong text-strong`,children:e.title}),(0,$.jsx)(`code`,{className:`mt-1.5 inline-block w-fit max-w-full overflow-x-auto rounded bg-bg-elevated/80 px-2 py-1 text-label-12-mono text-neutral`,children:e.command}),(0,$.jsx)(`p`,{className:`mt-1 text-copy-13 text-muted`,children:e.note})]})]},e.title))})]})})}let k=m.data,A=p.data?.locations??[],j=A.filter(e=>e.selected),M=h.data?.keywords??[],N=g.data?.lodging??[],P=_.data?.placeActions??[],F=v.data?.places??[],I=A.length>0?A[0].accountName:u.domain,L=r?A.find(e=>e.locationName===r)?.displayName??null:null,R=r?A.filter(e=>e.locationName===r):j,ee=new Set(R.map(e=>e.locationName)),te=N.filter(e=>ee.has(e.locationName)),ne=P.filter(e=>ee.has(e.locationName)),re=F.filter(e=>ee.has(e.locationName)),ie=new Set(j.map(e=>e.locationName)),z=r?M:M.filter(e=>ie.has(e.locationName)),ae=!r&&j.length>1,B=(y.data??[]).filter(e=>!e.dismissed&&Pd.has(e.type)&&(!L||e.query===L||e.query===r||e.title.startsWith(L)));return(0,$.jsx)(`section`,{className:`page-section-divider`,children:(0,$.jsxs)(Z,{className:`surface-card`,children:[(0,$.jsxs)(`div`,{className:`section-head section-head-inline`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`eyebrow eyebrow-soft`,children:`Local presence`}),(0,$.jsxs)(`h2`,{className:`flex items-center gap-2`,children:[`Google Business Profile`,(0,$.jsx)(X,{text:`How AI answer engines and Maps surface this business: performance, search terms, and how your public listing compares to the profile you control.`})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(J,{tone:`positive`,children:`Connected`}),!Y()&&(0,$.jsx)(vs,{type:`button`,variant:`outline`,size:`sm`,disabled:D,onClick:()=>x.mutate({client:K,path:{name:e},body:{}}),children:D?`Syncing…`:`Sync`})]})]}),(0,$.jsxs)(`p`,{className:`mb-4 text-copy-13 text-muted`,children:[I?(0,$.jsxs)($.Fragment,{children:[`Account `,(0,$.jsx)(`span`,{className:`font-mono text-secondary`,children:I}),` · `]}):null,p.data?`${p.data.totalSelected} of ${p.data.totalDiscovered} locations tracked`:`Loading locations…`]}),j.length>1&&(0,$.jsxs)(`div`,{className:`mb-5 max-w-xs`,children:[(0,$.jsx)(`label`,{htmlFor:`local-presence-location`,className:`mb-1 block text-label-14-strong text-secondary`,children:`Location`}),(0,$.jsxs)(`select`,{id:`local-presence-location`,value:r??``,onChange:e=>i(e.target.value||null),className:`w-full rounded-md border border-base bg-bg px-3 py-2 text-label-14 text-strong focus:outline-none focus-visible:ring-2 focus-visible:ring-mono-500/60`,children:[(0,$.jsx)(`option`,{value:``,children:`All locations`}),j.map(e=>(0,$.jsx)(`option`,{value:e.locationName,children:e.displayName},e.id))]})]}),j.length===0?(0,$.jsxs)(`p`,{className:`text-copy-14 text-muted`,children:[`No locations are tracked yet. Open `,(0,$.jsx)(`span`,{className:`text-copy-14-strong text-neutral`,children:`Manage locations`}),` below to track the one(s) for this business.`]}):(0,$.jsxs)($.Fragment,{children:[B.length>0&&(0,$.jsxs)(`div`,{className:`mb-6 grid gap-2`,children:[(0,$.jsx)(`p`,{className:`eyebrow eyebrow-soft`,children:`Needs attention`}),B.map(e=>(0,$.jsx)(`div`,{className:[`surface-card insight-card`,Qd(e.severity),`p-3`].filter(Boolean).join(` `),children:(0,$.jsxs)(`p`,{className:`flex items-center gap-2 text-copy-14-strong text-strong`,children:[e.title,e.recommendation?.reason&&(0,$.jsx)(X,{text:e.recommendation.reason})]})},e.id))]}),k&&(0,$.jsx)(sf,{performance:k.performance,freshness:k.freshness,timeseries:k.timeseries}),k?.profileCompleteness&&(0,$.jsx)(Id,{summary:k.profileCompleteness}),R.length>0&&(0,$.jsx)(Ld,{locations:R,lodging:te,places:re,placeActions:ne,expandedLocation:a,onToggleExpanded:e=>{o(t=>t===e?null:e)}}),(0,$.jsxs)(`div`,{className:`mb-2`,children:[(0,$.jsxs)(`div`,{className:`section-head section-head-inline mb-2`,children:[(0,$.jsx)(`p`,{className:`eyebrow eyebrow-soft`,children:`Search terms`}),h.data&&h.data.total>0&&(0,$.jsxs)(`span`,{className:`text-label-12 text-faint`,children:[G(h.data.thresholdedPct,rt.percent),` privacy-thresholded`]})]}),z.length===0?(0,$.jsx)(`p`,{className:`text-copy-14 text-muted`,children:`No keyword impressions stored yet.`}):(0,$.jsxs)(`table`,{className:`data-table w-full text-label-14`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{className:`text-left`,children:`Search term`}),ae&&(0,$.jsx)(`th`,{className:`text-left`,children:`Location`}),(0,$.jsx)(`th`,{className:`text-right`,children:`Impressions`}),(0,$.jsx)(`th`,{className:`text-right`,children:`Window`})]})}),(0,$.jsx)(`tbody`,{children:z.slice(0,25).map(e=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{className:`text-neutral`,children:e.keyword}),ae&&(0,$.jsx)(`td`,{className:`text-muted`,children:A.find(t=>t.locationName===e.locationName)?.displayName??e.locationName}),(0,$.jsx)(`td`,{className:`text-right font-mono text-strong`,children:e.valueCount===null?(0,$.jsxs)(`span`,{className:`text-muted`,title:`Privacy floor — Google withheld the exact count`,children:[`<`,e.valueThreshold]}):e.valueCount.toLocaleString()}),(0,$.jsxs)(`td`,{className:`text-right text-label-12-mono text-faint`,children:[e.periodStart,`–`,e.periodEnd]})]},`${e.locationName}:${e.keyword}`))})]})]})]}),(0,$.jsxs)(`div`,{className:`mt-6 border-t border-default pt-4`,children:[(0,$.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1.5 text-button-14 text-secondary hover:text-strong`,onClick:()=>c(e=>!e),"aria-expanded":s,children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,children:s?`▾`:`▸`}),` Manage locations (`,A.length,`)`]}),s&&(0,$.jsx)(`div`,{className:`mt-3`,children:A.length===0?(0,$.jsxs)(`p`,{className:`text-copy-14 text-muted`,children:[`No locations discovered. Run `,(0,$.jsx)(`span`,{className:`font-mono`,children:`canonry gbp locations discover`}),`.`]}):(0,$.jsxs)(`table`,{className:`data-table w-full text-label-14`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{className:`text-left`,children:`Location`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Address`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Status`}),!Y()&&(0,$.jsx)(`th`,{className:`text-right`,children:`Action`})]})}),(0,$.jsx)(`tbody`,{children:A.map(t=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{className:`text-strong`,children:t.displayName}),(0,$.jsx)(`td`,{className:`text-muted`,children:t.storefrontAddress??`—`}),(0,$.jsx)(`td`,{children:(0,$.jsx)(J,{tone:t.selected?`positive`:`neutral`,children:t.selected?`Tracked`:`Not tracked`})}),!Y()&&(0,$.jsx)(`td`,{className:`text-right`,children:(0,$.jsx)(vs,{type:`button`,variant:`outline`,size:`sm`,disabled:O.isPending,onClick:()=>O.mutate({client:K,path:{name:e,locationName:t.locationName},body:{selected:!t.selected}}),children:t.selected?`Untrack`:`Track`})})]},t.id))})]})})]})]})})}function Id({summary:e}){if(e.locationCount===0)return null;let t=e.locationCount,n=[{label:`Description`,value:`${e.withDescription}/${t}`,tone:Xd(e.withDescription,t,`caution`)},{label:`Hours`,value:`${e.withHours}/${t}`,tone:Xd(e.withHours,t,`caution`)},{label:`Phone`,value:`${e.withPrimaryPhone}/${t}`,tone:Xd(e.withPrimaryPhone,t,`caution`)},{label:`Service area`,value:`${e.withServiceArea}/${t}`,tone:Xd(e.withServiceArea,t,`neutral`)},{label:`Secondary categories`,value:`${e.withSecondaryCategories}/${t}`,detail:`${e.secondaryCategoryTotal} total`,tone:Xd(e.withSecondaryCategories,t,`caution`)},{label:`Closed`,value:String(e.permanentlyClosed+e.temporarilyClosed),detail:e.permanentlyClosed||e.temporarilyClosed?`${e.permanentlyClosed} permanent, ${e.temporarilyClosed} temporary`:`reported open`,tone:e.permanentlyClosed>0?`negative`:e.temporarilyClosed>0?`caution`:`positive`}];return(0,$.jsxs)(`div`,{className:`mb-6 border-y border-default py-3`,children:[(0,$.jsxs)(`div`,{className:`mb-3 flex items-center gap-2`,children:[(0,$.jsx)(`p`,{className:`eyebrow eyebrow-soft`,children:`Owner profile · Business Information`}),(0,$.jsx)(X,{text:`Counts selected locations where Google Business Information returned the owner-authored field. A missing value means it was not returned by this API response, not that every Google surface is empty.`})]}),(0,$.jsx)(`div`,{className:`grid gap-x-5 gap-y-3 sm:grid-cols-2 lg:grid-cols-3`,children:n.map(e=>(0,$.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_auto] items-baseline gap-3`,children:[(0,$.jsx)(`span`,{className:`text-label-12 text-muted`,children:e.label}),(0,$.jsx)(`span`,{className:`text-label-14-mono tabular-nums ${Zd(e.tone)}`,children:e.value}),e.detail&&(0,$.jsx)(`span`,{className:`col-span-2 text-label-12 text-faint`,children:e.detail})]},e.label))})]})}function Ld({locations:e,lodging:t,places:n,placeActions:r,expandedLocation:i,onToggleExpanded:a}){let o=new Map(t.map(e=>[e.locationName,e])),s=new Map(n.map(e=>[e.locationName,e])),c=new Map;for(let e of r){let t=c.get(e.locationName)??[];t.push(e),c.set(e.locationName,t)}return(0,$.jsxs)(`div`,{className:`mb-6`,children:[(0,$.jsxs)(`div`,{className:`section-head section-head-inline mb-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`p`,{className:`eyebrow eyebrow-soft`,children:`Source evidence`}),(0,$.jsx)(X,{text:Y()?`Each column names the Google surface it came from. Missing or empty means that surface did not return a value in the latest sync, not that every Google product lacks the information.`:`Each column names the Google surface it came from. Missing or empty means that surface did not return a value in the latest Canonry sync, not that every Google product lacks the information.`})]}),(0,$.jsxs)(`span`,{className:`text-label-12 text-faint`,children:[e.length,` location`,e.length===1?``:`s`]})]}),(0,$.jsx)(`div`,{className:`data-table-wrapper`,children:(0,$.jsxs)(`table`,{className:`data-table`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{className:`min-w-[14rem]`,children:`Location`}),(0,$.jsx)(`th`,{className:`min-w-[15rem]`,children:`Owner profile`}),(0,$.jsx)(`th`,{className:`min-w-[11rem]`,children:`Hotel data`}),(0,$.jsx)(`th`,{className:`min-w-[11rem]`,children:`Public Maps`}),(0,$.jsx)(`th`,{className:`min-w-[10rem]`,children:`CTAs`}),(0,$.jsx)(`th`,{className:`text-right`,children:`Detail`})]})}),(0,$.jsx)(`tbody`,{children:e.map(e=>{let t=o.get(e.locationName)??null,n=s.get(e.locationName)??null,r=c.get(e.locationName)??[],l=i===e.locationName;return(0,$.jsxs)(Q.Fragment,{children:[(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{children:(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`p`,{className:`text-copy-14-strong text-strong`,children:e.displayName}),(0,$.jsx)(`p`,{className:`mt-1 text-copy-13 text-faint`,children:e.primaryCategoryDisplayName??`Primary category not returned`}),(0,$.jsxs)(`div`,{className:`mt-2 flex flex-wrap gap-1.5`,children:[(0,$.jsx)(J,{tone:e.selected?`positive`:`neutral`,children:e.selected?`Tracked`:`Not tracked`}),e.openStatus&&e.openStatus!==`OPEN`&&(0,$.jsx)(J,{tone:e.openStatus===`CLOSED_PERMANENTLY`?`negative`:`caution`,children:ef(e.openStatus)})]})]})}),(0,$.jsx)(`td`,{children:(0,$.jsx)(zd,{location:e})}),(0,$.jsx)(`td`,{children:(0,$.jsx)(Bd,{lodging:t})}),(0,$.jsx)(`td`,{children:(0,$.jsx)(Hd,{place:n,mapsUri:e.mapsUri})}),(0,$.jsx)(`td`,{children:(0,$.jsx)(Wd,{actions:r})}),(0,$.jsx)(`td`,{className:`text-right`,children:(0,$.jsx)(q,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>a(e.locationName),children:l?`Hide`:`Details`})})]}),l&&(0,$.jsx)(`tr`,{className:`bg-mono-950/35 hover:bg-mono-950/35`,children:(0,$.jsx)(`td`,{colSpan:6,className:`px-4 py-4`,children:(0,$.jsx)(qd,{location:e,lodging:t,place:n,placeActions:r})})})]},e.id)})})]})})]})}function Rd(e){return[{label:`Description`,tone:$d(e.description)?`positive`:`neutral`,value:$d(e.description)?`set`:`not returned`},{label:`Hours`,tone:e.regularHours?`positive`:`neutral`,value:e.regularHours?`set`:`not returned`},{label:`Phone`,tone:$d(e.primaryPhone)?`positive`:`neutral`,value:$d(e.primaryPhone)?`set`:`not returned`},{label:`Website`,tone:$d(e.websiteUri)?`positive`:`neutral`,value:$d(e.websiteUri)?`set`:`not returned`},{label:`Secondary`,tone:e.additionalCategories.length>0?`positive`:`neutral`,value:e.additionalCategories.length>0?String(e.additionalCategories.length):`not returned`},{label:`Service area`,tone:e.serviceArea?`positive`:`neutral`,value:e.serviceArea?`set`:`not returned`}]}function zd({location:e}){let t=Rd(e);return(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:t.map(e=>(0,$.jsxs)(J,{tone:e.tone,children:[e.label,` `,e.value]},e.label))})}function Bd({lodging:e}){return(0,$.jsx)(Kd,{...Vd(e)})}function Vd(e){return e?e.populatedGroupCount===0?{tone:`neutral`,label:`0 groups returned`,detail:`Lodging API returned no readable groups; verify Hotel details.`}:{tone:`positive`,label:`${e.populatedGroupCount} group${e.populatedGroupCount===1?``:`s`} returned`,detail:`Owner lodging attributes.`}:{tone:`neutral`,label:`No Lodging API snapshot`,detail:`Not returned for this scoped location.`}}function Hd({place:e,mapsUri:t}){return(0,$.jsx)(Kd,{...Ud(e,t)})}function Ud(e,t){if(!e)return{tone:`neutral`,label:`Public listing not checked`,detail:t?`Maps link available.`:`No Places snapshot.`};let n=e.amenities.length;return{tone:n>0?`positive`:`neutral`,label:n>0?`${n} signal${n===1?``:`s`} detected`:`0 supported signals detected`,detail:`Places tier: ${e.tier}`}}function Wd({actions:e}){return(0,$.jsx)(Kd,{...Gd(e)})}function Gd(e){if(e.length===0)return{tone:`neutral`,label:`No CTAs stored`,detail:`No placeActionLinks returned.`};let t=e.filter(e=>e.providerType===`MERCHANT`).length;return t===0?{tone:`neutral`,label:`${e.length} aggregator CTA${e.length===1?``:`s`}`,detail:`No merchant-owned CTA returned.`}:{tone:`positive`,label:`${t} merchant CTA${t===1?``:`s`}`,detail:`${e.length} total returned.`}}function Kd({tone:e,label:t,detail:n}){return(0,$.jsxs)(`div`,{children:[(0,$.jsx)(J,{tone:e,children:t}),(0,$.jsx)(`p`,{className:`mt-1.5 text-copy-13 text-faint`,children:n})]})}function qd({location:e,lodging:t,place:n,placeActions:r}){let i=t?af(t.attributes):[];return(0,$.jsxs)(`div`,{className:`grid gap-5 text-label-12 lg:grid-cols-3`,children:[(0,$.jsxs)(Jd,{title:`Owner profile · Business Information`,children:[(0,$.jsx)(Yd,{label:`Primary category`,value:e.primaryCategoryDisplayName??`Not returned`}),(0,$.jsx)(Yd,{label:`Secondary categories`,value:e.additionalCategories.length>0?e.additionalCategories.join(`, `):`Not returned`}),(0,$.jsx)(Yd,{label:`Description`,value:$d(e.description)?e.description:`Not returned`}),(0,$.jsx)(Yd,{label:`Hours`,value:e.regularHours?`Returned by Google`:`Not returned`}),(0,$.jsx)(Yd,{label:`Service area`,value:e.serviceArea?`Returned by Google`:`Not returned`}),(0,$.jsx)(Yd,{label:`Phone`,value:e.primaryPhone??`Not returned`}),(0,$.jsx)(Yd,{label:`Website`,value:e.websiteUri??`Not returned`}),(0,$.jsx)(Yd,{label:`Open status`,value:ef(e.openStatus)}),(0,$.jsx)(Yd,{label:`Opening date`,value:e.openingDate??`Not returned`})]}),(0,$.jsx)(Jd,{title:`Hotel data · Lodging API`,children:t?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Yd,{label:`Last checked`,value:rf(t.syncedAt)}),(0,$.jsx)(Yd,{label:`Groups returned`,value:String(t.populatedGroupCount)}),(0,$.jsx)(Yd,{label:`Populated groups`,value:i.length>0?i.join(`, `):`None returned`})]}):(0,$.jsx)(`p`,{className:`text-copy-13 text-secondary`,children:`No Lodging API snapshot was stored for this location.`})}),(0,$.jsxs)(Jd,{title:`Public listing + CTAs`,children:[n?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Yd,{label:`Places tier`,value:n.tier}),(0,$.jsx)(Yd,{label:`Last checked`,value:rf(n.syncedAt)}),(0,$.jsx)(Yd,{label:`Public signals`,value:n.amenities.length>0?n.amenities.join(`, `):`No supported signals detected`})]}):(0,$.jsx)(`p`,{className:`text-copy-13 text-secondary`,children:`No Places Details snapshot was stored for this location.`}),e.mapsUri&&(0,$.jsx)(`a`,{href:e.mapsUri,target:`_blank`,rel:`noopener noreferrer`,className:`inline-block text-muted hover:text-neutral`,children:`View on Google Maps →`}),(0,$.jsx)(`div`,{className:`mt-3 border-t border-default pt-3`,children:r.length===0?(0,$.jsx)(`p`,{className:`text-copy-13 text-secondary`,children:`No placeActionLinks returned.`}):(0,$.jsx)(`div`,{className:`grid gap-2`,children:r.map(e=>(0,$.jsxs)(`div`,{className:`grid gap-0.5`,children:[(0,$.jsxs)(`span`,{className:`text-label-12-strong text-neutral`,children:[tf(e.placeActionType),e.isPreferred?` · preferred`:``]}),(0,$.jsxs)(`span`,{className:`text-faint`,children:[tf(e.providerType),e.uri?` · ${nf(e.uri)}`:``]})]},e.placeActionLinkName))})})]})]})}function Jd({title:e,children:t}){return(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`mb-2 text-label-12-strong normal-case text-muted`,children:e}),(0,$.jsx)(`div`,{className:`grid gap-2`,children:t})]})}function Yd({label:e,value:t}){return(0,$.jsxs)(`div`,{className:`grid grid-cols-[7.25rem_minmax(0,1fr)] gap-3`,children:[(0,$.jsx)(`span`,{className:`text-faint`,children:e}),(0,$.jsx)(`span`,{className:`min-w-0 break-words text-secondary`,children:t})]})}function Xd(e,t,n){return e===t?`positive`:e===0?n:`caution`}function Zd(e){switch(e){case`positive`:return`text-positive`;case`caution`:return`text-caution`;case`negative`:return`text-negative`;case`neutral`:return`text-neutral`}}function Qd(e){return e===`critical`||e===`high`?`insight-card-negative`:e===`medium`?`insight-card-caution`:``}function $d(e){return typeof e==`string`&&e.trim().length>0}function ef(e){return e?tf(e):`Not returned`}function tf(e){return e?e.toLowerCase().split(`_`).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `):`Unknown`}function nf(e){try{return new URL(e).hostname.replace(/^www\./,``)}catch{return e}}function rf(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString(void 0,{month:`short`,day:`numeric`,year:`numeric`})}function af(e){return Object.entries(e).filter(([e,t])=>e!==`name`&&e!==`metadata`&&of(t)).map(([e])=>tf(e.replace(/([a-z])([A-Z])/g,`$1_$2`)))}function of(e){return e==null?!1:Array.isArray(e)?e.length>0:typeof e!=`object`||Object.keys(e).length>0}function sf({performance:e,freshness:t,timeseries:n}){let r=e.totals,i=ge.filter(e=>(r[e]??0)>0),a=De.filter(e=>(r[e]??0)>0),o=Object.keys(r).filter(e=>(r[e]??0)>0&&tn(e)===`other`).sort((e,t)=>(r[t]??0)-(r[e]??0)),s=Object.keys(r).filter(e=>(r[e]??0)===0).sort(),c=n.map(e=>{let t={date:e.date};for(let[n,r]of Object.entries(e.metrics))t[n]=r;return t}),l=n.find(e=>e.pending)?.date,u=n.length>0?n[n.length-1].date:void 0,d=c.length>0,f=t.dataThroughDate?`Data through ${_a(t.dataThroughDate)}${t.pendingDays>0?` · ${t.pendingDays}d pending`:``}`:null,p=[...i,...o];return(0,$.jsxs)(`div`,{className:`mb-6 grid gap-6`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:`mb-2 flex flex-wrap items-baseline justify-between gap-x-3 gap-y-1`,children:[(0,$.jsx)(`p`,{className:`eyebrow eyebrow-soft`,children:`Profile actions · daily`}),f&&(0,$.jsx)(`span`,{className:`text-label-12 text-muted`,children:f})]}),!d||i.length===0?(0,$.jsx)(`p`,{className:`text-copy-14 text-muted`,children:`No profile action activity yet — run a sync.`}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(cf,{data:c,metrics:i,kind:`line`,firstPending:l,lastDate:u}),(0,$.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-x-5 gap-y-1`,children:p.map(e=>(0,$.jsxs)(`span`,{className:`text-label-14 text-secondary`,children:[Ee(e),` `,(0,$.jsx)(`span`,{className:`font-mono text-heading`,children:(r[e]??0).toLocaleString()})]},e))})]})]}),d&&a.length>0&&(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`eyebrow eyebrow-soft mb-2`,children:`Reach · impressions, daily`}),(0,$.jsx)(cf,{data:c,metrics:a,kind:`area`,firstPending:l,lastDate:u})]}),s.length>0&&(0,$.jsxs)(`p`,{className:`text-copy-13 text-faint`,children:[`Not active: `,s.map(e=>Ee(e)).join(`, `)]})]})}function cf({data:e,metrics:t,kind:n,firstPending:r,lastDate:i}){return(0,$.jsx)(`div`,{className:`h-48 w-full`,children:(0,$.jsx)(I,{width:`100%`,height:`100%`,children:(0,$.jsxs)(ne,{data:e,margin:{top:8,right:8,bottom:0,left:0},children:[(0,$.jsx)(M,{stroke:xa,vertical:!1}),(0,$.jsx)(P,{dataKey:`date`,tick:va,tickLine:!1,axisLine:{stroke:Ca},tickFormatter:fa,minTickGap:24}),(0,$.jsx)(ee,{tick:va,tickLine:!1,axisLine:!1,allowDecimals:!1,width:36}),(0,$.jsx)(N,{...Sa,labelFormatter:_a,formatter:(e,t)=>[typeof e==`number`?e.toLocaleString():String(e??0),Ee(String(t??``))]}),(0,$.jsx)(R,{wrapperStyle:{fontSize:12,color:ga.text},formatter:e=>Ee(e)}),r&&i&&(0,$.jsx)(F,{x1:r,x2:i,fill:ga.surface,fillOpacity:.55,stroke:`none`,label:{value:`pending`,position:`insideTopRight`,fill:ga.textDim,fontSize:12}}),t.map((e,t)=>n===`line`?(0,$.jsx)(te,{type:`monotone`,dataKey:e,stroke:ua[t%ua.length],strokeWidth:2,dot:!1,isAnimationActive:!1},e):(0,$.jsx)(L,{type:`monotone`,dataKey:e,stackId:`reach`,stroke:ua[t%ua.length],fill:ua[t%ua.length],fillOpacity:.25,strokeWidth:1.5,isAnimationActive:!1},e))]})})})}var lf=25;function uf(e){return typeof window>`u`?e:`${window.__CANONRY_CONFIG__?.basePath?.replace(/\/$/,``)??``}${e}`}function df(e){return e.toLocaleString()}function ff(e){let t=Date.now()-new Date(e).getTime(),n=Math.floor(t/6e4);if(n<1)return`just now`;if(n<60)return`${n}m ago`;let r=Math.floor(n/60);return r<24?`${r}h ago`:`${Math.floor(r/24)}d ago`}function pf(e){let t=e.filter(e=>e.kind===Se[`backlink-extract`]&&!Ro(e.status));return t.length===0?null:t.reduce((e,t)=>e.createdAt>t.createdAt?e:t)}function mf(e,t){let n=new Date(e??t).getTime(),r=Math.max(0,Math.floor((Date.now()-n)/1e3));if(r<60)return`${r}s`;let i=Math.floor(r/60),a=r%60;return a===0?`${i}m`:`${i}m ${a}s`}function hf({projectName:e}){let t=We(),[n,r]=(0,Q.useState)(null),[s,c]=(0,Q.useState)(null),[u,d]=(0,Q.useState)(null),[f,p]=(0,Q.useState)(null),[m,h]=(0,Q.useState)(null),[g,_]=(0,Q.useState)(null),[v,y]=(0,Q.useState)(Date.now()),[x,S]=(0,Q.useState)(0),[C,w]=(0,Q.useState)(!0),[T,E]=(0,Q.useState)(!1),[D,O]=(0,Q.useState)(null),k=(0,Q.useCallback)(async()=>{w(!0),O(null);try{let[t,n,i,a,o]=await Promise.all([Ge().catch(()=>null),xe(e,{excludeCrawlers:!0}).catch(()=>null),fe(e,{limit:lf,offset:x,excludeCrawlers:!0}).catch(e=>{if(e instanceof ot&&e.code===`NOT_FOUND`)return null;throw e}),Nt(e,{surface:vt.backlinks}).catch(()=>null),he(e).catch(()=>[])]);p(t),r(n),c(i),d(a);let s=pf(o);h(s)}catch(e){O(e instanceof Error?e.message:`Failed to load backlinks`)}finally{w(!1)}},[e,x]);(0,Q.useEffect)(()=>{k()},[k]),(0,Q.useEffect)(()=>{if(!m)return;let e=m.id,t=!1,n=async()=>{try{let n=await Te(e);if(t)return;Ro(n.status)?(h(null),_(n),await k()):h(e=>e?.id===n.id?{...e,...n}:e)}catch{}},r=window.setInterval(()=>{n()},3e3);return()=>{t=!0,window.clearInterval(r)}},[m,k]),(0,Q.useEffect)(()=>{if(!m)return;let e=window.setInterval(()=>y(Date.now()),1e3);return()=>window.clearInterval(e)},[m]),(0,Q.useEffect)(()=>{if(!g||g.status===`failed`)return;let e=window.setTimeout(()=>_(null),1e4);return()=>window.clearTimeout(e)},[g]);async function A(){E(!0),O(null);try{let t=await ct(e);h(t)}catch(e){e instanceof ot&&e.code===`MISSING_DEPENDENCY`?O(`DuckDB is not installed. Visit the Backlinks admin page to install it.`):O(e instanceof Error?e.message:`Failed to trigger extract`)}finally{E(!1)}}let j=s?.rows??[],M=s?.total??0,N=n?.excludedLinkingDomains??0,P=Math.floor(x/lf)+1;return(0,Q.useEffect)(()=>{x>0&&x>=M&&S(0)},[x,M]),(0,$.jsxs)(`section`,{className:`page-section-divider`,children:[(0,$.jsx)(`div`,{className:`section-head section-head-inline`,children:(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`eyebrow eyebrow-soft`,children:`Backlinks`}),(0,$.jsx)(`h2`,{children:`Referring domains`})]})}),D&&(0,$.jsx)(Z,{className:`surface-card p-4 mb-4 bg-negative-soft`,children:(0,$.jsx)(`p`,{className:`text-copy-14 text-negative`,children:D})}),m&&(0,$.jsx)(Z,{className:`surface-card p-4 mb-4 bg-info-soft`,children:(0,$.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,$.jsx)(i,{className:`h-5 w-5 text-info-400 animate-spin shrink-0 mt-0.5`,"aria-hidden":!0}),(0,$.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,$.jsx)(`p`,{className:`text-copy-14-strong text-heading`,children:`Extract running`}),(0,$.jsx)(J,{tone:`neutral`,children:m.status}),(0,$.jsxs)(`span`,{className:`text-label-14 text-secondary tabular-nums`,children:[mf(m.startedAt??null,m.createdAt),` elapsed · refreshing every 3s`]}),(0,$.jsxs)(`span`,{className:`sr-only`,children:[`now=`,v]})]}),(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary mt-1`,children:`Refreshing this project from the current Common Crawl release.`})]})]})}),g&&!m&&(0,$.jsx)(Z,{className:`surface-card p-4 mb-4 ${g.status===`failed`?`bg-negative-soft`:`bg-positive-soft`}`,children:(0,$.jsxs)(`div`,{className:`flex items-start gap-3`,children:[g.status===`failed`?(0,$.jsx)(`span`,{className:`h-5 w-5 shrink-0 mt-0.5 text-negative-400 text-label-18`,"aria-hidden":!0,children:`!`}):(0,$.jsx)(a,{className:`h-5 w-5 text-positive-400 shrink-0 mt-0.5`,"aria-hidden":!0}),(0,$.jsxs)(`div`,{className:`flex-1`,children:[(0,$.jsx)(`p`,{className:`text-copy-14-strong ${g.status===`failed`?`text-negative`:`text-positive`}`,children:g.status===`failed`?`Extract failed`:`Extract complete`}),g.error?(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary mt-1`,children:An(g.error)}):g.status===`failed`?null:(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary mt-1`,children:`Backlinks refreshed from the cached release.`})]})]})}),F()]});function F(){return C?(0,$.jsx)(Z,{className:`surface-card p-6`,children:(0,$.jsx)(`p`,{className:`text-copy-14 text-muted`,children:`Loading backlinks…`})}):I()}function I(){let e=n!==null&&n.totalLinkingDomains>0,r=g?.status===`failed`,i=n!==null&&n.totalLinkingDomains===0&&!r,a=f?.status===`ready`,s=f?.status===`failed`,c=f&&(f.status===`downloading`||f.status===`querying`||f.status===`queued`);return e?L((0,$.jsxs)($.Fragment,{children:[!Y()&&!t&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(q,{type:`button`,variant:`outline`,size:`sm`,disabled:T||m!==null,onClick:Jn(A),children:[(0,$.jsx)(l,{className:`h-4 w-4 mr-1.5`,"aria-hidden":!0}),m?`Extract running…`:T?`Queuing…`:`Re-run extract`]}),(0,$.jsx)(Ms,{label:`About re-running`,children:`Re-queries the current release for this project without downloading it again.`})]}),!Y()&&!t&&(0,$.jsx)(q,{asChild:!0,type:`button`,variant:`outline`,size:`sm`,children:(0,$.jsx)(`a`,{href:uf(`/backlinks`),children:`Open admin`})})]})):(0,$.jsx)(Z,{className:`surface-card p-6`,children:(0,$.jsxs)(`div`,{className:`flex items-start gap-4`,children:[(0,$.jsx)(`div`,{className:`flex h-10 w-10 shrink-0 items-center justify-center rounded-md bg-bg-elevated text-secondary`,children:(0,$.jsx)(o,{className:`h-5 w-5`,"aria-hidden":!0})}),(0,$.jsxs)(`div`,{className:`flex-1`,children:[!f&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`h3`,{className:`text-heading-16 text-heading`,children:`No release sync yet`}),(0,$.jsx)(`p`,{className:`text-copy-14 text-muted mt-1`,children:`Run a workspace release sync to populate backlinks for every project in this workspace.`}),!Y()&&!t&&(0,$.jsx)(`div`,{className:`mt-4`,children:(0,$.jsx)(q,{asChild:!0,type:`button`,size:`sm`,children:(0,$.jsx)(`a`,{href:uf(`/backlinks`),children:`Set up backlinks`})})})]}),c&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`h3`,{className:`text-heading-16 text-heading`,children:`Sync in progress`}),(0,$.jsxs)(`p`,{className:`text-copy-14 text-muted mt-1`,children:[`A workspace release sync is running (`,f.status,f.phaseDetail?` — ${f.phaseDetail}`:``,`). Backlinks will appear here once it finishes.`]}),!Y()&&!t&&(0,$.jsx)(`div`,{className:`mt-4`,children:(0,$.jsx)(q,{asChild:!0,type:`button`,variant:`outline`,size:`sm`,children:(0,$.jsx)(`a`,{href:uf(`/backlinks`),children:`View sync status`})})})]}),s&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`h3`,{className:`text-heading-16 text-heading`,children:`Last sync failed`}),(0,$.jsx)(`p`,{className:`text-copy-14 text-muted mt-1`,children:f.error??`The workspace release sync failed. Retry from the Backlinks admin page.`}),!Y()&&!t&&(0,$.jsx)(`div`,{className:`mt-4`,children:(0,$.jsx)(q,{asChild:!0,type:`button`,size:`sm`,children:(0,$.jsx)(`a`,{href:uf(`/backlinks`),children:`Go to Backlinks admin`})})})]}),a&&!c&&!i&&!r&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`h3`,{className:`text-heading-16 text-heading`,children:`No backlinks yet for this project`}),(0,$.jsxs)(`p`,{className:`text-copy-14 text-secondary mt-1`,children:[`Release `,(0,$.jsx)(`code`,{className:`text-neutral`,children:f.release}),` is ready. Run an extract for this project.`]}),!Y()&&!t&&(0,$.jsxs)(`div`,{className:`mt-4 flex items-center gap-3 flex-wrap`,children:[(0,$.jsxs)(q,{type:`button`,size:`sm`,disabled:T||m!==null,onClick:Jn(A),children:[(0,$.jsx)(b,{className:`h-4 w-4 mr-1.5`,"aria-hidden":!0}),m?`Extract running…`:T?`Queuing…`:`Run extract`]}),(0,$.jsx)(Ms,{label:`About extraction`,children:`Queries the current release for this project without downloading it again.`})]})]}),r&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`h3`,{className:`text-heading-16 text-heading`,children:`Last extract failed`}),(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary mt-1`,children:`See the error above, then check the workspace source before retrying.`}),!Y()&&!t&&(0,$.jsx)(`div`,{className:`mt-4 flex items-center gap-3 flex-wrap`,children:(0,$.jsx)(q,{asChild:!0,type:`button`,size:`sm`,children:(0,$.jsx)(`a`,{href:uf(`/backlinks`),children:`Go to Backlinks admin`})})})]}),i&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`h3`,{className:`text-heading-16 text-heading`,children:`No referring domains found`}),(0,$.jsxs)(`p`,{className:`text-copy-14 text-secondary mt-1`,children:[`The latest release found no referring domains for `,n.targetDomain,`. Try a newer release or re-run this extract.`]}),!Y()&&!t&&(0,$.jsxs)(`div`,{className:`mt-4 flex items-center gap-3 flex-wrap`,children:[(0,$.jsx)(q,{asChild:!0,type:`button`,size:`sm`,children:(0,$.jsx)(`a`,{href:uf(`/backlinks`),children:`Go to Backlinks admin`})}),(0,$.jsxs)(q,{type:`button`,variant:`outline`,size:`sm`,disabled:T||m!==null,onClick:Jn(A),children:[(0,$.jsx)(b,{className:`h-4 w-4 mr-1.5`,"aria-hidden":!0}),m?`Extract running…`:T?`Queuing…`:`Re-run extract`]}),(0,$.jsxs)(Ms,{label:`What does Re-run extract do?`,children:[(0,$.jsxs)(`span`,{className:`block`,children:[`Re-queries the cached release for `,(0,$.jsx)(`span`,{className:`text-strong`,children:n.targetDomain}),`. Only useful if the cache files were incomplete last time.`]}),(0,$.jsx)(`span`,{className:`mt-2 block text-secondary`,children:`No re-download. ~5 min. If the release genuinely has no links for your domain, this won’t help — sync a different release instead.`})]})]})]})]})]})})}function L(e){if(!n)return null;let t=`release`;return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(gf,{summary:n,trend:u}),(0,$.jsxs)(`p`,{className:`text-copy-13 text-muted mt-2`,children:[(0,$.jsx)(`span`,{className:`text-secondary`,children:`Common Crawl`}),` · `,t,` `,(0,$.jsx)(`code`,{className:`text-secondary`,children:n.release}),` · queried `,ff(n.queriedAt),N>0&&(0,$.jsxs)($.Fragment,{children:[` · `,N,` excluded domain`,N===1?``:`s`]})]}),(0,$.jsxs)(`div`,{className:`mt-4`,children:[(0,$.jsx)(`p`,{className:`eyebrow eyebrow-soft mb-2`,children:`Top referring domains`}),(0,$.jsx)(Z,{className:`surface-card overflow-hidden`,children:(0,$.jsxs)(`table`,{className:`w-full text-label-14`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{className:`border-b border-base text-left text-label-12 normal-case text-faint`,children:[(0,$.jsx)(`th`,{className:`px-4 py-2 text-label-12-strong`,children:`Domain`}),(0,$.jsx)(`th`,{className:`px-4 py-2 text-right text-label-12-strong`,children:`Linking hosts`})]})}),(0,$.jsxs)(`tbody`,{children:[j.map(e=>(0,$.jsxs)(`tr`,{className:`border-b border-mono-900 last:border-0`,children:[(0,$.jsx)(`td`,{className:`px-4 py-2 text-strong`,children:e.linkingDomain}),(0,$.jsx)(`td`,{className:`px-4 py-2 text-right text-secondary tabular-nums`,children:df(e.numHosts)})]},e.linkingDomain)),j.length===0&&(0,$.jsx)(`tr`,{children:(0,$.jsx)(`td`,{className:`px-4 py-4 text-label-14 text-muted`,colSpan:2,children:N>0&&M===0?`Every referring domain in this ${t} was a crawler/proxy host (${N} hidden).`:`No referring domains in this ${t}.`})})]})]})}),(0,$.jsx)(Ts,{page:P,pageSize:lf,visibleRows:j.length,totalRows:M,onPageChange:e=>S((e-1)*lf)})]}),(0,$.jsx)(`div`,{className:`mt-4 flex items-center gap-3 flex-wrap`,children:e})]})}}function gf({summary:e,trend:t}){let[n,r]=(0,Q.useState)(`referring-domains`),i=t?.groups.find(e=>e.key===`backlinks`),a=new Map(i?.figures.map(e=>[e.key,e])),o=(e,t,n,r,i)=>{let o=a.get(e);return{key:e,label:t,help:n,value:i(r),change:o?bs(o.change,o.unit):void 0,series:o?ks(o):void 0,formatValue:i,allowDecimals:o?.unit===`fraction`}},s=[o(`referring-domains`,`Referring domains`,`Unique domains linking to ${e.targetDomain}.`,e.totalLinkingDomains,df),o(`hosts`,`Total linking hosts`,`Aggregate linking hosts across referring domains.`,e.totalHosts,df),o(`top-10-concentration`,`Top-10 concentration`,`Share of linking hosts from the 10 largest linking domains.`,Number(e.top10HostsShare),e=>G(e))],c=s.some(ws),l=a.get(`referring-domains`)?.series??[],u=l[0],d=l.at(-1);return(0,$.jsx)(Os,{name:`Backlinks figures`,groups:[{key:`backlinks`,label:`Every release`,basis:i?Es(i.figures):void 0,figures:s}],selected:c?[n]:[],onSelect:r,cadence:`release`,span:c&&u&&d?xs(u,d):void 0,emptyChartMessage:t?`One release so far. The trend starts with the next one.`:`Release history could not be loaded.`})}var _f={[U[`keyword-metrics`]]:`Search demand`,[U[`domain-intelligence`]]:`Domain comparison`,[U[`ranked-keywords`]]:`Searches you rank for`,[U[`market-rankings`]]:`Market rankings`,[U[`competitor-discovery`]]:`Organic competitors`,[U[`keyword-gaps`]]:`Search gaps`},vf={[tt.shared]:`Shared`,[tt.missing]:`Missing`,[tt.outranked]:`Competitor ahead`},yf=`Your organic position minus the competitor’s position. Positive means the competitor ranks higher; negative means you rank higher. No gap is calculated when either position is unavailable.`,bf={[cn.queued]:`Queued`,[cn.running]:`Refreshing`,[cn.completed]:`Completed`,[cn.partial]:`Partial results`,[cn.failed]:`Failed`,[cn.cancelled]:`Cancelled`,[cn[`reconciliation-required`]]:`Needs review`},xf=25,Sf=new Intl.NumberFormat(`en-US`,{maximumFractionDigits:1}),Cf=new Intl.NumberFormat(`en-US`,{style:`currency`,currency:`USD`,maximumFractionDigits:2}),wf=Intl.DateTimeFormat().resolvedOptions().timeZone,Tf=`min-h-11 w-full rounded-md border border-default bg-bg px-3 py-2 text-label-14 text-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-mono-400`,Ef=`px-4 py-3 text-right align-top tabular-nums whitespace-nowrap`,Df=`min-w-56 px-4 py-3 text-left align-top text-label-14`,Of=`Position on the page, counting maps and other blocks`;function kf(e){return e?.status===cn.queued||e?.status===cn.running}function Af({value:e,currency:t=!1}){return e===null?(0,$.jsx)(`span`,{className:`text-muted`,"aria-label":`Not supplied`,children:`—`}):(0,$.jsx)($.Fragment,{children:t?Cf.format(e):Sf.format(e)})}function jf({status:e}){let t=e===cn.completed?`positive`:e===cn.failed?`negative`:e===cn.partial||e===cn[`reconciliation-required`]?`caution`:`neutral`;return(0,$.jsx)(J,{tone:t,children:bf[e]})}function Mf(e){let t=pn(e).split(`/`).at(-1)??e,n=Zt.safeParse(t.replaceAll(`_`,`-`));return n.success?_f[n.data]:t.replaceAll(/[-_]/g,` `)}function Nf(e){return e===`mobile`?`phone results`:e===`desktop`?`computer results`:`device not specified by source`}function Pf(e){return e.capabilities.includes(U[`market-rankings`])?`Market locations`:`Location ${e.locationCode}`}function Ff(e){return e.capabilities.includes(U[`market-rankings`])?`searches`:`tasks`}function If(e){return e.capability!==U[`market-rankings`]||![cn.queued,cn.running,cn.completed].includes(e.status)}function Lf(e,t){let n=e.capabilities.includes(U[`market-rankings`]);return`${t} ${t===1?n?`search`:`task`:Ff(e)}`}function Rf(e,t){return Number.isFinite(Date.parse(e))?Ct(Ot(e,t)):null}var zf={[cn.failed]:`Latest refresh failed`,[cn.cancelled]:`Latest refresh cancelled`,[cn[`reconciliation-required`]]:`Latest refresh needs review`};function Bf(e,t){let n=e&&e.id!==t?.id?zf[e.status]:void 0;if(e&&n)return{label:n,text:`${n}. ${e.error??`Open Activity for refresh details.`}${t?` Showing the refresh before it.`:``}`};if(!t)return null;if(t.failedTasks>0){let e=`${Lf(t,t.failedTasks)} failed`,n=t.capabilities.includes(U[`market-rankings`])?`Their queries show as Failed.`:`Open Activity for details.`;return{label:e,text:`${e}: ${t.failedTasks} of ${Lf(t,t.taskCount)} in this refresh returned no results. ${n}`}}return t.status===cn.partial?{label:`Partial results`,text:`Partial results: ${t.error??`some ${Ff(t)} returned only part of their results or did not run. Open Activity for details.`}`}:null}function Vf({source:e}){return(0,$.jsxs)(`dl`,{className:`grid gap-x-8 gap-y-2 text-label-13 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`dt`,{className:`text-muted`,children:`Dataset`}),(0,$.jsx)(`dd`,{children:Mf(e.dataset)})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`dt`,{className:`text-muted`,children:`Search engine`}),(0,$.jsxs)(`dd`,{children:[`Google · `,Nf(e.device)]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`dt`,{className:`text-muted`,children:`Provider geography`}),(0,$.jsxs)(`dd`,{children:[`Location `,e.locationCode,` · `,e.languageCode]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`dt`,{className:`text-muted`,children:`Collected`}),(0,$.jsx)(`dd`,{children:ut(e.collectedAt,wf)})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`dt`,{className:`text-muted`,children:`Source updated`}),(0,$.jsx)(`dd`,{children:e.sourceUpdatedAt?en(e.sourceUpdatedAt):`Not supplied`})]})]})}function Hf({label:e,source:t,children:n}){return(0,$.jsxs)(`details`,{className:`text-left`,children:[(0,$.jsxs)(`summary`,{className:`flex min-h-11 cursor-pointer items-center text-label-13 text-secondary hover:text-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-mono-400`,children:[`Details`,(0,$.jsxs)(`span`,{className:`sr-only`,children:[` for `,e]})]}),(0,$.jsxs)(`div`,{className:`min-w-56 space-y-4 pb-3 text-label-13 text-secondary`,children:[n,t&&(0,$.jsx)(Vf,{source:t})]})]})}function Uf({error:e,retry:t}){return(0,$.jsxs)(`div`,{role:`alert`,className:`flex flex-wrap items-center justify-between gap-3 rounded-md border border-default p-4 text-label-14`,children:[(0,$.jsx)(`p`,{children:Co(e)}),(0,$.jsx)(q,{variant:`secondary`,className:`pointer-coarse:min-h-11`,onClick:t,children:`Retry`})]})}function Wf({title:e,children:t}){return(0,$.jsxs)(`div`,{className:`py-12 text-center`,children:[(0,$.jsx)(`h3`,{className:`text-heading-14 text-heading`,children:e}),(0,$.jsx)(`p`,{className:`mx-auto mt-2 max-w-lg text-copy-14 text-secondary`,children:t})]})}function Gf({projectName:e}){let t=E({strict:!1}),n=T(),i=w(ji({client:K,path:{name:e}})),a=w(qr({client:K,path:{name:e}})),o=w({...cr({client:K,path:{name:e,id:t.seoRunId??``}}),enabled:!!t.seoRunId}),[s,c]=(0,Q.useState)(null),l=(0,Q.useRef)(null),u=(0,Q.useRef)(null),d=t.seoProfileId??o.data?.profileId,f=d?a.data?.profiles.find(e=>e.id===d):t.seoRunId?void 0:a.data?.profiles[0],p=t=>{c(null),n({to:`/projects/$projectName/seo-data`,params:{projectName:e},search:e=>({...e,seoProfileId:t,seoRunId:void 0,seoRegion:void 0,seoMarket:void 0,seoShow:void 0,seoSort:void 0,seoQ:void 0})})},m=i.data?.access.canWrite===!0&&!Y()&&!We(),h=()=>{c(null),l.current?.focus()};if((0,Q.useEffect)(()=>{!t.seoProfileId&&f&&n({to:`/projects/$projectName/seo-data`,params:{projectName:e},search:e=>({...e,seoProfileId:f.id}),replace:!0})},[n,e,t.seoProfileId,f]),i.error)return(0,$.jsx)(Uf,{error:i.error,retry:()=>{i.refetch()}});if(a.error)return(0,$.jsx)(Uf,{error:a.error,retry:()=>{a.refetch()}});if(!i.data||!a.data)return(0,$.jsx)(`p`,{role:`status`,className:`py-10 text-copy-14 text-secondary`,children:`Loading SEO data…`});let g=i.data.available&&i.data.connections.some(e=>e.capabilities.length>0),_=g&&i.data.connections.some(e=>e.capabilities.some(e=>i.data.scopes.some(t=>t.capabilities?.includes(e)??!0))),v=f&&i.data.scopes.find(e=>e.kind===f.scope.kind&&e.key===(f.scope.key??null));return(0,$.jsxs)(`section`,{"aria-label":`SEO`,className:`min-w-0 space-y-5`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-end justify-between gap-3`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h2`,{className:`text-heading-20 text-heading`,children:`SEO`}),(0,$.jsx)(`p`,{className:`mt-1 text-copy-14 text-secondary`,children:`Search demand and organic rankings.`})]}),m&&_&&(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[f&&(0,$.jsx)(q,{variant:`ghost`,className:`pointer-coarse:min-h-11`,onClick:e=>{l.current=e.currentTarget,c({profile:f,id:f.id})},children:`Edit profile`}),(0,$.jsxs)(q,{variant:`secondary`,className:`pointer-coarse:min-h-11`,onClick:e=>{l.current=e.currentTarget,c({id:crypto.randomUUID()})},children:[(0,$.jsx)(r,{"aria-hidden":`true`,className:`size-4`}),`New profile`]})]})]}),a.data.profiles.length>0&&(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-5 gap-y-3 border-y border-subtle py-3`,children:[(0,$.jsxs)(`label`,{className:`flex min-w-0 flex-1 items-center gap-3 sm:flex-none`,children:[(0,$.jsx)(`span`,{className:`text-label-13 text-secondary`,children:`Profile`}),(0,$.jsxs)(`select`,{ref:u,"aria-label":`SEO profile`,value:f?.id??``,onChange:e=>p(e.target.value),className:`${Tf} min-w-0 sm:w-64`,children:[!f&&(0,$.jsx)(`option`,{value:``,disabled:!0,children:`Profile unavailable`}),a.data.profiles.map(e=>(0,$.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]}),f&&(0,$.jsxs)(`div`,{className:`min-w-0 text-label-13 text-secondary`,children:[(0,$.jsx)(`p`,{className:`break-words text-copy-13-strong text-primary`,children:v?.label??`${f.scope.kind}${f.scope.key?`: ${f.scope.key}`:``}`}),(0,$.jsxs)(`p`,{children:[f.rankings?`${f.rankings.locations.length} search location${f.rankings.locations.length===1?``:`s`}`:`Location ${f.locationCode}`,` · `,f.languageCode]})]})]}),s&&(0,$.jsx)(Op,{projectName:e,context:i.data,profile:s.profile,id:s.id,onClose:h,onSaved:e=>{p(e),requestAnimationFrame(()=>u.current?.focus())}},s.id),!We()&&!i.data.available&&a.data.profiles.length>0&&(0,$.jsx)(`p`,{role:`status`,className:`rounded-md border border-default px-4 py-3 text-copy-14 text-secondary`,children:i.data.reason??`Configure an SEO data provider to refresh saved profiles.`}),t.seoRunId&&o.error?(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsx)(Uf,{error:o.error,retry:()=>{o.refetch()}}),f?(0,$.jsx)(q,{variant:`secondary`,className:`pointer-coarse:min-h-11`,onClick:()=>p(f.id),children:`View latest data`}):(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:`Select a profile to view its latest data.`})]}):t.seoRunId&&o.isPending?(0,$.jsx)(`p`,{role:`status`,className:`py-10 text-copy-14 text-secondary`,children:`Loading refresh…`}):f&&o.data&&o.data.profileId!==f.id?(0,$.jsxs)(Wf,{title:`Refresh belongs to another profile`,children:[`Choose the refresh’s profile, or return to the selected profile’s latest data.`,(0,$.jsx)(q,{variant:`secondary`,className:`mt-4 pointer-coarse:min-h-11`,onClick:()=>p(f.id),children:`View latest data`})]}):f?(0,$.jsx)(Kf,{projectName:e,profile:f,context:i.data,selectedRunId:t.seoRunId,onLatest:()=>p(f.id)},`${f.id}:${f.revision}:${t.seoRunId??``}`):!_&&a.data.profiles.length===0?(0,$.jsx)(Wf,{title:g?`SEO scope unavailable`:`Configure an SEO data provider`,children:g?i.data.scopes.find(e=>e.reason)?.reason??`No datasets are available for this project’s measurement scopes.`:`Connect a provider before creating an SEO profile.`}):d?(0,$.jsx)(Wf,{title:`Profile unavailable`,children:`This saved profile is no longer available. Select another profile to view its data.`}):!s&&(0,$.jsx)(Wf,{title:`No SEO data yet`,children:m?`Create a profile to choose the scope, source, and searches to measure.`:`An SEO profile is needed before data can be collected.`})]})}function Kf({projectName:e,profile:t,context:n,selectedRunId:r,onLatest:a}){let o=S(),[s,c]=(0,Q.useState)(r?`activity`:t.capabilities.includes(U[`ranked-keywords`])?U[`ranked-keywords`]:t.capabilities.at(0)??`activity`),[l,u]=(0,Q.useState)(null),d=(0,Q.useRef)(null),f=(0,Q.useRef)(null),m={name:e},h=w({...jr({client:K,path:m,query:{profileId:t.id,runId:r}}),refetchInterval:e=>kf(e.state.data?.latestRun)?2e3:!1}),g=C({...Ai({client:K}),meta:{skipGlobalErrorToast:!0}}),_=C({...Ir({client:K}),meta:{skipGlobalErrorToast:!0}}),v=h.data?.latestRun,y=h.data?.evidenceRun,b=h.data?.evidenceRun?.capabilities??t.capabilities,x=s===`activity`||b.includes(s)?s:b.at(0)??`activity`,T=kf(v),E=g.isPending||_.isPending,D=n.access.canRun&&!Y()&&!We(),O=n.connections.find(e=>e.id===t.connectionId),k=n.scopes.find(e=>e.kind===t.scope.kind&&e.key===(t.scope.key??null)),A=w({...mr({client:K,path:m,query:{kind:At[`seo-sync`]}}),retry:!1}),j=!A.isError&&A.data?.enabled&&A.data.nextRunAt?A.data.nextRunAt:null,M=j?Rf(j,A.data?.timezone??`UTC`):null,N=y?.finishedAt&&(y.status===cn.completed||y.status===cn.partial)?Rf(y.finishedAt,wf):null,P=T?null:Bf(v,y);return(0,Q.useEffect)(()=>{v&&(kf(v)?f.current=v.id:f.current===v.id&&(f.current=null,Zn(o,`seo`,{projectName:e,profileId:t.id})))},[v,t.id,e,o]),(0,$.jsxs)(`div`,{className:`space-y-5`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-x-3 gap-y-1 text-label-14 text-secondary`,children:[(0,$.jsx)(`div`,{"aria-live":`polite`,children:T&&v?(0,$.jsxs)(`p`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(i,{className:`size-4 animate-spin`,"aria-hidden":`true`}),v.cancelRequested?`Cancellation requested`:bf[v.status],` · `,v.completedTasks,` of `,v.taskCount,` `,Ff(v),` completed`]}):(0,$.jsxs)(`p`,{children:[N&&y?.finishedAt?(0,$.jsxs)($.Fragment,{children:[`Updated `,(0,$.jsx)(`time`,{dateTime:y.finishedAt,title:ut(y.finishedAt,wf)??void 0,children:N})]}):`No completed refresh`,M&&j&&(0,$.jsxs)($.Fragment,{children:[` · Next refresh `,(0,$.jsx)(`time`,{dateTime:j,children:M})]})]})}),P&&(0,$.jsx)(X,{tone:`caution`,placement:`bottom`,label:P.label,text:P.text})]}),r?(0,$.jsx)(q,{variant:`secondary`,className:`pointer-coarse:min-h-11`,onClick:a,children:`View latest data`}):D&&(0,$.jsxs)(q,{className:`pointer-coarse:min-h-11`,disabled:E||T||!n.available||!O,onClick:Jn(async()=>{if(!(!D||r||T||E)){u(null);try{if(!d.current){let e=await g.mutateAsync({path:m,body:{profileId:t.id}});if(e.availability!==nn.ready){u(e.reason??`This profile cannot be refreshed. Review its scope and source.`);return}d.current={quoteToken:e.token,idempotencyKey:crypto.randomUUID()}}let e=await _.mutateAsync({path:m,body:d.current});d.current=null,kf(e)&&(f.current=e.id),await o.fetchQuery(jr({client:K,path:m,query:{profileId:t.id}}))}catch(e){Fo(e).code===`VALIDATION_ERROR`&&(d.current=null),u(Co(e))}}}),children:[(0,$.jsx)(p,{"aria-hidden":`true`,className:`size-4 ${E?`animate-spin`:``}`}),E?`Starting refresh…`:T?`Refresh in progress`:d.current?`Retry refresh`:`Refresh data`]})]}),l&&(0,$.jsxs)(`p`,{role:`alert`,className:`rounded-md border border-default p-4 text-copy-14 text-secondary`,children:[l,d.current&&` Retry uses the same request, so it will not start a duplicate refresh.`]}),r&&(0,$.jsxs)(`p`,{className:`break-all text-copy-13 text-secondary`,children:[`Viewing saved refresh `,r,`.`]}),h.data?.evidenceRun&&h.data.evidenceRun.profileRevision!==t.revision&&(0,$.jsxs)(`p`,{role:`status`,className:`text-copy-14 text-secondary`,children:[`Saved data uses profile revision `,h.data.evidenceRun.profileRevision,` · `,Pf(h.data.evidenceRun),` · `,h.data.evidenceRun.languageCode,`. The current profile has changed.`]}),!We()&&k&&!k.supported&&(0,$.jsx)(`p`,{role:`status`,className:`text-copy-14 text-secondary`,children:k.reason??`This scope is not supported for domain data.`}),h.error?(0,$.jsx)(Uf,{error:h.error,retry:()=>{h.refetch()}}):h.data?.summary&&(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`p`,{className:`mb-3 break-words text-copy-13 text-secondary`,children:[h.data.summary.target.value,h.data.summary.target.includeSubdomains?` · includes subdomains`:` · exact host`]}),(0,$.jsxs)(`dl`,{className:`grid grid-cols-1 gap-5 border-b border-subtle pb-5 sm:grid-cols-3`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`dt`,{className:`text-label-13 text-secondary`,children:`Searches you rank for`}),(0,$.jsx)(`dd`,{className:`mt-2 text-heading-32 tabular-nums text-heading`,children:(0,$.jsx)(Af,{value:h.data.summary.organicKeywords})})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`dt`,{className:`text-label-13 text-secondary`,children:`In the top 10`}),(0,$.jsx)(`dd`,{className:`mt-2 text-heading-32 tabular-nums text-heading`,children:(0,$.jsx)(Af,{value:h.data.summary.inTop10})})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`dt`,{className:`flex items-center gap-1.5 text-label-13 text-secondary`,children:[`Estimated organic traffic`,(0,$.jsx)(X,{text:`Modeled search traffic for this target and provider geography. This is not measured site traffic.`})]}),(0,$.jsx)(`dd`,{className:`mt-2 text-heading-32 tabular-nums text-heading`,children:(0,$.jsx)(Af,{value:h.data.summary.estimatedOrganicTraffic})})]})]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`flex flex-wrap gap-x-5 border-b border-subtle`,"aria-label":`SEO views`,children:[...b,`activity`].map(e=>(0,$.jsx)(`button`,{type:`button`,"aria-pressed":x===e,className:`min-h-11 border-b-2 text-button-14 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-mono-400 ${x===e?`border-strong text-primary`:`border-transparent text-secondary hover:text-primary`}`,onClick:()=>c(e),children:e===`activity`?`Activity`:_f[e]},e))}),x===`activity`?(0,$.jsx)(Dp,{projectName:e,profileId:t.id,canRun:D,selectedRunId:r}):h.isPending?(0,$.jsx)(`p`,{role:`status`,className:`py-8 text-copy-14 text-secondary`,children:`Loading saved data…`}):h.data&&(0,$.jsx)(qf,{projectName:e,profileId:t.id,runId:h.data.evidenceRunId,view:x,active:T,nextRefresh:M},`${t.id}:${x}:${h.data.evidenceRunId??`empty`}`)]}),(0,$.jsxs)(`details`,{className:`border-t border-subtle text-label-14 text-secondary`,children:[(0,$.jsx)(`summary`,{className:`flex min-h-11 cursor-pointer items-center text-label-14-strong focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-mono-400`,children:`Data details`}),(0,$.jsxs)(`div`,{className:`space-y-4 pb-3 text-label-13`,children:[(0,$.jsxs)(`p`,{children:[`Current profile source: `,We()?`Fictional demo data`:O?.label??`Source unavailable`,`. Google; `,Nf(t.rankings?.device??`unspecified`),`.`]}),h.data?.evidenceRun&&(0,$.jsxs)(`p`,{children:[`Saved evidence: `,h.data.evidenceRun.scope.kind,h.data.evidenceRun.scope.key?` · ${h.data.evidenceRun.scope.key}`:``,h.data.evidenceRun.scope.expectedPlanRevision===void 0?``:` · plan revision ${h.data.evidenceRun.scope.expectedPlanRevision}`,`. `,Pf(h.data.evidenceRun),` · `,h.data.evidenceRun.languageCode,` · profile revision `,h.data.evidenceRun.profileRevision,`.`]}),(0,$.jsx)(`p`,{children:`These are provider estimates and observed search rankings. Missing values are shown as a dash. Difficulty is a source score out of 100.`}),(0,$.jsx)(`p`,{children:`Current profile targets:`}),(0,$.jsx)(`ul`,{className:`space-y-1`,children:t.targets.map((e,t)=>(0,$.jsxs)(`li`,{className:`break-words`,children:[e.value,` · `,e.includeSubdomains?`includes subdomains`:`exact host`]},t))}),t.scope.expectedPlanRevision!==void 0&&(0,$.jsxs)(`p`,{children:[`Saved measurement plan revision `,t.scope.expectedPlanRevision,`.`]}),h.data?.summary&&(0,$.jsx)(Vf,{source:h.data.summary.provenance})]})]})]})}function qf({projectName:e,profileId:t,runId:n,view:r,active:i,nextRefresh:a}){return r===U[`market-rankings`]?n?(0,$.jsx)(_p,{projectName:e,profileId:t,runId:n,active:i}):(0,$.jsx)(Wf,{title:`No market rankings yet`,children:a?`First refresh ${a}`:`Refresh this profile to rank its tracked queries in each market.`}):(0,$.jsx)(Jf,{projectName:e,profileId:t,runId:n,view:r,active:i})}function Jf({projectName:e,profileId:t,runId:n,view:r,active:i}){let[a,o]=(0,Q.useState)(1),[s,c]=(0,Q.useState)(``),[l,u]=(0,Q.useState)(),[d,f]=(0,Q.useState)(),p={client:K,path:{name:e},query:{profileId:t,runId:n??void 0,limit:xf,offset:(a-1)*xf}},m=w({...ca(p),enabled:!!n&&r===U[`ranked-keywords`]}),h=w({...Ur(p),enabled:!!n&&r===U[`keyword-metrics`]}),g=w({...Pr(p),enabled:!!n&&r===U[`domain-intelligence`]}),_=w({...or({...p,query:{...p.query,sort:l}}),placeholderData:j,enabled:!!n&&r===U[`competitor-discovery`]}),v=w({...Lr({...p,query:{...p.query,kind:s||void 0,sort:d}}),placeholderData:j,enabled:!!n&&r===U[`keyword-gaps`]}),y=r===U[`ranked-keywords`]?m:r===U[`keyword-metrics`]?h:r===U[`competitor-discovery`]?_:r===U[`keyword-gaps`]?v:g;return n?(0,$.jsxs)(`div`,{className:`space-y-3 pt-4`,children:[r===U[`keyword-gaps`]&&(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsxs)(`label`,{className:`flex items-center gap-3 text-label-14`,children:[(0,$.jsx)(`span`,{children:`Show`}),(0,$.jsxs)(`select`,{"aria-label":`Show search gaps`,className:`${Tf} w-auto`,value:s,onChange:e=>{c(e.target.value),o(1)},children:[(0,$.jsx)(`option`,{value:``,children:`All comparisons`}),(0,$.jsx)(`option`,{value:tt.missing,children:`Missing`}),(0,$.jsx)(`option`,{value:tt.shared,children:`Shared`}),(0,$.jsx)(`option`,{value:tt.outranked,children:`Competitor ahead`})]})]}),(0,$.jsx)(X,{text:`Missing: the source lists the search for the competitor but not your domain. Shared includes searches where the competitor ranks higher. These are bounded observations from the source’s organic search database, not a live check of every Google result.`})]}),r===U[`competitor-discovery`]&&(0,$.jsxs)(`p`,{className:`flex items-center gap-1.5 text-label-13 text-secondary`,children:[`Domains sharing organic searches`,(0,$.jsx)(X,{text:`Discovery uses this profile’s whole domains, location and language. Suggested domains are not automatically added to tracked competitors. Counts describe the source’s database; the table is limited to this refresh’s saved results.`})]}),y.error?(0,$.jsx)(Uf,{error:y.error,retry:()=>{y.refetch()}}):y.data?y.data.items.length===0?(0,$.jsx)(Wf,{title:i?`Refresh in progress`:s?`No matching comparisons`:`No results returned`,children:i?`This profile is collecting data.`:s?`Choose another comparison filter to see the remaining saved results.`:`The source did not return records for this scope. Review the refresh in Activity before changing the profile.`}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`relative overflow-x-auto material-base`,role:`region`,"aria-label":`${_f[r]} table`,"aria-busy":y.isFetching,tabIndex:0,children:[r===U[`ranked-keywords`]&&m.data&&(0,$.jsx)($f,{rows:m.data.items}),r===U[`keyword-metrics`]&&h.data&&(0,$.jsx)(ep,{rows:h.data.items}),r===U[`domain-intelligence`]&&g.data&&(0,$.jsx)(tp,{rows:g.data.items}),r===U[`competitor-discovery`]&&_.data&&(0,$.jsx)(Zf,{rows:_.data.items,sort:l,onSort:e=>{u(e),o(1)}}),r===U[`keyword-gaps`]&&v.data&&(0,$.jsx)(Qf,{rows:v.data.items,sort:d,onSort:e=>{f(e),o(1)}})]}),(0,$.jsx)(Ts,{page:a,pageSize:xf,visibleRows:y.data.items.length,totalRows:y.data.total,onPageChange:o,disabled:y.isFetching,className:`text-label-13 [&_button]:min-h-11`})]}):(0,$.jsxs)(`p`,{role:`status`,className:`py-8 text-label-14 text-secondary`,children:[`Loading `,_f[r].toLowerCase(),`…`]})]}):(0,$.jsxs)(Wf,{title:`No saved data yet`,children:[`Refresh this profile to collect `,_f[r].toLowerCase(),` for its saved scope.`]})}function Yf({value:e}){return e===null?(0,$.jsx)(Af,{value:null}):(0,$.jsxs)($.Fragment,{children:[e>0?`+`:``,Sf.format(e)]})}function Xf({label:e,sort:t,ascending:n,descending:r,align:i=`right`,onSort:a,help:o}){return(0,$.jsx)(gp,{label:e,align:i,sorted:t===n?`ascending`:t===r?`descending`:null,onSort:()=>a(t===n?r:n),help:o,showUnsorted:!0})}function Zf({rows:e,sort:t,onSort:n}){return(0,$.jsxs)(`table`,{className:`w-full text-label-14`,children:[(0,$.jsx)(`caption`,{className:`sr-only`,children:`Organic competitors, from the selected refresh`}),(0,$.jsx)(`thead`,{className:`bg-surface text-label-13 text-secondary`,children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(Xf,{label:`Competitor`,align:`left`,sort:t,ascending:nt.domain,descending:nt[`-domain`],onSort:n}),(0,$.jsx)(Xf,{label:`Shared searches`,sort:t,ascending:nt.shared,descending:nt[`-shared`],onSort:n}),(0,$.jsx)(Xf,{label:`Avg. position`,sort:t,ascending:nt.position,descending:nt[`-position`],onSort:n}),(0,$.jsx)(Xf,{label:`Est. organic traffic`,sort:t,ascending:nt.traffic,descending:nt[`-traffic`],onSort:n}),(0,$.jsx)(`th`,{className:`px-4`,children:(0,$.jsx)(`span`,{className:`sr-only`,children:`Evidence`})})]})}),(0,$.jsx)(`tbody`,{className:`divide-y divide-subtle`,children:e.map((e,t)=>(0,$.jsxs)(`tr`,{children:[(0,$.jsxs)(`th`,{scope:`row`,className:Df,children:[(0,$.jsx)(`p`,{className:`text-primary`,children:e.domain}),(0,$.jsxs)(`p`,{className:`mt-1 text-label-13 text-secondary`,children:[`Compared with `,e.target.value]})]}),(0,$.jsx)(`td`,{className:Ef,children:(0,$.jsx)(Af,{value:e.sharedKeywords})}),(0,$.jsx)(`td`,{className:Ef,children:(0,$.jsx)(Af,{value:e.averagePosition})}),(0,$.jsx)(`td`,{className:Ef,children:(0,$.jsx)(Af,{value:e.estimatedOrganicTraffic})}),(0,$.jsx)(`td`,{className:`px-4 align-top`,children:(0,$.jsxs)(Hf,{label:e.domain,source:e.provenance,children:[(0,$.jsx)(`p`,{children:`Average position covers shared searches. Traffic covers the competitor’s whole domain.`}),(0,$.jsxs)(`p`,{children:[`Competitor’s ranked searches: `,(0,$.jsx)(Af,{value:e.organicKeywords})]}),(0,$.jsxs)(`p`,{children:[`Target: `,e.target.value,` · includes subdomains`]})]})})]},`${e.target.value}:${e.domain}:${t}`))})]})}function Qf({rows:e,sort:t,onSort:n}){return(0,$.jsxs)(`table`,{className:`w-full text-label-14`,children:[(0,$.jsx)(`caption`,{className:`sr-only`,children:`Search gaps, from the selected refresh`}),(0,$.jsx)(`thead`,{className:`bg-surface text-label-13 text-secondary`,children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(Xf,{label:`Search`,align:`left`,sort:t,ascending:it.keyword,descending:it[`-keyword`],onSort:n}),(0,$.jsx)(Xf,{label:`Comparison`,align:`left`,sort:t,ascending:it.kind,descending:it[`-kind`],onSort:n}),(0,$.jsx)(Xf,{label:`Your rank`,sort:t,ascending:it[`target-rank`],descending:it[`-target-rank`],onSort:n}),(0,$.jsx)(Xf,{label:`Competitor rank`,sort:t,ascending:it[`competitor-rank`],descending:it[`-competitor-rank`],onSort:n}),(0,$.jsx)(Xf,{label:`Rank gap`,sort:t,ascending:it[`rank-gap`],descending:it[`-rank-gap`],onSort:n,help:yf}),(0,$.jsx)(Xf,{label:`Monthly searches`,sort:t,ascending:it.volume,descending:it[`-volume`],onSort:n}),(0,$.jsx)(`th`,{className:`px-4`,children:(0,$.jsx)(`span`,{className:`sr-only`,children:`Evidence`})})]})}),(0,$.jsx)(`tbody`,{className:`divide-y divide-subtle`,children:e.map((e,t)=>(0,$.jsxs)(`tr`,{children:[(0,$.jsxs)(`th`,{scope:`row`,className:Df,children:[(0,$.jsx)(`p`,{className:`text-primary`,children:e.keyword}),(0,$.jsxs)(`p`,{className:`mt-1 text-label-13 text-secondary`,children:[e.target.value,` · `,e.competitor.value]})]}),(0,$.jsx)(`td`,{className:`px-4 py-3 align-top`,children:(0,$.jsx)(J,{tone:e.kind===tt.shared?`neutral`:`caution`,children:vf[e.kind]})}),(0,$.jsx)(`td`,{className:Ef,children:e.kind===tt.missing?(0,$.jsx)(`span`,{className:`text-secondary`,children:`Not found`}):(0,$.jsx)(Af,{value:e.targetRankOrganic})}),(0,$.jsx)(`td`,{className:Ef,children:(0,$.jsx)(Af,{value:e.competitorRankOrganic})}),(0,$.jsx)(`td`,{className:Ef,children:(0,$.jsx)(Yf,{value:e.rankGap})}),(0,$.jsx)(`td`,{className:Ef,children:(0,$.jsx)(Af,{value:e.searchVolume})}),(0,$.jsx)(`td`,{className:`px-4 align-top`,children:(0,$.jsxs)(Hf,{label:`${e.keyword} against ${e.competitor.value}`,source:e.provenance,children:[(0,$.jsxs)(`p`,{children:[`Your ranking page: `,e.targetUrl?(0,$.jsx)(os,{url:e.targetUrl}):`Not supplied`]}),(0,$.jsxs)(`p`,{children:[`Competitor’s ranking page: `,e.competitorUrl?(0,$.jsx)(os,{url:e.competitorUrl}):`Not supplied`]}),(0,$.jsxs)(`p`,{children:[`Difficulty /100: `,(0,$.jsx)(Af,{value:e.keywordDifficulty})]}),(0,$.jsxs)(`p`,{children:[`CPC: `,(0,$.jsx)(Af,{value:e.cpcUsd,currency:!0})]})]})})]},`${e.target.value}:${e.competitor.value}:${e.keyword}:${t}`))})]})}function $f({rows:e}){return(0,$.jsxs)(`table`,{className:`w-full text-label-14`,children:[(0,$.jsx)(`caption`,{className:`sr-only`,children:`Searches you rank for, from the selected refresh`}),(0,$.jsx)(`thead`,{className:`bg-surface text-label-13 text-secondary`,children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{className:`px-4 py-3 text-left text-label-13-strong`,children:`Search`}),(0,$.jsx)(`th`,{className:`${Ef} text-label-13-strong`,children:`Position`}),(0,$.jsx)(`th`,{className:`${Ef} text-label-13-strong`,children:`Monthly searches`}),(0,$.jsx)(`th`,{className:`${Ef} text-label-13-strong`,children:`Est. traffic`}),(0,$.jsx)(`th`,{className:`${Ef} text-label-13-strong`,children:`Difficulty /100`}),(0,$.jsx)(`th`,{className:`px-4`,children:(0,$.jsx)(`span`,{className:`sr-only`,children:`Evidence`})})]})}),(0,$.jsx)(`tbody`,{className:`divide-y divide-subtle`,children:e.map((e,t)=>(0,$.jsxs)(`tr`,{children:[(0,$.jsxs)(`th`,{scope:`row`,className:Df,children:[(0,$.jsx)(`p`,{className:`text-primary`,children:e.keyword}),(0,$.jsx)(`p`,{className:`mt-1 text-copy-13 text-secondary`,children:(0,$.jsx)(Ss,{value:e.url??e.target.value})})]}),(0,$.jsx)(`td`,{className:Ef,children:(0,$.jsx)(Af,{value:e.rankOrganic})}),(0,$.jsx)(`td`,{className:Ef,children:(0,$.jsx)(Af,{value:e.searchVolume})}),(0,$.jsx)(`td`,{className:Ef,children:(0,$.jsx)(Af,{value:e.estimatedTraffic})}),(0,$.jsx)(`td`,{className:Ef,children:(0,$.jsx)(Af,{value:e.keywordDifficulty})}),(0,$.jsx)(`td`,{className:`px-4 align-top`,children:(0,$.jsxs)(Hf,{label:e.keyword,source:e.provenance,children:[(0,$.jsx)(`p`,{className:`break-all`,children:e.url??`Ranking URL not supplied`}),(0,$.jsxs)(`p`,{children:[`Target: `,e.target.value,` · `,e.target.includeSubdomains?`includes subdomains`:`exact host`]}),(0,$.jsxs)(`p`,{children:[Of,`: `,(0,$.jsx)(Af,{value:e.rankAbsolute})]}),(0,$.jsxs)(`p`,{children:[`CPC: `,(0,$.jsx)(Af,{value:e.cpcUsd,currency:!0})]}),(0,$.jsxs)(`p`,{children:[`Results page features: `,e.serpFeatures.length?e.serpFeatures.map(e=>e.replaceAll(`_`,` `)).join(`, `):`Not supplied`]})]})})]},`${e.target.value}:${e.keyword}:${t}`))})]})}function ep({rows:e}){return(0,$.jsxs)(`table`,{className:`w-full text-label-14`,children:[(0,$.jsx)(`caption`,{className:`sr-only`,children:`Search demand from the selected refresh`}),(0,$.jsx)(`thead`,{className:`bg-surface text-label-13 text-secondary`,children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{className:`px-4 py-3 text-left text-label-13-strong`,children:`Search`}),(0,$.jsx)(`th`,{className:`${Ef} text-label-13-strong`,children:`Monthly searches`}),(0,$.jsx)(`th`,{className:`${Ef} text-label-13-strong`,children:`CPC`}),(0,$.jsx)(`th`,{className:`${Ef} text-label-13-strong`,children:`Difficulty /100`}),(0,$.jsx)(`th`,{className:`px-4 py-3 text-left text-label-13-strong`,children:`Intent`}),(0,$.jsx)(`th`,{className:`px-4`,children:(0,$.jsx)(`span`,{className:`sr-only`,children:`Evidence`})})]})}),(0,$.jsx)(`tbody`,{className:`divide-y divide-subtle`,children:e.map((e,t)=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{scope:`row`,className:`${Df} text-primary`,children:e.keyword}),(0,$.jsx)(`td`,{className:Ef,children:(0,$.jsx)(Af,{value:e.searchVolume})}),(0,$.jsx)(`td`,{className:Ef,children:(0,$.jsx)(Af,{value:e.cpcUsd,currency:!0})}),(0,$.jsx)(`td`,{className:Ef,children:(0,$.jsx)(Af,{value:e.keywordDifficulty})}),(0,$.jsx)(`td`,{className:`px-4 py-3 align-top`,children:e.searchIntent??`Not supplied`}),(0,$.jsx)(`td`,{className:`px-4 align-top`,children:(0,$.jsxs)(Hf,{label:e.keyword,source:e.provenance,children:[(0,$.jsxs)(`p`,{children:[`Ad competition: `,e.adCompetition===null?`Not supplied`:G(e.adCompetition,rt.fraction)]}),(0,$.jsxs)(`p`,{children:[`Core search: `,e.coreKeyword??`Not supplied`]}),e.monthlySearches.length>0&&(0,$.jsx)(`dl`,{children:e.monthlySearches.map(e=>(0,$.jsxs)(`div`,{className:`flex justify-between gap-5`,children:[(0,$.jsxs)(`dt`,{children:[e.year,`-`,String(e.month).padStart(2,`0`)]}),(0,$.jsx)(`dd`,{children:(0,$.jsx)(Af,{value:e.searchVolume})})]},`${e.year}-${e.month}`))})]})})]},`${e.keyword}:${t}`))})]})}function tp({rows:e}){return(0,$.jsxs)(`table`,{className:`w-full text-label-14`,children:[(0,$.jsx)(`caption`,{className:`sr-only`,children:`Domain comparison from the selected refresh`}),(0,$.jsx)(`thead`,{className:`bg-surface text-label-13 text-secondary`,children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`th`,{className:`px-4 py-3 text-left text-label-13-strong`,children:`Domain`}),(0,$.jsx)(`th`,{className:`${Ef} text-label-13-strong`,children:`Searches ranked for`}),(0,$.jsx)(`th`,{className:`${Ef} text-label-13-strong`,children:`Est. organic traffic`}),(0,$.jsx)(`th`,{className:`px-4`,children:(0,$.jsx)(`span`,{className:`sr-only`,children:`Evidence`})})]})}),(0,$.jsx)(`tbody`,{className:`divide-y divide-subtle`,children:e.map((e,t)=>(0,$.jsxs)(`tr`,{children:[(0,$.jsxs)(`th`,{scope:`row`,className:Df,children:[(0,$.jsx)(`p`,{className:`text-primary`,children:e.target.value}),(0,$.jsx)(`p`,{className:`mt-1 text-copy-13 text-secondary`,children:e.target.includeSubdomains?`Includes subdomains`:`Exact host`})]}),(0,$.jsx)(`td`,{className:Ef,children:(0,$.jsx)(Af,{value:e.organicKeywords})}),(0,$.jsx)(`td`,{className:Ef,children:(0,$.jsx)(Af,{value:e.estimatedOrganicTraffic})}),(0,$.jsx)(`td`,{className:`px-4 align-top`,children:(0,$.jsx)(Hf,{label:e.target.value,source:e.provenance,children:(0,$.jsxs)(`dl`,{className:`grid grid-cols-2 gap-2`,children:[(0,$.jsx)(`dt`,{children:`Position 1`}),(0,$.jsx)(`dd`,{children:(0,$.jsx)(Af,{value:e.top1})}),(0,$.jsx)(`dt`,{children:`Positions 2–3`}),(0,$.jsx)(`dd`,{children:(0,$.jsx)(Af,{value:e.top2To3})}),(0,$.jsx)(`dt`,{children:`Positions 4–10`}),(0,$.jsx)(`dd`,{children:(0,$.jsx)(Af,{value:e.top4To10})}),(0,$.jsx)(`dt`,{children:`Positions 11–20`}),(0,$.jsx)(`dd`,{children:(0,$.jsx)(Af,{value:e.top11To20})}),(0,$.jsx)(`dt`,{children:`Est. traffic value`}),(0,$.jsx)(`dd`,{children:(0,$.jsx)(Af,{value:e.estimatedOrganicTrafficValueUsd,currency:!0})})]})})})]},`${e.target.value}:${t}`))})]})}var np=5,rp=10,ip=`all`;function ap(e){return e===ip?ip:gt.safeParse(e).data??null}var op={column:`ranks11To20`,descending:!0},sp={3:`sm:grid-cols-3`,4:`sm:grid-cols-4`,5:`sm:grid-cols-5`},cp=`inline-flex min-h-11 cursor-pointer select-none items-center rounded-sm hover:text-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-mono-400`,lp=`inline-flex min-h-11 items-center rounded-sm text-secondary hover:text-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-mono-400`;function up(e,t){switch(e.count){case`page1`:return`Google rank 1 to 10.`;case`ranks11To20`:return`Google rank 11 to 20: the closest to page 1.`;case`ranks21Plus`:return t!==null&&t>21?`Google rank 21 to ${t}.`:`Google rank 21 or deeper.`;case`notRanked`:return t===null?`Searched, and the site is not in the results checked.`:`Searched, and the site is not in the top ${t} results. A search that returned only part of them counts as partly checked instead.`;default:return e.count}}function dp(e){return`Overlaps the figures beside it: queries where a tracked competitor ranks above the site, or ranks while the site is not in ${e===null?`the results`:`the top ${e}`}.`}function fp(e){let t=e.filter(e=>e.kind===z.region).length;return t===e.length?{label:`Region`,plural:`regions`}:t===0?{label:`Market`,plural:`markets`}:{label:`Region or market`,plural:`regions and markets`}}function pp(e,t){return e.counts[t]}function mp(e){let t=e.descending?-1:1,n=e.column;return n===`label`?(e,n)=>t*(Ht(e.label,n.label)||Ht(e.key,n.key)):(e,r)=>t*(pp(e,n)-pp(r,n))||Ht(e.label,r.label)||Ht(e.key,r.key)}function hp(e,t=250){let[n,r]=(0,Q.useState)(e),i=e.trim()===``;return(0,Q.useEffect)(()=>{if(i){r(``);return}let n=setTimeout(()=>r(e),t);return()=>clearTimeout(n)},[i,e,t]),i?``:n}function gp({label:e,align:t,sorted:n,onSort:r,help:i,showUnsorted:a=!1}){return(0,$.jsx)(`th`,{scope:`col`,"aria-sort":n??void 0,className:`px-4 text-label-14-strong whitespace-nowrap ${t===`right`?`text-right`:`text-left`}`,children:(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:r,className:`${cp} ${n?`text-primary`:``}`,children:[e,(n||a)&&(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`ml-0.5`,children:n===`ascending`?`↑`:n===`descending`?`↓`:`↕`})]}),i&&(0,$.jsx)(X,{text:i})]})})}function _p({projectName:e,profileId:t,runId:n,active:r}){let i=E({strict:!1}),a=T(),o=i.seoRegion,s=i.seoMarket,c=ap(i.seoShow),l=Rt.safeParse(i.seoSort).data??Gt.rank,u=t=>{a({to:`/projects/$projectName/seo-data`,params:{projectName:e},search:e=>({...e,...t}),replace:!0})},d=(0,Q.useId)(),f=w(Er({client:K,path:{name:e},query:{profileId:t,runId:n,regionKey:o,marketKey:s}}));if(f.error)return(0,$.jsx)(`div`,{className:`py-4`,children:(0,$.jsx)(Uf,{error:f.error,retry:()=>{f.refetch()}})});if(!f.data)return(0,$.jsx)(`p`,{role:`status`,className:`py-8 text-copy-14 text-secondary`,children:`Loading market rankings…`});let{totals:p,depth:m,groups:h}=f.data,g=`${o??``}\u0000${s??``}`,_=o!==void 0||s!==void 0,v=_&&(0,$.jsx)(yp,{projectName:e,regionKey:o,marketKey:s,regionLabel:f.data.regionLabel,marketLabel:f.data.marketLabel});if(p.queries===0)return(0,$.jsxs)(`div`,{className:`pt-4`,children:[v,_?(0,$.jsxs)(Wf,{title:`No rankings here`,children:[`This refresh has no rankings for this `,s===void 0?`region`:`market`,`.`]}):(0,$.jsx)(Wf,{title:r?`Refresh in progress`:`No results returned`,children:r?`This profile is collecting data.`:`The source did not return records for this scope. Review the refresh in Activity before changing the profile.`})]});let y=Oe(m,p),b=c??(p.needsWork>0?ze[`needs-work`]:ip),x=h.length>1||h.some(e=>e.kind===z.region),S=[`${Sf.format(p.queries)} ${p.queries===1?`query`:`queries`}`,...p.partlyChecked>0?[`${Sf.format(p.partlyChecked)} partly checked`]:[],...p.failed>0?[`${Sf.format(p.failed)} failed`]:[],...p.cancelled>0?[`${Sf.format(p.cancelled)} not searched`]:[]].join(` · `);return(0,$.jsxs)(`div`,{className:`space-y-6 pt-4`,children:[v,(0,$.jsxs)(`section`,{"aria-labelledby":d,className:`space-y-3`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-baseline justify-between gap-3`,children:[(0,$.jsx)(`h3`,{id:d,className:`text-heading-16 text-heading`,children:`Google rank`}),(0,$.jsx)(`p`,{className:`text-copy-13 tabular-nums text-secondary`,children:S})]}),(0,$.jsxs)(`dl`,{className:`grid grid-cols-2 gap-5 border-b border-subtle pb-5 ${sp[y.length+1]??`sm:grid-cols-5`}`,children:[y.map(e=>(0,$.jsx)(vp,{label:e.label,help:up(e,m),value:p[e.count]},e.count)),(0,$.jsx)(vp,{label:`Rival ahead`,help:dp(m),value:p.rivalAhead,className:`sm:border-l sm:border-subtle sm:pl-5`})]})]}),x&&(0,$.jsx)(bp,{projectName:e,groups:h,bands:y},`groups\u0000${g}`),(0,$.jsx)(xp,{projectName:e,profileId:t,runId:n,regionKey:o,marketKey:s,totals:p,bands:y,depth:m,show:b,onShow:e=>u({seoShow:e}),sort:l,onSort:e=>u({seoSort:e===Gt.rank?void 0:e}),urlQ:i.seoQ??``,onQ:e=>u({seoQ:e||void 0}),onClear:()=>u({seoShow:ip,seoQ:void 0})},`queries\u0000${g}`)]})}function vp({label:e,help:t,value:n,className:r}){return(0,$.jsxs)(`div`,{className:r,children:[(0,$.jsxs)(`dt`,{className:`flex items-center gap-1.5 text-label-13 text-secondary`,children:[e,(0,$.jsx)(X,{text:t,placement:`bottom`})]}),(0,$.jsx)(`dd`,{className:`mt-2 text-heading-32 tabular-nums text-heading`,children:Sf.format(n)})]})}function yp({projectName:e,regionKey:t,marketKey:n,regionLabel:r,marketLabel:i}){let a=r??`Region not in this refresh`;return(0,$.jsxs)(`nav`,{"aria-label":`Market rankings scope`,className:`flex flex-wrap items-center gap-x-2 text-label-14`,children:[(0,$.jsx)(A,{to:`/projects/$projectName/seo-data`,params:{projectName:e},search:e=>({...e,seoRegion:void 0,seoMarket:void 0}),className:lp,children:`All markets`}),t!==void 0&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`text-muted`,children:`/`}),n===void 0?(0,$.jsx)(`span`,{"aria-current":`page`,className:`text-label-14-strong text-primary`,children:a}):(0,$.jsx)(A,{to:`/projects/$projectName/seo-data`,params:{projectName:e},search:e=>({...e,seoMarket:void 0}),className:lp,children:a})]}),n!==void 0&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`text-muted`,children:`/`}),(0,$.jsx)(`span`,{"aria-current":`page`,className:`text-label-14-strong text-primary`,children:i??`Market not in this refresh`})]})]})}function bp({projectName:e,groups:t,bands:n}){let r=T(),[i,a]=(0,Q.useState)(null),[o,s]=(0,Q.useState)(1),c=fp(t),l=(i===null?t:[...t].sort(mp(i))).slice((o-1)*np,o*np),d=i??(n.some(e=>e.count===op.column)?op:null),f=[{column:`queries`,label:`Queries`},...n.map(e=>({column:e.count,label:e.label})),{column:`rivalAhead`,label:`Rival ahead`}],p=e=>{let t=i??op;a(t.column===e?{column:e,descending:!t.descending}:{column:e,descending:e!==`label`}),s(1)},m=e=>d?.column===e?d.descending?`descending`:`ascending`:null,h=e=>e.kind===z.region?t=>({...t,seoRegion:e.key,seoMarket:void 0}):t=>({...t,seoMarket:e.key}),g=`Google rank by ${c.label.toLowerCase()}`;return(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsxs)(`h3`,{className:`text-heading-16 text-heading`,children:[`By `,c.label.toLowerCase()]}),(0,$.jsx)(`div`,{className:`relative overflow-x-auto rounded-md border border-default`,role:`region`,"aria-label":g,tabIndex:0,children:(0,$.jsxs)(`table`,{className:`w-full text-label-14`,children:[(0,$.jsx)(`caption`,{className:`sr-only`,children:g}),(0,$.jsx)(`thead`,{className:`bg-surface text-label-13 text-secondary`,children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(gp,{label:c.label,align:`left`,sorted:m(`label`),onSort:()=>p(`label`)}),f.map(e=>(0,$.jsx)(gp,{label:e.label,align:`right`,sorted:m(e.column),onSort:()=>p(e.column)},e.column)),(0,$.jsx)(`th`,{className:`px-4`,children:(0,$.jsx)(`span`,{className:`sr-only`,children:`Open`})})]})}),(0,$.jsx)(`tbody`,{className:`divide-y divide-subtle`,children:l.map(t=>(0,$.jsxs)(`tr`,{className:`cursor-pointer hover:bg-surface-hover`,onClick:n=>{n.target.closest(`a, button`)||r({to:`/projects/$projectName/seo-data`,params:{projectName:e},search:h(t)})},children:[(0,$.jsx)(`th`,{scope:`row`,className:`min-w-36 px-4 py-3 text-left align-top text-label-14`,children:(0,$.jsx)(A,{to:`/projects/$projectName/seo-data`,params:{projectName:e},search:h(t),className:`rounded-sm text-primary hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-mono-400`,children:t.label})}),f.map(e=>(0,$.jsx)(`td`,{className:Ef,children:Sf.format(t.counts[e.column])},e.column)),(0,$.jsx)(`td`,{className:`px-4 py-3 text-right align-top`,children:(0,$.jsx)(u,{"aria-hidden":`true`,className:`ml-auto size-4 text-muted`})})]},`${t.kind}:${t.key}`))})]})}),(0,$.jsx)(Ts,{page:o,pageSize:np,visibleRows:l.length,totalRows:t.length,onPageChange:s,itemLabel:c.plural,className:`text-label-13 [&_button]:min-h-11`})]})}function xp({projectName:e,profileId:t,runId:n,regionKey:r,marketKey:i,totals:a,bands:o,depth:s,show:c,onShow:l,sort:u,onSort:d,urlQ:f,onQ:p,onClear:m}){let h=(0,Q.useId)(),[g,_]=(0,Q.useState)(f),v=hp(g).trim().slice(0,200),y=(0,Q.useRef)(f);(0,Q.useEffect)(()=>{v!==y.current&&(y.current=v,p(v))},[v]);let b=`${c}\u0000${u}\u0000${v}`,[x,S]=(0,Q.useState)({filterKey:b,page:1});x.filterKey!==b&&S({filterKey:b,page:1});let C=x.filterKey===b?x.page:1,T=w({...br({client:K,path:{name:e},query:{profileId:t,runId:n,regionKey:r,marketKey:i,outcome:c===ip?void 0:c,q:v||void 0,sort:u,limit:rp,offset:(C-1)*rp}}),placeholderData:j}),E=[{value:ze[`needs-work`],label:`Needs work`,count:a.needsWork},...o.map(e=>({value:e.filter,label:e.label,count:a[e.count]})),{value:ze[`rival-ahead`],label:`Rival ahead`,count:a.rivalAhead},{value:ze[`partly-checked`],label:`Partly checked`,count:a.partlyChecked},{value:ze.failed,label:`Failed`,count:a.failed},{value:ze.cancelled,label:`Not searched`,count:a.cancelled},{value:ip,label:`All`,count:a.queries}],D=[ze[`partly-checked`],ze.failed,ze.cancelled],O=E.filter(e=>e.value===c||e.count>0||!D.includes(e.value)),k=O.find(e=>e.value===c)?.label??`All`,A=u===Gt.rank?`ascending`:u===Gt[`-rank`]?`descending`:null,M=u===Gt.query?`ascending`:u===Gt[`-query`]?`descending`:null,N=T.data?.items??[],P=s===null?`not ranked`:`not in the top ${s}`,F=!T.data||T.isPlaceholderData?null:T.data.total===0?`No queries match`:`${Sf.format(T.data.total)} ${T.data.total===1?`query`:`queries`}: ${k}`;return(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`h3`,{className:`text-heading-16 text-heading`,id:h,children:`Queries`}),(0,$.jsx)(X,{placement:`bottom`,text:`Needs work: queries ranking 11 or deeper, ${P}, or partly checked. Rival ahead: a tracked competitor ranks above the site.`})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,$.jsxs)(`label`,{className:`flex min-w-0 items-center gap-3`,children:[(0,$.jsx)(`span`,{className:`text-label-13 text-secondary`,children:`Show`}),(0,$.jsx)(`select`,{"aria-label":`Show queries`,value:c,onChange:e=>l(e.target.value),className:`${Tf} min-w-0 sm:w-56`,children:O.map(e=>(0,$.jsxs)(`option`,{value:e.value,children:[e.label,` (`,Sf.format(e.count),`)`]},e.value))})]}),(0,$.jsx)(js,{value:g,onChange:_,label:`Find a query`,placeholder:`Find a query`,className:`min-w-48 flex-1 sm:max-w-xs [&_input]:h-11`})]}),(0,$.jsx)(`p`,{role:`status`,className:`sr-only`,children:F}),T.error?(0,$.jsx)(Uf,{error:T.error,retry:()=>{T.refetch()}}):T.data?T.data.total===0?(0,$.jsxs)(`div`,{className:`py-12 text-center`,children:[(0,$.jsx)(`h4`,{className:`text-heading-14 text-heading`,children:`No queries match`}),(0,$.jsx)(q,{variant:`secondary`,className:`mt-4 pointer-coarse:min-h-11`,onClick:()=>{y.current=``,_(``),m()},children:`Clear filters`})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`relative overflow-x-auto rounded-md border border-default ${T.isPlaceholderData?`opacity-60`:``}`,role:`region`,"aria-label":`Queries`,"aria-busy":T.isPlaceholderData,tabIndex:0,children:(0,$.jsxs)(`table`,{className:`w-full text-label-14`,children:[(0,$.jsxs)(`caption`,{className:`sr-only`,children:[`Queries: `,k]}),(0,$.jsx)(`thead`,{className:`bg-surface text-label-13 text-secondary`,children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(gp,{label:`Query`,align:`left`,sorted:M,onSort:()=>d(u===Gt.query?Gt[`-query`]:Gt.query)}),(0,$.jsx)(gp,{label:`Google rank`,align:`right`,sorted:A,onSort:()=>d(u===Gt.rank?Gt[`-rank`]:Gt.rank)}),(0,$.jsx)(`th`,{className:`px-4 py-3 text-left text-label-13-strong whitespace-nowrap`,children:`Top rival`}),(0,$.jsx)(`th`,{className:`${Ef} text-label-13-strong`,children:`Rival rank`}),(0,$.jsx)(`th`,{className:`${Ef} text-label-13-strong`,children:(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[`Rank gap`,(0,$.jsx)(X,{text:yf,placement:`bottom`})]})}),(0,$.jsx)(`th`,{className:`px-4`,children:(0,$.jsx)(`span`,{className:`sr-only`,children:`Evidence`})})]})}),(0,$.jsx)(`tbody`,{className:`divide-y divide-subtle`,children:N.map((e,t)=>(0,$.jsx)(Sp,{row:e,requested:s},`${e.marketKey}\u0000${e.queryId??e.queryText}\u0000${t}`))})]})}),(0,$.jsx)(Ts,{page:C,pageSize:rp,visibleRows:N.length,totalRows:T.data.total,onPageChange:e=>S({filterKey:b,page:e}),disabled:T.isFetching,itemLabel:`queries`,className:`text-label-13 [&_button]:min-h-11`})]}):(0,$.jsx)(`p`,{className:`py-8 text-copy-14 text-secondary`,children:`Loading queries…`})]})}function Sp({row:e,requested:t}){let[n,r]=(0,Q.useState)(!1),i=(0,Q.useId)();return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`tr`,{className:n?`border-b-0`:void 0,children:[(0,$.jsxs)(`th`,{scope:`row`,className:Df,children:[(0,$.jsx)(`p`,{className:`text-primary`,children:e.queryText}),(0,$.jsx)(`p`,{className:`mt-1 text-copy-13 text-secondary`,children:e.marketLabel})]}),(0,$.jsx)(`td`,{className:Ef,children:(0,$.jsx)(wp,{row:e,requested:t})}),(0,$.jsx)(`td`,{className:`px-4 py-3 align-top text-label-13`,children:(0,$.jsx)(Tp,{row:e})}),(0,$.jsx)(`td`,{className:Ef,children:(0,$.jsx)(Af,{value:e.topCompetitor?.rankOrganic??null})}),(0,$.jsx)(`td`,{className:Ef,children:(0,$.jsx)(Yf,{value:e.rankGap})}),(0,$.jsx)(`td`,{className:`px-4 text-right align-top`,children:(0,$.jsxs)(`button`,{type:`button`,"aria-expanded":n,"aria-controls":i,onClick:()=>r(e=>!e),className:`inline-flex min-h-11 items-center whitespace-nowrap rounded-sm text-button-14 text-secondary hover:text-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-mono-400`,children:[n?`Hide details`:`Details`,(0,$.jsxs)(`span`,{className:`sr-only`,children:[` for `,e.queryText,` in `,e.marketLabel]})]})})]}),(0,$.jsx)(`tr`,{id:i,hidden:!n,children:(0,$.jsx)(`td`,{colSpan:6,className:`bg-surface-subtle px-4 pb-4 pt-3`,children:(0,$.jsx)(Ep,{row:e,requested:t})})})]})}function Cp(e){return e.outcome===xt.failed||e.outcome===xt.cancelled}function wp({row:e,requested:t}){return e.outcome===xt.failed?(0,$.jsx)(X,{tone:`caution`,label:`Failed`,placement:`bottom`,text:`Failed: the source returned no results for this search in this refresh.`}):e.outcome===xt.cancelled?(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-secondary`,children:[`Not searched`,(0,$.jsx)(X,{placement:`bottom`,text:`The refresh was cancelled, or reached a spending limit, before this search ran.`})]}):e.rankOrganic===null?e.outcome===xt[`partly-checked`]?(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-secondary`,children:[`Not in top `,e.depth,(0,$.jsx)(X,{placement:`bottom`,text:`Only the top ${e.depth}${t===null?``:` of ${t}`} results came back for this search, so ranks past ${e.depth} are unknown.`})]}):(0,$.jsxs)(`span`,{className:`text-secondary`,children:[`Not in top `,e.depth]}):(0,$.jsx)($.Fragment,{children:e.rankOrganic})}function Tp({row:e}){if(Cp(e))return(0,$.jsxs)(`span`,{className:`text-muted`,children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,children:`—`}),(0,$.jsx)(`span`,{className:`sr-only`,children:`No result`})]});let t=e.topCompetitor;return t?(0,$.jsxs)(`span`,{className:`inline-flex flex-wrap items-center gap-x-1.5 gap-y-1`,children:[(0,$.jsx)(`span`,{className:`text-primary`,children:t.domain}),e.rivalAhead&&(0,$.jsx)(J,{tone:`caution`,children:`Ahead`})]}):(0,$.jsxs)(`span`,{className:`text-secondary`,children:[`None in top `,e.depth]})}function Ep({row:e,requested:t}){let n=`text-muted`,r=`mt-0.5 text-primary`,i=e.outcome===xt.failed?`No result: the search failed`:e.outcome===xt.cancelled?`No result: not searched`:`Not in the top ${e.depth}`;return(0,$.jsxs)(`div`,{className:`grid gap-x-8 gap-y-3 text-label-13 text-secondary sm:grid-cols-2 lg:grid-cols-4`,children:[(0,$.jsxs)(`div`,{className:`sm:col-span-2 lg:col-span-4`,children:[(0,$.jsx)(`p`,{className:n,children:`Ranking page`}),e.url?(0,$.jsx)(os,{url:e.url}):(0,$.jsx)(`p`,{className:r,children:i})]}),(0,$.jsxs)(`div`,{className:`lg:col-span-2`,children:[(0,$.jsx)(`p`,{className:n,children:`Searched as`}),(0,$.jsxs)(`p`,{className:r,children:[`“`,e.searchText,`” from `,e.locationLabel]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:n,children:`Target`}),(0,$.jsxs)(`p`,{className:`${r} break-words`,children:[e.target.value,` · `,e.target.includeSubdomains?`includes subdomains`:`exact host`]})]}),e.rankOrganic!==null&&(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:n,children:Of}),(0,$.jsx)(`p`,{className:`${r} tabular-nums`,children:(0,$.jsx)(Af,{value:e.rankAbsolute})})]}),e.searchStatus===mn.partial&&(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:n,children:`Results checked`}),(0,$.jsxs)(`p`,{className:`${r} tabular-nums`,children:[`Top `,e.depth,t===null?``:` of ${t}`]})]}),!Cp(e)&&(0,$.jsxs)(`div`,{className:`sm:col-span-2 lg:col-span-2`,children:[(0,$.jsx)(`p`,{className:n,children:`Tracked competitors in these results`}),e.competitors.length?(0,$.jsx)(`dl`,{className:`mt-0.5 grid grid-cols-[minmax(0,1fr)_auto] gap-x-6 gap-y-1`,children:e.competitors.map(e=>(0,$.jsxs)(Q.Fragment,{children:[(0,$.jsx)(`dt`,{className:`break-all text-primary`,children:e.domain}),(0,$.jsxs)(`dd`,{className:`text-right tabular-nums text-primary`,children:[`#`,e.rankOrganic]})]},e.domain))}):(0,$.jsxs)(`p`,{className:r,children:[`None in the top `,e.depth]})]}),e.provenance&&(0,$.jsx)(`div`,{className:`sm:col-span-2 lg:col-span-4`,children:(0,$.jsx)(Vf,{source:e.provenance})})]})}function Dp({projectName:e,profileId:t,canRun:n,selectedRunId:r}){let[i,a]=(0,Q.useState)(r??null),[o,s]=(0,Q.useState)(null),c=w({...ri({client:K,path:{name:e},query:{profileId:t}}),refetchInterval:e=>e.state.data?.runs.some(kf)?2e3:!1}),l=w({...cr({client:K,path:{name:e,id:i??``}}),enabled:!!i,refetchInterval:e=>kf(e.state.data)?2e3:!1}),u=C({...Nr({client:K}),meta:{skipGlobalErrorToast:!0}}),d=async t=>{if(n&&!u.isPending){s(null);try{await u.mutateAsync({path:{name:e,id:t}})}catch(e){s(Co(e))}}};if(c.error)return(0,$.jsx)(`div`,{className:`py-4`,children:(0,$.jsx)(Uf,{error:c.error,retry:()=>{c.refetch()}})});if(!c.data)return(0,$.jsx)(`p`,{role:`status`,className:`py-8 text-copy-14 text-secondary`,children:`Loading activity…`});let f=l.data&&!c.data.runs.some(e=>e.id===l.data.id)?[l.data,...c.data.runs]:c.data.runs;return f.length?(0,$.jsxs)(`div`,{className:`divide-y divide-subtle`,children:[o&&(0,$.jsx)(`p`,{role:`alert`,className:`py-3 text-copy-14`,children:o}),f.map(e=>(0,$.jsxs)(`div`,{className:`py-4`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,$.jsx)(jf,{status:e.status}),(0,$.jsx)(`span`,{className:`text-label-14`,children:ut(e.createdAt,wf)})]}),(0,$.jsxs)(`p`,{className:`text-copy-13 text-secondary`,children:[e.completedTasks,` of `,e.taskCount,` `,Ff(e),` completed`,e.failedTasks>0?` · ${e.failedTasks} failed`:``]})]}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsxs)(q,{variant:`ghost`,className:`pointer-coarse:min-h-11`,"aria-expanded":i===e.id,"aria-controls":`seo-run-${e.id}`,onClick:()=>a(i===e.id?null:e.id),children:[`Details`,(0,$.jsxs)(`span`,{className:`sr-only`,children:[` for refresh `,e.id]})]}),n&&kf(e)&&(0,$.jsx)(q,{variant:`secondary`,className:`pointer-coarse:min-h-11`,disabled:u.isPending||e.cancelRequested,onClick:Jn(()=>d(e.id)),children:e.cancelRequested?`Cancellation requested`:`Cancel refresh`})]})]}),i===e.id&&(0,$.jsxs)(`div`,{id:`seo-run-${e.id}`,className:`mt-4 space-y-3 rounded-md bg-surface p-4 text-label-13 text-secondary`,children:[(0,$.jsxs)(`p`,{className:`break-all`,children:[`Refresh `,e.id]}),(0,$.jsxs)(`p`,{children:[`Profile revision `,e.profileRevision,` · `,Pf(e),` · `,e.languageCode]}),(0,$.jsxs)(`p`,{children:[`Scope: `,e.scope.kind,e.scope.key?` · ${e.scope.key}`:``,e.scope.expectedPlanRevision===void 0?``:` · plan revision ${e.scope.expectedPlanRevision}`]}),e.error&&(0,$.jsx)(`p`,{children:e.error}),l.error?(0,$.jsx)(Uf,{error:l.error,retry:()=>{l.refetch()}}):l.data?l.data.tasks.some(If)&&(0,$.jsx)(`ul`,{className:`space-y-3`,children:l.data.tasks.filter(If).map(e=>(0,$.jsxs)(`li`,{children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,$.jsxs)(`span`,{children:[_f[e.capability],e.searchText===null?e.target?` · ${e.target.value}`:``:` · “${e.searchText}” from ${e.locationLabel??`its market`}`,e.comparison?` · ${e.comparison.competitor.value} · ${vf[e.comparison.mode]} searches`:``,e.retried?` · retried once`:``]}),(0,$.jsx)(jf,{status:e.status})]}),e.error&&(0,$.jsx)(`p`,{className:`mt-1`,children:e.error})]},e.id))}):(0,$.jsx)(`p`,{role:`status`,children:`Loading refresh details…`})]})]},e.id))]}):(0,$.jsx)(Wf,{title:`No refreshes yet`,children:`Refresh this profile to collect its first saved results.`})}function Op({projectName:e,context:t,profile:n,id:r,onClose:i,onSaved:a}){let o=S(),[s,c]=(0,Q.useState)(n?.name??``),[l,u]=(0,Q.useState)(n?.connectionId??t.connections.at(0)?.id??``),[d,f]=(0,Q.useState)(n?.capabilities??[U[`ranked-keywords`]]),[p,m]=(0,Q.useState)(n?.targets??[{kind:lt.domain,value:``,includeSubdomains:!0}]),[h,g]=(0,Q.useState)(n?.competitors?.map(e=>e.value).join(`
2
2
  `)??``),[v,y]=(0,Q.useState)(n?.keywords.join(`
3
3
  `)??``),[b,x]=(0,Q.useState)(n?.locationCode.toString()??``),[w,T]=(0,Q.useState)(n?.languageCode??`en`),[E,D]=(0,Q.useState)(n?.limit.toString()??`100`),[O,k]=(0,Q.useState)(n?`${n.scope.kind}:${n.scope.key??``}`:`${Mt.project}:`),[A,j]=(0,Q.useState)(null),M=C({...Kr({client:K}),meta:{skipGlobalErrorToast:!0}}),N=t.connections.find(e=>e.id===l),P=t.scopes.find(e=>`${e.kind}:${e.key??``}`===O),F=N?.capabilities.filter(e=>P?.capabilities?.includes(e)??!0)??[],I=d.filter(e=>F.includes(e)),L=I.includes(U[`keyword-gaps`]),R=L||I.includes(U[`competitor-discovery`]),ee=I.some(e=>e!==U[`keyword-metrics`]),te=I.includes(U[`ranked-keywords`])||R,ne=(0,Q.useId)(),re=I.includes(U[`market-rankings`]),ie=e=>e===U[`market-rankings`]?!n?.rankings||I.some(e=>e!==U[`market-rankings`]):re,z=F.includes(U[`market-rankings`])?n?.rankings?`Market rankings use their own profile.`:`Set up market rankings with the CLI or API.`:null,ae=async()=>{if(!t.access.canWrite||Y()||We()||M.isPending)return;if(!P){j(`Choose a measurement scope.`);return}if(R&&p.some(e=>e.kind!==lt.domain||!e.includeSubdomains)){j(`Organic competitors and search gaps require whole-domain targets including subdomains.`);return}let i={name:s,connectionId:l,capabilities:I,targets:ee?p:[],keywords:v.split(`
4
4
  `).map(e=>e.trim()).filter(Boolean),locationCode:Number(b),languageCode:w,limit:te?Number(E):n?.limit??100,scope:{kind:P.kind,...P.key?{key:P.key}:{},...P.planRevision===void 0?{}:{expectedPlanRevision:P.planRevision}},...I.includes(U[`market-rankings`])&&n?.rankings?{rankings:n.rankings}:{},...L?{competitors:h.split(`