@canonry/canonry 7.83.2 → 7.85.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/ai-traffic-tracking.md +2 -1
  2. package/assets/agent-workspace/skills/canonry/references/ai-traffic-tracking.md +2 -1
  3. package/assets/agent-workspace/skills/canonry/references/canonry-cli.md +4 -0
  4. package/assets/agent-workspace/skills/canonry/references/server-side-traffic.md +45 -8
  5. package/assets/assets/{AgentSetupPage-B9NOQP8a.js → AgentSetupPage-NdqmQkYa.js} +1 -1
  6. package/assets/assets/{AuditHistoryPanel-Fvh4WFjq.js → AuditHistoryPanel-CuqdFCb9.js} +1 -1
  7. package/assets/assets/{BacklinksPage-D1UHFLoV.js → BacklinksPage-CVjZiG1i.js} +1 -1
  8. package/assets/assets/{HistoryPage-CBcacDgP.js → HistoryPage-DRvdgemW.js} +1 -1
  9. package/assets/assets/{MeasurementPropertyPage-ZuZpurwr.js → MeasurementPropertyPage-Bc5EpJFV.js} +1 -1
  10. package/assets/assets/{ProjectPage-BoqDyoGi.js → ProjectPage-CGGBSiK7.js} +1 -1
  11. package/assets/assets/{RunsPage-tlCk_gOw.js → RunsPage-B6_o81G3.js} +1 -1
  12. package/assets/assets/{SettingsPage-7mRTFLFQ.js → SettingsPage-DjmVapHO.js} +1 -1
  13. package/assets/assets/{SiteHealthSection-l_A_AmY_.js → SiteHealthSection-BPPB0D9D.js} +2 -2
  14. package/assets/assets/{ToneBadge-CXyUIWzB.js → ToneBadge-DwUBSAjL.js} +1 -1
  15. package/assets/assets/{TrafficPage-DQbBT3TP.js → TrafficPage-BvbjxOw3.js} +1 -1
  16. package/assets/assets/{TrafficSourceDetailPage-D3DwE6Qd.js → TrafficSourceDetailPage-BGJwxS_Q.js} +1 -1
  17. package/assets/assets/{account-context-Bhgg1lEH.js → account-context-D7M4W4wP.js} +1 -1
  18. package/assets/assets/agent-trust-copy-WXXeDvDs.js +1 -0
  19. package/assets/assets/{card-B16Dvxau.js → card-DULVRmzI.js} +1 -1
  20. package/assets/assets/{extract-error-message-B5_v_-U8.js → extract-error-message-B9-6WgLm.js} +1 -1
  21. package/assets/assets/{format-helpers-Bs9rrO74.js → format-helpers-Cgq0VzXz.js} +1 -1
  22. package/assets/assets/{index-3aBRkQpI.js → index-A-4JN4Pv.js} +4 -4
  23. package/assets/assets/{query-client-D-tt1sn3.js → query-client-1Q6EwPba.js} +1 -1
  24. package/assets/assets/{react-query-DQr9PoNm.js → react-query-D0OiMBt3.js} +1 -1
  25. package/assets/assets/{react-sigma_core.esm.min-BfZVKh7v.js → react-sigma_core.esm.min-CR09uPhZ.js} +1 -1
  26. package/assets/assets/{service-Cmt36bhL.js → service-Bu-7icpb.js} +1 -1
  27. package/assets/index.html +7 -7
  28. package/dist/{ads-BSVYKQ2L.js → ads-ETZIGLL5.js} +3 -3
  29. package/dist/{agent-L7VUHOHS.js → agent-WG2FUC7C.js} +7 -7
  30. package/dist/{agent-ask-A4HQCNLV.js → agent-ask-775XBFOH.js} +3 -3
  31. package/dist/{agent-conversations-L3TJJKPJ.js → agent-conversations-AYZ3LQJQ.js} +3 -3
  32. package/dist/{agent-journeys-FEXRAZYN.js → agent-journeys-GWNZG73C.js} +3 -3
  33. package/dist/{agent-memory-LBTLOHUA.js → agent-memory-E5MRRS5P.js} +3 -3
  34. package/dist/{agent-providers-X7V2IHRK.js → agent-providers-DEQZWO2M.js} +3 -3
  35. package/dist/{agent-transcript-YSP2HKUZ.js → agent-transcript-4AKVVHQC.js} +3 -3
  36. package/dist/{analytics-FBPHES6M.js → analytics-HSLTWKDA.js} +3 -3
  37. package/dist/{apply-PBCXZC5F.js → apply-4GD7VGG7.js} +3 -3
  38. package/dist/{backfill-PZBLCRPI.js → backfill-LNE2BW34.js} +10 -9
  39. package/dist/{backlinks-QMLTF2VF.js → backlinks-TGE3DWA2.js} +3 -3
  40. package/dist/{bing-H65WGTXU.js → bing-56GNRC55.js} +3 -3
  41. package/dist/{bootstrap-JAZNMAKP.js → bootstrap-42XCWZTS.js} +10 -10
  42. package/dist/{cdp-4DAMAHTB.js → cdp-UODIMKE3.js} +7 -7
  43. package/dist/{chunk-UGUON7IK.js → chunk-2O5XBKEO.js} +7 -7
  44. package/dist/{chunk-IQTMHY23.js → chunk-2R6WI237.js} +17643 -17454
  45. package/dist/{chunk-OMNS42ZQ.js → chunk-2X6UAPAC.js} +523 -4
  46. package/dist/{chunk-SEAXXCU6.js → chunk-4KK3OTHE.js} +1 -1
  47. package/dist/{chunk-X7U7XYJQ.js → chunk-5NEZO3SC.js} +3 -3
  48. package/dist/{chunk-SVMTN7MI.js → chunk-6SGHSSWQ.js} +2 -2
  49. package/dist/{chunk-NCM6PX64.js → chunk-AICFUZ6X.js} +1 -1
  50. package/dist/{chunk-QAJDHHC5.js → chunk-BQTXXXUG.js} +1 -1
  51. package/dist/{chunk-V52KSHH7.js → chunk-C2H5TPKD.js} +338 -338
  52. package/dist/{chunk-IJQJSNOZ.js → chunk-D45AMUYA.js} +4 -4
  53. package/dist/{chunk-WA4FD5Y6.js → chunk-DWK6NIJF.js} +1 -1
  54. package/dist/{chunk-CBAYQHNX.js → chunk-GR7VVRNN.js} +1 -1
  55. package/dist/{chunk-SKH3N6WI.js → chunk-IOW23XNK.js} +3 -3
  56. package/dist/{chunk-5AGYH5PX.js → chunk-JVO5GQZH.js} +4287 -3934
  57. package/dist/{chunk-3GXAL3F7.js → chunk-KBLMQDUZ.js} +37 -171
  58. package/dist/{chunk-PHVIMUAQ.js → chunk-KNKOTLVW.js} +6 -2
  59. package/dist/{chunk-3UFQI4KL.js → chunk-L5R5S57T.js} +75 -1
  60. package/dist/{chunk-32U5LFIT.js → chunk-NY252PIY.js} +3 -3
  61. package/dist/{chunk-W5ZBMBBZ.js → chunk-OHDSI5XS.js} +1 -1
  62. package/dist/{chunk-KCFIQJOL.js → chunk-OS5BVALI.js} +2 -2
  63. package/dist/{chunk-AA6P5NK3.js → chunk-PQWZCAVS.js} +1 -1
  64. package/dist/{chunk-WDEDEEWA.js → chunk-PX2KVGOJ.js} +1 -1
  65. package/dist/{chunk-HIC62JTS.js → chunk-Q7354YI3.js} +3 -3
  66. package/dist/{chunk-KFMU6CLU.js → chunk-QEATYB7C.js} +1 -1
  67. package/dist/{chunk-Y7WHB65J.js → chunk-RCAB7M6A.js} +2 -2
  68. package/dist/{chunk-LZGVQSZL.js → chunk-SS33RWKG.js} +1 -1
  69. package/dist/{chunk-YCRPOY2Y.js → chunk-TPUBPXBN.js} +2 -2
  70. package/dist/{chunk-QHUCHZA3.js → chunk-TVZMFCX2.js} +6 -6
  71. package/dist/{chunk-4D2QHIRS.js → chunk-UMEQ7EYN.js} +4 -4
  72. package/dist/{chunk-IPPNN5KE.js → chunk-UMV4HYHD.js} +2 -2
  73. package/dist/{chunk-7Q5BSCKN.js → chunk-VFSHZHZS.js} +2 -2
  74. package/dist/{chunk-YJOGWS7F.js → chunk-X7XKMARG.js} +2 -2
  75. package/dist/{chunk-KVSCEZBR.js → chunk-YDC2V5FQ.js} +30 -25
  76. package/dist/{chunk-JCWXEVYW.js → chunk-Z53CKLDS.js} +3 -3
  77. package/dist/{chunk-P76XOEWL.js → chunk-ZXMDIWW6.js} +4 -4
  78. package/dist/{citations-MNLMO33V.js → citations-RXBPR5MX.js} +3 -3
  79. package/dist/{cli-catalog-IKF4A7ZS.js → cli-catalog-QVCJWPCI.js} +3 -3
  80. package/dist/{cli-commands-KNMPQFQO.js → cli-commands-ZXR4Z2RW.js} +7 -7
  81. package/dist/cli.js +13 -13
  82. package/dist/{competitor-5DY5PKNU.js → competitor-MDNNHRSD.js} +3 -3
  83. package/dist/{content-XNK2YY4S.js → content-D3JZZQ64.js} +3 -3
  84. package/dist/{dashboard-SMI6A6OF.js → dashboard-5S2A46GM.js} +6 -6
  85. package/dist/{demo-DIP5JBEI.js → demo-DQHWRIKR.js} +1 -1
  86. package/dist/{demo-server-EWOBWWV4.js → demo-server-FY2XBSD2.js} +12 -12
  87. package/dist/{discover-D4H4ALIE.js → discover-NVNWHOTZ.js} +3 -3
  88. package/dist/{discover-eval-2CID2IBT.js → discover-eval-CJB6GYUS.js} +3 -3
  89. package/dist/{doctor-OWRQNDWF.js → doctor-DLSKNC4W.js} +3 -3
  90. package/dist/{evidence-SQX4IMQM.js → evidence-QNJULIXM.js} +3 -3
  91. package/dist/{export-cmd-73PYMZZ5.js → export-cmd-Z2YG2WLK.js} +3 -3
  92. package/dist/{ga-S6AKEVAL.js → ga-RSNHBP2B.js} +3 -3
  93. package/dist/{gbp-57J3AXEY.js → gbp-ZEV62LSZ.js} +3 -3
  94. package/dist/{google-PPU5MJSV.js → google-RZHEIKW5.js} +4 -4
  95. package/dist/{google-marketing-W4KZ74HX.js → google-marketing-DYQXPTD3.js} +1 -1
  96. package/dist/{health-cmd-QYP4MS3E.js → health-cmd-6ATPYUYG.js} +3 -3
  97. package/dist/{history-MFHBHYH7.js → history-KLX6XRY4.js} +3 -3
  98. package/dist/index.d.ts +337 -47
  99. package/dist/index.js +25 -25
  100. package/dist/{init-UZPL4H55.js → init-5BALV6SU.js} +12 -12
  101. package/dist/{insights-IIMMXGRO.js → insights-ARCEFFK5.js} +3 -3
  102. package/dist/intelligence-service-YJFZ6IBI.js +16 -0
  103. package/dist/{journeys-DXXRNANM.js → journeys-WVRQRZQJ.js} +3 -3
  104. package/dist/{keys-O3T52MLX.js → keys-5KAJFRZZ.js} +3 -3
  105. package/dist/{keyword-MS23BR7O.js → keyword-PTUH3TFD.js} +3 -3
  106. package/dist/{logs-SKR5OLTY.js → logs-NM7ACXGQ.js} +3 -3
  107. package/dist/{mcp-NFC2PBGD.js → mcp-ALRQXYL3.js} +4 -4
  108. package/dist/mcp.js +9 -9
  109. package/dist/{measurement-plan-Z73LMQYB.js → measurement-plan-T52JHK2J.js} +5 -5
  110. package/dist/{notify-2RUWK2AR.js → notify-MJBMRDXD.js} +3 -3
  111. package/dist/{organic-evidence-BGAOEVMZ.js → organic-evidence-ZUCQFWD5.js} +3 -3
  112. package/dist/{overview-DONWVYZT.js → overview-74IHPU2A.js} +4 -4
  113. package/dist/{project-FFSPWR6R.js → project-DKQOPMH6.js} +3 -3
  114. package/dist/{query-AXEUWIW3.js → query-YDJ5T46L.js} +3 -3
  115. package/dist/{research-YURAJRCV.js → research-5DU6DFZW.js} +3 -3
  116. package/dist/{results-export-ECSJKZHZ.js → results-export-EDVVXKVW.js} +3 -3
  117. package/dist/{run-27EXPBE4.js → run-HRHGSIYE.js} +4 -4
  118. package/dist/{schedule-NY55SZZF.js → schedule-GZVKQGMP.js} +3 -3
  119. package/dist/{search-RXCBX3ST.js → search-M37GRKVC.js} +3 -3
  120. package/dist/{serve-KGZW5WPA.js → serve-DW6PPZPJ.js} +26 -26
  121. package/dist/{session-BY2FSRYU.js → session-H427H2SK.js} +13 -13
  122. package/dist/{settings-IPC5SSDU.js → settings-WGS7GP7C.js} +3 -3
  123. package/dist/{skills-Y3VNCWQM.js → skills-CDDUPMAU.js} +2 -2
  124. package/dist/{snapshot-TPDSMADU.js → snapshot-5MAK7PWE.js} +3 -3
  125. package/dist/{src-IDX2F2SR.js → src-FEV4KYXN.js} +8 -2
  126. package/dist/{status-YSQJBNM7.js → status-EHFOYTXQ.js} +4 -4
  127. package/dist/{technical-aeo-NMUQVIFG.js → technical-aeo-KVY4RQWT.js} +3 -3
  128. package/dist/{telemetry-OA6W7Q54.js → telemetry-7XRRIHVC.js} +4 -4
  129. package/dist/{tools-5YRH5NEI.js → tools-EHONHGB6.js} +11 -11
  130. package/dist/{traffic-CE47IFFI.js → traffic-TBR6GOWN.js} +5 -5
  131. package/dist/{users-NMWBTCDI.js → users-YQS4X47Q.js} +3 -3
  132. package/dist/{visibility-stats-DE64FVOJ.js → visibility-stats-JXIOSJXC.js} +3 -3
  133. package/dist/{wordpress-AJWIJSM7.js → wordpress-HVOLEPQY.js} +3 -3
  134. package/package.json +1 -1
  135. package/assets/assets/agent-trust-copy-CKZsKhc0.js +0 -1
  136. package/dist/intelligence-service-AMXDCTS2.js +0 -16
@@ -1,4 +1,4 @@
1
- import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{C as t,F as n,K as r,P as i,R as a,S as o,V as s,X as c,Y as l,i as u,it as d,k as f,nt as p,o as m,ot as h,q as g,r as _,s as v,st as y,t as b,w as x,y as S}from"./vendor-lucide-CoTHJwai.js";import{r as C}from"./vendor-markdown-cQgSk2i0.js";import{E as w,_ as T,b as E,d as D,f as O,g as k,p as A,r as j,u as M,w as N}from"./vendor-tanstack-q5SvZtcv.js";import{c as P,f as F,i as I,l as L,m as R,o as ee,p as te,r as z,s as B,t as ne,u as V}from"./vendor-recharts-AnNqECZW.js";import{$n as H,A as re,Ai as ie,Ar as ae,Ci as oe,Ct as se,Di as ce,Dn as le,Dr as ue,Dt as de,Er as fe,F as pe,Fi as me,Fr as he,Ft as ge,Gi as _e,Gn as ve,H as ye,Hi as be,Hn as xe,Ht as Se,I as Ce,Ii as we,Ir as U,It as Te,Ji as Ee,Jn as De,Jr as Oe,K as ke,Ki as Ae,Kn as je,Kt as Me,Lr as Ne,Lt as Pe,Mi as Fe,Mr as Ie,N as Le,Ni as Re,Nr as ze,Ns as Be,Nt as Ve,Oi as He,On as Ue,Or as We,P as Ge,Pi as Ke,Pr as qe,Ps as Je,Pt as Ye,Qi as Xe,Qn as Ze,Qr as Qe,Rt as $e,Ti as et,Tt as W,Un as tt,Ut as nt,V as rt,Vi as it,Vt as at,W as ot,Wi as st,Wn as G,Wt as ct,Xi as lt,Xn as ut,Xr as dt,Y as ft,Yi as pt,Yn as mt,Yr as ht,Zn as gt,_n as _t,_r as vt,_t as yt,a as bt,ai as xt,an as St,ar as Ct,b as wt,c as Tt,ci as Et,cn as Dt,cr as Ot,dr as kt,dt as At,ei as jt,er as Mt,f as Nt,fr as Pt,gr as Ft,gt as It,h as Lt,hr as Rt,ht as zt,ii as Bt,ir as Vt,it as Ht,j as Ut,jr as Wt,k as Gt,ki as Kt,kr as qt,l as Jt,lr as Yt,lt as Xt,m as Zt,mr as Qt,mt as K,ni as $t,nn as en,nr as tn,o as nn,oi as rn,on as an,or as on,ot as sn,p as cn,pr as ln,qn as un,qr as dn,r as q,ri as fn,rr as pn,rt as mn,s as hn,si as gn,sn as _n,t as J,ti as vn,tr as yn,u as bn,ur as xn,ut as Sn,vr as Cn,wi as wn,wr as Tn,wt as Y,yr as En,yt as Dn,zi as On}from"./ToneBadge-CXyUIWzB.js";import{_ as kn,a as An,b as jn,c as Mn,d as Nn,f as Pn,g as Fn,h as In,i as Ln,m as Rn,n as zn,o as Bn,p as Vn,r as Hn,t as Un,u as Wn,v as Gn,x as Kn,y as qn}from"./format-helpers-Bs9rrO74.js";import{r as Jn}from"./account-context-Bhgg1lEH.js";import{t as Yn}from"./async-handler-Bj3TnIRw.js";import{a as Xn,d as Zn,l as Qn,n as $n,o as er,s as tr,t as nr,u as rr}from"./query-client-D-tt1sn3.js";import{$ as ir,A as ar,At as or,B as sr,C as cr,Cn as lr,Ct as ur,D as dr,Dn as fr,Dt as pr,E as mr,En as hr,Et as gr,F as _r,Ft as vr,G as yr,H as br,I as xr,J as Sr,K as Cr,L as wr,M as Tr,Mt as Er,N as Dr,Nt as Or,O as kr,On as Ar,Ot as jr,P as Mr,Pt as Nr,Q as Pr,R as Fr,S as Ir,Sn as Lr,St as Rr,T as zr,Tn as Br,Tt as Vr,U as Hr,V as Ur,W as Wr,X as Gr,Xt as Kr,Z as qr,Zt as Jr,_ as Yr,_n as Xr,_t as Zr,at as Qr,b as $r,bn as ei,bt as ti,c as ni,cn as ri,ct as ii,d as ai,dn as oi,dt as si,f as ci,fn as li,g as ui,gn as di,gt as fi,h as pi,hn as mi,ht as hi,j as gi,jt as _i,k as vi,kt as yi,l as bi,lt as xi,m as Si,mn as Ci,mt as wi,n as Ti,nn as Ei,nt as Di,o as Oi,ot as ki,p as Ai,pn as ji,pt as Mi,q as Ni,qt as Pi,r as Fi,rn as Ii,s as Li,sn as Ri,t as zi,u as Bi,ut as Vi,v as Hi,vn as Ui,vt as Wi,w as Gi,wn as Ki,wt as qi,x as Ji,xn as Yi,xt as Xi,y as Zi,yn as Qi,yt as $i,z as ea}from"./react-query-DQr9PoNm.js";import{_ as ta,a as na,c as ra,d as ia,f as aa,g as oa,h as sa,i as ca,l as la,m as ua,n as da,o as fa,p as pa,r as ma,s as ha,t as ga,u as _a}from"./ChartPrimitives-B5L9FUj3.js";import{t as X}from"./InfoTooltip-DrBIPuSU.js";import{t as Z}from"./card-B16Dvxau.js";import{$ as va,$t as ya,A as ba,At as xa,Bt as Sa,C as Ca,Ct as wa,D as Ta,Dt as Ea,E as Da,Et as Oa,F as ka,Ft as Aa,G as ja,Gt as Ma,H as Na,Ht as Pa,I as Fa,It as Ia,J as La,Jt as Ra,K as za,Kt as Ba,L as Va,Lt as Ha,M as Ua,Mt as Wa,N as Ga,Nt as Ka,O as qa,Ot as Ja,P as Ya,Pt as Xa,Qt as Za,Rt as Qa,St as $a,Tt as eo,U as to,Ut as no,V as ro,Vt as io,W as ao,Wt as oo,X as so,Xt as co,Y as lo,Yt as uo,Z as fo,Zt as po,_ as mo,_t as ho,a as go,an as _o,at as vo,b as yo,bt as bo,c as xo,cn as So,ct as Co,dn as wo,dt as To,en as Eo,et as Do,ft as Oo,gt as ko,ht as Ao,i as jo,in as Mo,it as No,j as Po,jt as Fo,k as Io,kt as Lo,l as Ro,ln as zo,lt as Bo,mt as Vo,nn as Ho,nt as Uo,o as Wo,on as Go,ot as Ko,q as qo,qt as Jo,r as Yo,s as Xo,tn as Zo,u as Qo,un as $o,ut as es,vt as ts,wt as ns,x as rs,xt as is,y as as,yt as os,z as ss,zt as cs}from"./index-3aBRkQpI.js";import{a as ls,i as us,o as ds,r as fs,s as ps,t as ms}from"./SiteHealthSection-l_A_AmY_.js";import{t as hs}from"./Hint-CfeZmZig.js";import{t as gs}from"./AuditHistoryPanel-Fvh4WFjq.js";import{a as _s,i as vs,l as ys,n as bs,o as xs,r as Ss,t as Cs}from"./service-Cmt36bhL.js";import{l as ws,n as Ts,r as Es,s as Ds,t as Os,u as ks}from"./extract-error-message-B5_v_-U8.js";import{i as As,n as js,r as Ms}from"./agent-trust-copy-CKZsKhc0.js";var Ns=1e6;function Ps(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/Ns);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(y(),1),Fs={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 Is(e,t){return e!==`viewer`||t!==null}function Ls(e,t){return e===`research`&&!t?`tracked`:e}function Rs(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 zs(e,t){return e.find(e=>e.kind===t.measurementScope&&(e.kind===`project`||e.id===t.measurementScopeKey))}function Bs(e){return e.measurementScope!==`project`||e.marketKey!==void 0}function Vs(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 $=C();function Hs({state:e,label:t,className:n}){return(0,$.jsx)(J,{tone:Go(e),className:n,children:t??qn(e)})}var Us=[{value:`non-brand`,label:`Non-brand`},{value:`branded`,label:`Branded`}],Ws={"non-brand":`Non-brand`,branded:`Branded`,pooled:`All queries`},Gs={"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.`},Ks=`Mentioned = brand in the answer. Cited = domain in the sources. Neither implies the other.`;function qs(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:rn(e.score,On.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 Js({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:Ks})]}),(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:rn(e.share)})]},e.label))})]})}function Ys({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=qs(u,{hasCompetitors:n.length>0,unavailable:e.unavailable===!0,noRun:e.breakdown.snapshotsTotal===0&&e.branded.snapshotsTotal===0,otherClassHasData:d.snapshotsTotal>0}),p=kn(f.headline),m=l===`non-brand`?Mo[e.tone]:`text-secondary`;function h(e){let t=Us.findIndex(e=>e.value===c),n=null;e.key===`ArrowRight`||e.key===`ArrowDown`?n=(t+1)%Us.length:e.key===`ArrowLeft`||e.key===`ArrowUp`?n=(t-1+Us.length)%Us.length:e.key===`Home`?n=0:e.key===`End`&&(n=Us.length-1),n!==null&&(e.preventDefault(),i(Us[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:Gs[l]})]}),s?(0,$.jsx)(`div`,{role:`radiogroup`,"aria-labelledby":a,className:`segmented flex-wrap`,onKeyDown:h,children:Us.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:Ws[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:Ws[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)(Js,{breakdown:u,projectLabel:t})]})}function Xs({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 Zs=[{value:`7d`,label:`7 days`},{value:`30d`,label:`30 days`},{value:`90d`,label:`90 days`},{value:`all`,label:`All`}],Qs={"7d":`last 7 days`,"30d":`last 30 days`,"90d":`last 90 days`,all:`all checks`},$s={"non-brand":`Non-brand`,branded:`Branded`,all:`All queries`},ec={"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.`},tc={"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`},nc=`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.`,rc=100;function ic(e){return e?e.evidence.answeredResults>0||e.evidence.sourceResults>0?`measured`:`not-measured`:`unavailable`}function ac(e){return e===`unavailable`?`Unavailable`:`Not measured`}function oc(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 sc(e,t,n){return e===1?t:n}function cc(e){let t=e.label.trim(),n=it(e.domain);return t&&t.toLowerCase()!==e.domain.toLowerCase()&&t.toLowerCase()!==n.toLowerCase()?t:null}function lc({row:e,aliases:t=[],autoAliases:n=[]}){let r=cc(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 uc(e){let t=cc(e);return t?`${t} (${e.domain})`:e.domain}function dc(e,t){return t&&e>=rc?(0,$.jsxs)($.Fragment,{children:[`top `,(0,$.jsx)(`strong`,{children:e})]}):(0,$.jsx)(`strong`,{children:e})}function fc({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 pc({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 mc({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:ac(n)})}function hc({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`:ac(t)});let{figure:r,sign:i}=kn(rn(e,On.percent));return(0,$.jsxs)(`span`,{className:`av-n-sm ${n}`,children:[r,i?(0,$.jsx)(`span`,{className:`text-faint`,children:i}):null]})}function gc({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)(lc,{row:e})}),(0,$.jsx)(`td`,{className:`text-label-13 text-secondary`,children:oc(e.surfaceClass)}),(0,$.jsx)(`td`,{children:(0,$.jsx)(mc,{count:e.mentionCount,of:n,state:t,toneClass:`text-primary`})}),(0,$.jsx)(`td`,{children:(0,$.jsx)(mc,{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)(pc,{urls:e.sampleUrls}):null,i?(0,$.jsx)(fc,{action:`pin`,domain:e.domain,mutation:i}):null]})})]},e.domain))})]})})}function _c({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 vc({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=ic(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?Mo[_o(t.project.shareOfVoice)]:`text-primary`,M=e=>_?e.pinned?l?(0,$.jsx)(fc,{action:`unpin`,domain:e.domain,mutation:l}):null:c?(0,$.jsx)(fc,{action:`pin`,domain:e.domain,mutation:c}):null:null,N=w.some(e=>M(e)!==null),P=[m,E?$s[E]:null,Qs[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: ${tc[t.reason]}`}),t&&T.length>0){let e=T.length;F.push({key:`others`,text:O&&e>=rc?`${rc} or more other competitors seen`:`${e} other ${sc(e,`competitor`,`competitors`)} seen`})}D>0&&F.push({key:`pending`,text:`${t?.scope.kind===`all-markets`?`Pending publication across markets`:`Pending publication`}: ${D} ${sc(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:Mo.caution});let L=[];if(t&&x){L.push(t.runCount===void 0?(0,$.jsxs)($.Fragment,{children:[`Base: `,(0,$.jsx)(`strong`,{children:x.answeredResults}),` `,sc(x.answeredResults,`answer`,`answers`)]}):(0,$.jsxs)($.Fragment,{children:[`Base: `,(0,$.jsx)(`strong`,{children:t.runCount}),` `,sc(t.runCount,`check`,`checks`),`, `,(0,$.jsx)(`strong`,{children:x.answeredResults}),` `,sc(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}),` `,sc(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}),` `,sc(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}),` `,sc(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)(gc,{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,` `,sc(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:[uc(e),` · `,oc(e.surfaceClass),` · `,e.citationCount,` `,sc(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?`${ec[E]} ${nc}`:nc})]}),(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)(Vo,{label:`Competitors over time window`,className:`flex-wrap`,options:Zs,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)(hc,{percent:t.project.shareOfVoice,state:S,toneClass:j})}),(0,$.jsx)(`td`,{children:(0,$.jsx)(mc,{count:t.project.mentionCount,of:k,state:S,toneClass:j})}),(0,$.jsxs)(`td`,{children:[(0,$.jsx)(mc,{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)(lc,{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:oc(e.surfaceClass)}),(0,$.jsx)(`td`,{children:(0,$.jsx)(hc,{percent:e.shareOfVoice,state:S,toneClass:`text-primary`})}),(0,$.jsx)(`td`,{children:(0,$.jsx)(mc,{count:e.mentionCount,of:k,state:S,toneClass:`text-primary`})}),(0,$.jsx)(`td`,{children:(0,$.jsx)(mc,{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)(Xs,{items:L}),_&&u?(0,$.jsx)(`div`,{className:`border-t border-subtle px-5 py-3`,children:(0,$.jsx)(_c,{onAddCompetitor:u})}):null]})}function yc({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 bc(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 xc=320;function Sc(e){return e===`branded`?`Branded`:e===`non-brand`?`Non-brand`:`Unclassified`}function Cc(e){return e===`non-brand`?0:e===`branded`?1:2}function wc(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 Tc(e){return e.phrase}function Ec(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 Dc(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 Oc(e,t){return e.map(e=>kc(e,t))}function kc(e,t){return t===`citations`?e:{...e,citationState:Ec(e,t),runHistory:e.runHistory.map(e=>({...e,citationState:Ec(e,t)}))}}function Ac(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 jc(e){let t=bc(Oc(e,`mentions`)),n=bc(e);return[Ac(t,`mentions`),Ac(n,`citations`)]}function Mc({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 Nc({items:e}){return(0,$.jsx)(`div`,{className:`query-evidence-signals`,"aria-label":`Latest run mention and citation signals`,children:jc(e).map(e=>(0,$.jsx)(Mc,{signal:e},e.key))})}function Pc({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)(qa,{}),t]})}):null,e?(0,$.jsx)(Io,{queryClass:e,manage:!!t}):null]})}function Fc({evidence:e,compareLocations:t=!1,defaultDensity:n=`detailed`,providerSelection:r,onProviderSelectionChange:i,addedQueries:a=[],actions:o,actionPanel:s}){let{openEvidence:c}=fo(),l=(0,Q.useId)(),[u,d]=(0,Q.useState)(new Set),f=Ua(),[p,m]=(0,Q.useState)(`mentions`),[h,_]=(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(kc(r,p)),s.rawItems.push(r),n.set(o,s)}return[...n.values()].sort((e,t)=>Cc(e.queryClass)-Cc(t.queryClass))},[e,p,t,S]),E=(0,Q.useMemo)(()=>T.filter(e=>v===`all`||(v===`unclassified`?e.queryClass===null:e.queryClass===v)),[T,v]),D=ps({rows:E,getSearchText:Tc}),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(Tn)),[a]),A=f?6:5,j=D.rows.map(e=>e.key),M=j.length>0&&j.every(e=>u.has(e)),N=e=>{d(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},P=p===`mentions`?`mentioned`:`cited`,F=p===`mentions`?`Mention History`:`Citation History`,I=p===`mentions`?`mentioned`:`cited`;return(0,$.jsxs)(`div`,{className:`query-evidence`,children:[(0,$.jsx)(Pc,{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":p===e,tabIndex:p===e?0:-1,onClick:()=>m(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`;m(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:h===`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:()=>{d(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)(us,{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:Ha(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}-${p}`,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`}),f&&(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`})})]})}),wc(D.rows).map(e=>(0,$.jsxs)(`tbody`,{children:[(0,$.jsx)(`tr`,{className:`query-evidence-group`,children:(0,$.jsxs)(`th`,{scope:`rowgroup`,colSpan:A,children:[Sc(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=u.has(e),d=j.indexOf(e),m=`${l}-query-${d}`,_=k.has(Tn(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=bc(a),C=a.filter(e=>e.citationState===oe.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":m,"aria-expanded":s,onClick:t=>{t.stopPropagation(),N(e)},children:[(0,$.jsx)(g,{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:m,className:`query-evidence-meta`,children:[(0,$.jsx)(`span`,{children:Sc(r)}),t&&(0,$.jsx)(`span`,{children:i??`No location`}),a.filter(e=>e.provider).map(e=>(0,$.jsx)(`span`,{children:Ha(e.provider)},e.id))]})]})]})}),(0,$.jsx)(`td`,{children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(Hs,{state:y,label:Dc(y,p),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]})]})}),f&&(0,$.jsx)(`td`,{children:(0,$.jsx)(ba,{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)(yc,{history:S,signal:p})}),(0,$.jsx)(`td`,{className:`evidence-change-cell`,children:_?(0,$.jsx)(`span`,{className:`query-evidence-new`,children:`new query`}):(0,$.jsx)(Nc,{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?Ha(e.provider):`Awaiting engine`})}),(0,$.jsx)(`td`,{children:(0,$.jsx)(Hs,{state:e.citationState,className:`rounded-none border-0 bg-transparent p-0 text-label-14`,label:Dc(e.citationState,p)})}),f&&(0,$.jsx)(`td`,{children:(0,$.jsx)(Ta,{queryId:e.queryId,sourceSnapshotIds:e.sourceSnapshotId?[e.sourceSnapshotId]:[],queryClass:e.queryClass,provider:e.provider,location:e.location??null})}),(0,$.jsx)(`td`,{children:(0,$.jsx)(yc,{history:e.runHistory,signal:p})}),(0,$.jsx)(`td`,{className:`evidence-change-cell`,children:_?null:(0,$.jsx)(Nc,{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?Ha(e.provider):`saved`} answer for ${e.query}`,onClick:t=>{t.stopPropagation(),c(e.id)},children:`View`})})]}),h===`detailed`&&(0,$.jsx)(`tr`,{className:`query-evidence-preview-row`,children:(0,$.jsx)(`td`,{colSpan:A,children:(0,$.jsx)(Rc,{item:e,mode:p,onViewFull:()=>c(e.id)},p)})})]},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)(fs,{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 Ic(e){let t=(e.matchedTerms??[]).filter(e=>e.trim().length>2),n=No(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 Lc(e,t){let n=t.toLowerCase().replace(/^www\./,``);return(e.citedCompetitorDomains??[]).some(e=>e.toLowerCase().replace(/^www\./,``)===n)}function Rc({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)(zc,{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)(vo,{url:t.uri,title:t.title}),Lc(e,be(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,Lc(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)(zc,{item:e,onViewFull:n,contextOnly:!0})]}):(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:`No answer text captured for this run.`})]})}function zc({item:e,onViewFull:t,contextOnly:n=!1}){let{matchedTerms:r,mentionedCompetitorDomains:i,mentionedCompetitorTerms:a,recommendedCompetitors:o}=e,s=(0,Q.useMemo)(()=>Ic({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>xc;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)(Va,{headingLevel:4,highlightGroups:s,previewLength:xc,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,Lc(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 Bc({label:e,value:t,tone:n}){return(0,$.jsxs)(`div`,{className:`material-base p-3`,children:[(0,$.jsx)(`p`,{className:`text-label-12 normal-case text-muted`,children:e}),(0,$.jsx)(`p`,{className:`mt-2 text-copy-24-strong ${n===`positive`?`text-positive-400`:n===`negative`?`text-negative-400`:`text-strong`}`,children:t})]})}function Vc({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&&Ue(`window`),n(e)},children:i?i(e):e},e))})}var Hc=`baseline`;function Uc(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,[Hc]:i.get(e)??null};for(let e of n)a[e.dataKey]=t?.[e.key]??0;return a}),series:n}}var Wc=`text-label-12-strong normal-case text-muted`;function Gc({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 Kc({children:e}){return(0,$.jsx)(`div`,{className:`[&>details:first-child]:border-t-0`,children:e})}function qc({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 Jc={3:`lg:grid-cols-3`,4:`lg:grid-cols-4`,5:`lg:grid-cols-5`};function Yc({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 ${Jc[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 Xc({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:`${Wc} 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 Zc({label:e,align:t}){return(0,$.jsx)(`th`,{className:`py-2 ${t===`right`?`pl-4 text-right`:`text-left`}`,children:(0,$.jsx)(`span`,{className:Wc,children:e})})}function Qc(e,t,n=`desc`){return e.key===t?{key:t,dir:e.dir===`desc`?`asc`:`desc`}:{key:t,dir:n}}function $c(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 el({groups:e,groupLabel:t,caption:n,childColumns:r,childRowKey:i,renderChildCells:a,pinLast:o}){let s=(0,Q.useId)(),[c,u]=(0,Q.useState)(new Set),[d,f]=(0,Q.useState)({key:`sessions`,dir:`desc`}),p=(0,Q.useMemo)(()=>{let t=$c(d.key,d.dir);return[...e].sort((e,n)=>Number(o?.(e)??!1)-Number(o?.(n)??!1)||t(e,n))},[e,d,o]),m=e=>f(t=>Qc(t,e,e===`label`?`asc`:`desc`)),h=e=>u(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)(Xc,{label:t,sortKey:`label`,current:d.key,dir:d.dir,onSort:m,align:`left`}),(0,$.jsx)(Xc,{label:`Sessions`,sortKey:`sessions`,current:d.key,dir:d.dir,onSort:m,align:`right`}),(0,$.jsx)(Xc,{label:`Organic`,sortKey:`organicSessions`,current:d.key,dir:d.dir,onSort:m,align:`right`}),(0,$.jsx)(Xc,{label:`Paid`,sortKey:`paidSessions`,current:d.key,dir:d.dir,onSort:m,align:`right`}),(0,$.jsx)(Zc,{label:`Share`,align:`right`})]})}),(0,$.jsx)(`tbody`,{children:p.map((e,t)=>{let n=c.has(e.label),o=`${s}-group-${t}`,u=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:()=>h(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)(l,{"aria-hidden":`true`,className:`size-3.5 shrink-0 text-secondary`}):(0,$.jsx)(g,{"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:[u,` `,u===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:rn(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)(Zc,{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 tl(e,t){return e===`other`?ca.textDim:na[t%na.length]}function nl({input:e,baseline:t,baselineLabel:n,label:r,height:i=224}){let{rows:a,series:o}=(0,Q.useMemo)(()=>Uc(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)(R,{width:`100%`,height:`100%`,children:(0,$.jsxs)(ne,{data:a,margin:{top:4,right:4,bottom:0,left:0},children:[(0,$.jsx)(P,{stroke:ma,vertical:!1}),(0,$.jsx)(I,{dataKey:`date`,tick:da,tickLine:!1,axisLine:{stroke:ga},tickFormatter:ia,minTickGap:24}),(0,$.jsx)(z,{tick:da,tickLine:!1,axisLine:!1,allowDecimals:!1,width:36}),(0,$.jsx)(F,{...ha,labelFormatter:la,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=tl(e.key,o.indexOf(e));return(0,$.jsx)(ee,{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)(B,{type:`monotone`,dataKey:`baseline`,name:`baseline`,stroke:ca.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:tl(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:ca.textFaint,strokeWidth:`2`,strokeDasharray:`5 3`})}),n]})]})]})}var rl=[`sessions`,`activeUsers`,`organicSessions`,`engagementRate`,`keyEvents`],il=`canonry.siteTraffic.slots`,al=na[1],ol={current:`current`,previous:`previous`};function sl(e){return typeof e==`string`&&ue.some(t=>t===e)}function cl(){try{let e=JSON.parse(window.localStorage.getItem(il)??`null`);if(Array.isArray(e)&&e.length===rl.length&&e.every(sl))return[...e]}catch{}return[...rl]}function ll(e){try{window.localStorage.setItem(il,JSON.stringify(e))}catch{}}function ul(){return typeof window<`u`&&typeof window.matchMedia==`function`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches}function dl(e){return e===null?`no earlier data`:e===0?`no change on the previous period`:`${e>0?`up`:`down`} ${rn(Math.abs(e),On.percent)} on the previous period`}function fl({metric:e,change:t}){let n=qe(e,t);if(n===null||t===null)return(0,$.jsx)(`span`,{className:`block text-label-13 text-secondary`,children:`No earlier data`});let r=n===Wt.better?`text-positive`:n===Wt.worse?`text-negative`:`text-secondary`,i=t>0?p:t<0?h:null;return(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 text-label-13-strong tabular-nums ${r}`,children:[i&&(0,$.jsx)(i,{"aria-hidden":`true`,className:`size-3.5`,strokeWidth:2.5}),rn(Math.abs(t),On.percent)]})}function pl({active:e,payload:t,metric:n}){let r=t?.[0]?.payload;return!e||!r?null:(0,$.jsxs)(`div`,{className:`material-tooltip min-w-48 px-3 py-2 text-label-13`,children:[(0,$.jsx)(`p`,{className:`mb-1 text-copy-13-strong text-heading`,children:fe[n].label}),(0,$.jsxs)(`p`,{className:`flex items-center justify-between gap-6`,children:[(0,$.jsxs)(`span`,{className:`flex items-center gap-2 text-secondary`,children:[(0,$.jsx)(`svg`,{"aria-hidden":`true`,width:`14`,height:`6`,className:`shrink-0`,children:(0,$.jsx)(`line`,{x1:`0`,y1:`3`,x2:`14`,y2:`3`,stroke:al,strokeWidth:`2.5`})}),la(r.date)]}),(0,$.jsx)(`span`,{className:`tabular-nums text-primary`,children:ze(n,r.current)})]}),(0,$.jsxs)(`p`,{className:`flex items-center justify-between gap-6`,children:[(0,$.jsxs)(`span`,{className:`flex items-center gap-2 text-secondary`,children:[(0,$.jsx)(`svg`,{"aria-hidden":`true`,width:`14`,height:`6`,className:`shrink-0`,children:(0,$.jsx)(`line`,{x1:`0`,y1:`3`,x2:`14`,y2:`3`,stroke:al,strokeWidth:`1.5`,strokeDasharray:`3 2`})}),la(r.previousDate)]}),(0,$.jsx)(`span`,{className:`tabular-nums text-secondary`,children:ze(n,r.previous)})]})]})}function ml({overview:e,refreshing:t=!1}){let n=(0,Q.useId)(),[r,i]=(0,Q.useState)(cl),[a,o]=(0,Q.useState)(0),[s,c]=(0,Q.useState)(new Set),u=!ul(),d=r[a]??rl[0],f=(0,Q.useMemo)(()=>e.days.map(e=>({date:e.date,previousDate:e.previousDate,current:e.values[d],previous:e.previousValues[d]})),[e.days,d]),p=f.some(e=>e.current!==null||e.previous!==null),m=Ne(e.window)?We[e.window]:null,h=m===null?`This period`:`Last ${m} days`,g=(e,t)=>i(n=>{let r=[...n],i=r.indexOf(t);return i!==-1&&i!==e&&(r[i]=r[e]),r[e]=t,ll(r),r}),_=e=>{o(e),document.getElementById(`${n}-tab-${e}`)?.focus()},v=(e,t)=>{let n=r.length-1,i=e.key===`ArrowRight`?t===n?0:t+1:e.key===`ArrowLeft`?t===0?n:t-1:e.key===`Home`?0:e.key===`End`?n:null;i!==null&&(e.preventDefault(),_(i))},y=e=>c(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n});return(0,$.jsxs)(`div`,{className:`overflow-hidden material-base transition-opacity duration-200 ${t?`opacity-60`:``}`,children:[(0,$.jsx)(`div`,{role:`tablist`,"aria-label":`Site traffic figures`,className:`grid grid-cols-2 border-b border-default sm:grid-cols-3 lg:grid-cols-5`,children:r.map((t,r)=>{let i=r===a,s=ze(t,e.totals[t],{compact:!0});return(0,$.jsxs)(`div`,{className:`relative min-w-0 px-4 pb-4 pt-4`,children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`absolute inset-x-4 top-0 h-[3px] rounded-b-sm bg-link transition-opacity duration-200 ${i?`opacity-100`:`opacity-0`}`}),(0,$.jsxs)(`div`,{className:`relative inline-flex max-w-full items-center`,children:[(0,$.jsx)(`select`,{"aria-label":`Figure ${r+1}`,value:t,onChange:e=>{sl(e.target.value)&&g(r,e.target.value)},className:`max-w-full cursor-pointer appearance-none truncate rounded-sm bg-transparent py-0.5 pr-5 text-label-14-strong [field-sizing:content] transition-colors duration-150 hover:text-heading focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-mono-400 ${i?`text-link`:`text-secondary`}`,children:ue.map(e=>(0,$.jsx)(`option`,{value:e,children:fe[e].label},e))}),(0,$.jsx)(l,{"aria-hidden":`true`,className:`pointer-events-none absolute right-0 size-3.5 ${i?`text-link`:`text-muted`}`})]}),(0,$.jsxs)(`button`,{type:`button`,role:`tab`,id:`${n}-tab-${r}`,"aria-selected":i,"aria-controls":`${n}-panel`,"aria-label":`${fe[t].label} ${s}, ${dl(e.changePct[t])}`,tabIndex:i?0:-1,onClick:()=>o(r),onKeyDown:e=>v(e,r),className:`mt-1 block w-full rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-mono-400`,children:[(0,$.jsx)(`span`,{className:`block truncate text-heading-32 tabular-nums transition-colors duration-150 ${i?`text-primary`:`text-strong`}`,title:ze(t,e.totals[t]),children:s}),(0,$.jsx)(fl,{metric:t,change:e.changePct[t]})]})]},r)})}),(0,$.jsxs)(`div`,{role:`tabpanel`,id:`${n}-panel`,"aria-labelledby":`${n}-tab-${a}`,className:`px-4 pb-3 pt-4`,children:[e.syncedAt===null&&(0,$.jsx)(`p`,{className:`mb-3 text-copy-14 text-secondary`,children:`These figures fill in after the next GA4 sync.`}),p?(0,$.jsx)(`div`,{role:`img`,"aria-label":`${fe[d].label} per day, ${h.toLowerCase()} and the previous period`,style:{height:240},children:(0,$.jsx)(R,{width:`100%`,height:`100%`,children:(0,$.jsxs)(ne,{data:f,margin:{top:8,right:0,bottom:0,left:4},children:[(0,$.jsx)(P,{stroke:ma,vertical:!1}),(0,$.jsx)(I,{dataKey:`date`,tick:da,tickLine:!1,axisLine:{stroke:ga},tickFormatter:ia,minTickGap:32}),(0,$.jsx)(z,{orientation:`right`,tick:da,tickLine:!1,axisLine:!1,width:52,allowDecimals:fe[d].unit!==Ie.count,tickFormatter:e=>ze(d,e,{compact:!0})}),(0,$.jsx)(F,{cursor:{stroke:ca.textFaint,strokeWidth:1},wrapperStyle:{outline:`none`},content:(0,$.jsx)(pl,{metric:d})}),!s.has(ol.previous)&&(0,$.jsx)(B,{type:`monotone`,dataKey:ol.previous,stroke:al,strokeOpacity:.65,strokeWidth:1.5,strokeDasharray:`4 4`,dot:!1,activeDot:{r:3,strokeWidth:0,fill:al},connectNulls:!1,isAnimationActive:u,animationDuration:320,animationEasing:`ease-out`}),!s.has(ol.current)&&(0,$.jsx)(B,{type:`monotone`,dataKey:ol.current,stroke:al,strokeWidth:2.25,dot:!1,activeDot:{r:5,strokeWidth:2,stroke:al,fill:`var(--color-bg)`},connectNulls:!1,isAnimationActive:u,animationDuration:320,animationEasing:`ease-out`})]})})}):(0,$.jsxs)(`p`,{className:`py-8 text-copy-14 text-secondary`,children:[`No daily `,fe[d].label.toLowerCase(),` yet.`]}),(0,$.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center justify-between gap-x-6 gap-y-1`,children:[(0,$.jsxs)(`fieldset`,{className:`flex flex-wrap gap-x-5 text-label-13 text-secondary`,children:[(0,$.jsx)(`legend`,{className:`sr-only`,children:`${fe[d].label} series`}),[[ol.current,h,``],[ol.previous,`Previous period`,`4 3`]].map(([e,t,n])=>{let r=!s.has(e),i=r&&s.size===1;return(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:r,disabled:i,onChange:()=>y(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:al,strokeWidth:e===ol.current?2.5:1.5,strokeDasharray:n||void 0})}),t]},e)})]}),e.current.startDate&&e.current.endDate&&e.previous.startDate&&e.previous.endDate&&(0,$.jsxs)(`p`,{className:`text-copy-13 text-secondary`,children:[hl(e.current.startDate,e.current.endDate,!0),` vs `,hl(e.previous.startDate,e.previous.endDate,!1)]})]})]})]})}function hl(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)}`}var gl=na[0],_l=na[1],vl=na[2],yl=na[3],bl=[`both`,`server`,`ga4`],xl={fontSize:12,paddingTop:6},Sl=e=>typeof e==`number`?xt(Math.round(e)):String(e),Cl=e=>typeof e==`number`&&Number.isFinite(e)?e:0;function wl(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 Tl(e,t){return n=>{let{cx:r,cy:i,index:a,key:o}=n,s=a??-1;return e[s]==null||e[s-1]!=null||e[s+1]!=null||r===void 0||i===void 0?(0,$.jsx)(`g`,{},o):(0,$.jsx)(`circle`,{cx:r,cy:i,r:2.6,fill:t,stroke:`none`},o)}}function El({projectName:e,sinceMinutes:t}){let[n,r]=(0,Q.useState)(!0),[i,a]=(0,Q.useState)(!0),[o,s]=(0,Q.useState)(`both`),c=Ds(e,{sinceMinutes:t,granularity:`day`,limit:1}),l=ws(e),u=E({...Ir({client:K,path:{name:e}}),enabled:!!e,staleTime:tr}).data?.connected===!0,d=E({...Hi({client:K,path:{name:e},query:{window:t>=129600?`90d`:t>=43200?`30d`:`7d`}}),enabled:!!e&&u,staleTime:tr}),f=(0,Q.useMemo)(()=>c.data?.series?.points??[],[c.data]),p=(0,Q.useMemo)(()=>{let e=d.data;return new Map((e?.days??[]).map(e=>[e.date,e.sessions]))},[d.data]),m=(0,Q.useMemo)(()=>{let e=e=>e.measured!==!1;if(f.length===0||e(f[0]))return null;let t=f.findIndex(e)-1;return t<0?{from:f[0].bucket,to:f[f.length-1].bucket}:{from:f[0].bucket,to:f[t].bucket}},[f]),h=c.data?.series?.coverageStart??null,g=c.data?.series?.trends,_=(0,Q.useMemo)(()=>{let e=wl(g?.crawlerContentHits,f.length),t=wl(g?.aiUserFetchHits,f.length),n=wl(g?.aiReferralLandedHits,f.length);return f.map((r,i)=>({...r,crawlerContentHits:r.measured===!1?null:Cl(r.crawlerContentHits),aiUserFetchHits:r.measured===!1?null:Cl(r.aiUserFetchHits),aiReferralLandedHits:r.measured===!1?null:Cl(r.aiReferralLandedHits),ga4Visits:p.get(r.bucket)??null,crawlTrend:e[i],fetchTrend:t[i],visitTrend:n[i]}))},[f,p,g]),v=c.data?.totals,y=v&&{crawlers:Cl(v.crawlerContentHits),fetches:Cl(v.aiUserFetchHits),visits:Cl(v.aiReferralLandedHits)},b=(0,Q.useMemo)(()=>f.reduce((e,t)=>({crawlers:e.crawlers+Cl(t.crawlerContentHits),fetches:e.fetches+Cl(t.aiUserFetchHits),visits:e.visits+Cl(t.aiReferralLandedHits)}),{crawlers:0,fetches:0,visits:0}),[f]),x=y??b,S=x.crawlers>0||x.fetches>0||x.visits>0;if(c.isLoading)return(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:`Loading AI traffic history…`});if(c.isError)return(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.`})]});if(!S){let e=l.data?.sources,t=e!==void 0&&e.length===0,n=!t&&h===null;return(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:[(0,$.jsx)(`div`,{className:`mb-5`,children:(0,$.jsx)(Yc,{label:`AI traffic totals`,items:[{label:`AI crawlers`,value:xt(x.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:xt(x.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:xt(x.visits),detail:`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.`}]})}),f.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:Cl(f[f.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:Cl(f[f.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:Cl(f[f.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:p.get(f[f.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)(R,{width:`100%`,height:206,children:(0,$.jsxs)(ne,{data:_,margin:{top:4,right:8,left:-18,bottom:0},children:[(0,$.jsx)(P,{stroke:ma,vertical:!1}),(0,$.jsx)(I,{dataKey:`bucket`,tick:da,stroke:ga,tickFormatter:ia,minTickGap:28}),(0,$.jsx)(z,{tick:da,stroke:ga,width:48,allowDecimals:!1}),(0,$.jsx)(F,{contentStyle:ha.contentStyle,labelStyle:ha.labelStyle,itemStyle:ha.itemStyle,labelFormatter:la,formatter:Sl}),m&&(0,$.jsx)(L,{x1:m.from,x2:m.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)(te,{wrapperStyle:xl,iconType:`plainline`,iconSize:14}),(0,$.jsx)(ee,{type:`monotone`,dataKey:`crawlerContentHits`,name:`Pages crawled`,stroke:gl,fill:gl,fillOpacity:.22,strokeWidth:1.8}),n&&(0,$.jsx)(ee,{type:`monotone`,dataKey:`aiUserFetchHits`,name:`Page fetches`,stroke:_l,fill:_l,fillOpacity:.18,strokeWidth:1.6}),i&&(0,$.jsx)(B,{type:`linear`,dataKey:`crawlTrend`,legendType:`none`,name:`Pages crawled trend`,dot:!1,tooltipType:`none`,stroke:gl,strokeWidth:1.4,strokeDasharray:`5 4`,connectNulls:!0}),i&&n&&(0,$.jsx)(B,{type:`linear`,dataKey:`fetchTrend`,legendType:`none`,name:`Page fetches trend`,dot:!1,tooltipType:`none`,stroke:_l,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,$.jsx)(Vc,{windows:bl,value:o,onChange:s,label:`Visit measurement source`,formatOption:e=>e===`ga4`?`GA4`:e===`both`?`Both`:`Server`})]}),(0,$.jsx)(R,{width:`100%`,height:176,children:(0,$.jsxs)(ne,{data:_,margin:{top:4,right:8,left:-18,bottom:0},children:[(0,$.jsx)(P,{stroke:ma,vertical:!1}),(0,$.jsx)(I,{dataKey:`bucket`,tick:da,stroke:ga,tickFormatter:ia,minTickGap:28}),(0,$.jsx)(z,{tick:da,stroke:ga,width:48,allowDecimals:!1}),(0,$.jsx)(F,{contentStyle:ha.contentStyle,labelStyle:ha.labelStyle,itemStyle:ha.itemStyle,labelFormatter:la,formatter:Sl}),m&&(0,$.jsx)(L,{x1:m.from,x2:m.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)(te,{wrapperStyle:xl,iconType:`plainline`,iconSize:14}),o!==`ga4`&&(0,$.jsx)(B,{type:`monotone`,dataKey:`aiReferralLandedHits`,name:`Visits, server`,stroke:vl,strokeWidth:2,dot:!1}),o!==`server`&&(0,$.jsx)(B,{type:`monotone`,dataKey:`ga4Visits`,name:`Visits, GA4`,connectNulls:!1,stroke:yl,strokeWidth:1.8,strokeDasharray:`5 3`,dot:Tl(_.map(e=>e.ga4Visits),yl)}),i&&o!==`ga4`&&(0,$.jsx)(B,{type:`linear`,dataKey:`visitTrend`,legendType:`none`,name:`Visits trend`,dot:!1,tooltipType:`none`,stroke:vl,strokeWidth:1.3,strokeDasharray:`5 4`,connectNulls:!0})]})})]})}function Dl(e){return e.replace(/\+/g,` `)}var Ol=[`7d`,`30d`,`90d`],kl={"7d":10080,"30d":43200,"90d":129600,all:129600};function Al(e){return ds(e.landingPage)}var jl=25,Ml=10,Nl={days:[],sources:[],totalSessions:0,totalPaidSessions:0,totalOrganicSessions:0,byEngine:{series:[],otherCount:0,days:[]}},Pl={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 Fl(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 Il(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toLocaleString()}function Ll(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 Rl({projectName:e}){let{data:t,isLoading:n,isError:r}=ks(e),i=t?.sources??[];return(0,$.jsxs)(`section`,{"aria-labelledby":`server-activity-heading`,children:[(0,$.jsx)(Gc,{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)(M,{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)(M,{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)(Zc,{label:`Source`,align:`left`}),(0,$.jsx)(Zc,{label:`Status`,align:`left`}),(0,$.jsx)(Zc,{label:`Crawler hits`,align:`right`}),(0,$.jsx)(Zc,{label:`AI hits`,align:`right`}),(0,$.jsx)(Zc,{label:`AI sessions`,align:`right`}),(0,$.jsx)(Zc,{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:Es(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:Ms(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?Fl(t.lastSyncedAt):`never`}),(0,$.jsx)(`td`,{className:`py-2 pl-3 text-right`,children:!Y()&&(0,$.jsx)(M,{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 zl({projectName:e}){let[t,n]=(0,Q.useState)(`30d`);return(0,$.jsxs)(`div`,{children:[(0,$.jsx)(Rl,{projectName:e}),(0,$.jsx)(`div`,{className:`page-section-divider`}),(0,$.jsx)(Jl,{projectName:e,window:t,periodControl:(0,$.jsx)(Vc,{windows:Ol,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)(Gc,{id:`ai-traffic-history-heading`,title:`AI traffic history`,tooltip:Pl.aiHistoryTooltip}),(0,$.jsx)(El,{projectName:e,sinceMinutes:kl[t]})]})]})})]})}var Bl={session:`Session`,first_user:`First visit`,manual_utm:`UTM`},Vl={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)`},Hl=[{label:`Source`,align:`left`},{label:`Medium`,align:`left`},{label:`Class`,align:`left`},{label:`Attribution`,align:`left`},{label:`Sessions`,align:`right`},{label:`Share`,align:`right`}],Ul=[{label:`Source`,align:`left`},{label:`Medium`,align:`left`},{label:`Channel`,align:`left`},{label:`Sessions`,align:`right`},{label:`Share`,align:`right`}];function Wl(e){return e.engine===null}function Gl({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:Vl[e.sourceDimension]??``,children:Bl[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:rn(e.share)})]})}function Kl({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:Dl(e.source)}),(0,$.jsx)(`td`,{className:`max-w-[160px] truncate py-1.5 pr-3 text-secondary`,title:e.medium,children:Dl(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:rn(e.share)})]})}function ql(e,t){let n=w(),[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)(Nl),[y,b]=(0,Q.useState)([]),[x,S]=(0,Q.useState)(null);async function C(r){c(!0),m(null);try{let a=await n.fetchQuery({...Ir({client:K,path:{name:e}}),staleTime:tr});if(r.current)return;if(i(a),!a.connected){o(null),v(Nl),b([]),S(null),c(!1);return}let s=t===`all`?void 0:t,[l,u,d,f]=await Promise.all([n.fetchQuery({...cr({client:K,path:{name:e},query:s?{window:s}:void 0}),staleTime:tr}),n.fetchQuery({...Hi({client:K,path:{name:e},query:s?{window:s}:void 0}),staleTime:tr}).catch(()=>Nl),n.fetchQuery({...Ji({client:K,path:{name:e},query:s?{window:s}:void 0}),staleTime:tr}).catch(()=>[]),n.fetchQuery({...Zi({client:K,path:{name:e},query:{window:Ne(t)?t:`30d`}}),staleTime:tr}).catch(()=>null)]);if(r.current)return;o(l),v(u),b(d),S(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 C(e),()=>{e.current=!0}},[e,t,n]);async function T(){u(!0),m(null),g(null);try{let t=await _n(e);g(`Synced ${t.rowCount.toLocaleString()} page rows, ${t.aiReferralCount.toLocaleString()} AI and ${t.socialReferralCount.toLocaleString()} social referral rows (${t.days} days)`),await Qn(n,`ga`),await C({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 re(e),await Qn(n,`ga`),i({connected:!1,propertyId:null,clientEmail:null,lastSyncedAt:null,createdAt:null,updatedAt:null}),o(null),S(null),g(`GA4 disconnected`)}catch(e){m(e instanceof Error?e.message:`Disconnect failed`)}finally{f(!1)}}async function D(){await Qn(n,`ga`),await C({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 Jl({projectName:e,window:t,periodControl:n,between:r}){let i=ql(e,t??`30d`);return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Yl,{ga:i,projectName:e,periodControl:n}),r,(0,$.jsx)(Xl,{ga:i,projectName:e})]})}function Yl({ga:e,projectName:t,periodControl:n}){let{status:r,traffic:i,syncing:a,disconnecting:o,handleSync:s,handleDisconnect:c}=e,l=r?.connected===!0,d=l&&!Y()&&!W(),f=i?Ll(i.windowStart,i.windowEnd):null,p;return p=e.loading&&!r?(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:`Loading traffic data…`}):l?i&&e.overview?(0,$.jsx)(ml,{overview:e.overview,refreshing:e.loading}):i?(0,$.jsx)($.Fragment,{children:(0,$.jsx)(Yc,{label:`Site traffic`,items:[{label:`Total sessions`,value:Il(i.totalSessions),detail:i.totalSessions.toLocaleString()},{label:`Organic sessions`,value:Il(i.totalOrganicSessions),detail:`${i.organicSharePctDisplay} of total`},{label:`Total users`,value:i.totalUsers===null?`n/a`:Il(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()&&!W()&&(0,$.jsxs)(q,{variant:`outline`,size:`sm`,disabled:a,onClick:Yn(s),children:[(0,$.jsx)(S,{className:`mr-1.5 size-3.5 ${a?`animate-spin`:``}`}),`Sync from GA4`]})]}):Y()||W()?(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:`No Google Analytics 4 property connected.`}):(0,$.jsx)(au,{projectName:t,onConnected:()=>{e.handleConnected()}}),(0,$.jsxs)(`section`,{"aria-labelledby":`site-traffic-heading`,children:[(0,$.jsx)(Gc,{id:`site-traffic-heading`,title:`Site traffic`,tooltip:e.overview?Pl.siteTrafficTooltip:f?`${Pl.siteTrafficFallbackTooltip} Data covers ${f}.`:Pl.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||d?(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[n,d&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(q,{variant:`outline`,size:`sm`,disabled:a,onClick:Yn(s),children:[(0,$.jsx)(S,{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:Yn(c),children:[(0,$.jsx)(u,{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}),p]})}function Xl({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=ps({rows:l,getSearchText:e=>ds(e.landingPage),pageSize:Ml}),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=ps({rows:d,getSearchText:Al,pageSize:jl}),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?Ll(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)(Gc,{id:`traffic-by-channel-heading`,title:`Traffic by channel`,tooltip:Pl.channelTooltip,meta:g}),(0,$.jsx)(Yc,{label:`Sessions by channel`,items:[{label:`Organic search`,value:_.organic.sharePctDisplay,detail:`${_.organic.sessions.toLocaleString()} sessions`,tooltip:Pl.organicTooltip},{label:`Social`,value:_.social.sharePctDisplay,detail:`${_.social.sessions.toLocaleString()} sessions`,tooltip:Pl.socialTooltip},{label:`Direct`,value:_.direct.sharePctDisplay,detail:`${_.direct.sessions.toLocaleString()} sessions`,tooltip:Pl.directTooltip},{label:`AI (at least)`,value:_.ai.sharePctDisplay,detail:v>0?`${_.ai.sessions.toLocaleString()} sessions · ${v.toLocaleString()} paid`:`${_.ai.sessions.toLocaleString()} sessions`,tooltip:Pl.aiTooltip},{label:`Other channels`,value:_.other.sharePctDisplay,detail:`${_.other.sessions.toLocaleString()} sessions`,tooltip:Pl.otherTooltip}]}),(0,$.jsxs)(Kc,{children:[(0,$.jsx)(qc,{label:Pl.aiChartLabel,meta:r.days.length>0?Zl(r.totalSessions,`session`):Pl.noneInPeriod,children:r.days.length>0?(0,$.jsx)(nl,{input:r.byEngine,baseline:p,baselineLabel:`Total sessions`,label:Pl.aiChartLabel}):(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:Pl.noAiReferrals})}),(0,$.jsx)(qc,{label:`Where AI visitors came from`,meta:y.length>0?`${Zl(y.filter(e=>e.engine!==null).length,`engine`)} · ${Zl(n.aiReferrals.length,`source`)}`:Pl.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)(el,{groups:y,groupLabel:`Engine`,caption:`AI referral sessions by engine`,childColumns:Hl,childRowKey:e=>`${e.source}:${e.medium}:${e.sourceDimension}:${e.trafficClass}`,renderChildCells:e=>(0,$.jsx)(Gl,{row:e}),pinLast:Wl})}),(0,$.jsx)(X,{text:Pl.aiEnginesTooltip})]}):(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:Pl.noAiReferrals})}),(0,$.jsx)(qc,{label:`Pages AI visitors landed on`,meta:S??Pl.noneInPeriod,children:n.aiReferralLandingPages.length>0?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(us,{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)(Xc,{label:`Landing page`,sortKey:`landingPage`,current:s.key,dir:s.dir,onSort:h,align:`left`}),(0,$.jsx)(Xc,{label:`Source`,sortKey:`source`,current:s.key,dir:s.dir,onSort:h,align:`left`}),(0,$.jsx)(Zc,{label:`Attribution`,align:`left`}),(0,$.jsx)(Xc,{label:`Sessions`,sortKey:`sessions`,current:s.key,dir:s.dir,onSort:h,align:`right`})]})}),(0,$.jsx)(`tbody`,{children:f.rows.map(e=>(0,$.jsx)(su,{row:e},`${e.landingPage}:${e.source}:${e.medium}:${e.sourceDimension}`))})]})}),(0,$.jsx)(fs,{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:Pl.noAiLandingPages})})]})]}),(0,$.jsx)(`div`,{className:`page-section-divider`}),(0,$.jsxs)(`section`,{"aria-labelledby":`social-heading`,children:[(0,$.jsx)(Gc,{id:`social-heading`,title:`Social`,tooltip:Pl.socialTooltip2,meta:g}),(0,$.jsx)(Yc,{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:Pl.platformsTooltip},{label:`Paid social`,value:(n.paidSocialSessions??0).toLocaleString(),detail:`${rn(n.paidSocialShare??0)} of social`,tooltip:Pl.paidSocialTooltip},{label:`Top platform`,value:x?.label??`None`,detail:x?`${x.sessions.toLocaleString()} sessions`:void 0}]}),(0,$.jsxs)(Kc,{children:[(0,$.jsx)(qc,{label:Pl.socialChartLabel,meta:b.length>0?Zl(n.socialSessions,`session`):Pl.noneInPeriod,children:b.length>0?(0,$.jsx)(nl,{input:n.socialPlatformDaily,label:Pl.socialChartLabel}):(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:Pl.noSocial})}),(0,$.jsx)(qc,{label:`Social platforms`,meta:b.length>0?`${Zl(b.length,`platform`)} · ${Zl(n.socialReferrals.length,`source`)}`:Pl.noneInPeriod,children:b.length>0?(0,$.jsx)(el,{groups:b,groupLabel:`Platform`,caption:`Social sessions by platform`,childColumns:Ul,childRowKey:e=>`${e.source}:${e.medium}:${e.channelGroup}`,renderChildCells:e=>(0,$.jsx)(Kl,{row:e})}):(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:Pl.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)(Gc,{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)(us,{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)(Xc,{label:`Landing page`,sortKey:`landingPage`,current:a.key,dir:a.dir,onSort:m,align:`left`}),(0,$.jsx)(Xc,{label:`Sessions`,sortKey:`sessions`,current:a.key,dir:a.dir,onSort:m,align:`right`}),(0,$.jsx)(Xc,{label:`Organic`,sortKey:`organicSessions`,current:a.key,dir:a.dir,onSort:m,align:`right`}),(0,$.jsx)(Zc,{label:`Organic share`,align:`right`})]})}),(0,$.jsx)(`tbody`,{children:u.rows.map(e=>(0,$.jsx)(ou,{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)(fs,{page:u.page,pageSize:u.pageSize,visibleRows:u.rows.length,totalRows:u.totalRows,onPageChange:u.setPage,itemLabel:u.hasQuery?`matches`:`pages`})]})]}),(0,$.jsx)(iu,{projectName:t}),(0,$.jsx)(`p`,{className:`mt-6 text-copy-13 text-secondary`,children:n?.lastSyncedAt?`Last synced ${Fl(n.lastSyncedAt)}`:`Never synced`})]})}function Zl(e,t){return`${e.toLocaleString()} ${e===1?t:`${t}s`}`}var Ql=25,$l=`n/a`,eu={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 tu(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 nu(e){return e===null?$l:e.toFixed(1)}function ru(e){return e===null?$l:rn(e)}function iu({projectName:e}){let[t,n]=(0,Q.useState)(`28d`),[r,i]=(0,Q.useState)(`clicks`),[a,o]=(0,Q.useState)(`desc`),s=E({...$r({client:K,path:{name:e},query:{window:t,limit:qt}}),staleTime:tr}),c=s.data,l=(0,Q.useMemo)(()=>[...c?.rows??[]].sort((e,t)=>{let n=tu(e,r),i=tu(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=ps({rows:l,getSearchText:e=>ds(U(e.landingPage)),pageSize:Ql});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()&&!W();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:eu.heading}),(0,$.jsx)(X,{text:eu.tooltip})]}),c?.windowStart&&c.windowEnd&&(0,$.jsxs)(`p`,{className:`text-copy-14 text-secondary mt-1`,children:[fn(c.windowStart),` to `,fn(c.windowEnd),c.timeZone?` (${c.timeZone})`:``]})]}),(0,$.jsx)(Vc,{windows:ae,value:t,onChange:e=>{u.setPage(1),n(e)},label:eu.windowLabel})]}),s.isPending?(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary py-6 text-center`,children:eu.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:eu.loadError}),(0,$.jsx)(q,{variant:`outline`,size:`sm`,onClick:()=>{s.refetch()},children:eu.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:eu.notLinkedBadge}),(0,$.jsx)(X,{text:eu.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:eu.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:eu.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:eu.thresholdedBadge}),(0,$.jsx)(X,{text:eu.thresholded})]}),c.status!==`ready`&&f&&c.syncedAt&&(0,$.jsxs)(`span`,{className:`text-label-14 text-secondary`,children:[eu.previousSnapshot,` `,Fl(c.syncedAt),`.`]}),c.status===`unavailable`&&f&&(0,$.jsx)(`p`,{className:`w-full text-copy-14 text-secondary`,children:eu.unavailableAction})]}),f?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(us,{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)(Xc,{label:`Landing page`,sortKey:`landingPage`,current:r,dir:a,onSort:d,align:`left`}),(0,$.jsx)(Xc,{label:`Clicks`,sortKey:`clicks`,current:r,dir:a,onSort:d,align:`right`}),(0,$.jsx)(Xc,{label:`Impressions`,sortKey:`impressions`,current:r,dir:a,onSort:d,align:`right`}),(0,$.jsx)(Xc,{label:`CTR`,sortKey:`ctr`,current:r,dir:a,onSort:d,align:`right`}),(0,$.jsx)(Xc,{label:`Avg. position`,sortKey:`position`,current:r,dir:a,onSort:d,align:`right`}),(0,$.jsx)(Xc,{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:[eu.totalLabel,` `,(0,$.jsx)(`span`,{className:`text-label-14 text-secondary`,children:eu.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:ru(f.organicGoogleSearchClickThroughRate)}),(0,$.jsx)(`td`,{className:`py-1.5 pl-4 text-right text-primary tabular-nums`,children:nu(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:U(e.landingPage),children:U(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:ru(e.organicGoogleSearchClickThroughRate)}),(0,$.jsx)(`td`,{className:`py-1.5 pl-4 text-right text-secondary tabular-nums`,children:nu(e.organicGoogleSearchAveragePosition)}),(0,$.jsx)(`td`,{className:`py-1.5 pl-4 text-right text-secondary tabular-nums`,children:e.activeUsers.toLocaleString()})]},e.landingPage))]})]})}),!he(f)&&!p&&(0,$.jsxs)(`div`,{className:`text-label-14 text-secondary mt-3 space-y-1`,children:[(0,$.jsx)(`p`,{children:eu.noSearchTraffic}),(0,$.jsx)(`p`,{children:c.searchConsoleLink?.state===`no-search-data`?eu.noSearchTrafficConfirmed:eu.noSearchTrafficAction})]}),u.totalRows===0&&u.hasQuery&&(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary mt-3`,children:c.totalRows>c.rows.length?eu.noFilterMatchInLoaded(c.rows.length):eu.noFilterMatch}),(0,$.jsx)(fs,{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 `,Fl(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:eu.unavailable}),(0,$.jsx)(`p`,{children:eu.unavailableAction})]}):c.status===`error`?(0,$.jsxs)(`div`,{className:`text-label-14 text-secondary space-y-1`,children:[(0,$.jsx)(`p`,{className:`text-neutral`,children:eu.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:eu.neverSynced}),m&&(0,$.jsx)(`p`,{children:eu.neverSyncedAction})]})})]})]})]})}function au({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 wt(e,{propertyId:n.trim(),keyJson:o});try{await _n(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)(_,{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:Yn(m),children:c?`Connecting & syncing…`:`Connect GA4`})]})}function ou({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:rn(e.organicShare)})]})}function su({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)(ls,{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:Vl[e.sourceDimension]??``,children:Bl[e.sourceDimension]??e.sourceDimension}),(0,$.jsx)(`td`,{className:`py-1.5 pl-4 text-right text-primary tabular-nums`,children:e.sessions.toLocaleString()})]})}function cu(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 lu=`Search Console is not connected yet. Your Canonry team can set this up.`,uu=[`7d`,`30d`,`90d`,`all`],du=500,fu=[{key:`clicks`,label:`Clicks`,color:na[1],format:e=>e.toLocaleString()},{key:`impressions`,label:`Impressions`,color:na[4],format:e=>e.toLocaleString()},{key:`ctr`,label:`CTR`,color:fa.caution,format:e=>rn(e)},{key:`position`,label:`Avg position`,color:na[2],inverted:!0,format:e=>e.toFixed(1)}],pu=25,mu=`canonry:google-oauth-complete`;function hu(e,t,n){if(!e)return`no comparison period`;let r=e.days;if(!e.comparable)return`property-level comparison unavailable`;let i=e.change[t];if(i===null||!Number.isFinite(i)){let n=e.prior[t],i=e.trailing[t];return n!==null&&i!==null&&n<=0&&i>0?`new in the last ${r}d`:n===null||n<=0?`no prior ${r}d to compare`:i===null?`no value in the last ${r}d`:`comparison unavailable`}return i===0?`→ no change vs prior ${r}d`:`${(n?i<0:i>0)?`↑`:`↓`} ${rn(Math.abs(i))} vs prior ${r}d`}function gu(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 _u(e){return e.contents?.reduce((e,t)=>e+Number(t.submitted||0),0)??0}function vu(e){let t=Number(e.errors??0),n=Number(e.warnings??0);return[t>0?`${t} error${t===1?``:`s`}`:``,n>0?`${n} warning${n===1?``:`s`}`:``].filter(Boolean).join(` · `)}function yu(e){return e.isPending?`Processing`:Number(e.errors??0)>0?`Errors`:Number(e.warnings??0)>0?`Warnings`:`Success`}function bu({projectName:e,refreshNonce:t}){let n=w(),{isAdmin:r}=Jn(),i=W(),[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,S]=(0,Q.useState)(``),[C,T]=(0,Q.useState)(``),[E,D]=(0,Q.useState)(`30`),[O,k]=(0,Q.useState)(!1),[A,j]=(0,Q.useState)(`30d`),[N,P]=(0,Q.useState)([`clicks`,`impressions`]),[F,I]=(0,Q.useState)(!0),[L,R]=(0,Q.useState)(null),[ee,te]=(0,Q.useState)(0),[z,B]=(0,Q.useState)({startDate:``,endDate:``,query:``,page:``}),[ne,V]=(0,Q.useState)(0),[H,re]=(0,Q.useState)(!1),[ie,ae]=(0,Q.useState)(0),[oe,se]=(0,Q.useState)(!1),[le,ue]=(0,Q.useState)(``),[de,fe]=(0,Q.useState)(!0),[pe,me]=(0,Q.useState)(!1),[he,ge]=(0,Q.useState)(!1),[_e,ve]=(0,Q.useState)(!1),[ye,be]=(0,Q.useState)(!1),[xe,Se]=(0,Q.useState)(!1),[Ce,we]=(0,Q.useState)(!1),[U,Te]=(0,Q.useState)(null),[Ee,De]=(0,Q.useState)(!1),[Oe,ke]=(0,Q.useState)(!1),[Ae,je]=(0,Q.useState)(null),[Me,Ne]=(0,Q.useState)(null),[Pe,Fe]=(0,Q.useState)([]),[Ie,Le]=(0,Q.useState)(new Set),[Re,ze]=(0,Q.useState)({}),[Be,Ve]=(0,Q.useState)(new Set),[He,Ue]=(0,Q.useState)(``),[We,Ge]=(0,Q.useState)(null),[Ke,qe]=(0,Q.useState)(``),[Je,Ye]=(0,Q.useState)(!1),[Xe,Ze]=(0,Q.useState)(!1),[Qe,tt]=(0,Q.useState)(!1),[it,ot]=(0,Q.useState)(!1),[st,G]=(0,Q.useState)(`indexed`),[ct,lt]=(0,Q.useState)(null),ut=!!(z.query.trim()||z.page.trim()||ct),dt=ct!==null,ft=(0,Q.useMemo)(()=>{if(!ct)return d;let{key:e,dir:t}=ct;return[...d].sort((n,r)=>{let i=e===Hn.CTR?Number.isFinite(n.ctr)?n.ctr:0:n[e],a=e===Hn.CTR?Number.isFinite(r.ctr)?r.ctr:0:r[e];return t===`asc`?i-a:a-i})},[d,ct]),pt=ps({rows:ft,pageSize:25}),mt=oe?pt.rows:ft,ht=ps({rows:(Ae??[]).filter(e=>e.path.toLowerCase().includes(He.trim().toLowerCase())),pageSize:25}),[gt,_t]=(0,Q.useState)([]),[vt,bt]=(0,Q.useState)(null),[xt,St]=(0,Q.useState)(1),Ct=(0,Q.useMemo)(()=>{if(gt.length<2)return null;let e=gt[gt.length-1],t=gt[gt.length-2];return{indexed:e.indexed-t.indexed,notIndexed:e.notIndexed-t.notIndexed}},[gt]);(0,Q.useEffect)(()=>{St(1)},[U,st,vt]);let wt=(0,Q.useMemo)(()=>vt?(U?.reasonGroups??[]).find(e=>e.reason===vt):void 0,[U,vt]),Tt=(0,Q.useMemo)(()=>U?st===`indexed`?U.indexed:st===`deindexed`?U.deindexed:st===`notIndexed`?vt?wt?.urls??[]:(U.reasonGroups??[]).length===0?U.notIndexed:[]:[]:[],[U,st,vt,wt]),Et=Math.max(1,Math.ceil(Tt.length/pu)),Dt=Math.min(Math.max(1,xt),Et),Ot=(Dt-1)*pu,kt=(0,Q.useMemo)(()=>U?.indexed.slice(Ot,Ot+pu)??[],[U,Ot]),jt=(0,Q.useMemo)(()=>U?.notIndexed.slice(Ot,Ot+pu)??[],[U,Ot]),Mt=(0,Q.useMemo)(()=>U?.deindexed.slice(Ot,Ot+pu)??[],[U,Ot]),Nt=(0,Q.useMemo)(()=>(wt?.urls??[]).slice(Ot,Ot+pu),[wt,Ot]),[Pt,Ft]=(0,Q.useState)(!1),[It,Lt]=(0,Q.useState)(null),[Rt,zt]=(0,Q.useState)(null),[Bt,Vt]=(0,Q.useState)(null),[Ht,Ut]=(0,Q.useState)(null);function Wt(e,t){let n=Os(e),r=cu(n);r?(zt(r),Lt(null)):(zt(null),Lt(n.message||t))}let Gt=s.find(e=>e.connectionType===`gsc`),Kt=(Gt?.scopes??[]).includes(`https://www.googleapis.com/auth/webmasters`),qt=Pe.length>0?Pe:(Ae??[]).map(e=>e.path),Jt=qt.filter(e=>Ae?.some(t=>t.path===e&&t.isSitemapsIndex)).length,Yt=Jt===1?`Resubmit sitemap index`:Jt>1?`Resubmit sitemap indexes`:`Resubmit all sitemaps`,Xt=d.length>0||h.length>0||_.length>0,Zt=as(),Qt=yo();async function $t(t,r=!1){if(i)u([]);else if(!t)u([]),S(``);else{ge(!0);try{let{sites:i}=await n.fetchQuery({...br({client:K,path:{name:e}}),staleTime:r?0:$n});u(i),S(t.propertyId??i[0]?.siteUrl??``),zt(null)}catch(e){u([]),Wt(e,`Failed to load Search Console properties`)}finally{ge(!1)}}}async function tn(t){be(!0);let r=t??ne;try{let t=ut?du:25,i=ut?0:r,a={limit:String(t)};z.startDate&&(a.startDate=z.startDate),z.endDate&&(a.endDate=z.endDate),z.query&&(a.query=z.query),z.page&&(a.page=z.page),i>0&&(a.offset=String(i)),A&&A!==`all`&&!z.startDate&&(a.window=A);let o=await n.fetchQuery({...sr({client:K,path:{name:e},query:a}),staleTime:$n}),s=o.rows;ut?(re(!1),f(s),ae(s.length),se(!0)):(re(i+s.length<o.totalMatching),f(s),ae(0),se(!1))}catch(e){f([]),re(!1),ae(0),Lt(e instanceof Error?e.message:`Failed to load GSC performance data`)}finally{be(!1)}}async function nn(){try{let t={};z.startDate&&(t.startDate=z.startDate),z.endDate&&(t.endDate=z.endDate),A&&A!==`all`&&!z.startDate&&(t.window=A);let r=await n.fetchQuery({...ea({client:K,path:{name:e},query:t}),staleTime:$n});m(r)}catch{m(null)}}async function an(t=!1){Se(!0);try{let r=le.trim()||void 0,i={limit:`20`};r&&(i.url=r);let[a,o]=await Promise.all([n.fetchQuery({...Fr({client:K,path:{name:e},query:i}),staleTime:t?0:$n}),n.fetchQuery({...wr({client:K,path:{name:e}}),staleTime:t?0:$n})]);g(a),v(o)}catch(e){g([]),v([]),Lt(e instanceof Error?e.message:`Failed to load GSC inspection history`)}finally{Se(!1)}}async function on(t=!1){De(!0);try{let[r,i]=await Promise.all([n.fetchQuery({...xr({client:K,path:{name:e}}),staleTime:t?0:$n}),n.fetchQuery({..._r({client:K,path:{name:e}}),staleTime:t?0:$n}).catch(()=>[])]);Te(r),_t(i)}catch(e){Te(null),_t([]),Lt(e instanceof Error?e.message:`Failed to load coverage data`)}finally{De(!1)}}async function sn(t){Ft(!0),Lt(null);try{let{succeeded:n,failed:r,total:i}=(await $e(e,{urls:t})).summary;Zn({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){Lt(e instanceof Error?e.message:`Failed to request indexing`)}finally{Ft(!1)}}async function cn(){Ft(!0),Lt(null);try{let{succeeded:t,failed:n,total:r}=(await $e(e,{urls:[],allUnindexed:!0})).summary;Zn({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){Lt(e instanceof Error?e.message:`Failed to request indexing`)}finally{Ft(!1)}}async function ln(){ke(!0),Lt(null);try{let t=await rt(e);n.setQueryData(Ur({client:K,path:{name:e}}),t),je(t.sitemaps),Ne(t.summary),Fe(t.preferredSubmissionUrls),Le(new Set),ze({}),t.sitemaps.length===0&&Vt(`No sitemaps found in this GSC property. Submit one here to start Google processing it.`)}catch(e){Lt(e instanceof Error?e.message:`Failed to list sitemaps`)}finally{ke(!1)}}async function un(t){let n=Ie.has(t);if(Le(e=>{let r=new Set(e);return n?r.delete(t):r.add(t),r}),!(n||Re[t])){Ve(e=>new Set(e).add(t));try{let n=await rt(e,t);ze(e=>({...e,[t]:n.sitemaps}))}catch(e){Lt(e instanceof Error?e.message:`Failed to load sitemap files`)}finally{Ve(e=>{let n=new Set(e);return n.delete(t),n})}}}async function dn(t){if(!Kt||t.length===0)return;let n=[...new Set(t)];Ze(!0),Lt(null),Ge({completed:0,total:n.length});let r=0,i=0,a=0,o=null;try{for(let t=0;t<n.length;t+=50){let s=n.slice(t,t+50);try{let t=await en(e,s);r+=t.summary.accepted,i+=t.summary.failed,a+=s.length,Ge({completed:a,total:n.length})}catch(t){a+=s.length;let c=s.length,l=n.length-a,u=t instanceof Error?t.message:`The batch request failed`,d=`${r} accepted, ${i} failed, ${c} unconfirmed, ${l} not attempted. Google may still process accepted sitemaps; indexing is not guaranteed.`;o=`Sitemap submission stopped after a batch request failed. ${d} ${u}`,Lt(o),Zn({title:`Sitemap resubmission partially completed`,detail:d,tone:`caution`,dedupeKey:`gsc:sitemap-submit:${e}`,dedupeMode:`replace`});return}}let t=n.length;Zn({title:i===0?`Sitemap submitted to Google`:`Some sitemap submissions need attention`,detail:i===0?`Google accepted the sitemap submission/refetch request; indexing is not guaranteed.`:`Google accepted ${r}/${t} sitemap submissions; ${i} failed. Indexing is not guaranteed.`,tone:i===0?`positive`:`caution`,dedupeKey:`gsc:sitemap-submit:${e}`,dedupeMode:`replace`}),qe(``)}catch(e){Lt(e instanceof Error?e.message:`Failed to submit sitemap to Google`)}finally{Ze(!1),Ge(null),await ln(),o&&Lt(o)}}async function fn(){Ze(!0);let t=Ae??[];try{let n=t.filter(e=>e.isSitemapsIndex),r=[];for(let t=0;t<n.length;t+=4)(await Promise.all(n.slice(t,t+4).map(async t=>{let n=Re[t.path];if(n)return n;let r=await rt(e,t.path);return ze(e=>({...e,[t.path]:r.sitemaps})),r.sitemaps}))).forEach((e,i)=>{r.push(...e.length>0?e.map(e=>e.path):[n[t+i].path])});await dn([...t.filter(e=>!e.isSitemapsIndex).map(e=>e.path),...r])}catch(e){Lt(e instanceof Error?e.message:`Failed to load sitemap files`),Ze(!1)}}async function pn(t){Ye(!0),Lt(null);try{await nt(e,`gsc`,t),await Qn(n,`google`),c(e=>e.map(e=>e.connectionType===`gsc`?{...e,sitemapUrl:t}:e)),Zn({title:`Default sitemap updated`,detail:t,tone:`positive`,dedupeKey:`gsc:sitemap-default:${e}`,dedupeMode:`replace`})}catch(e){Lt(e instanceof Error?e.message:`Failed to set the default sitemap`)}finally{Ye(!1)}}async function hn(t){try{await Qt.mutateAsync({projectName:e,projectLabel:e,opts:t?{sitemapUrl:t}:void 0})}catch{}}async function gn(){try{let t=(await n.fetchQuery({...$i({client:K,path:{name:e},query:{kind:wn[`gsc-sync`],limit:1}}),staleTime:$n}))[0];Ut(t?.status===et.failed&&t.error?`Last saved Search Console sync failed: ${ce(t.error)}`:null)}catch{Ut(`Saved Search Console sync status is unavailable.`)}}async function _n(){fe(!0),Lt(null);try{let[t,a]=await Promise.all([i||!r?Promise.resolve(null):mn().catch(()=>null),n.fetchQuery({...Mr({client:K,path:{name:e}}),staleTime:$n}).catch(()=>[])]);o(!!t?.google?.configured),c(a);let s=a.find(e=>e.connectionType===`gsc`);S(s?.propertyId??``),await Promise.all([!i&&s&&!s.propertyId?$t(s):Promise.resolve(),!i&&s?gn():Promise.resolve(),tn(),nn(),an(),on()])}finally{fe(!1)}}(0,Q.useEffect)(()=>{u([]),tt(!1),je(null),Ne(null),Fe([]),Ut(null),zt(null),Vt(null)},[e]),(0,Q.useEffect)(()=>{_n()},[e,t,r]),(0,Q.useEffect)(()=>{V(0),R(null),B(e=>e.startDate||e.endDate?{...e,startDate:``,endDate:``}:e),te(e=>e+1),nn()},[A]);let yn=(0,Q.useRef)(!1);(0,Q.useEffect)(()=>{yn.current?(V(0),pt.setPage(1),tn(0)):yn.current=!0},[ee]);function bn(e){let t=L===e?null:e;R(t),B(e=>({...e,startDate:t??``,endDate:t??``})),te(e=>e+1)}let xn=(0,Q.useRef)(!1);(0,Q.useEffect)(()=>{xn.current?(V(0),tn(0)):xn.current=!0},[dt]);async function Cn(){if(!a)Lt(`Google OAuth app credentials are not configured yet. Set them on the Settings page first.`);else{me(!0),Lt(null),Vt(null);try{let{authUrl:t,redirectUri:r}=await Sn(e,`gsc`);if(!t.startsWith(`https://accounts.google.com/`)){Lt(`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(),Vt(e?`Google connected. Refreshing access…`:`Refreshing Google connection…`);try{await Qn(n,`google`),await _n()}finally{Vt(null)}}};function u(e){if(e.source!==i||e.origin!==a||!e.data||typeof e.data!=`object`)return;let t=e.data;t.type===mu&&t.connectionType===`gsc`&&l(!0)}window.addEventListener(`message`,u),Vt(`Finish the Google consent flow in the popup. This page will refresh automatically.`),s=window.setInterval(()=>{i.closed&&l(!1)},1e3)}catch(e){Lt(e instanceof Error?e.message:`Failed to start OAuth flow`)}finally{me(!1)}}}async function Tn(){Lt(null),Vt(null);try{await At(e,`gsc`),await Qn(n,`google`),c(e=>e.filter(e=>e.connectionType!==`gsc`)),u([]),S(``)}catch(e){Lt(e instanceof Error?e.message:`Failed to disconnect`)}}async function Y(){if(x){ve(!0),Lt(null);try{await at(e,`gsc`,x),await Qn(n,`google`),c(e=>e.map(e=>e.connectionType===`gsc`?{...e,propertyId:x}:e)),Zn({title:`GSC property updated`,detail:`${e} is now linked to ${x}.`,tone:`positive`,dedupeKey:`gsc:property:${e}`,dedupeMode:`drop`})}catch(e){Lt(e instanceof Error?e.message:`Failed to save GSC property`)}finally{ve(!1)}}}async function En(){Lt(null),Vt(null);try{await Zt.mutateAsync({projectName:e,projectLabel:e,opts:{days:parseInt(E,10)||void 0,full:O||void 0}}),await Qn(n,`gsc`)}catch{}}async function Dn(){if(C.trim()){we(!0),Lt(null),Vt(null);try{let t=await yt(e,C.trim());await Qn(n,`gsc`),b(t),T(``),await an()}catch(e){Lt(e instanceof Error?e.message:`Failed to inspect URL`)}finally{we(!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`})]})}),Ht&&(0,$.jsx)(`p`,{role:`status`,className:`mb-3 text-copy-14 text-caution`,children:Ht}),Rt&&(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:Rt.title}),(0,$.jsx)(`p`,{className:`mt-0.5 text-caution-200/90`,children:Rt.message}),(Ko(Rt.enableUrl)||Ko(Rt.indexingApiUrl))&&(0,$.jsxs)(`div`,{className:`mt-2 flex flex-wrap gap-3`,children:[Ko(Rt.enableUrl)&&(0,$.jsx)(`a`,{href:Ko(Rt.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 ↗`}),Ko(Rt.indexingApiUrl)&&(0,$.jsx)(`a`,{href:Ko(Rt.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:()=>zt(null),children:`×`})]})}),It&&(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:[It,(0,$.jsx)(`button`,{type:`button`,className:`ml-2 text-negative-400 hover:text-negative-200`,onClick:()=>Lt(null),children:`×`})]}),Bt&&(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:[Bt,(0,$.jsx)(`button`,{type:`button`,className:`ml-2 text-positive-400 hover:text-positive-200`,onClick:()=>Vt(null),children:`×`})]}),de?(0,$.jsx)(`p`,{className:`text-copy-14 text-muted`,children:`Loading…`}):(0,$.jsxs)(`div`,{className:`space-y-3`,children:[Gt?(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:Gt.domain}),(0,$.jsx)(`span`,{className:`text-mono-700`,children:`·`}),(0,$.jsxs)(`span`,{children:[`Coverage measured`,` `,U?.lastInspectedAt?Pn(U.lastInspectedAt):`never`]}),!i&&(0,$.jsx)(`button`,{type:`button`,className:`ml-auto text-muted transition-colors hover:text-negative-400`,onClick:Yn(Tn),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:pe,onClick:Yn(Cn),children:pe?`Opening…`:`Connect Google Search Console`}):(0,$.jsx)(q,{type:`button`,variant:`outline`,size:`sm`,asChild:!0,children:(0,$.jsx)(M,{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:lu})}),(Gt||Xt)&&(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:`${gu(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 ${du.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)(Vc,{windows:uu,value:A,onChange:e=>{j(e),V(0),pt.setPage(1)},label:`Search Console time period`,formatOption:e=>e===`all`?`All`:e}),(0,$.jsx)(q,{type:`button`,variant:`outline`,size:`sm`,disabled:ye,onClick:()=>{V(0),pt.setPage(1),tn(0),nn()},children:ye?`Loading…`:`Apply filters`})]})]}),p&&p.daily.length>0&&(()=>{let{totals:e,daily:t,trends:n,periodComparison:r}=p,i=fu.filter(e=>N.includes(e.key)).map(e=>({dataKey:e.key,label:e.label,color:e.color,axisId:e.key,inverted:e.inverted,formatValue:e.format,trend:F?n?.[e.key]??null:null})),a=t=>e[t]??null,o=new Map(t.map(e=>[e.date,e])),s=t.length===0?[]:vn(t[0].date,t[t.length-1].date).map(e=>o.get(e)??{date:e});return(0,$.jsxs)(`div`,{className:`mt-3`,children:[(0,$.jsx)(`div`,{className:`grid grid-cols-2 gap-2 sm:grid-cols-4`,children:fu.map(e=>{let t=N.includes(e.key),n=a(e.key),i=n===null;return(0,$.jsxs)(`button`,{type:`button`,"aria-pressed":t,disabled:i,className:`rounded-md border px-3 py-2 text-left transition-colors ${t?`border-strong bg-surface-active`:`border-subtle bg-surface-subtle hover:bg-surface-hover`} ${i?`cursor-not-allowed opacity-50`:``}`,onClick:()=>{P(t=>t.includes(e.key)?t.length===1?t:t.filter(t=>t!==e.key):[...t,e.key])},children:[(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:`inline-block h-2 w-2 rounded-full`,style:{backgroundColor:t?e.color:`transparent`,border:`1px solid ${e.color}`}}),(0,$.jsx)(`span`,{className:`text-label-12 text-secondary`,children:e.label})]}),(0,$.jsx)(`span`,{className:`mt-0.5 block text-label-18 tabular-nums text-strong`,children:n===null?`—`:e.format(n)}),(0,$.jsx)(`span`,{className:`block text-label-12 tabular-nums text-muted`,children:hu(r,e.key,e.inverted)})]},e.key)})}),(0,$.jsx)(`div`,{className:`mt-2 flex items-center justify-end`,children:(0,$.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-1.5 text-label-12 text-secondary`,children:[(0,$.jsx)(`input`,{type:`checkbox`,className:`accent-mono-400`,checked:F,onChange:e=>I(e.target.checked)}),`Trend line`]})}),(0,$.jsx)(`div`,{className:`mt-1`,children:(0,$.jsx)(ra,{data:s,xKey:`date`,series:i,xTickFormatter:ia,labelFormatter:la,onSelectX:bn,selectedX:L})}),(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":L===e.date,onClick:()=>bn(e.date),children:[la(e.date),`: `,e.clicks,` clicks, `,e.impressions,` impressions`]},e.date))}),L&&(0,$.jsxs)(`div`,{className:`mt-1 flex items-center gap-2 text-label-12`,children:[(0,$.jsxs)(`span`,{className:`text-secondary`,children:[`Table showing `,la(L)]}),(0,$.jsxs)(`button`,{type:`button`,className:`text-link hover:underline`,onClick:()=>bn(L),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:z.startDate,onChange:e=>B(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:z.endDate,onChange:e=>B(t=>({...t,endDate:e.target.value}))}),(0,$.jsx)(us,{value:z.query,onChange:e=>B(t=>({...t,query:e})),label:`Filter search queries`,placeholder:`Contains query…`}),(0,$.jsx)(us,{value:z.page,onChange:e=>B(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(Hn).map(e=>(0,$.jsx)(`th`,{className:`text-right`,"aria-sort":ct?.key===e?ct.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:()=>{pt.setPage(1),lt(t=>t?.key===e?t.dir===`desc`?{key:e,dir:`asc`}:null:{key:e,dir:`desc`})},children:[Un[e],ct?.key===e?ct.dir===`desc`?` ↓`:` ↑`:``]})},e))]})}),(0,$.jsx)(`tbody`,{children:mt.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)(ls,{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:rn(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)(fs,{page:oe?pt.page:Math.floor(ne/25)+1,pageSize:25,visibleRows:mt.length,totalRows:oe?ie:void 0,hasNextPage:oe?void 0:H,disabled:ye,itemLabel:oe?`matches`:`rows`,onPageChange:e=>{if(oe){pt.setPage(e);return}let t=(e-1)*25;V(t),tn(t)}}),oe&&ie>=du?(0,$.jsxs)(`p`,{className:`mt-2 text-copy-13 text-muted`,children:[`Results are capped at `,du.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:[U&&U.notIndexed.length>0&&(0,$.jsx)(q,{type:`button`,variant:`outline`,size:`sm`,disabled:Pt,onClick:()=>void cn(),children:Pt?`Requesting…`:`Request indexing (${U.notIndexed.length})`}),(0,$.jsx)(q,{type:`button`,variant:`outline`,size:`sm`,disabled:Ee,onClick:()=>void on(!0),children:Ee?`Loading…`:`Reload saved coverage`})]})]}),U&&U.summary.total>0?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`mt-6 flex flex-col items-center`,children:(()=>{let e=U.summary.indexedShare??0,t=U.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:ca.trackSubtle,strokeWidth:`14`}),(0,$.jsx)(`circle`,{cx:`64`,cy:`64`,r:54,fill:`none`,stroke:fa.positiveDeep,strokeWidth:`14`,strokeDasharray:n,strokeDashoffset:r,strokeLinecap:`round`,transform:`rotate(-90 64 64)`,style:{transition:`stroke-dashoffset 0.6s ease`}}),U.summary.notIndexed>0&&(0,$.jsx)(`circle`,{cx:`64`,cy:`64`,r:54,fill:`none`,stroke:ca.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:rn(U.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:U.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:U.summary.notIndexed.toLocaleString()}),(0,$.jsxs)(`p`,{className:`text-label-12 normal-case text-muted`,children:[`Not indexed`,(U.reasonGroups??[]).length>0&&(0,$.jsxs)(`span`,{className:`ml-1 text-faint`,children:[`· `,(U.reasonGroups??[]).length,` `,(U.reasonGroups??[]).length===1?`reason`:`reasons`]})]})]})]}),U.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:U.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`?U.indexed.length:e===`notIndexed`?U.notIndexed.length:U.deindexed.length;return(0,$.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":st===e,className:`border-b-2 px-3 py-2 text-button-14 transition-colors ${st===e?`border-accent text-heading`:`border-transparent text-secondary hover:border-mono-600 hover:text-strong`}`,onClick:()=>{G(e),bt(null)},children:[e===`indexed`?`Indexed`:e===`notIndexed`?`Not Indexed`:`Deindexed`,` (`,t,`)`]},e)})}),(0,$.jsxs)(`div`,{className:`mt-3 overflow-x-auto`,children:[st===`indexed`&&U.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:kt.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))})]}),st===`notIndexed`&&!vt&&(U.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:(U.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:()=>bt(e.reason),onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),bt(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))})]}),st===`notIndexed`&&!vt&&(U.reasonGroups??[]).length===0&&U.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:jt.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))})]}),st===`notIndexed`&&vt&&(()=>{let e=(U.reasonGroups??[]).find(e=>e.reason===vt);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:()=>bt(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:Pt,onClick:()=>void sn(e.urls.map(e=>e.url)),children:Pt?`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:Nt.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:Pt,onClick:()=>void sn([e.url]),title:`Request indexing`,children:`Index`})})]},e.id))})]})]}):null})(),st===`deindexed`&&U.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:Mt.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}`))})]}),(st===`indexed`&&U.indexed.length===0||st===`notIndexed`&&!vt&&U.notIndexed.length===0||st===`deindexed`&&U.deindexed.length===0)&&(0,$.jsx)(`p`,{className:`text-copy-14 text-muted`,children:`No URLs in this category.`}),(0,$.jsx)(fs,{page:Dt,pageSize:pu,visibleRows:Math.min(pu,Tt.length-Ot),totalRows:Tt.length,onPageChange:St,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":it,onClick:()=>ot(e=>!e),children:[(0,$.jsx)(`span`,{children:`Coverage history`}),(0,$.jsx)(`span`,{children:it?`Hide snapshots`:gt.length>0?`View ${gt.length} snapshots`:`View history`})]}),(0,$.jsxs)(`p`,{className:`mt-1 text-copy-13 text-muted`,children:[`Current: `,U.summary.indexed.toLocaleString(),` indexed, `,U.summary.notIndexed.toLocaleString(),` not indexed.`,Ct&&(0,$.jsxs)($.Fragment,{children:[` Since the last snapshot: `,Ct.indexed>=0?`+`:``,Ct.indexed.toLocaleString(),` indexed, `,Ct.notIndexed>=0?`+`:``,Ct.notIndexed.toLocaleString(),` not indexed.`]})]}),it&&(0,$.jsx)(`div`,{className:`mt-3 overflow-x-auto`,children:gt.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:gt.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:Ee?`Loading coverage data…`:`No coverage data yet. Inspect your sitemap to populate this view.`})]}),!i&&(0,$.jsxs)($.Fragment,{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:`Sitemaps`}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`h3`,{children:`Sitemap operations`}),(0,$.jsx)(X,{text:`Submitting asks Google to refetch these sitemaps. Indexing is not guaranteed.`})]})]}),(0,$.jsx)(q,{type:`button`,variant:`outline`,size:`sm`,disabled:Oe||!Gt?.propertyId,onClick:()=>void ln(),children:Oe?`Loading…`:Ae===null?`Load from Google`:`Reload from Google`})]}),(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/sitemap.xml`,value:Ke,onChange:e=>qe(e.target.value),onKeyDown:e=>e.key===`Enter`&&void dn([Ke.trim()])}),(0,$.jsx)(q,{type:`button`,size:`sm`,disabled:!Kt||Xe||!Ke.trim(),onClick:()=>void dn([Ke.trim()]),children:Xe?`Submitting…`:`Submit sitemap to Google`})]}),(0,$.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(q,{type:`button`,size:`sm`,variant:`outline`,disabled:!Kt||Xe||qt.length===0,onClick:()=>void dn(qt),children:Xe?`Resubmitting…`:Yt}),(0,$.jsx)(q,{type:`button`,size:`sm`,variant:`outline`,disabled:!Kt||Xe||!Ae?.length,onClick:()=>void fn(),children:`Resubmit all files`}),Me&&(0,$.jsxs)(`span`,{className:`text-label-12 text-muted`,children:[`Top level: `,Me.indexes,` index`,Me.indexes===1?``:`es`,`, `,Me.files,` file`,Me.files===1?``:`s`]}),We&&(0,$.jsxs)(`span`,{className:`text-label-12 text-secondary`,children:[`Submitting `,We.completed,`/`,We.total]})]}),!Kt&&Gt&&(0,$.jsxs)(`div`,{className:`mt-2 flex items-center gap-2 text-label-12 text-caution`,children:[(0,$.jsx)(`span`,{children:`Reconnect to let Canonry submit sitemaps. Your current Canonry OAuth grant is read-only.`}),(0,$.jsx)(`button`,{type:`button`,className:`text-secondary underline hover:text-strong`,onClick:Yn(Cn),children:`Reconnect`})]}),Ae===null&&(0,$.jsx)(`p`,{className:`mt-3 text-copy-14 text-secondary`,children:`Load sitemaps from Google to view them and enable resubmission.`}),Ae&&(0,$.jsx)(`div`,{className:`mt-3 overflow-x-auto`,children:Ae.length>0?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(us,{value:He,onChange:e=>{Ue(e),ht.setPage(1)},label:`Filter sitemaps`,placeholder:`Filter sitemaps…`}),(0,$.jsxs)(`table`,{className:`data-table mt-3 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:`Type`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Google status`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Last submitted`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Last read`}),(0,$.jsx)(`th`,{className:`text-right`,children:`Discovered URLs`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Issues`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Actions`})]})}),(0,$.jsx)(`tbody`,{children:ht.rows.flatMap(e=>{let t=_u(e),n=vu(e),r=yu(e),i=Re[e.path]??[],a=Ie.has(e.path);return[(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{className:`max-w-xs text-strong`,children:(0,$.jsx)(ls,{value:e.path})}),(0,$.jsx)(`td`,{className:`text-secondary`,children:e.isSitemapsIndex?(0,$.jsx)(`button`,{type:`button`,className:`text-secondary hover:text-strong`,"aria-expanded":a,"aria-label":`${a?`Collapse`:`Expand`} files in ${e.path}`,onClick:()=>void un(e.path),children:Be.has(e.path)?`Loading…`:`${a?`▾`:`▸`} Index${Re[e.path]?` (${i.length})`:``}`}):`Sitemap`}),(0,$.jsx)(`td`,{className:`text-secondary`,children:r}),(0,$.jsx)(`td`,{className:`text-secondary`,children:e.lastSubmitted?e.lastSubmitted.split(`T`)[0]:`—`}),(0,$.jsx)(`td`,{className:`text-secondary`,children:e.lastDownloaded?e.lastDownloaded.split(`T`)[0]:`—`}),(0,$.jsx)(`td`,{className:`text-right tabular-nums text-neutral`,children:t.toLocaleString()}),(0,$.jsx)(`td`,{className:`max-w-48 text-secondary`,children:n||`—`}),(0,$.jsx)(`td`,{children:(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,$.jsx)(`button`,{type:`button`,className:`text-button-14 text-secondary hover:text-strong`,disabled:!Kt||Xe,onClick:()=>void dn([e.path]),children:e.lastSubmitted?`Resubmit to Google`:`Submit to Google`}),Gt?.sitemapUrl===e.path?(0,$.jsx)(`span`,{className:`text-label-12 text-muted`,title:`Used when no sitemap URL is provided for Canonry GSC operations.`,children:`Default sitemap`}):(0,$.jsx)(`button`,{type:`button`,className:`text-button-14 text-secondary hover:text-strong`,disabled:Je,title:`Use this sitemap by default for Canonry GSC operations.`,onClick:()=>void pn(e.path),children:`Set as default`}),(0,$.jsx)(`button`,{type:`button`,className:`text-button-14 text-secondary hover:text-strong`,disabled:Qt.isPending,onClick:()=>void hn(e.path),children:`Inspect URLs`})]})})]},e.path),...e.isSitemapsIndex&&a?i.map(t=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{className:`max-w-xs pl-6 text-secondary`,children:(0,$.jsx)(ls,{value:t.path})}),(0,$.jsx)(`td`,{className:`text-secondary`,children:`File`}),(0,$.jsx)(`td`,{className:`text-secondary`,children:yu(t)}),(0,$.jsx)(`td`,{className:`text-secondary`,children:t.lastSubmitted?t.lastSubmitted.split(`T`)[0]:`—`}),(0,$.jsx)(`td`,{className:`text-secondary`,children:t.lastDownloaded?t.lastDownloaded.split(`T`)[0]:`—`}),(0,$.jsx)(`td`,{className:`text-right tabular-nums text-neutral`,children:_u(t).toLocaleString()}),(0,$.jsx)(`td`,{className:`text-secondary`,children:vu(t)||`—`}),(0,$.jsx)(`td`,{children:(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,$.jsx)(`button`,{type:`button`,className:`text-button-14 text-secondary hover:text-strong`,disabled:!Kt||Xe,onClick:()=>void dn([t.path]),children:`Resubmit`}),Gt?.sitemapUrl===t.path?(0,$.jsx)(`span`,{className:`text-label-12 text-muted`,title:`Used when no sitemap URL is provided for Canonry GSC operations.`,children:`Default sitemap`}):(0,$.jsx)(`button`,{type:`button`,className:`text-button-14 text-secondary hover:text-strong`,disabled:Je,title:`Use this sitemap by default for Canonry GSC operations.`,onClick:()=>void pn(t.path),children:`Set as default`}),(0,$.jsx)(`button`,{type:`button`,className:`text-button-14 text-secondary hover:text-strong`,disabled:Qt.isPending,onClick:()=>void hn(t.path),children:`Inspect URLs`})]})})]},`${e.path}:${t.path}`)):[]]})})]}),(0,$.jsx)(fs,{page:ht.page,pageSize:25,visibleRows:ht.rows.length,totalRows:ht.totalRows,onPageChange:ht.setPage,itemLabel:`sitemaps`})]}):(0,$.jsx)(`p`,{className:`text-copy-14 text-muted`,children:`No sitemaps found for this 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:`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:C,onChange:e=>T(e.target.value),onKeyDown:e=>e.key===`Enter`&&void Dn()}),(0,$.jsx)(q,{type:`button`,size:`sm`,disabled:Ce||!Gt?.propertyId||!C.trim(),onClick:Yn(Dn),children:Ce?`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:Bn(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:Pn(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:xe,onClick:()=>void an(!0),children:xe?`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:le,onChange:e=>ue(e.target.value)}),(0,$.jsx)(q,{type:`button`,size:`sm`,variant:`outline`,disabled:xe,onClick:()=>void an(!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:Bn(e.isMobileFriendly??null)}),(0,$.jsx)(`td`,{className:`text-secondary`,children:Pn(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:Pn(e.transitionDate)})]},`${e.url}:${e.transitionDate}`))})]})}):(0,$.jsx)(`p`,{className:`mt-3 text-copy-14 text-muted`,children:`No deindexed transitions recorded.`})]})]}),Gt&&!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:()=>{Qe||$t(Gt),tt(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 ${Qe?`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`})]})}),Qe&&(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:he||l.length===0,onChange:e=>S(e.target.value),children:l.length===0?(0,$.jsx)(`option`,{value:``,children:he?`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:he,onClick:()=>void $t(Gt,!0),children:he?`Refreshing…`:`Refresh properties`}),(0,$.jsx)(q,{type:`button`,size:`sm`,disabled:!x||_e,onClick:Yn(Y),children:_e?`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:E,onChange:e=>D(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:O,onChange:e=>k(e.target.checked)}),`Replace existing imported rows for the requested range`]})]}),(0,$.jsx)(q,{type:`button`,size:`sm`,disabled:Zt.isPending||!Gt.propertyId,onClick:Yn(En),children:Zt.isPending?`Queueing…`:`Queue sync`}),!Gt.propertyId&&(0,$.jsx)(`p`,{className:`text-copy-13 text-caution-400`,children:`Select a Search Console property before queueing a sync.`})]})]})]})})]})]})]})}var xu=new Set([`gbp-listing-discrepancy`,`gbp-lodging-gap`,`gbp-cta-gap`,`gbp-metric-drop`,`gbp-keyword-drop`]);function Su({projectName:e,projectId:t}){let n=w(),[r,i]=(0,Q.useState)(null),[a,o]=(0,Q.useState)(null),[s,c]=(0,Q.useState)(!1),l=E(Mr({client:K,path:{name:e}})),u=l.data?.find(e=>e.connectionType===`gbp`),d=!!u,f=r?{locationName:r}:void 0,p=E({...zr({client:K,path:{name:e}}),enabled:d}),m=E({...vi({client:K,path:{name:e},query:f}),enabled:d}),h=E({...Gi({client:K,path:{name:e},query:f}),enabled:d}),g=E({...mr({client:K,path:{name:e},query:f}),enabled:d}),_=E({...dr({client:K,path:{name:e},query:f}),enabled:d}),v=E({...kr({client:K,path:{name:e},query:f}),enabled:d}),y=E({queryKey:[`gbp-section-insights`,e],queryFn:()=>ye(e),enabled:d});function b(){Qn(n,`gbp`)}let x=T({...li(),onSuccess:n=>{Ho({id:n.runId,projectId:t,kind:wn[`gbp-sync`],projectLabel:e,sourceAction:`gbp-sync`}),Zn({title:`Business Profile sync started`,detail:`${e} will refresh when the sync completes.`,tone:`neutral`,dedupeKey:`gbp-sync:${e}`,dedupeMode:`replace`})}}),S=(0,Q.useSyncExternalStore)(Zo,ya,ya),C=Object.values(S.runs).some(e=>e.kind===wn[`gbp-sync`]&&e.projectId===t),D=x.isPending||C,O=T({...Ki(),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)),z=P.filter(e=>ee.has(e.locationName)),B=F.filter(e=>ee.has(e.locationName)),ne=new Set(j.map(e=>e.locationName)),V=r?M:M.filter(e=>ne.has(e.locationName)),H=!r&&j.length>1,re=(y.data??[]).filter(e=>!e.dismissed&&xu.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)(ss,{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:[re.length>0&&(0,$.jsxs)(`div`,{className:`mb-6 grid gap-2`,children:[(0,$.jsx)(`p`,{className:`eyebrow eyebrow-soft`,children:`Needs attention`}),re.map(e=>(0,$.jsx)(`div`,{className:[`surface-card insight-card`,zu(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)(qu,{performance:k.performance,freshness:k.freshness,timeseries:k.timeseries}),k?.profileCompleteness&&(0,$.jsx)(Cu,{summary:k.profileCompleteness}),R.length>0&&(0,$.jsx)(wu,{locations:R,lodging:te,places:B,placeActions:z,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:[rn(h.data.thresholdedPct,On.percent),` privacy-thresholded`]})]}),V.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`}),H&&(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:V.slice(0,25).map(e=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{className:`text-neutral`,children:e.keyword}),H&&(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)(ss,{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 Cu({summary:e}){if(e.locationCount===0)return null;let t=e.locationCount,n=[{label:`Description`,value:`${e.withDescription}/${t}`,tone:Lu(e.withDescription,t,`caution`)},{label:`Hours`,value:`${e.withHours}/${t}`,tone:Lu(e.withHours,t,`caution`)},{label:`Phone`,value:`${e.withPrimaryPhone}/${t}`,tone:Lu(e.withPrimaryPhone,t,`caution`)},{label:`Service area`,value:`${e.withServiceArea}/${t}`,tone:Lu(e.withServiceArea,t,`neutral`)},{label:`Secondary categories`,value:`${e.withSecondaryCategories}/${t}`,detail:`${e.secondaryCategoryTotal} total`,tone:Lu(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 ${Ru(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 wu({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:Vu(e.openStatus)})]})]})}),(0,$.jsx)(`td`,{children:(0,$.jsx)(Eu,{location:e})}),(0,$.jsx)(`td`,{children:(0,$.jsx)(Du,{lodging:t})}),(0,$.jsx)(`td`,{children:(0,$.jsx)(ku,{place:n,mapsUri:e.mapsUri})}),(0,$.jsx)(`td`,{children:(0,$.jsx)(ju,{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)(Pu,{location:e,lodging:t,place:n,placeActions:r})})})]},e.id)})})]})})]})}function Tu(e){return[{label:`Description`,tone:Bu(e.description)?`positive`:`neutral`,value:Bu(e.description)?`set`:`not returned`},{label:`Hours`,tone:e.regularHours?`positive`:`neutral`,value:e.regularHours?`set`:`not returned`},{label:`Phone`,tone:Bu(e.primaryPhone)?`positive`:`neutral`,value:Bu(e.primaryPhone)?`set`:`not returned`},{label:`Website`,tone:Bu(e.websiteUri)?`positive`:`neutral`,value:Bu(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 Eu({location:e}){let t=Tu(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 Du({lodging:e}){return(0,$.jsx)(Nu,{...Ou(e)})}function Ou(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 ku({place:e,mapsUri:t}){return(0,$.jsx)(Nu,{...Au(e,t)})}function Au(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 ju({actions:e}){return(0,$.jsx)(Nu,{...Mu(e)})}function Mu(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 Nu({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 Pu({location:e,lodging:t,place:n,placeActions:r}){let i=t?Gu(t.attributes):[];return(0,$.jsxs)(`div`,{className:`grid gap-5 text-label-12 lg:grid-cols-3`,children:[(0,$.jsxs)(Fu,{title:`Owner profile · Business Information`,children:[(0,$.jsx)(Iu,{label:`Primary category`,value:e.primaryCategoryDisplayName??`Not returned`}),(0,$.jsx)(Iu,{label:`Secondary categories`,value:e.additionalCategories.length>0?e.additionalCategories.join(`, `):`Not returned`}),(0,$.jsx)(Iu,{label:`Description`,value:Bu(e.description)?e.description:`Not returned`}),(0,$.jsx)(Iu,{label:`Hours`,value:e.regularHours?`Returned by Google`:`Not returned`}),(0,$.jsx)(Iu,{label:`Service area`,value:e.serviceArea?`Returned by Google`:`Not returned`}),(0,$.jsx)(Iu,{label:`Phone`,value:e.primaryPhone??`Not returned`}),(0,$.jsx)(Iu,{label:`Website`,value:e.websiteUri??`Not returned`}),(0,$.jsx)(Iu,{label:`Open status`,value:Vu(e.openStatus)}),(0,$.jsx)(Iu,{label:`Opening date`,value:e.openingDate??`Not returned`})]}),(0,$.jsx)(Fu,{title:`Hotel data · Lodging API`,children:t?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Iu,{label:`Last checked`,value:Wu(t.syncedAt)}),(0,$.jsx)(Iu,{label:`Groups returned`,value:String(t.populatedGroupCount)}),(0,$.jsx)(Iu,{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)(Fu,{title:`Public listing + CTAs`,children:[n?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Iu,{label:`Places tier`,value:n.tier}),(0,$.jsx)(Iu,{label:`Last checked`,value:Wu(n.syncedAt)}),(0,$.jsx)(Iu,{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:[Hu(e.placeActionType),e.isPreferred?` · preferred`:``]}),(0,$.jsxs)(`span`,{className:`text-faint`,children:[Hu(e.providerType),e.uri?` · ${Uu(e.uri)}`:``]})]},e.placeActionLinkName))})})]})]})}function Fu({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 Iu({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 Lu(e,t,n){return e===t?`positive`:e===0?n:`caution`}function Ru(e){switch(e){case`positive`:return`text-positive`;case`caution`:return`text-caution`;case`negative`:return`text-negative`;case`neutral`:return`text-neutral`}}function zu(e){return e===`critical`||e===`high`?`insight-card-negative`:e===`medium`?`insight-card-caution`:``}function Bu(e){return typeof e==`string`&&e.trim().length>0}function Vu(e){return e?Hu(e):`Not returned`}function Hu(e){return e?e.toLowerCase().split(`_`).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `):`Unknown`}function Uu(e){try{return new URL(e).hostname.replace(/^www\./,``)}catch{return e}}function Wu(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString(void 0,{month:`short`,day:`numeric`,year:`numeric`})}function Gu(e){return Object.entries(e).filter(([e,t])=>e!==`name`&&e!==`metadata`&&Ku(t)).map(([e])=>Hu(e.replace(/([a-z])([A-Z])/g,`$1_$2`)))}function Ku(e){return e==null?!1:Array.isArray(e)?e.length>0:typeof e!=`object`||Object.keys(e).length>0}function qu({performance:e,freshness:t,timeseries:n}){let r=e.totals,i=Re.filter(e=>(r[e]??0)>0),a=Ke.filter(e=>(r[e]??0)>0),o=Object.keys(r).filter(e=>(r[e]??0)>0&&me(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 ${la(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)(Ju,{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:[we(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)(Ju,{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=>we(e)).join(`, `)]})]})}function Ju({data:e,metrics:t,kind:n,firstPending:r,lastDate:i}){return(0,$.jsx)(`div`,{className:`h-48 w-full`,children:(0,$.jsx)(R,{width:`100%`,height:`100%`,children:(0,$.jsxs)(ne,{data:e,margin:{top:8,right:8,bottom:0,left:0},children:[(0,$.jsx)(P,{stroke:ma,vertical:!1}),(0,$.jsx)(I,{dataKey:`date`,tick:da,tickLine:!1,axisLine:{stroke:ga},tickFormatter:ia,minTickGap:24}),(0,$.jsx)(z,{tick:da,tickLine:!1,axisLine:!1,allowDecimals:!1,width:36}),(0,$.jsx)(F,{...ha,labelFormatter:la,formatter:(e,t)=>[typeof e==`number`?e.toLocaleString():String(e??0),we(String(t??``))]}),(0,$.jsx)(te,{wrapperStyle:{fontSize:12,color:ca.text},formatter:e=>we(e)}),r&&i&&(0,$.jsx)(L,{x1:r,x2:i,fill:ca.surface,fillOpacity:.55,stroke:`none`,label:{value:`pending`,position:`insideTopRight`,fill:ca.textDim,fontSize:12}}),t.map((e,t)=>n===`line`?(0,$.jsx)(B,{type:`monotone`,dataKey:e,stroke:na[t%na.length],strokeWidth:2,dot:!1,isAnimationActive:!1},e):(0,$.jsx)(ee,{type:`monotone`,dataKey:e,stackId:`reach`,stroke:na[t%na.length],fill:na[t%na.length],fillOpacity:.25,strokeWidth:1.5,isAnimationActive:!1},e))]})})})}function Yu(e){return ua(sa(String(e)))}function Xu(e){return aa(sa(String(e)))}var Zu=25;function Qu(e){return typeof window>`u`?e:`${window.__CANONRY_CONFIG__?.basePath?.replace(/\/$/,``)??``}${e}`}function $u(e){return e.toLocaleString()}function ed(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 td(e){let t=e.filter(e=>e.kind===wn[`backlink-extract`]&&!Eo(e.status));return t.length===0?null:t.reduce((e,t)=>e.createdAt>t.createdAt?e:t)}function nd(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 rd({projectName:e}){let a=W(),[o,c]=(0,Q.useState)(null),[l,u]=(0,Q.useState)(null),[d,f]=(0,Q.useState)([]),[p,m]=(0,Q.useState)(null),[h,g]=(0,Q.useState)(null),[_,v]=(0,Q.useState)(null),[y,b]=(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,r,i,a]=await Promise.all([ot().catch(()=>null),Ce(e,{excludeCrawlers:!0}).catch(()=>null),Ge(e,{limit:Zu,offset:x,excludeCrawlers:!0}).catch(e=>{if(e instanceof bt&&e.code===`NOT_FOUND`)return null;throw e}),pe(e).catch(()=>[]),ke(e).catch(()=>[])]);m(t),c(n),u(r),f(i);let o=td(a);g(o)}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(!h)return;let e=h.id,t=!1,n=async()=>{try{let n=await ft(e);if(t)return;Eo(n.status)?(g(null),v(n),await k()):g(e=>e?.id===n.id?{...e,...n}:e)}catch{}},r=window.setInterval(()=>{n()},3e3);return()=>{t=!0,window.clearInterval(r)}},[h,k]),(0,Q.useEffect)(()=>{if(!h)return;let e=window.setInterval(()=>b(Date.now()),1e3);return()=>window.clearInterval(e)},[h]),(0,Q.useEffect)(()=>{if(!_||_.status===`failed`)return;let e=window.setTimeout(()=>v(null),1e4);return()=>window.clearTimeout(e)},[_]);async function A(){E(!0),O(null);try{let t=await St(e);g(t)}catch(e){e instanceof bt&&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=(0,Q.useMemo)(()=>d.slice().sort((e,t)=>e.queriedAt.localeCompare(t.queriedAt)).map(e=>({date:e.queriedAt,linkingDomains:e.totalLinkingDomains})),[d]),M=l?.rows??[],N=l?.total??0,P=o?.excludedLinkingDomains??0,L=Math.floor(x/Zu)+1;return(0,Q.useEffect)(()=>{x>0&&x>=N&&S(0)},[x,N]),(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})}),h&&(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:h.status}),(0,$.jsxs)(`span`,{className:`text-label-14 text-secondary tabular-nums`,children:[nd(h.startedAt??null,h.createdAt),` elapsed · refreshing every 3s`]}),(0,$.jsxs)(`span`,{className:`sr-only`,children:[`now=`,y]})]}),(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary mt-1`,children:`Refreshing this project from the current Common Crawl release.`})]})]})}),_&&!h&&(0,$.jsx)(Z,{className:`surface-card p-4 mb-4 ${_.status===`failed`?`bg-negative-soft`:`bg-positive-soft`}`,children:(0,$.jsxs)(`div`,{className:`flex items-start gap-3`,children:[_.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)(r,{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 ${_.status===`failed`?`text-negative`:`text-positive`}`,children:_.status===`failed`?`Extract failed`:`Extract complete`}),_.error?(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary mt-1`,children:Gn(_.error)}):_.status===`failed`?null:(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary mt-1`,children:`Backlinks refreshed from the cached release.`})]})]})}),te()]});function te(){return C?(0,$.jsx)(Z,{className:`surface-card p-6`,children:(0,$.jsx)(`p`,{className:`text-copy-14 text-muted`,children:`Loading backlinks…`})}):B()}function B(){let e=o!==null&&o.totalLinkingDomains>0,r=_?.status===`failed`,i=o!==null&&o.totalLinkingDomains===0&&!r,c=p?.status===`ready`,l=p?.status===`failed`,u=p&&(p.status===`downloading`||p.status===`querying`||p.status===`queued`);return e?V((0,$.jsxs)($.Fragment,{children:[!Y()&&!a&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(q,{type:`button`,variant:`outline`,size:`sm`,disabled:T||h!==null,onClick:Yn(A),children:[(0,$.jsx)(s,{className:`h-4 w-4 mr-1.5`,"aria-hidden":!0}),h?`Extract running…`:T?`Queuing…`:`Re-run extract`]}),(0,$.jsx)(hs,{label:`About re-running`,children:`Re-queries the current release for this project without downloading it again.`})]}),!Y()&&!a&&(0,$.jsx)(q,{asChild:!0,type:`button`,variant:`outline`,size:`sm`,children:(0,$.jsx)(`a`,{href:Qu(`/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)(n,{className:`h-5 w-5`,"aria-hidden":!0})}),(0,$.jsxs)(`div`,{className:`flex-1`,children:[!p&&(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()&&!a&&(0,$.jsx)(`div`,{className:`mt-4`,children:(0,$.jsx)(q,{asChild:!0,type:`button`,size:`sm`,children:(0,$.jsx)(`a`,{href:Qu(`/backlinks`),children:`Set up backlinks`})})})]}),u&&(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 (`,p.status,p.phaseDetail?` — ${p.phaseDetail}`:``,`). Backlinks will appear here once it finishes.`]}),!Y()&&!a&&(0,$.jsx)(`div`,{className:`mt-4`,children:(0,$.jsx)(q,{asChild:!0,type:`button`,variant:`outline`,size:`sm`,children:(0,$.jsx)(`a`,{href:Qu(`/backlinks`),children:`View sync status`})})})]}),l&&(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:p.error??`The workspace release sync failed. Retry from the Backlinks admin page.`}),!Y()&&!a&&(0,$.jsx)(`div`,{className:`mt-4`,children:(0,$.jsx)(q,{asChild:!0,type:`button`,size:`sm`,children:(0,$.jsx)(`a`,{href:Qu(`/backlinks`),children:`Go to Backlinks admin`})})})]}),c&&!u&&!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:p.release}),` is ready. Run an extract for this project.`]}),!Y()&&!a&&(0,$.jsxs)(`div`,{className:`mt-4 flex items-center gap-3 flex-wrap`,children:[(0,$.jsxs)(q,{type:`button`,size:`sm`,disabled:T||h!==null,onClick:Yn(A),children:[(0,$.jsx)(t,{className:`h-4 w-4 mr-1.5`,"aria-hidden":!0}),h?`Extract running…`:T?`Queuing…`:`Run extract`]}),(0,$.jsx)(hs,{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()&&!a&&(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:Qu(`/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 `,o.targetDomain,`. Try a newer release or re-run this extract.`]}),!Y()&&!a&&(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:Qu(`/backlinks`),children:`Go to Backlinks admin`})}),(0,$.jsxs)(q,{type:`button`,variant:`outline`,size:`sm`,disabled:T||h!==null,onClick:Yn(A),children:[(0,$.jsx)(t,{className:`h-4 w-4 mr-1.5`,"aria-hidden":!0}),h?`Extract running…`:T?`Queuing…`:`Re-run extract`]}),(0,$.jsxs)(hs,{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:o.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 V(e){if(!o)return null;let t=`linking hosts`,n=`release`;return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`gauge-row`,children:[(0,$.jsxs)(`div`,{className:`metric-card`,children:[(0,$.jsx)(`p`,{className:`metric-card-eyebrow`,children:`Referring domains`}),(0,$.jsx)(`p`,{className:`metric-card-big-value`,children:(0,$.jsx)(`span`,{className:`text-primary`,children:$u(o.totalLinkingDomains)})}),(0,$.jsxs)(`p`,{className:`metric-card-sub`,children:[`unique domains linking to `,o.targetDomain]})]}),(0,$.jsxs)(`div`,{className:`metric-card`,children:[(0,$.jsxs)(`p`,{className:`metric-card-eyebrow`,children:[`Total `,t]}),(0,$.jsx)(`p`,{className:`metric-card-big-value`,children:(0,$.jsx)(`span`,{className:`text-primary`,children:$u(o.totalHosts)})}),(0,$.jsxs)(`p`,{className:`metric-card-sub`,children:[`aggregate `,t,` across referring domains`]})]}),(0,$.jsxs)(`div`,{className:`metric-card`,children:[(0,$.jsx)(`p`,{className:`metric-card-eyebrow`,children:`Top-10 concentration`}),(0,$.jsx)(`p`,{className:`metric-card-big-value`,children:(0,$.jsx)(`span`,{className:`text-primary`,children:rn(Number(o.top10HostsShare))})}),(0,$.jsxs)(`p`,{className:`metric-card-sub`,children:[`share of `,t,` from the 10 largest linking domains`]})]})]}),(0,$.jsxs)(`p`,{className:`text-copy-13 text-muted mt-2`,children:[(0,$.jsx)(`span`,{className:`text-secondary`,children:`Common Crawl`}),` · `,n,` `,(0,$.jsx)(`code`,{className:`text-secondary`,children:o.release}),` · queried `,ed(o.queriedAt),P>0&&(0,$.jsxs)($.Fragment,{children:[` · `,P,` excluded domain`,P===1?``:`s`]})]}),j.length>=2&&(0,$.jsxs)(Z,{className:`surface-card p-4 mt-4`,children:[(0,$.jsx)(`p`,{className:`eyebrow eyebrow-soft`,children:`Referring domains over time`}),(0,$.jsx)(`div`,{className:`h-40 mt-2`,children:(0,$.jsx)(R,{width:`100%`,height:`100%`,children:(0,$.jsxs)(ne,{data:j,margin:{top:8,right:12,bottom:0,left:12},children:[(0,$.jsx)(`defs`,{children:(0,$.jsxs)(`linearGradient`,{id:`bl-gradient`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,$.jsx)(`stop`,{offset:`0%`,stopColor:na[0],stopOpacity:.4}),(0,$.jsx)(`stop`,{offset:`100%`,stopColor:na[0],stopOpacity:0})]})}),(0,$.jsx)(I,{dataKey:`date`,tick:da,stroke:`var(--chart-axis, #2e2e2e)`,tickFormatter:Yu}),(0,$.jsx)(z,{tick:da,stroke:`var(--chart-axis, #2e2e2e)`,allowDecimals:!1}),(0,$.jsx)(F,{contentStyle:ha.contentStyle,labelStyle:ha.labelStyle,itemStyle:ha.itemStyle,labelFormatter:Xu}),(0,$.jsx)(ee,{type:`monotone`,dataKey:`linkingDomains`,name:`Referring domains`,stroke:na[0],fill:`url(#bl-gradient)`,strokeWidth:2})]})})})]}),(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:[M.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:$u(e.numHosts)})]},e.linkingDomain)),M.length===0&&(0,$.jsx)(`tr`,{children:(0,$.jsx)(`td`,{className:`px-4 py-4 text-label-14 text-muted`,colSpan:2,children:P>0&&N===0?`Every referring domain in this ${n} was a crawler/proxy host (${P} hidden).`:`No referring domains in this ${n}.`})})]})]})}),(0,$.jsx)(fs,{page:L,pageSize:Zu,visibleRows:M.length,totalRows:N,onPageChange:e=>S((e-1)*Zu)})]}),(0,$.jsx)(`div`,{className:`mt-4 flex items-center gap-3 flex-wrap`,children:e})]})}}var id={[G[`keyword-metrics`]]:`Search demand`,[G[`domain-intelligence`]]:`Domain comparison`,[G[`ranked-keywords`]]:`Searches you rank for`,[G[`market-rankings`]]:`Market rankings`,[G[`competitor-discovery`]]:`Organic competitors`,[G[`keyword-gaps`]]:`Search gaps`},ad={[je.shared]:`Shared`,[je.missing]:`Missing`,[je.outranked]:`Competitor ahead`},od=`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.`,sd={[H.queued]:`Queued`,[H.running]:`Refreshing`,[H.completed]:`Completed`,[H.partial]:`Partial results`,[H.failed]:`Failed`,[H.cancelled]:`Cancelled`,[H[`reconciliation-required`]]:`Needs review`},cd=25,ld=new Intl.NumberFormat(`en-US`,{maximumFractionDigits:1}),ud=new Intl.NumberFormat(`en-US`,{style:`currency`,currency:`USD`,maximumFractionDigits:2}),dd=Intl.DateTimeFormat().resolvedOptions().timeZone,fd=`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`,pd=`px-4 py-3 text-right align-top tabular-nums whitespace-nowrap`,md=`min-w-56 px-4 py-3 text-left align-top text-label-14`,hd=`Position on the page, counting maps and other blocks`;function gd(e){return e?.status===H.queued||e?.status===H.running}function _d({value:e,currency:t=!1}){return e===null?(0,$.jsx)(`span`,{className:`text-muted`,"aria-label":`Not supplied`,children:`—`}):(0,$.jsx)($.Fragment,{children:t?ud.format(e):ld.format(e)})}function vd({status:e}){let t=e===H.completed?`positive`:e===H.failed?`negative`:e===H.partial||e===H[`reconciliation-required`]?`caution`:`neutral`;return(0,$.jsx)(J,{tone:t,children:sd[e]})}function yd(e){let t=pn(e).split(`/`).at(-1)??e,n=tn.safeParse(t.replaceAll(`_`,`-`));return n.success?id[n.data]:t.replaceAll(/[-_]/g,` `)}function bd(e){return e===`mobile`?`phone results`:e===`desktop`?`computer results`:`device not specified by source`}function xd(e){return e.capabilities.includes(G[`market-rankings`])?`Market locations`:`Location ${e.locationCode}`}function Sd(e){return e.capabilities.includes(G[`market-rankings`])?`searches`:`tasks`}function Cd(e){return e.capability!==G[`market-rankings`]||![H.queued,H.running,H.completed].includes(e.status)}function wd(e,t){let n=e.capabilities.includes(G[`market-rankings`]);return`${t} ${t===1?n?`search`:`task`:Sd(e)}`}function Td(e,t){return Number.isFinite(Date.parse(e))?$t(Bt(e,t)):null}var Ed={[H.failed]:`Latest refresh failed`,[H.cancelled]:`Latest refresh cancelled`,[H[`reconciliation-required`]]:`Latest refresh needs review`};function Dd(e,t){let n=e&&e.id!==t?.id?Ed[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=`${wd(t,t.failedTasks)} failed`,n=t.capabilities.includes(G[`market-rankings`])?`Their queries show as Failed.`:`Open Activity for details.`;return{label:e,text:`${e}: ${t.failedTasks} of ${wd(t,t.taskCount)} in this refresh returned no results. ${n}`}}return t.status===H.partial?{label:`Partial results`,text:`Partial results: ${t.error??`some ${Sd(t)} returned only part of their results or did not run. Open Activity for details.`}`}:null}function Od({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:yd(e.dataset)})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`dt`,{className:`text-muted`,children:`Search engine`}),(0,$.jsxs)(`dd`,{children:[`Google · `,bd(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:Et(e.collectedAt,dd)})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`dt`,{className:`text-muted`,children:`Source updated`}),(0,$.jsx)(`dd`,{children:e.sourceUpdatedAt?fn(e.sourceUpdatedAt):`Not supplied`})]})]})}function kd({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)(Od,{source:t})]})]})}function Ad({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:Ts(e)}),(0,$.jsx)(q,{variant:`secondary`,className:`pointer-coarse:min-h-11`,onClick:t,children:`Retry`})]})}function jd({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 Md({projectName:e}){let t=O({strict:!1}),n=D(),r=E(qi({client:K,path:{name:e}})),i=E(_i({client:K,path:{name:e}})),a=E({...Or({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??a.data?.profileId,f=d?i.data?.profiles.find(e=>e.id===d):t.seoRunId?void 0:i.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=r.data?.access.canWrite===!0&&!Y()&&!W(),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]),r.error)return(0,$.jsx)(Ad,{error:r.error,retry:()=>{r.refetch()}});if(i.error)return(0,$.jsx)(Ad,{error:i.error,retry:()=>{i.refetch()}});if(!r.data||!i.data)return(0,$.jsx)(`p`,{role:`status`,className:`py-10 text-copy-14 text-secondary`,children:`Loading SEO data…`});let g=r.data.available&&r.data.connections.some(e=>e.capabilities.length>0),_=g&&r.data.connections.some(e=>e.capabilities.some(e=>r.data.scopes.some(t=>t.capabilities?.includes(e)??!0))),v=f&&r.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)(o,{"aria-hidden":`true`,className:`size-4`}),`New profile`]})]})]}),i.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:`${fd} min-w-0 sm:w-64`,children:[!f&&(0,$.jsx)(`option`,{value:``,disabled:!0,children:`Profile unavailable`}),i.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)(gf,{projectName:e,context:r.data,profile:s.profile,id:s.id,onClose:h,onSaved:e=>{p(e),requestAnimationFrame(()=>u.current?.focus())}},s.id),!W()&&!r.data.available&&i.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:r.data.reason??`Configure an SEO data provider to refresh saved profiles.`}),t.seoRunId&&a.error?(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsx)(Ad,{error:a.error,retry:()=>{a.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&&a.isPending?(0,$.jsx)(`p`,{role:`status`,className:`py-10 text-copy-14 text-secondary`,children:`Loading refresh…`}):f&&a.data&&a.data.profileId!==f.id?(0,$.jsxs)(jd,{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)(Nd,{projectName:e,profile:f,context:r.data,selectedRunId:t.seoRunId,onLatest:()=>p(f.id)},`${f.id}:${f.revision}:${t.seoRunId??``}`):!_&&i.data.profiles.length===0?(0,$.jsx)(jd,{title:g?`SEO scope unavailable`:`Configure an SEO data provider`,children:g?r.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)(jd,{title:`Profile unavailable`,children:`This saved profile is no longer available. Select another profile to view its data.`}):!s&&(0,$.jsx)(jd,{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 Nd({projectName:e,profile:t,context:n,selectedRunId:r,onLatest:a}){let o=w(),[s,c]=(0,Q.useState)(r?`activity`:t.capabilities.includes(G[`ranked-keywords`])?G[`ranked-keywords`]:t.capabilities.at(0)??`activity`),[l,u]=(0,Q.useState)(null),d=(0,Q.useRef)(null),f=(0,Q.useRef)(null),p={name:e},m=E({...or({client:K,path:p,query:{profileId:t.id,runId:r}}),refetchInterval:e=>gd(e.state.data?.latestRun)?2e3:!1}),h=T({...Yi({client:K}),meta:{skipGlobalErrorToast:!0}}),g=T({...lr({client:K}),meta:{skipGlobalErrorToast:!0}}),_=m.data?.latestRun,v=m.data?.evidenceRun,y=m.data?.evidenceRun?.capabilities??t.capabilities,b=s===`activity`||y.includes(s)?s:y.at(0)??`activity`,x=gd(_),C=h.isPending||g.isPending,D=n.access.canRun&&!Y()&&!W(),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=E({...ti({client:K,path:p,query:{kind:Ae[`seo-sync`]}}),retry:!1}),j=!A.isError&&A.data?.enabled&&A.data.nextRunAt?A.data.nextRunAt:null,M=j?Td(j,A.data?.timezone??`UTC`):null,N=v?.finishedAt&&(v.status===H.completed||v.status===H.partial)?Td(v.finishedAt,dd):null,P=x?null:Dd(_,v);return(0,Q.useEffect)(()=>{_&&(gd(_)?f.current=_.id:f.current===_.id&&(f.current=null,Qn(o,`seo`,{projectName:e,profileId:t.id})))},[_,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:x&&_?(0,$.jsxs)(`p`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(i,{className:`size-4 animate-spin`,"aria-hidden":`true`}),_.cancelRequested?`Cancellation requested`:sd[_.status],` · `,_.completedTasks,` of `,_.taskCount,` `,Sd(_),` completed`]}):(0,$.jsxs)(`p`,{children:[N&&v?.finishedAt?(0,$.jsxs)($.Fragment,{children:[`Updated `,(0,$.jsx)(`time`,{dateTime:v.finishedAt,title:Et(v.finishedAt,dd)??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:C||x||!n.available||!O,onClick:Yn(async()=>{if(!(!D||r||x||C)){u(null);try{if(!d.current){let e=await h.mutateAsync({path:p,body:{profileId:t.id}});if(e.availability!==tt.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 g.mutateAsync({path:p,body:d.current});d.current=null,gd(e)&&(f.current=e.id),await o.fetchQuery(or({client:K,path:p,query:{profileId:t.id}}))}catch(e){Os(e).code===`VALIDATION_ERROR`&&(d.current=null),u(Ts(e))}}}),children:[(0,$.jsx)(S,{"aria-hidden":`true`,className:`size-4 ${C?`animate-spin`:``}`}),C?`Starting refresh…`:x?`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,`.`]}),m.data?.evidenceRun&&m.data.evidenceRun.profileRevision!==t.revision&&(0,$.jsxs)(`p`,{role:`status`,className:`text-copy-14 text-secondary`,children:[`Saved data uses profile revision `,m.data.evidenceRun.profileRevision,` · `,xd(m.data.evidenceRun),` · `,m.data.evidenceRun.languageCode,`. The current profile has changed.`]}),!W()&&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.`}),m.error?(0,$.jsx)(Ad,{error:m.error,retry:()=>{m.refetch()}}):m.data?.summary&&(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`p`,{className:`mb-3 break-words text-copy-13 text-secondary`,children:[m.data.summary.target.value,m.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)(_d,{value:m.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)(_d,{value:m.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)(_d,{value:m.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:[...y,`activity`].map(e=>(0,$.jsx)(`button`,{type:`button`,"aria-pressed":b===e,className:`min-h-11 border-b-2 text-button-14 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-mono-400 ${b===e?`border-strong text-primary`:`border-transparent text-secondary hover:text-primary`}`,onClick:()=>c(e),children:e===`activity`?`Activity`:id[e]},e))}),b===`activity`?(0,$.jsx)(hf,{projectName:e,profileId:t.id,canRun:D,selectedRunId:r}):m.isPending?(0,$.jsx)(`p`,{role:`status`,className:`py-8 text-copy-14 text-secondary`,children:`Loading saved data…`}):m.data&&(0,$.jsx)(Pd,{projectName:e,profileId:t.id,runId:m.data.evidenceRunId,view:b,active:x,nextRefresh:M},`${t.id}:${b}:${m.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: `,W()?`Fictional demo data`:O?.label??`Source unavailable`,`. Google; `,bd(t.rankings?.device??`unspecified`),`.`]}),m.data?.evidenceRun&&(0,$.jsxs)(`p`,{children:[`Saved evidence: `,m.data.evidenceRun.scope.kind,m.data.evidenceRun.scope.key?` · ${m.data.evidenceRun.scope.key}`:``,m.data.evidenceRun.scope.expectedPlanRevision===void 0?``:` · plan revision ${m.data.evidenceRun.scope.expectedPlanRevision}`,`. `,xd(m.data.evidenceRun),` · `,m.data.evidenceRun.languageCode,` · profile revision `,m.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,`.`]}),m.data?.summary&&(0,$.jsx)(Od,{source:m.data.summary.provenance})]})]})]})}function Pd({projectName:e,profileId:t,runId:n,view:r,active:i,nextRefresh:a}){return r===G[`market-rankings`]?n?(0,$.jsx)(af,{projectName:e,profileId:t,runId:n,active:i}):(0,$.jsx)(jd,{title:`No market rankings yet`,children:a?`First refresh ${a}`:`Refresh this profile to rank its tracked queries in each market.`}):(0,$.jsx)(Fd,{projectName:e,profileId:t,runId:n,view:r,active:i})}function Fd({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:cd,offset:(a-1)*cd}},m=E({...Er(p),enabled:!!n&&r===G[`ranked-keywords`]}),h=E({...pr(p),enabled:!!n&&r===G[`keyword-metrics`]}),g=E({...Vr(p),enabled:!!n&&r===G[`domain-intelligence`]}),_=E({...ur({...p,query:{...p.query,sort:l}}),placeholderData:N,enabled:!!n&&r===G[`competitor-discovery`]}),v=E({...gr({...p,query:{...p.query,kind:s||void 0,sort:d}}),placeholderData:N,enabled:!!n&&r===G[`keyword-gaps`]}),y=r===G[`ranked-keywords`]?m:r===G[`keyword-metrics`]?h:r===G[`competitor-discovery`]?_:r===G[`keyword-gaps`]?v:g;return n?(0,$.jsxs)(`div`,{className:`space-y-3 pt-4`,children:[r===G[`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:`${fd} w-auto`,value:s,onChange:e=>{c(e.target.value),o(1)},children:[(0,$.jsx)(`option`,{value:``,children:`All comparisons`}),(0,$.jsx)(`option`,{value:je.missing,children:`Missing`}),(0,$.jsx)(`option`,{value:je.shared,children:`Shared`}),(0,$.jsx)(`option`,{value:je.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===G[`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)(Ad,{error:y.error,retry:()=>{y.refetch()}}):y.data?y.data.items.length===0?(0,$.jsx)(jd,{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":`${id[r]} table`,"aria-busy":y.isFetching,tabIndex:0,children:[r===G[`ranked-keywords`]&&m.data&&(0,$.jsx)(Bd,{rows:m.data.items}),r===G[`keyword-metrics`]&&h.data&&(0,$.jsx)(Vd,{rows:h.data.items}),r===G[`domain-intelligence`]&&g.data&&(0,$.jsx)(Hd,{rows:g.data.items}),r===G[`competitor-discovery`]&&_.data&&(0,$.jsx)(Rd,{rows:_.data.items,sort:l,onSort:e=>{u(e),o(1)}}),r===G[`keyword-gaps`]&&v.data&&(0,$.jsx)(zd,{rows:v.data.items,sort:d,onSort:e=>{f(e),o(1)}})]}),(0,$.jsx)(fs,{page:a,pageSize:cd,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 `,id[r].toLowerCase(),`…`]})]}):(0,$.jsxs)(jd,{title:`No saved data yet`,children:[`Refresh this profile to collect `,id[r].toLowerCase(),` for its saved scope.`]})}function Id({value:e}){return e===null?(0,$.jsx)(_d,{value:null}):(0,$.jsxs)($.Fragment,{children:[e>0?`+`:``,ld.format(e)]})}function Ld({label:e,sort:t,ascending:n,descending:r,align:i=`right`,onSort:a,help:o}){return(0,$.jsx)(rf,{label:e,align:i,sorted:t===n?`ascending`:t===r?`descending`:null,onSort:()=>a(t===n?r:n),help:o,showUnsorted:!0})}function Rd({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)(Ld,{label:`Competitor`,align:`left`,sort:t,ascending:ve.domain,descending:ve[`-domain`],onSort:n}),(0,$.jsx)(Ld,{label:`Shared searches`,sort:t,ascending:ve.shared,descending:ve[`-shared`],onSort:n}),(0,$.jsx)(Ld,{label:`Avg. position`,sort:t,ascending:ve.position,descending:ve[`-position`],onSort:n}),(0,$.jsx)(Ld,{label:`Est. organic traffic`,sort:t,ascending:ve.traffic,descending:ve[`-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:md,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:pd,children:(0,$.jsx)(_d,{value:e.sharedKeywords})}),(0,$.jsx)(`td`,{className:pd,children:(0,$.jsx)(_d,{value:e.averagePosition})}),(0,$.jsx)(`td`,{className:pd,children:(0,$.jsx)(_d,{value:e.estimatedOrganicTraffic})}),(0,$.jsx)(`td`,{className:`px-4 align-top`,children:(0,$.jsxs)(kd,{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)(_d,{value:e.organicKeywords})]}),(0,$.jsxs)(`p`,{children:[`Target: `,e.target.value,` · includes subdomains`]})]})})]},`${e.target.value}:${e.domain}:${t}`))})]})}function zd({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)(Ld,{label:`Search`,align:`left`,sort:t,ascending:un.keyword,descending:un[`-keyword`],onSort:n}),(0,$.jsx)(Ld,{label:`Comparison`,align:`left`,sort:t,ascending:un.kind,descending:un[`-kind`],onSort:n}),(0,$.jsx)(Ld,{label:`Your rank`,sort:t,ascending:un[`target-rank`],descending:un[`-target-rank`],onSort:n}),(0,$.jsx)(Ld,{label:`Competitor rank`,sort:t,ascending:un[`competitor-rank`],descending:un[`-competitor-rank`],onSort:n}),(0,$.jsx)(Ld,{label:`Rank gap`,sort:t,ascending:un[`rank-gap`],descending:un[`-rank-gap`],onSort:n,help:od}),(0,$.jsx)(Ld,{label:`Monthly searches`,sort:t,ascending:un.volume,descending:un[`-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:md,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===je.shared?`neutral`:`caution`,children:ad[e.kind]})}),(0,$.jsx)(`td`,{className:pd,children:e.kind===je.missing?(0,$.jsx)(`span`,{className:`text-secondary`,children:`Not found`}):(0,$.jsx)(_d,{value:e.targetRankOrganic})}),(0,$.jsx)(`td`,{className:pd,children:(0,$.jsx)(_d,{value:e.competitorRankOrganic})}),(0,$.jsx)(`td`,{className:pd,children:(0,$.jsx)(Id,{value:e.rankGap})}),(0,$.jsx)(`td`,{className:pd,children:(0,$.jsx)(_d,{value:e.searchVolume})}),(0,$.jsx)(`td`,{className:`px-4 align-top`,children:(0,$.jsxs)(kd,{label:`${e.keyword} against ${e.competitor.value}`,source:e.provenance,children:[(0,$.jsxs)(`p`,{children:[`Your ranking page: `,e.targetUrl?(0,$.jsx)(vo,{url:e.targetUrl}):`Not supplied`]}),(0,$.jsxs)(`p`,{children:[`Competitor’s ranking page: `,e.competitorUrl?(0,$.jsx)(vo,{url:e.competitorUrl}):`Not supplied`]}),(0,$.jsxs)(`p`,{children:[`Difficulty /100: `,(0,$.jsx)(_d,{value:e.keywordDifficulty})]}),(0,$.jsxs)(`p`,{children:[`CPC: `,(0,$.jsx)(_d,{value:e.cpcUsd,currency:!0})]})]})})]},`${e.target.value}:${e.competitor.value}:${e.keyword}:${t}`))})]})}function Bd({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:`${pd} text-label-13-strong`,children:`Position`}),(0,$.jsx)(`th`,{className:`${pd} text-label-13-strong`,children:`Monthly searches`}),(0,$.jsx)(`th`,{className:`${pd} text-label-13-strong`,children:`Est. traffic`}),(0,$.jsx)(`th`,{className:`${pd} 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:md,children:[(0,$.jsx)(`p`,{className:`text-primary`,children:e.keyword}),(0,$.jsx)(`p`,{className:`mt-1 text-copy-13 text-secondary`,children:(0,$.jsx)(ls,{value:e.url??e.target.value})})]}),(0,$.jsx)(`td`,{className:pd,children:(0,$.jsx)(_d,{value:e.rankOrganic})}),(0,$.jsx)(`td`,{className:pd,children:(0,$.jsx)(_d,{value:e.searchVolume})}),(0,$.jsx)(`td`,{className:pd,children:(0,$.jsx)(_d,{value:e.estimatedTraffic})}),(0,$.jsx)(`td`,{className:pd,children:(0,$.jsx)(_d,{value:e.keywordDifficulty})}),(0,$.jsx)(`td`,{className:`px-4 align-top`,children:(0,$.jsxs)(kd,{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:[hd,`: `,(0,$.jsx)(_d,{value:e.rankAbsolute})]}),(0,$.jsxs)(`p`,{children:[`CPC: `,(0,$.jsx)(_d,{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 Vd({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:`${pd} text-label-13-strong`,children:`Monthly searches`}),(0,$.jsx)(`th`,{className:`${pd} text-label-13-strong`,children:`CPC`}),(0,$.jsx)(`th`,{className:`${pd} 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:`${md} text-primary`,children:e.keyword}),(0,$.jsx)(`td`,{className:pd,children:(0,$.jsx)(_d,{value:e.searchVolume})}),(0,$.jsx)(`td`,{className:pd,children:(0,$.jsx)(_d,{value:e.cpcUsd,currency:!0})}),(0,$.jsx)(`td`,{className:pd,children:(0,$.jsx)(_d,{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)(kd,{label:e.keyword,source:e.provenance,children:[(0,$.jsxs)(`p`,{children:[`Ad competition: `,e.adCompetition===null?`Not supplied`:rn(e.adCompetition,On.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)(_d,{value:e.searchVolume})})]},`${e.year}-${e.month}`))})]})})]},`${e.keyword}:${t}`))})]})}function Hd({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:`${pd} text-label-13-strong`,children:`Searches ranked for`}),(0,$.jsx)(`th`,{className:`${pd} 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:md,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:pd,children:(0,$.jsx)(_d,{value:e.organicKeywords})}),(0,$.jsx)(`td`,{className:pd,children:(0,$.jsx)(_d,{value:e.estimatedOrganicTraffic})}),(0,$.jsx)(`td`,{className:`px-4 align-top`,children:(0,$.jsx)(kd,{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)(_d,{value:e.top1})}),(0,$.jsx)(`dt`,{children:`Positions 2–3`}),(0,$.jsx)(`dd`,{children:(0,$.jsx)(_d,{value:e.top2To3})}),(0,$.jsx)(`dt`,{children:`Positions 4–10`}),(0,$.jsx)(`dd`,{children:(0,$.jsx)(_d,{value:e.top4To10})}),(0,$.jsx)(`dt`,{children:`Positions 11–20`}),(0,$.jsx)(`dd`,{children:(0,$.jsx)(_d,{value:e.top11To20})}),(0,$.jsx)(`dt`,{children:`Est. traffic value`}),(0,$.jsx)(`dd`,{children:(0,$.jsx)(_d,{value:e.estimatedOrganicTrafficValueUsd,currency:!0})})]})})})]},`${e.target.value}:${t}`))})]})}var Ud=5,Wd=10,Gd=`all`;function Kd(e){return e===Gd?Gd:Vt.safeParse(e).data??null}var qd={column:`ranks11To20`,descending:!0},Jd={3:`sm:grid-cols-3`,4:`sm:grid-cols-4`,5:`sm:grid-cols-5`},Yd=`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`,Xd=`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 Zd(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 Qd(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 $d(e){let t=e.filter(e=>e.kind===mt.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 ef(e,t){return e.counts[t]}function tf(e){let t=e.descending?-1:1,n=e.column;return n===`label`?(e,n)=>t*(st(e.label,n.label)||st(e.key,n.key)):(e,r)=>t*(ef(e,n)-ef(r,n))||st(e.label,r.label)||st(e.key,r.key)}function nf(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 rf({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:`${Yd} ${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 af({projectName:e,profileId:t,runId:n,active:r}){let i=O({strict:!1}),a=D(),o=i.seoRegion,s=i.seoMarket,c=Kd(i.seoShow),l=Ct.safeParse(i.seoSort).data??Ze.rank,u=t=>{a({to:`/projects/$projectName/seo-data`,params:{projectName:e},search:e=>({...e,...t}),replace:!0})},d=(0,Q.useId)(),f=E(yi({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)(Ad,{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)(sf,{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)(jd,{title:`No rankings here`,children:[`This refresh has no rankings for this `,s===void 0?`region`:`market`,`.`]}):(0,$.jsx)(jd,{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=xe(m,p),b=c??(p.needsWork>0?De[`needs-work`]:Gd),x=h.length>1||h.some(e=>e.kind===mt.region),S=[`${ld.format(p.queries)} ${p.queries===1?`query`:`queries`}`,...p.partlyChecked>0?[`${ld.format(p.partlyChecked)} partly checked`]:[],...p.failed>0?[`${ld.format(p.failed)} failed`]:[],...p.cancelled>0?[`${ld.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 ${Jd[y.length+1]??`sm:grid-cols-5`}`,children:[y.map(e=>(0,$.jsx)(of,{label:e.label,help:Zd(e,m),value:p[e.count]},e.count)),(0,$.jsx)(of,{label:`Rival ahead`,help:Qd(m),value:p.rivalAhead,className:`sm:border-l sm:border-subtle sm:pl-5`})]})]}),x&&(0,$.jsx)(cf,{projectName:e,groups:h,bands:y},`groups\u0000${g}`),(0,$.jsx)(lf,{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===Ze.rank?void 0:e}),urlQ:i.seoQ??``,onQ:e=>u({seoQ:e||void 0}),onClear:()=>u({seoShow:Gd,seoQ:void 0})},`queries\u0000${g}`)]})}function of({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:ld.format(n)})]})}function sf({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)(M,{to:`/projects/$projectName/seo-data`,params:{projectName:e},search:e=>({...e,seoRegion:void 0,seoMarket:void 0}),className:Xd,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)(M,{to:`/projects/$projectName/seo-data`,params:{projectName:e},search:e=>({...e,seoMarket:void 0}),className:Xd,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 cf({projectName:e,groups:t,bands:n}){let r=D(),[i,a]=(0,Q.useState)(null),[o,s]=(0,Q.useState)(1),c=$d(t),l=(i===null?t:[...t].sort(tf(i))).slice((o-1)*Ud,o*Ud),u=i??(n.some(e=>e.count===qd.column)?qd:null),d=[{column:`queries`,label:`Queries`},...n.map(e=>({column:e.count,label:e.label})),{column:`rivalAhead`,label:`Rival ahead`}],f=e=>{let t=i??qd;a(t.column===e?{column:e,descending:!t.descending}:{column:e,descending:e!==`label`}),s(1)},p=e=>u?.column===e?u.descending?`descending`:`ascending`:null,m=e=>e.kind===mt.region?t=>({...t,seoRegion:e.key,seoMarket:void 0}):t=>({...t,seoMarket:e.key}),h=`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":h,tabIndex:0,children:(0,$.jsxs)(`table`,{className:`w-full text-label-14`,children:[(0,$.jsx)(`caption`,{className:`sr-only`,children:h}),(0,$.jsx)(`thead`,{className:`bg-surface text-label-13 text-secondary`,children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(rf,{label:c.label,align:`left`,sorted:p(`label`),onSort:()=>f(`label`)}),d.map(e=>(0,$.jsx)(rf,{label:e.label,align:`right`,sorted:p(e.column),onSort:()=>f(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:m(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)(M,{to:`/projects/$projectName/seo-data`,params:{projectName:e},search:m(t),className:`rounded-sm text-primary hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-mono-400`,children:t.label})}),d.map(e=>(0,$.jsx)(`td`,{className:pd,children:ld.format(t.counts[e.column])},e.column)),(0,$.jsx)(`td`,{className:`px-4 py-3 text-right align-top`,children:(0,$.jsx)(g,{"aria-hidden":`true`,className:`ml-auto size-4 text-muted`})})]},`${t.kind}:${t.key}`))})]})}),(0,$.jsx)(fs,{page:o,pageSize:Ud,visibleRows:l.length,totalRows:t.length,onPageChange:s,itemLabel:c.plural,className:`text-label-13 [&_button]:min-h-11`})]})}function lf({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=nf(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,w=E({...jr({client:K,path:{name:e},query:{profileId:t,runId:n,regionKey:r,marketKey:i,outcome:c===Gd?void 0:c,q:v||void 0,sort:u,limit:Wd,offset:(C-1)*Wd}}),placeholderData:N}),T=[{value:De[`needs-work`],label:`Needs work`,count:a.needsWork},...o.map(e=>({value:e.filter,label:e.label,count:a[e.count]})),{value:De[`rival-ahead`],label:`Rival ahead`,count:a.rivalAhead},{value:De[`partly-checked`],label:`Partly checked`,count:a.partlyChecked},{value:De.failed,label:`Failed`,count:a.failed},{value:De.cancelled,label:`Not searched`,count:a.cancelled},{value:Gd,label:`All`,count:a.queries}],D=[De[`partly-checked`],De.failed,De.cancelled],O=T.filter(e=>e.value===c||e.count>0||!D.includes(e.value)),k=O.find(e=>e.value===c)?.label??`All`,A=u===Ze.rank?`ascending`:u===Ze[`-rank`]?`descending`:null,j=u===Ze.query?`ascending`:u===Ze[`-query`]?`descending`:null,M=w.data?.items??[],P=s===null?`not ranked`:`not in the top ${s}`,F=!w.data||w.isPlaceholderData?null:w.data.total===0?`No queries match`:`${ld.format(w.data.total)} ${w.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:`${fd} min-w-0 sm:w-56`,children:O.map(e=>(0,$.jsxs)(`option`,{value:e.value,children:[e.label,` (`,ld.format(e.count),`)`]},e.value))})]}),(0,$.jsx)(us,{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}),w.error?(0,$.jsx)(Ad,{error:w.error,retry:()=>{w.refetch()}}):w.data?w.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 ${w.isPlaceholderData?`opacity-60`:``}`,role:`region`,"aria-label":`Queries`,"aria-busy":w.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)(rf,{label:`Query`,align:`left`,sorted:j,onSort:()=>d(u===Ze.query?Ze[`-query`]:Ze.query)}),(0,$.jsx)(rf,{label:`Google rank`,align:`right`,sorted:A,onSort:()=>d(u===Ze.rank?Ze[`-rank`]:Ze.rank)}),(0,$.jsx)(`th`,{className:`px-4 py-3 text-left text-label-13-strong whitespace-nowrap`,children:`Top rival`}),(0,$.jsx)(`th`,{className:`${pd} text-label-13-strong`,children:`Rival rank`}),(0,$.jsx)(`th`,{className:`${pd} text-label-13-strong`,children:(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[`Rank gap`,(0,$.jsx)(X,{text:od,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:M.map((e,t)=>(0,$.jsx)(uf,{row:e,requested:s},`${e.marketKey}\u0000${e.queryId??e.queryText}\u0000${t}`))})]})}),(0,$.jsx)(fs,{page:C,pageSize:Wd,visibleRows:M.length,totalRows:w.data.total,onPageChange:e=>S({filterKey:b,page:e}),disabled:w.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 uf({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:md,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:pd,children:(0,$.jsx)(ff,{row:e,requested:t})}),(0,$.jsx)(`td`,{className:`px-4 py-3 align-top text-label-13`,children:(0,$.jsx)(pf,{row:e})}),(0,$.jsx)(`td`,{className:pd,children:(0,$.jsx)(_d,{value:e.topCompetitor?.rankOrganic??null})}),(0,$.jsx)(`td`,{className:pd,children:(0,$.jsx)(Id,{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)(mf,{row:e,requested:t})})})]})}function df(e){return e.outcome===ut.failed||e.outcome===ut.cancelled}function ff({row:e,requested:t}){return e.outcome===ut.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===ut.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===ut[`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 pf({row:e}){if(df(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 mf({row:e,requested:t}){let n=`text-muted`,r=`mt-0.5 text-primary`,i=e.outcome===ut.failed?`No result: the search failed`:e.outcome===ut.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)(vo,{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:hd}),(0,$.jsx)(`p`,{className:`${r} tabular-nums`,children:(0,$.jsx)(_d,{value:e.rankAbsolute})})]}),e.searchStatus===gt.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}`]})]}),!df(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)(Od,{source:e.provenance})})]})}function hf({projectName:e,profileId:t,canRun:n,selectedRunId:r}){let[i,a]=(0,Q.useState)(r??null),[o,s]=(0,Q.useState)(null),c=E({...Nr({client:K,path:{name:e},query:{profileId:t}}),refetchInterval:e=>e.state.data?.runs.some(gd)?2e3:!1}),l=E({...Or({client:K,path:{name:e,id:i??``}}),enabled:!!i,refetchInterval:e=>gd(e.state.data)?2e3:!1}),u=T({...Lr({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(Ts(e))}}};if(c.error)return(0,$.jsx)(`div`,{className:`py-4`,children:(0,$.jsx)(Ad,{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)(vd,{status:e.status}),(0,$.jsx)(`span`,{className:`text-label-14`,children:Et(e.createdAt,dd)})]}),(0,$.jsxs)(`p`,{className:`text-copy-13 text-secondary`,children:[e.completedTasks,` of `,e.taskCount,` `,Sd(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&&gd(e)&&(0,$.jsx)(q,{variant:`secondary`,className:`pointer-coarse:min-h-11`,disabled:u.isPending||e.cancelRequested,onClick:Yn(()=>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,` · `,xd(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)(Ad,{error:l.error,retry:()=>{l.refetch()}}):l.data?l.data.tasks.some(Cd)&&(0,$.jsx)(`ul`,{className:`space-y-3`,children:l.data.tasks.filter(Cd).map(e=>(0,$.jsxs)(`li`,{children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,$.jsxs)(`span`,{children:[id[e.capability],e.searchText===null?e.target?` · ${e.target.value}`:``:` · “${e.searchText}” from ${e.locationLabel??`its market`}`,e.comparison?` · ${e.comparison.competitor.value} · ${ad[e.comparison.mode]} searches`:``,e.retried?` · retried once`:``]}),(0,$.jsx)(vd,{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)(jd,{title:`No refreshes yet`,children:`Refresh this profile to collect its first saved results.`})}function gf({projectName:e,context:t,profile:n,id:r,onClose:i,onSaved:a}){let o=w(),[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??[G[`ranked-keywords`]]),[p,m]=(0,Q.useState)(n?.targets??[{kind:yn.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{C as t,F as n,K as r,P as i,R as a,S as o,V as s,X as c,Y as l,i as u,it as d,k as f,nt as p,o as m,ot as h,q as g,r as _,s as v,st as y,t as b,w as x,y as S}from"./vendor-lucide-CoTHJwai.js";import{r as C}from"./vendor-markdown-cQgSk2i0.js";import{E as w,_ as T,b as E,d as D,f as O,g as k,p as A,r as j,u as M,w as N}from"./vendor-tanstack-q5SvZtcv.js";import{c as P,f as F,i as I,l as L,m as R,o as ee,p as te,r as z,s as B,t as ne,u as V}from"./vendor-recharts-AnNqECZW.js";import{$n as H,A as re,Ai as ie,Ar as ae,Ci as oe,Ct as se,Di as ce,Dn as le,Dr as ue,Dt as de,Er as fe,F as pe,Fi as me,Fr as he,Ft as ge,Gi as _e,Gn as ve,H as ye,Hi as be,Hn as xe,Ht as Se,I as Ce,Ii as we,Ir as U,It as Te,Ji as Ee,Jn as De,Jr as Oe,K as ke,Ki as Ae,Kn as je,Kt as Me,Lr as Ne,Lt as Pe,Mi as Fe,Mr as Ie,N as Le,Ni as Re,Nr as ze,Ns as Be,Nt as Ve,Oi as He,On as Ue,Or as We,P as Ge,Pi as Ke,Pr as qe,Ps as Je,Pt as Ye,Qi as Xe,Qn as Ze,Qr as Qe,Rt as $e,Ti as et,Tt as W,Un as tt,Ut as nt,V as rt,Vi as it,Vt as at,W as ot,Wi as st,Wn as G,Wt as ct,Xi as lt,Xn as ut,Xr as dt,Y as ft,Yi as pt,Yn as mt,Yr as ht,Zn as gt,_n as _t,_r as vt,_t as yt,a as bt,ai as xt,an as St,ar as Ct,b as wt,c as Tt,ci as Et,cn as Dt,cr as Ot,dr as kt,dt as At,ei as jt,er as Mt,f as Nt,fr as Pt,gr as Ft,gt as It,h as Lt,hr as Rt,ht as zt,ii as Bt,ir as Vt,it as Ht,j as Ut,jr as Wt,k as Gt,ki as Kt,kr as qt,l as Jt,lr as Yt,lt as Xt,m as Zt,mr as Qt,mt as K,ni as $t,nn as en,nr as tn,o as nn,oi as rn,on as an,or as on,ot as sn,p as cn,pr as ln,qn as un,qr as dn,r as q,ri as fn,rr as pn,rt as mn,s as hn,si as gn,sn as _n,t as J,ti as vn,tr as yn,u as bn,ur as xn,ut as Sn,vr as Cn,wi as wn,wr as Tn,wt as Y,yr as En,yt as Dn,zi as On}from"./ToneBadge-DwUBSAjL.js";import{_ as kn,a as An,b as jn,c as Mn,d as Nn,f as Pn,g as Fn,h as In,i as Ln,m as Rn,n as zn,o as Bn,p as Vn,r as Hn,t as Un,u as Wn,v as Gn,x as Kn,y as qn}from"./format-helpers-Cgq0VzXz.js";import{r as Jn}from"./account-context-D7M4W4wP.js";import{t as Yn}from"./async-handler-Bj3TnIRw.js";import{a as Xn,d as Zn,l as Qn,n as $n,o as er,s as tr,t as nr,u as rr}from"./query-client-1Q6EwPba.js";import{$ as ir,A as ar,At as or,B as sr,C as cr,Cn as lr,Ct as ur,D as dr,Dn as fr,Dt as pr,E as mr,En as hr,Et as gr,F as _r,Ft as vr,G as yr,H as br,I as xr,J as Sr,K as Cr,L as wr,M as Tr,Mt as Er,N as Dr,Nt as Or,O as kr,On as Ar,Ot as jr,P as Mr,Pt as Nr,Q as Pr,R as Fr,S as Ir,Sn as Lr,St as Rr,T as zr,Tn as Br,Tt as Vr,U as Hr,V as Ur,W as Wr,X as Gr,Xt as Kr,Z as qr,Zt as Jr,_ as Yr,_n as Xr,_t as Zr,at as Qr,b as $r,bn as ei,bt as ti,c as ni,cn as ri,ct as ii,d as ai,dn as oi,dt as si,f as ci,fn as li,g as ui,gn as di,gt as fi,h as pi,hn as mi,ht as hi,j as gi,jt as _i,k as vi,kt as yi,l as bi,lt as xi,m as Si,mn as Ci,mt as wi,n as Ti,nn as Ei,nt as Di,o as Oi,ot as ki,p as Ai,pn as ji,pt as Mi,q as Ni,qt as Pi,r as Fi,rn as Ii,s as Li,sn as Ri,t as zi,u as Bi,ut as Vi,v as Hi,vn as Ui,vt as Wi,w as Gi,wn as Ki,wt as qi,x as Ji,xn as Yi,xt as Xi,y as Zi,yn as Qi,yt as $i,z as ea}from"./react-query-D0OiMBt3.js";import{_ as ta,a as na,c as ra,d as ia,f as aa,g as oa,h as sa,i as ca,l as la,m as ua,n as da,o as fa,p as pa,r as ma,s as ha,t as ga,u as _a}from"./ChartPrimitives-B5L9FUj3.js";import{t as X}from"./InfoTooltip-DrBIPuSU.js";import{t as Z}from"./card-DULVRmzI.js";import{$ as va,$t as ya,A as ba,At as xa,Bt as Sa,C as Ca,Ct as wa,D as Ta,Dt as Ea,E as Da,Et as Oa,F as ka,Ft as Aa,G as ja,Gt as Ma,H as Na,Ht as Pa,I as Fa,It as Ia,J as La,Jt as Ra,K as za,Kt as Ba,L as Va,Lt as Ha,M as Ua,Mt as Wa,N as Ga,Nt as Ka,O as qa,Ot as Ja,P as Ya,Pt as Xa,Qt as Za,Rt as Qa,St as $a,Tt as eo,U as to,Ut as no,V as ro,Vt as io,W as ao,Wt as oo,X as so,Xt as co,Y as lo,Yt as uo,Z as fo,Zt as po,_ as mo,_t as ho,a as go,an as _o,at as vo,b as yo,bt as bo,c as xo,cn as So,ct as Co,dn as wo,dt as To,en as Eo,et as Do,ft as Oo,gt as ko,ht as Ao,i as jo,in as Mo,it as No,j as Po,jt as Fo,k as Io,kt as Lo,l as Ro,ln as zo,lt as Bo,mt as Vo,nn as Ho,nt as Uo,o as Wo,on as Go,ot as Ko,q as qo,qt as Jo,r as Yo,s as Xo,tn as Zo,u as Qo,un as $o,ut as es,vt as ts,wt as ns,x as rs,xt as is,y as as,yt as os,z as ss,zt as cs}from"./index-A-4JN4Pv.js";import{a as ls,i as us,o as ds,r as fs,s as ps,t as ms}from"./SiteHealthSection-BPPB0D9D.js";import{t as hs}from"./Hint-CfeZmZig.js";import{t as gs}from"./AuditHistoryPanel-CuqdFCb9.js";import{a as _s,i as vs,l as ys,n as bs,o as xs,r as Ss,t as Cs}from"./service-Bu-7icpb.js";import{l as ws,n as Ts,r as Es,s as Ds,t as Os,u as ks}from"./extract-error-message-B9-6WgLm.js";import{i as As,n as js,r as Ms}from"./agent-trust-copy-WXXeDvDs.js";var Ns=1e6;function Ps(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/Ns);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(y(),1),Fs={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 Is(e,t){return e!==`viewer`||t!==null}function Ls(e,t){return e===`research`&&!t?`tracked`:e}function Rs(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 zs(e,t){return e.find(e=>e.kind===t.measurementScope&&(e.kind===`project`||e.id===t.measurementScopeKey))}function Bs(e){return e.measurementScope!==`project`||e.marketKey!==void 0}function Vs(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 $=C();function Hs({state:e,label:t,className:n}){return(0,$.jsx)(J,{tone:Go(e),className:n,children:t??qn(e)})}var Us=[{value:`non-brand`,label:`Non-brand`},{value:`branded`,label:`Branded`}],Ws={"non-brand":`Non-brand`,branded:`Branded`,pooled:`All queries`},Gs={"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.`},Ks=`Mentioned = brand in the answer. Cited = domain in the sources. Neither implies the other.`;function qs(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:rn(e.score,On.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 Js({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:Ks})]}),(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:rn(e.share)})]},e.label))})]})}function Ys({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=qs(u,{hasCompetitors:n.length>0,unavailable:e.unavailable===!0,noRun:e.breakdown.snapshotsTotal===0&&e.branded.snapshotsTotal===0,otherClassHasData:d.snapshotsTotal>0}),p=kn(f.headline),m=l===`non-brand`?Mo[e.tone]:`text-secondary`;function h(e){let t=Us.findIndex(e=>e.value===c),n=null;e.key===`ArrowRight`||e.key===`ArrowDown`?n=(t+1)%Us.length:e.key===`ArrowLeft`||e.key===`ArrowUp`?n=(t-1+Us.length)%Us.length:e.key===`Home`?n=0:e.key===`End`&&(n=Us.length-1),n!==null&&(e.preventDefault(),i(Us[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:Gs[l]})]}),s?(0,$.jsx)(`div`,{role:`radiogroup`,"aria-labelledby":a,className:`segmented flex-wrap`,onKeyDown:h,children:Us.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:Ws[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:Ws[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)(Js,{breakdown:u,projectLabel:t})]})}function Xs({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 Zs=[{value:`7d`,label:`7 days`},{value:`30d`,label:`30 days`},{value:`90d`,label:`90 days`},{value:`all`,label:`All`}],Qs={"7d":`last 7 days`,"30d":`last 30 days`,"90d":`last 90 days`,all:`all checks`},$s={"non-brand":`Non-brand`,branded:`Branded`,all:`All queries`},ec={"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.`},tc={"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`},nc=`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.`,rc=100;function ic(e){return e?e.evidence.answeredResults>0||e.evidence.sourceResults>0?`measured`:`not-measured`:`unavailable`}function ac(e){return e===`unavailable`?`Unavailable`:`Not measured`}function oc(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 sc(e,t,n){return e===1?t:n}function cc(e){let t=e.label.trim(),n=it(e.domain);return t&&t.toLowerCase()!==e.domain.toLowerCase()&&t.toLowerCase()!==n.toLowerCase()?t:null}function lc({row:e,aliases:t=[],autoAliases:n=[]}){let r=cc(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 uc(e){let t=cc(e);return t?`${t} (${e.domain})`:e.domain}function dc(e,t){return t&&e>=rc?(0,$.jsxs)($.Fragment,{children:[`top `,(0,$.jsx)(`strong`,{children:e})]}):(0,$.jsx)(`strong`,{children:e})}function fc({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 pc({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 mc({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:ac(n)})}function hc({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`:ac(t)});let{figure:r,sign:i}=kn(rn(e,On.percent));return(0,$.jsxs)(`span`,{className:`av-n-sm ${n}`,children:[r,i?(0,$.jsx)(`span`,{className:`text-faint`,children:i}):null]})}function gc({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)(lc,{row:e})}),(0,$.jsx)(`td`,{className:`text-label-13 text-secondary`,children:oc(e.surfaceClass)}),(0,$.jsx)(`td`,{children:(0,$.jsx)(mc,{count:e.mentionCount,of:n,state:t,toneClass:`text-primary`})}),(0,$.jsx)(`td`,{children:(0,$.jsx)(mc,{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)(pc,{urls:e.sampleUrls}):null,i?(0,$.jsx)(fc,{action:`pin`,domain:e.domain,mutation:i}):null]})})]},e.domain))})]})})}function _c({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 vc({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=ic(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?Mo[_o(t.project.shareOfVoice)]:`text-primary`,M=e=>_?e.pinned?l?(0,$.jsx)(fc,{action:`unpin`,domain:e.domain,mutation:l}):null:c?(0,$.jsx)(fc,{action:`pin`,domain:e.domain,mutation:c}):null:null,N=w.some(e=>M(e)!==null),P=[m,E?$s[E]:null,Qs[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: ${tc[t.reason]}`}),t&&T.length>0){let e=T.length;F.push({key:`others`,text:O&&e>=rc?`${rc} or more other competitors seen`:`${e} other ${sc(e,`competitor`,`competitors`)} seen`})}D>0&&F.push({key:`pending`,text:`${t?.scope.kind===`all-markets`?`Pending publication across markets`:`Pending publication`}: ${D} ${sc(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:Mo.caution});let L=[];if(t&&x){L.push(t.runCount===void 0?(0,$.jsxs)($.Fragment,{children:[`Base: `,(0,$.jsx)(`strong`,{children:x.answeredResults}),` `,sc(x.answeredResults,`answer`,`answers`)]}):(0,$.jsxs)($.Fragment,{children:[`Base: `,(0,$.jsx)(`strong`,{children:t.runCount}),` `,sc(t.runCount,`check`,`checks`),`, `,(0,$.jsx)(`strong`,{children:x.answeredResults}),` `,sc(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}),` `,sc(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}),` `,sc(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}),` `,sc(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)(gc,{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,` `,sc(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:[uc(e),` · `,oc(e.surfaceClass),` · `,e.citationCount,` `,sc(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?`${ec[E]} ${nc}`:nc})]}),(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)(Vo,{label:`Competitors over time window`,className:`flex-wrap`,options:Zs,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)(hc,{percent:t.project.shareOfVoice,state:S,toneClass:j})}),(0,$.jsx)(`td`,{children:(0,$.jsx)(mc,{count:t.project.mentionCount,of:k,state:S,toneClass:j})}),(0,$.jsxs)(`td`,{children:[(0,$.jsx)(mc,{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)(lc,{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:oc(e.surfaceClass)}),(0,$.jsx)(`td`,{children:(0,$.jsx)(hc,{percent:e.shareOfVoice,state:S,toneClass:`text-primary`})}),(0,$.jsx)(`td`,{children:(0,$.jsx)(mc,{count:e.mentionCount,of:k,state:S,toneClass:`text-primary`})}),(0,$.jsx)(`td`,{children:(0,$.jsx)(mc,{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)(Xs,{items:L}),_&&u?(0,$.jsx)(`div`,{className:`border-t border-subtle px-5 py-3`,children:(0,$.jsx)(_c,{onAddCompetitor:u})}):null]})}function yc({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 bc(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 xc=320;function Sc(e){return e===`branded`?`Branded`:e===`non-brand`?`Non-brand`:`Unclassified`}function Cc(e){return e===`non-brand`?0:e===`branded`?1:2}function wc(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 Tc(e){return e.phrase}function Ec(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 Dc(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 Oc(e,t){return e.map(e=>kc(e,t))}function kc(e,t){return t===`citations`?e:{...e,citationState:Ec(e,t),runHistory:e.runHistory.map(e=>({...e,citationState:Ec(e,t)}))}}function Ac(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 jc(e){let t=bc(Oc(e,`mentions`)),n=bc(e);return[Ac(t,`mentions`),Ac(n,`citations`)]}function Mc({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 Nc({items:e}){return(0,$.jsx)(`div`,{className:`query-evidence-signals`,"aria-label":`Latest run mention and citation signals`,children:jc(e).map(e=>(0,$.jsx)(Mc,{signal:e},e.key))})}function Pc({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)(qa,{}),t]})}):null,e?(0,$.jsx)(Io,{queryClass:e,manage:!!t}):null]})}function Fc({evidence:e,compareLocations:t=!1,defaultDensity:n=`detailed`,providerSelection:r,onProviderSelectionChange:i,addedQueries:a=[],actions:o,actionPanel:s}){let{openEvidence:c}=fo(),l=(0,Q.useId)(),[u,d]=(0,Q.useState)(new Set),f=Ua(),[p,m]=(0,Q.useState)(`mentions`),[h,_]=(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(kc(r,p)),s.rawItems.push(r),n.set(o,s)}return[...n.values()].sort((e,t)=>Cc(e.queryClass)-Cc(t.queryClass))},[e,p,t,S]),E=(0,Q.useMemo)(()=>T.filter(e=>v===`all`||(v===`unclassified`?e.queryClass===null:e.queryClass===v)),[T,v]),D=ps({rows:E,getSearchText:Tc}),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(Tn)),[a]),A=f?6:5,j=D.rows.map(e=>e.key),M=j.length>0&&j.every(e=>u.has(e)),N=e=>{d(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},P=p===`mentions`?`mentioned`:`cited`,F=p===`mentions`?`Mention History`:`Citation History`,I=p===`mentions`?`mentioned`:`cited`;return(0,$.jsxs)(`div`,{className:`query-evidence`,children:[(0,$.jsx)(Pc,{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":p===e,tabIndex:p===e?0:-1,onClick:()=>m(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`;m(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:h===`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:()=>{d(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)(us,{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:Ha(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}-${p}`,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`}),f&&(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`})})]})}),wc(D.rows).map(e=>(0,$.jsxs)(`tbody`,{children:[(0,$.jsx)(`tr`,{className:`query-evidence-group`,children:(0,$.jsxs)(`th`,{scope:`rowgroup`,colSpan:A,children:[Sc(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=u.has(e),d=j.indexOf(e),m=`${l}-query-${d}`,_=k.has(Tn(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=bc(a),C=a.filter(e=>e.citationState===oe.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":m,"aria-expanded":s,onClick:t=>{t.stopPropagation(),N(e)},children:[(0,$.jsx)(g,{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:m,className:`query-evidence-meta`,children:[(0,$.jsx)(`span`,{children:Sc(r)}),t&&(0,$.jsx)(`span`,{children:i??`No location`}),a.filter(e=>e.provider).map(e=>(0,$.jsx)(`span`,{children:Ha(e.provider)},e.id))]})]})]})}),(0,$.jsx)(`td`,{children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(Hs,{state:y,label:Dc(y,p),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]})]})}),f&&(0,$.jsx)(`td`,{children:(0,$.jsx)(ba,{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)(yc,{history:S,signal:p})}),(0,$.jsx)(`td`,{className:`evidence-change-cell`,children:_?(0,$.jsx)(`span`,{className:`query-evidence-new`,children:`new query`}):(0,$.jsx)(Nc,{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?Ha(e.provider):`Awaiting engine`})}),(0,$.jsx)(`td`,{children:(0,$.jsx)(Hs,{state:e.citationState,className:`rounded-none border-0 bg-transparent p-0 text-label-14`,label:Dc(e.citationState,p)})}),f&&(0,$.jsx)(`td`,{children:(0,$.jsx)(Ta,{queryId:e.queryId,sourceSnapshotIds:e.sourceSnapshotId?[e.sourceSnapshotId]:[],queryClass:e.queryClass,provider:e.provider,location:e.location??null})}),(0,$.jsx)(`td`,{children:(0,$.jsx)(yc,{history:e.runHistory,signal:p})}),(0,$.jsx)(`td`,{className:`evidence-change-cell`,children:_?null:(0,$.jsx)(Nc,{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?Ha(e.provider):`saved`} answer for ${e.query}`,onClick:t=>{t.stopPropagation(),c(e.id)},children:`View`})})]}),h===`detailed`&&(0,$.jsx)(`tr`,{className:`query-evidence-preview-row`,children:(0,$.jsx)(`td`,{colSpan:A,children:(0,$.jsx)(Rc,{item:e,mode:p,onViewFull:()=>c(e.id)},p)})})]},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)(fs,{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 Ic(e){let t=(e.matchedTerms??[]).filter(e=>e.trim().length>2),n=No(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 Lc(e,t){let n=t.toLowerCase().replace(/^www\./,``);return(e.citedCompetitorDomains??[]).some(e=>e.toLowerCase().replace(/^www\./,``)===n)}function Rc({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)(zc,{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)(vo,{url:t.uri,title:t.title}),Lc(e,be(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,Lc(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)(zc,{item:e,onViewFull:n,contextOnly:!0})]}):(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:`No answer text captured for this run.`})]})}function zc({item:e,onViewFull:t,contextOnly:n=!1}){let{matchedTerms:r,mentionedCompetitorDomains:i,mentionedCompetitorTerms:a,recommendedCompetitors:o}=e,s=(0,Q.useMemo)(()=>Ic({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>xc;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)(Va,{headingLevel:4,highlightGroups:s,previewLength:xc,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,Lc(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 Bc({label:e,value:t,tone:n}){return(0,$.jsxs)(`div`,{className:`material-base p-3`,children:[(0,$.jsx)(`p`,{className:`text-label-12 normal-case text-muted`,children:e}),(0,$.jsx)(`p`,{className:`mt-2 text-copy-24-strong ${n===`positive`?`text-positive-400`:n===`negative`?`text-negative-400`:`text-strong`}`,children:t})]})}function Vc({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&&Ue(`window`),n(e)},children:i?i(e):e},e))})}var Hc=`baseline`;function Uc(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,[Hc]:i.get(e)??null};for(let e of n)a[e.dataKey]=t?.[e.key]??0;return a}),series:n}}var Wc=`text-label-12-strong normal-case text-muted`;function Gc({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 Kc({children:e}){return(0,$.jsx)(`div`,{className:`[&>details:first-child]:border-t-0`,children:e})}function qc({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 Jc={3:`lg:grid-cols-3`,4:`lg:grid-cols-4`,5:`lg:grid-cols-5`};function Yc({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 ${Jc[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 Xc({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:`${Wc} 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 Zc({label:e,align:t}){return(0,$.jsx)(`th`,{className:`py-2 ${t===`right`?`pl-4 text-right`:`text-left`}`,children:(0,$.jsx)(`span`,{className:Wc,children:e})})}function Qc(e,t,n=`desc`){return e.key===t?{key:t,dir:e.dir===`desc`?`asc`:`desc`}:{key:t,dir:n}}function $c(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 el({groups:e,groupLabel:t,caption:n,childColumns:r,childRowKey:i,renderChildCells:a,pinLast:o}){let s=(0,Q.useId)(),[c,u]=(0,Q.useState)(new Set),[d,f]=(0,Q.useState)({key:`sessions`,dir:`desc`}),p=(0,Q.useMemo)(()=>{let t=$c(d.key,d.dir);return[...e].sort((e,n)=>Number(o?.(e)??!1)-Number(o?.(n)??!1)||t(e,n))},[e,d,o]),m=e=>f(t=>Qc(t,e,e===`label`?`asc`:`desc`)),h=e=>u(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)(Xc,{label:t,sortKey:`label`,current:d.key,dir:d.dir,onSort:m,align:`left`}),(0,$.jsx)(Xc,{label:`Sessions`,sortKey:`sessions`,current:d.key,dir:d.dir,onSort:m,align:`right`}),(0,$.jsx)(Xc,{label:`Organic`,sortKey:`organicSessions`,current:d.key,dir:d.dir,onSort:m,align:`right`}),(0,$.jsx)(Xc,{label:`Paid`,sortKey:`paidSessions`,current:d.key,dir:d.dir,onSort:m,align:`right`}),(0,$.jsx)(Zc,{label:`Share`,align:`right`})]})}),(0,$.jsx)(`tbody`,{children:p.map((e,t)=>{let n=c.has(e.label),o=`${s}-group-${t}`,u=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:()=>h(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)(l,{"aria-hidden":`true`,className:`size-3.5 shrink-0 text-secondary`}):(0,$.jsx)(g,{"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:[u,` `,u===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:rn(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)(Zc,{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 tl(e,t){return e===`other`?ca.textDim:na[t%na.length]}function nl({input:e,baseline:t,baselineLabel:n,label:r,height:i=224}){let{rows:a,series:o}=(0,Q.useMemo)(()=>Uc(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)(R,{width:`100%`,height:`100%`,children:(0,$.jsxs)(ne,{data:a,margin:{top:4,right:4,bottom:0,left:0},children:[(0,$.jsx)(P,{stroke:ma,vertical:!1}),(0,$.jsx)(I,{dataKey:`date`,tick:da,tickLine:!1,axisLine:{stroke:ga},tickFormatter:ia,minTickGap:24}),(0,$.jsx)(z,{tick:da,tickLine:!1,axisLine:!1,allowDecimals:!1,width:36}),(0,$.jsx)(F,{...ha,labelFormatter:la,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=tl(e.key,o.indexOf(e));return(0,$.jsx)(ee,{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)(B,{type:`monotone`,dataKey:`baseline`,name:`baseline`,stroke:ca.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:tl(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:ca.textFaint,strokeWidth:`2`,strokeDasharray:`5 3`})}),n]})]})]})}var rl=[`sessions`,`activeUsers`,`organicSessions`,`engagementRate`,`keyEvents`],il=`canonry.siteTraffic.slots`,al=na[1],ol={current:`current`,previous:`previous`};function sl(e){return typeof e==`string`&&ue.some(t=>t===e)}function cl(){try{let e=JSON.parse(window.localStorage.getItem(il)??`null`);if(Array.isArray(e)&&e.length===rl.length&&e.every(sl))return[...e]}catch{}return[...rl]}function ll(e){try{window.localStorage.setItem(il,JSON.stringify(e))}catch{}}function ul(){return typeof window<`u`&&typeof window.matchMedia==`function`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches}function dl(e){return e===null?`no earlier data`:e===0?`no change on the previous period`:`${e>0?`up`:`down`} ${rn(Math.abs(e),On.percent)} on the previous period`}function fl({metric:e,change:t}){let n=qe(e,t);if(n===null||t===null)return(0,$.jsx)(`span`,{className:`block text-label-13 text-secondary`,children:`No earlier data`});let r=n===Wt.better?`text-positive`:n===Wt.worse?`text-negative`:`text-secondary`,i=t>0?p:t<0?h:null;return(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 text-label-13-strong tabular-nums ${r}`,children:[i&&(0,$.jsx)(i,{"aria-hidden":`true`,className:`size-3.5`,strokeWidth:2.5}),rn(Math.abs(t),On.percent)]})}function pl({active:e,payload:t,metric:n}){let r=t?.[0]?.payload;return!e||!r?null:(0,$.jsxs)(`div`,{className:`material-tooltip min-w-48 px-3 py-2 text-label-13`,children:[(0,$.jsx)(`p`,{className:`mb-1 text-copy-13-strong text-heading`,children:fe[n].label}),(0,$.jsxs)(`p`,{className:`flex items-center justify-between gap-6`,children:[(0,$.jsxs)(`span`,{className:`flex items-center gap-2 text-secondary`,children:[(0,$.jsx)(`svg`,{"aria-hidden":`true`,width:`14`,height:`6`,className:`shrink-0`,children:(0,$.jsx)(`line`,{x1:`0`,y1:`3`,x2:`14`,y2:`3`,stroke:al,strokeWidth:`2.5`})}),la(r.date)]}),(0,$.jsx)(`span`,{className:`tabular-nums text-primary`,children:ze(n,r.current)})]}),(0,$.jsxs)(`p`,{className:`flex items-center justify-between gap-6`,children:[(0,$.jsxs)(`span`,{className:`flex items-center gap-2 text-secondary`,children:[(0,$.jsx)(`svg`,{"aria-hidden":`true`,width:`14`,height:`6`,className:`shrink-0`,children:(0,$.jsx)(`line`,{x1:`0`,y1:`3`,x2:`14`,y2:`3`,stroke:al,strokeWidth:`1.5`,strokeDasharray:`3 2`})}),la(r.previousDate)]}),(0,$.jsx)(`span`,{className:`tabular-nums text-secondary`,children:ze(n,r.previous)})]})]})}function ml({overview:e,refreshing:t=!1}){let n=(0,Q.useId)(),[r,i]=(0,Q.useState)(cl),[a,o]=(0,Q.useState)(0),[s,c]=(0,Q.useState)(new Set),u=!ul(),d=r[a]??rl[0],f=(0,Q.useMemo)(()=>e.days.map(e=>({date:e.date,previousDate:e.previousDate,current:e.values[d],previous:e.previousValues[d]})),[e.days,d]),p=f.some(e=>e.current!==null||e.previous!==null),m=Ne(e.window)?We[e.window]:null,h=m===null?`This period`:`Last ${m} days`,g=(e,t)=>i(n=>{let r=[...n],i=r.indexOf(t);return i!==-1&&i!==e&&(r[i]=r[e]),r[e]=t,ll(r),r}),_=e=>{o(e),document.getElementById(`${n}-tab-${e}`)?.focus()},v=(e,t)=>{let n=r.length-1,i=e.key===`ArrowRight`?t===n?0:t+1:e.key===`ArrowLeft`?t===0?n:t-1:e.key===`Home`?0:e.key===`End`?n:null;i!==null&&(e.preventDefault(),_(i))},y=e=>c(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n});return(0,$.jsxs)(`div`,{className:`overflow-hidden material-base transition-opacity duration-200 ${t?`opacity-60`:``}`,children:[(0,$.jsx)(`div`,{role:`tablist`,"aria-label":`Site traffic figures`,className:`grid grid-cols-2 border-b border-default sm:grid-cols-3 lg:grid-cols-5`,children:r.map((t,r)=>{let i=r===a,s=ze(t,e.totals[t],{compact:!0});return(0,$.jsxs)(`div`,{className:`relative min-w-0 px-4 pb-4 pt-4`,children:[(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`absolute inset-x-4 top-0 h-[3px] rounded-b-sm bg-link transition-opacity duration-200 ${i?`opacity-100`:`opacity-0`}`}),(0,$.jsxs)(`div`,{className:`relative inline-flex max-w-full items-center`,children:[(0,$.jsx)(`select`,{"aria-label":`Figure ${r+1}`,value:t,onChange:e=>{sl(e.target.value)&&g(r,e.target.value)},className:`max-w-full cursor-pointer appearance-none truncate rounded-sm bg-transparent py-0.5 pr-5 text-label-14-strong [field-sizing:content] transition-colors duration-150 hover:text-heading focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-mono-400 ${i?`text-link`:`text-secondary`}`,children:ue.map(e=>(0,$.jsx)(`option`,{value:e,children:fe[e].label},e))}),(0,$.jsx)(l,{"aria-hidden":`true`,className:`pointer-events-none absolute right-0 size-3.5 ${i?`text-link`:`text-muted`}`})]}),(0,$.jsxs)(`button`,{type:`button`,role:`tab`,id:`${n}-tab-${r}`,"aria-selected":i,"aria-controls":`${n}-panel`,"aria-label":`${fe[t].label} ${s}, ${dl(e.changePct[t])}`,tabIndex:i?0:-1,onClick:()=>o(r),onKeyDown:e=>v(e,r),className:`mt-1 block w-full rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-mono-400`,children:[(0,$.jsx)(`span`,{className:`block truncate text-heading-32 tabular-nums transition-colors duration-150 ${i?`text-primary`:`text-strong`}`,title:ze(t,e.totals[t]),children:s}),(0,$.jsx)(fl,{metric:t,change:e.changePct[t]})]})]},r)})}),(0,$.jsxs)(`div`,{role:`tabpanel`,id:`${n}-panel`,"aria-labelledby":`${n}-tab-${a}`,className:`px-4 pb-3 pt-4`,children:[e.syncedAt===null&&(0,$.jsx)(`p`,{className:`mb-3 text-copy-14 text-secondary`,children:`These figures fill in after the next GA4 sync.`}),p?(0,$.jsx)(`div`,{role:`img`,"aria-label":`${fe[d].label} per day, ${h.toLowerCase()} and the previous period`,style:{height:240},children:(0,$.jsx)(R,{width:`100%`,height:`100%`,children:(0,$.jsxs)(ne,{data:f,margin:{top:8,right:0,bottom:0,left:4},children:[(0,$.jsx)(P,{stroke:ma,vertical:!1}),(0,$.jsx)(I,{dataKey:`date`,tick:da,tickLine:!1,axisLine:{stroke:ga},tickFormatter:ia,minTickGap:32}),(0,$.jsx)(z,{orientation:`right`,tick:da,tickLine:!1,axisLine:!1,width:52,allowDecimals:fe[d].unit!==Ie.count,tickFormatter:e=>ze(d,e,{compact:!0})}),(0,$.jsx)(F,{cursor:{stroke:ca.textFaint,strokeWidth:1},wrapperStyle:{outline:`none`},content:(0,$.jsx)(pl,{metric:d})}),!s.has(ol.previous)&&(0,$.jsx)(B,{type:`monotone`,dataKey:ol.previous,stroke:al,strokeOpacity:.65,strokeWidth:1.5,strokeDasharray:`4 4`,dot:!1,activeDot:{r:3,strokeWidth:0,fill:al},connectNulls:!1,isAnimationActive:u,animationDuration:320,animationEasing:`ease-out`}),!s.has(ol.current)&&(0,$.jsx)(B,{type:`monotone`,dataKey:ol.current,stroke:al,strokeWidth:2.25,dot:!1,activeDot:{r:5,strokeWidth:2,stroke:al,fill:`var(--color-bg)`},connectNulls:!1,isAnimationActive:u,animationDuration:320,animationEasing:`ease-out`})]})})}):(0,$.jsxs)(`p`,{className:`py-8 text-copy-14 text-secondary`,children:[`No daily `,fe[d].label.toLowerCase(),` yet.`]}),(0,$.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center justify-between gap-x-6 gap-y-1`,children:[(0,$.jsxs)(`fieldset`,{className:`flex flex-wrap gap-x-5 text-label-13 text-secondary`,children:[(0,$.jsx)(`legend`,{className:`sr-only`,children:`${fe[d].label} series`}),[[ol.current,h,``],[ol.previous,`Previous period`,`4 3`]].map(([e,t,n])=>{let r=!s.has(e),i=r&&s.size===1;return(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:r,disabled:i,onChange:()=>y(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:al,strokeWidth:e===ol.current?2.5:1.5,strokeDasharray:n||void 0})}),t]},e)})]}),e.current.startDate&&e.current.endDate&&e.previous.startDate&&e.previous.endDate&&(0,$.jsxs)(`p`,{className:`text-copy-13 text-secondary`,children:[hl(e.current.startDate,e.current.endDate,!0),` vs `,hl(e.previous.startDate,e.previous.endDate,!1)]})]})]})]})}function hl(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)}`}var gl=na[0],_l=na[1],vl=na[2],yl=na[3],bl=[`both`,`server`,`ga4`],xl={fontSize:12,paddingTop:6},Sl=e=>typeof e==`number`?xt(Math.round(e)):String(e),Cl=e=>typeof e==`number`&&Number.isFinite(e)?e:0;function wl(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 Tl(e,t){return n=>{let{cx:r,cy:i,index:a,key:o}=n,s=a??-1;return e[s]==null||e[s-1]!=null||e[s+1]!=null||r===void 0||i===void 0?(0,$.jsx)(`g`,{},o):(0,$.jsx)(`circle`,{cx:r,cy:i,r:2.6,fill:t,stroke:`none`},o)}}function El({projectName:e,sinceMinutes:t}){let[n,r]=(0,Q.useState)(!0),[i,a]=(0,Q.useState)(!0),[o,s]=(0,Q.useState)(`both`),c=Ds(e,{sinceMinutes:t,granularity:`day`,limit:1}),l=ws(e),u=E({...Ir({client:K,path:{name:e}}),enabled:!!e,staleTime:tr}).data?.connected===!0,d=E({...Hi({client:K,path:{name:e},query:{window:t>=129600?`90d`:t>=43200?`30d`:`7d`}}),enabled:!!e&&u,staleTime:tr}),f=(0,Q.useMemo)(()=>c.data?.series?.points??[],[c.data]),p=(0,Q.useMemo)(()=>{let e=d.data;return new Map((e?.days??[]).map(e=>[e.date,e.sessions]))},[d.data]),m=(0,Q.useMemo)(()=>{let e=e=>e.measured!==!1;if(f.length===0||e(f[0]))return null;let t=f.findIndex(e)-1;return t<0?{from:f[0].bucket,to:f[f.length-1].bucket}:{from:f[0].bucket,to:f[t].bucket}},[f]),h=c.data?.series?.coverageStart??null,g=c.data?.series?.trends,_=(0,Q.useMemo)(()=>{let e=wl(g?.crawlerContentHits,f.length),t=wl(g?.aiUserFetchHits,f.length),n=wl(g?.aiReferralLandedHits,f.length);return f.map((r,i)=>({...r,crawlerContentHits:r.measured===!1?null:Cl(r.crawlerContentHits),aiUserFetchHits:r.measured===!1?null:Cl(r.aiUserFetchHits),aiReferralLandedHits:r.measured===!1?null:Cl(r.aiReferralLandedHits),ga4Visits:p.get(r.bucket)??null,crawlTrend:e[i],fetchTrend:t[i],visitTrend:n[i]}))},[f,p,g]),v=c.data?.totals,y=v&&{crawlers:Cl(v.crawlerContentHits),fetches:Cl(v.aiUserFetchHits),visits:Cl(v.aiReferralLandedHits)},b=(0,Q.useMemo)(()=>f.reduce((e,t)=>({crawlers:e.crawlers+Cl(t.crawlerContentHits),fetches:e.fetches+Cl(t.aiUserFetchHits),visits:e.visits+Cl(t.aiReferralLandedHits)}),{crawlers:0,fetches:0,visits:0}),[f]),x=y??b,S=x.crawlers>0||x.fetches>0||x.visits>0;if(c.isLoading)return(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:`Loading AI traffic history…`});if(c.isError)return(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.`})]});if(!S){let e=l.data?.sources,t=e!==void 0&&e.length===0,n=!t&&h===null;return(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:[(0,$.jsx)(`div`,{className:`mb-5`,children:(0,$.jsx)(Yc,{label:`AI traffic totals`,items:[{label:`AI crawlers`,value:xt(x.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:xt(x.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:xt(x.visits),detail:`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.`}]})}),f.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:Cl(f[f.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:Cl(f[f.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:Cl(f[f.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:p.get(f[f.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)(R,{width:`100%`,height:206,children:(0,$.jsxs)(ne,{data:_,margin:{top:4,right:8,left:-18,bottom:0},children:[(0,$.jsx)(P,{stroke:ma,vertical:!1}),(0,$.jsx)(I,{dataKey:`bucket`,tick:da,stroke:ga,tickFormatter:ia,minTickGap:28}),(0,$.jsx)(z,{tick:da,stroke:ga,width:48,allowDecimals:!1}),(0,$.jsx)(F,{contentStyle:ha.contentStyle,labelStyle:ha.labelStyle,itemStyle:ha.itemStyle,labelFormatter:la,formatter:Sl}),m&&(0,$.jsx)(L,{x1:m.from,x2:m.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)(te,{wrapperStyle:xl,iconType:`plainline`,iconSize:14}),(0,$.jsx)(ee,{type:`monotone`,dataKey:`crawlerContentHits`,name:`Pages crawled`,stroke:gl,fill:gl,fillOpacity:.22,strokeWidth:1.8}),n&&(0,$.jsx)(ee,{type:`monotone`,dataKey:`aiUserFetchHits`,name:`Page fetches`,stroke:_l,fill:_l,fillOpacity:.18,strokeWidth:1.6}),i&&(0,$.jsx)(B,{type:`linear`,dataKey:`crawlTrend`,legendType:`none`,name:`Pages crawled trend`,dot:!1,tooltipType:`none`,stroke:gl,strokeWidth:1.4,strokeDasharray:`5 4`,connectNulls:!0}),i&&n&&(0,$.jsx)(B,{type:`linear`,dataKey:`fetchTrend`,legendType:`none`,name:`Page fetches trend`,dot:!1,tooltipType:`none`,stroke:_l,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,$.jsx)(Vc,{windows:bl,value:o,onChange:s,label:`Visit measurement source`,formatOption:e=>e===`ga4`?`GA4`:e===`both`?`Both`:`Server`})]}),(0,$.jsx)(R,{width:`100%`,height:176,children:(0,$.jsxs)(ne,{data:_,margin:{top:4,right:8,left:-18,bottom:0},children:[(0,$.jsx)(P,{stroke:ma,vertical:!1}),(0,$.jsx)(I,{dataKey:`bucket`,tick:da,stroke:ga,tickFormatter:ia,minTickGap:28}),(0,$.jsx)(z,{tick:da,stroke:ga,width:48,allowDecimals:!1}),(0,$.jsx)(F,{contentStyle:ha.contentStyle,labelStyle:ha.labelStyle,itemStyle:ha.itemStyle,labelFormatter:la,formatter:Sl}),m&&(0,$.jsx)(L,{x1:m.from,x2:m.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)(te,{wrapperStyle:xl,iconType:`plainline`,iconSize:14}),o!==`ga4`&&(0,$.jsx)(B,{type:`monotone`,dataKey:`aiReferralLandedHits`,name:`Visits, server`,stroke:vl,strokeWidth:2,dot:!1}),o!==`server`&&(0,$.jsx)(B,{type:`monotone`,dataKey:`ga4Visits`,name:`Visits, GA4`,connectNulls:!1,stroke:yl,strokeWidth:1.8,strokeDasharray:`5 3`,dot:Tl(_.map(e=>e.ga4Visits),yl)}),i&&o!==`ga4`&&(0,$.jsx)(B,{type:`linear`,dataKey:`visitTrend`,legendType:`none`,name:`Visits trend`,dot:!1,tooltipType:`none`,stroke:vl,strokeWidth:1.3,strokeDasharray:`5 4`,connectNulls:!0})]})})]})}function Dl(e){return e.replace(/\+/g,` `)}var Ol=[`7d`,`30d`,`90d`],kl={"7d":10080,"30d":43200,"90d":129600,all:129600};function Al(e){return ds(e.landingPage)}var jl=25,Ml=10,Nl={days:[],sources:[],totalSessions:0,totalPaidSessions:0,totalOrganicSessions:0,byEngine:{series:[],otherCount:0,days:[]}},Pl={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 Fl(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 Il(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toLocaleString()}function Ll(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 Rl({projectName:e}){let{data:t,isLoading:n,isError:r}=ks(e),i=t?.sources??[];return(0,$.jsxs)(`section`,{"aria-labelledby":`server-activity-heading`,children:[(0,$.jsx)(Gc,{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)(M,{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)(M,{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)(Zc,{label:`Source`,align:`left`}),(0,$.jsx)(Zc,{label:`Status`,align:`left`}),(0,$.jsx)(Zc,{label:`Crawler hits`,align:`right`}),(0,$.jsx)(Zc,{label:`AI hits`,align:`right`}),(0,$.jsx)(Zc,{label:`AI sessions`,align:`right`}),(0,$.jsx)(Zc,{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:Es(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:Ms(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?Fl(t.lastSyncedAt):`never`}),(0,$.jsx)(`td`,{className:`py-2 pl-3 text-right`,children:!Y()&&(0,$.jsx)(M,{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 zl({projectName:e}){let[t,n]=(0,Q.useState)(`30d`);return(0,$.jsxs)(`div`,{children:[(0,$.jsx)(Rl,{projectName:e}),(0,$.jsx)(`div`,{className:`page-section-divider`}),(0,$.jsx)(Jl,{projectName:e,window:t,periodControl:(0,$.jsx)(Vc,{windows:Ol,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)(Gc,{id:`ai-traffic-history-heading`,title:`AI traffic history`,tooltip:Pl.aiHistoryTooltip}),(0,$.jsx)(El,{projectName:e,sinceMinutes:kl[t]})]})]})})]})}var Bl={session:`Session`,first_user:`First visit`,manual_utm:`UTM`},Vl={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)`},Hl=[{label:`Source`,align:`left`},{label:`Medium`,align:`left`},{label:`Class`,align:`left`},{label:`Attribution`,align:`left`},{label:`Sessions`,align:`right`},{label:`Share`,align:`right`}],Ul=[{label:`Source`,align:`left`},{label:`Medium`,align:`left`},{label:`Channel`,align:`left`},{label:`Sessions`,align:`right`},{label:`Share`,align:`right`}];function Wl(e){return e.engine===null}function Gl({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:Vl[e.sourceDimension]??``,children:Bl[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:rn(e.share)})]})}function Kl({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:Dl(e.source)}),(0,$.jsx)(`td`,{className:`max-w-[160px] truncate py-1.5 pr-3 text-secondary`,title:e.medium,children:Dl(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:rn(e.share)})]})}function ql(e,t){let n=w(),[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)(Nl),[y,b]=(0,Q.useState)([]),[x,S]=(0,Q.useState)(null);async function C(r){c(!0),m(null);try{let a=await n.fetchQuery({...Ir({client:K,path:{name:e}}),staleTime:tr});if(r.current)return;if(i(a),!a.connected){o(null),v(Nl),b([]),S(null),c(!1);return}let s=t===`all`?void 0:t,[l,u,d,f]=await Promise.all([n.fetchQuery({...cr({client:K,path:{name:e},query:s?{window:s}:void 0}),staleTime:tr}),n.fetchQuery({...Hi({client:K,path:{name:e},query:s?{window:s}:void 0}),staleTime:tr}).catch(()=>Nl),n.fetchQuery({...Ji({client:K,path:{name:e},query:s?{window:s}:void 0}),staleTime:tr}).catch(()=>[]),n.fetchQuery({...Zi({client:K,path:{name:e},query:{window:Ne(t)?t:`30d`}}),staleTime:tr}).catch(()=>null)]);if(r.current)return;o(l),v(u),b(d),S(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 C(e),()=>{e.current=!0}},[e,t,n]);async function T(){u(!0),m(null),g(null);try{let t=await _n(e);g(`Synced ${t.rowCount.toLocaleString()} page rows, ${t.aiReferralCount.toLocaleString()} AI and ${t.socialReferralCount.toLocaleString()} social referral rows (${t.days} days)`),await Qn(n,`ga`),await C({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 re(e),await Qn(n,`ga`),i({connected:!1,propertyId:null,clientEmail:null,lastSyncedAt:null,createdAt:null,updatedAt:null}),o(null),S(null),g(`GA4 disconnected`)}catch(e){m(e instanceof Error?e.message:`Disconnect failed`)}finally{f(!1)}}async function D(){await Qn(n,`ga`),await C({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 Jl({projectName:e,window:t,periodControl:n,between:r}){let i=ql(e,t??`30d`);return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Yl,{ga:i,projectName:e,periodControl:n}),r,(0,$.jsx)(Xl,{ga:i,projectName:e})]})}function Yl({ga:e,projectName:t,periodControl:n}){let{status:r,traffic:i,syncing:a,disconnecting:o,handleSync:s,handleDisconnect:c}=e,l=r?.connected===!0,d=l&&!Y()&&!W(),f=i?Ll(i.windowStart,i.windowEnd):null,p;return p=e.loading&&!r?(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:`Loading traffic data…`}):l?i&&e.overview?(0,$.jsx)(ml,{overview:e.overview,refreshing:e.loading}):i?(0,$.jsx)($.Fragment,{children:(0,$.jsx)(Yc,{label:`Site traffic`,items:[{label:`Total sessions`,value:Il(i.totalSessions),detail:i.totalSessions.toLocaleString()},{label:`Organic sessions`,value:Il(i.totalOrganicSessions),detail:`${i.organicSharePctDisplay} of total`},{label:`Total users`,value:i.totalUsers===null?`n/a`:Il(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()&&!W()&&(0,$.jsxs)(q,{variant:`outline`,size:`sm`,disabled:a,onClick:Yn(s),children:[(0,$.jsx)(S,{className:`mr-1.5 size-3.5 ${a?`animate-spin`:``}`}),`Sync from GA4`]})]}):Y()||W()?(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:`No Google Analytics 4 property connected.`}):(0,$.jsx)(au,{projectName:t,onConnected:()=>{e.handleConnected()}}),(0,$.jsxs)(`section`,{"aria-labelledby":`site-traffic-heading`,children:[(0,$.jsx)(Gc,{id:`site-traffic-heading`,title:`Site traffic`,tooltip:e.overview?Pl.siteTrafficTooltip:f?`${Pl.siteTrafficFallbackTooltip} Data covers ${f}.`:Pl.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||d?(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[n,d&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(q,{variant:`outline`,size:`sm`,disabled:a,onClick:Yn(s),children:[(0,$.jsx)(S,{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:Yn(c),children:[(0,$.jsx)(u,{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}),p]})}function Xl({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=ps({rows:l,getSearchText:e=>ds(e.landingPage),pageSize:Ml}),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=ps({rows:d,getSearchText:Al,pageSize:jl}),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?Ll(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)(Gc,{id:`traffic-by-channel-heading`,title:`Traffic by channel`,tooltip:Pl.channelTooltip,meta:g}),(0,$.jsx)(Yc,{label:`Sessions by channel`,items:[{label:`Organic search`,value:_.organic.sharePctDisplay,detail:`${_.organic.sessions.toLocaleString()} sessions`,tooltip:Pl.organicTooltip},{label:`Social`,value:_.social.sharePctDisplay,detail:`${_.social.sessions.toLocaleString()} sessions`,tooltip:Pl.socialTooltip},{label:`Direct`,value:_.direct.sharePctDisplay,detail:`${_.direct.sessions.toLocaleString()} sessions`,tooltip:Pl.directTooltip},{label:`AI (at least)`,value:_.ai.sharePctDisplay,detail:v>0?`${_.ai.sessions.toLocaleString()} sessions · ${v.toLocaleString()} paid`:`${_.ai.sessions.toLocaleString()} sessions`,tooltip:Pl.aiTooltip},{label:`Other channels`,value:_.other.sharePctDisplay,detail:`${_.other.sessions.toLocaleString()} sessions`,tooltip:Pl.otherTooltip}]}),(0,$.jsxs)(Kc,{children:[(0,$.jsx)(qc,{label:Pl.aiChartLabel,meta:r.days.length>0?Zl(r.totalSessions,`session`):Pl.noneInPeriod,children:r.days.length>0?(0,$.jsx)(nl,{input:r.byEngine,baseline:p,baselineLabel:`Total sessions`,label:Pl.aiChartLabel}):(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:Pl.noAiReferrals})}),(0,$.jsx)(qc,{label:`Where AI visitors came from`,meta:y.length>0?`${Zl(y.filter(e=>e.engine!==null).length,`engine`)} · ${Zl(n.aiReferrals.length,`source`)}`:Pl.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)(el,{groups:y,groupLabel:`Engine`,caption:`AI referral sessions by engine`,childColumns:Hl,childRowKey:e=>`${e.source}:${e.medium}:${e.sourceDimension}:${e.trafficClass}`,renderChildCells:e=>(0,$.jsx)(Gl,{row:e}),pinLast:Wl})}),(0,$.jsx)(X,{text:Pl.aiEnginesTooltip})]}):(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:Pl.noAiReferrals})}),(0,$.jsx)(qc,{label:`Pages AI visitors landed on`,meta:S??Pl.noneInPeriod,children:n.aiReferralLandingPages.length>0?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(us,{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)(Xc,{label:`Landing page`,sortKey:`landingPage`,current:s.key,dir:s.dir,onSort:h,align:`left`}),(0,$.jsx)(Xc,{label:`Source`,sortKey:`source`,current:s.key,dir:s.dir,onSort:h,align:`left`}),(0,$.jsx)(Zc,{label:`Attribution`,align:`left`}),(0,$.jsx)(Xc,{label:`Sessions`,sortKey:`sessions`,current:s.key,dir:s.dir,onSort:h,align:`right`})]})}),(0,$.jsx)(`tbody`,{children:f.rows.map(e=>(0,$.jsx)(su,{row:e},`${e.landingPage}:${e.source}:${e.medium}:${e.sourceDimension}`))})]})}),(0,$.jsx)(fs,{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:Pl.noAiLandingPages})})]})]}),(0,$.jsx)(`div`,{className:`page-section-divider`}),(0,$.jsxs)(`section`,{"aria-labelledby":`social-heading`,children:[(0,$.jsx)(Gc,{id:`social-heading`,title:`Social`,tooltip:Pl.socialTooltip2,meta:g}),(0,$.jsx)(Yc,{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:Pl.platformsTooltip},{label:`Paid social`,value:(n.paidSocialSessions??0).toLocaleString(),detail:`${rn(n.paidSocialShare??0)} of social`,tooltip:Pl.paidSocialTooltip},{label:`Top platform`,value:x?.label??`None`,detail:x?`${x.sessions.toLocaleString()} sessions`:void 0}]}),(0,$.jsxs)(Kc,{children:[(0,$.jsx)(qc,{label:Pl.socialChartLabel,meta:b.length>0?Zl(n.socialSessions,`session`):Pl.noneInPeriod,children:b.length>0?(0,$.jsx)(nl,{input:n.socialPlatformDaily,label:Pl.socialChartLabel}):(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:Pl.noSocial})}),(0,$.jsx)(qc,{label:`Social platforms`,meta:b.length>0?`${Zl(b.length,`platform`)} · ${Zl(n.socialReferrals.length,`source`)}`:Pl.noneInPeriod,children:b.length>0?(0,$.jsx)(el,{groups:b,groupLabel:`Platform`,caption:`Social sessions by platform`,childColumns:Ul,childRowKey:e=>`${e.source}:${e.medium}:${e.channelGroup}`,renderChildCells:e=>(0,$.jsx)(Kl,{row:e})}):(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary`,children:Pl.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)(Gc,{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)(us,{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)(Xc,{label:`Landing page`,sortKey:`landingPage`,current:a.key,dir:a.dir,onSort:m,align:`left`}),(0,$.jsx)(Xc,{label:`Sessions`,sortKey:`sessions`,current:a.key,dir:a.dir,onSort:m,align:`right`}),(0,$.jsx)(Xc,{label:`Organic`,sortKey:`organicSessions`,current:a.key,dir:a.dir,onSort:m,align:`right`}),(0,$.jsx)(Zc,{label:`Organic share`,align:`right`})]})}),(0,$.jsx)(`tbody`,{children:u.rows.map(e=>(0,$.jsx)(ou,{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)(fs,{page:u.page,pageSize:u.pageSize,visibleRows:u.rows.length,totalRows:u.totalRows,onPageChange:u.setPage,itemLabel:u.hasQuery?`matches`:`pages`})]})]}),(0,$.jsx)(iu,{projectName:t}),(0,$.jsx)(`p`,{className:`mt-6 text-copy-13 text-secondary`,children:n?.lastSyncedAt?`Last synced ${Fl(n.lastSyncedAt)}`:`Never synced`})]})}function Zl(e,t){return`${e.toLocaleString()} ${e===1?t:`${t}s`}`}var Ql=25,$l=`n/a`,eu={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 tu(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 nu(e){return e===null?$l:e.toFixed(1)}function ru(e){return e===null?$l:rn(e)}function iu({projectName:e}){let[t,n]=(0,Q.useState)(`28d`),[r,i]=(0,Q.useState)(`clicks`),[a,o]=(0,Q.useState)(`desc`),s=E({...$r({client:K,path:{name:e},query:{window:t,limit:qt}}),staleTime:tr}),c=s.data,l=(0,Q.useMemo)(()=>[...c?.rows??[]].sort((e,t)=>{let n=tu(e,r),i=tu(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=ps({rows:l,getSearchText:e=>ds(U(e.landingPage)),pageSize:Ql});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()&&!W();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:eu.heading}),(0,$.jsx)(X,{text:eu.tooltip})]}),c?.windowStart&&c.windowEnd&&(0,$.jsxs)(`p`,{className:`text-copy-14 text-secondary mt-1`,children:[fn(c.windowStart),` to `,fn(c.windowEnd),c.timeZone?` (${c.timeZone})`:``]})]}),(0,$.jsx)(Vc,{windows:ae,value:t,onChange:e=>{u.setPage(1),n(e)},label:eu.windowLabel})]}),s.isPending?(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary py-6 text-center`,children:eu.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:eu.loadError}),(0,$.jsx)(q,{variant:`outline`,size:`sm`,onClick:()=>{s.refetch()},children:eu.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:eu.notLinkedBadge}),(0,$.jsx)(X,{text:eu.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:eu.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:eu.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:eu.thresholdedBadge}),(0,$.jsx)(X,{text:eu.thresholded})]}),c.status!==`ready`&&f&&c.syncedAt&&(0,$.jsxs)(`span`,{className:`text-label-14 text-secondary`,children:[eu.previousSnapshot,` `,Fl(c.syncedAt),`.`]}),c.status===`unavailable`&&f&&(0,$.jsx)(`p`,{className:`w-full text-copy-14 text-secondary`,children:eu.unavailableAction})]}),f?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(us,{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)(Xc,{label:`Landing page`,sortKey:`landingPage`,current:r,dir:a,onSort:d,align:`left`}),(0,$.jsx)(Xc,{label:`Clicks`,sortKey:`clicks`,current:r,dir:a,onSort:d,align:`right`}),(0,$.jsx)(Xc,{label:`Impressions`,sortKey:`impressions`,current:r,dir:a,onSort:d,align:`right`}),(0,$.jsx)(Xc,{label:`CTR`,sortKey:`ctr`,current:r,dir:a,onSort:d,align:`right`}),(0,$.jsx)(Xc,{label:`Avg. position`,sortKey:`position`,current:r,dir:a,onSort:d,align:`right`}),(0,$.jsx)(Xc,{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:[eu.totalLabel,` `,(0,$.jsx)(`span`,{className:`text-label-14 text-secondary`,children:eu.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:ru(f.organicGoogleSearchClickThroughRate)}),(0,$.jsx)(`td`,{className:`py-1.5 pl-4 text-right text-primary tabular-nums`,children:nu(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:U(e.landingPage),children:U(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:ru(e.organicGoogleSearchClickThroughRate)}),(0,$.jsx)(`td`,{className:`py-1.5 pl-4 text-right text-secondary tabular-nums`,children:nu(e.organicGoogleSearchAveragePosition)}),(0,$.jsx)(`td`,{className:`py-1.5 pl-4 text-right text-secondary tabular-nums`,children:e.activeUsers.toLocaleString()})]},e.landingPage))]})]})}),!he(f)&&!p&&(0,$.jsxs)(`div`,{className:`text-label-14 text-secondary mt-3 space-y-1`,children:[(0,$.jsx)(`p`,{children:eu.noSearchTraffic}),(0,$.jsx)(`p`,{children:c.searchConsoleLink?.state===`no-search-data`?eu.noSearchTrafficConfirmed:eu.noSearchTrafficAction})]}),u.totalRows===0&&u.hasQuery&&(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary mt-3`,children:c.totalRows>c.rows.length?eu.noFilterMatchInLoaded(c.rows.length):eu.noFilterMatch}),(0,$.jsx)(fs,{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 `,Fl(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:eu.unavailable}),(0,$.jsx)(`p`,{children:eu.unavailableAction})]}):c.status===`error`?(0,$.jsxs)(`div`,{className:`text-label-14 text-secondary space-y-1`,children:[(0,$.jsx)(`p`,{className:`text-neutral`,children:eu.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:eu.neverSynced}),m&&(0,$.jsx)(`p`,{children:eu.neverSyncedAction})]})})]})]})]})}function au({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 wt(e,{propertyId:n.trim(),keyJson:o});try{await _n(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)(_,{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:Yn(m),children:c?`Connecting & syncing…`:`Connect GA4`})]})}function ou({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:rn(e.organicShare)})]})}function su({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)(ls,{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:Vl[e.sourceDimension]??``,children:Bl[e.sourceDimension]??e.sourceDimension}),(0,$.jsx)(`td`,{className:`py-1.5 pl-4 text-right text-primary tabular-nums`,children:e.sessions.toLocaleString()})]})}function cu(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 lu=`Search Console is not connected yet. Your Canonry team can set this up.`,uu=[`7d`,`30d`,`90d`,`all`],du=500,fu=[{key:`clicks`,label:`Clicks`,color:na[1],format:e=>e.toLocaleString()},{key:`impressions`,label:`Impressions`,color:na[4],format:e=>e.toLocaleString()},{key:`ctr`,label:`CTR`,color:fa.caution,format:e=>rn(e)},{key:`position`,label:`Avg position`,color:na[2],inverted:!0,format:e=>e.toFixed(1)}],pu=25,mu=`canonry:google-oauth-complete`;function hu(e,t,n){if(!e)return`no comparison period`;let r=e.days;if(!e.comparable)return`property-level comparison unavailable`;let i=e.change[t];if(i===null||!Number.isFinite(i)){let n=e.prior[t],i=e.trailing[t];return n!==null&&i!==null&&n<=0&&i>0?`new in the last ${r}d`:n===null||n<=0?`no prior ${r}d to compare`:i===null?`no value in the last ${r}d`:`comparison unavailable`}return i===0?`→ no change vs prior ${r}d`:`${(n?i<0:i>0)?`↑`:`↓`} ${rn(Math.abs(i))} vs prior ${r}d`}function gu(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 _u(e){return e.contents?.reduce((e,t)=>e+Number(t.submitted||0),0)??0}function vu(e){let t=Number(e.errors??0),n=Number(e.warnings??0);return[t>0?`${t} error${t===1?``:`s`}`:``,n>0?`${n} warning${n===1?``:`s`}`:``].filter(Boolean).join(` · `)}function yu(e){return e.isPending?`Processing`:Number(e.errors??0)>0?`Errors`:Number(e.warnings??0)>0?`Warnings`:`Success`}function bu({projectName:e,refreshNonce:t}){let n=w(),{isAdmin:r}=Jn(),i=W(),[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,S]=(0,Q.useState)(``),[C,T]=(0,Q.useState)(``),[E,D]=(0,Q.useState)(`30`),[O,k]=(0,Q.useState)(!1),[A,j]=(0,Q.useState)(`30d`),[N,P]=(0,Q.useState)([`clicks`,`impressions`]),[F,I]=(0,Q.useState)(!0),[L,R]=(0,Q.useState)(null),[ee,te]=(0,Q.useState)(0),[z,B]=(0,Q.useState)({startDate:``,endDate:``,query:``,page:``}),[ne,V]=(0,Q.useState)(0),[H,re]=(0,Q.useState)(!1),[ie,ae]=(0,Q.useState)(0),[oe,se]=(0,Q.useState)(!1),[le,ue]=(0,Q.useState)(``),[de,fe]=(0,Q.useState)(!0),[pe,me]=(0,Q.useState)(!1),[he,ge]=(0,Q.useState)(!1),[_e,ve]=(0,Q.useState)(!1),[ye,be]=(0,Q.useState)(!1),[xe,Se]=(0,Q.useState)(!1),[Ce,we]=(0,Q.useState)(!1),[U,Te]=(0,Q.useState)(null),[Ee,De]=(0,Q.useState)(!1),[Oe,ke]=(0,Q.useState)(!1),[Ae,je]=(0,Q.useState)(null),[Me,Ne]=(0,Q.useState)(null),[Pe,Fe]=(0,Q.useState)([]),[Ie,Le]=(0,Q.useState)(new Set),[Re,ze]=(0,Q.useState)({}),[Be,Ve]=(0,Q.useState)(new Set),[He,Ue]=(0,Q.useState)(``),[We,Ge]=(0,Q.useState)(null),[Ke,qe]=(0,Q.useState)(``),[Je,Ye]=(0,Q.useState)(!1),[Xe,Ze]=(0,Q.useState)(!1),[Qe,tt]=(0,Q.useState)(!1),[it,ot]=(0,Q.useState)(!1),[st,G]=(0,Q.useState)(`indexed`),[ct,lt]=(0,Q.useState)(null),ut=!!(z.query.trim()||z.page.trim()||ct),dt=ct!==null,ft=(0,Q.useMemo)(()=>{if(!ct)return d;let{key:e,dir:t}=ct;return[...d].sort((n,r)=>{let i=e===Hn.CTR?Number.isFinite(n.ctr)?n.ctr:0:n[e],a=e===Hn.CTR?Number.isFinite(r.ctr)?r.ctr:0:r[e];return t===`asc`?i-a:a-i})},[d,ct]),pt=ps({rows:ft,pageSize:25}),mt=oe?pt.rows:ft,ht=ps({rows:(Ae??[]).filter(e=>e.path.toLowerCase().includes(He.trim().toLowerCase())),pageSize:25}),[gt,_t]=(0,Q.useState)([]),[vt,bt]=(0,Q.useState)(null),[xt,St]=(0,Q.useState)(1),Ct=(0,Q.useMemo)(()=>{if(gt.length<2)return null;let e=gt[gt.length-1],t=gt[gt.length-2];return{indexed:e.indexed-t.indexed,notIndexed:e.notIndexed-t.notIndexed}},[gt]);(0,Q.useEffect)(()=>{St(1)},[U,st,vt]);let wt=(0,Q.useMemo)(()=>vt?(U?.reasonGroups??[]).find(e=>e.reason===vt):void 0,[U,vt]),Tt=(0,Q.useMemo)(()=>U?st===`indexed`?U.indexed:st===`deindexed`?U.deindexed:st===`notIndexed`?vt?wt?.urls??[]:(U.reasonGroups??[]).length===0?U.notIndexed:[]:[]:[],[U,st,vt,wt]),Et=Math.max(1,Math.ceil(Tt.length/pu)),Dt=Math.min(Math.max(1,xt),Et),Ot=(Dt-1)*pu,kt=(0,Q.useMemo)(()=>U?.indexed.slice(Ot,Ot+pu)??[],[U,Ot]),jt=(0,Q.useMemo)(()=>U?.notIndexed.slice(Ot,Ot+pu)??[],[U,Ot]),Mt=(0,Q.useMemo)(()=>U?.deindexed.slice(Ot,Ot+pu)??[],[U,Ot]),Nt=(0,Q.useMemo)(()=>(wt?.urls??[]).slice(Ot,Ot+pu),[wt,Ot]),[Pt,Ft]=(0,Q.useState)(!1),[It,Lt]=(0,Q.useState)(null),[Rt,zt]=(0,Q.useState)(null),[Bt,Vt]=(0,Q.useState)(null),[Ht,Ut]=(0,Q.useState)(null);function Wt(e,t){let n=Os(e),r=cu(n);r?(zt(r),Lt(null)):(zt(null),Lt(n.message||t))}let Gt=s.find(e=>e.connectionType===`gsc`),Kt=(Gt?.scopes??[]).includes(`https://www.googleapis.com/auth/webmasters`),qt=Pe.length>0?Pe:(Ae??[]).map(e=>e.path),Jt=qt.filter(e=>Ae?.some(t=>t.path===e&&t.isSitemapsIndex)).length,Yt=Jt===1?`Resubmit sitemap index`:Jt>1?`Resubmit sitemap indexes`:`Resubmit all sitemaps`,Xt=d.length>0||h.length>0||_.length>0,Zt=as(),Qt=yo();async function $t(t,r=!1){if(i)u([]);else if(!t)u([]),S(``);else{ge(!0);try{let{sites:i}=await n.fetchQuery({...br({client:K,path:{name:e}}),staleTime:r?0:$n});u(i),S(t.propertyId??i[0]?.siteUrl??``),zt(null)}catch(e){u([]),Wt(e,`Failed to load Search Console properties`)}finally{ge(!1)}}}async function tn(t){be(!0);let r=t??ne;try{let t=ut?du:25,i=ut?0:r,a={limit:String(t)};z.startDate&&(a.startDate=z.startDate),z.endDate&&(a.endDate=z.endDate),z.query&&(a.query=z.query),z.page&&(a.page=z.page),i>0&&(a.offset=String(i)),A&&A!==`all`&&!z.startDate&&(a.window=A);let o=await n.fetchQuery({...sr({client:K,path:{name:e},query:a}),staleTime:$n}),s=o.rows;ut?(re(!1),f(s),ae(s.length),se(!0)):(re(i+s.length<o.totalMatching),f(s),ae(0),se(!1))}catch(e){f([]),re(!1),ae(0),Lt(e instanceof Error?e.message:`Failed to load GSC performance data`)}finally{be(!1)}}async function nn(){try{let t={};z.startDate&&(t.startDate=z.startDate),z.endDate&&(t.endDate=z.endDate),A&&A!==`all`&&!z.startDate&&(t.window=A);let r=await n.fetchQuery({...ea({client:K,path:{name:e},query:t}),staleTime:$n});m(r)}catch{m(null)}}async function an(t=!1){Se(!0);try{let r=le.trim()||void 0,i={limit:`20`};r&&(i.url=r);let[a,o]=await Promise.all([n.fetchQuery({...Fr({client:K,path:{name:e},query:i}),staleTime:t?0:$n}),n.fetchQuery({...wr({client:K,path:{name:e}}),staleTime:t?0:$n})]);g(a),v(o)}catch(e){g([]),v([]),Lt(e instanceof Error?e.message:`Failed to load GSC inspection history`)}finally{Se(!1)}}async function on(t=!1){De(!0);try{let[r,i]=await Promise.all([n.fetchQuery({...xr({client:K,path:{name:e}}),staleTime:t?0:$n}),n.fetchQuery({..._r({client:K,path:{name:e}}),staleTime:t?0:$n}).catch(()=>[])]);Te(r),_t(i)}catch(e){Te(null),_t([]),Lt(e instanceof Error?e.message:`Failed to load coverage data`)}finally{De(!1)}}async function sn(t){Ft(!0),Lt(null);try{let{succeeded:n,failed:r,total:i}=(await $e(e,{urls:t})).summary;Zn({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){Lt(e instanceof Error?e.message:`Failed to request indexing`)}finally{Ft(!1)}}async function cn(){Ft(!0),Lt(null);try{let{succeeded:t,failed:n,total:r}=(await $e(e,{urls:[],allUnindexed:!0})).summary;Zn({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){Lt(e instanceof Error?e.message:`Failed to request indexing`)}finally{Ft(!1)}}async function ln(){ke(!0),Lt(null);try{let t=await rt(e);n.setQueryData(Ur({client:K,path:{name:e}}),t),je(t.sitemaps),Ne(t.summary),Fe(t.preferredSubmissionUrls),Le(new Set),ze({}),t.sitemaps.length===0&&Vt(`No sitemaps found in this GSC property. Submit one here to start Google processing it.`)}catch(e){Lt(e instanceof Error?e.message:`Failed to list sitemaps`)}finally{ke(!1)}}async function un(t){let n=Ie.has(t);if(Le(e=>{let r=new Set(e);return n?r.delete(t):r.add(t),r}),!(n||Re[t])){Ve(e=>new Set(e).add(t));try{let n=await rt(e,t);ze(e=>({...e,[t]:n.sitemaps}))}catch(e){Lt(e instanceof Error?e.message:`Failed to load sitemap files`)}finally{Ve(e=>{let n=new Set(e);return n.delete(t),n})}}}async function dn(t){if(!Kt||t.length===0)return;let n=[...new Set(t)];Ze(!0),Lt(null),Ge({completed:0,total:n.length});let r=0,i=0,a=0,o=null;try{for(let t=0;t<n.length;t+=50){let s=n.slice(t,t+50);try{let t=await en(e,s);r+=t.summary.accepted,i+=t.summary.failed,a+=s.length,Ge({completed:a,total:n.length})}catch(t){a+=s.length;let c=s.length,l=n.length-a,u=t instanceof Error?t.message:`The batch request failed`,d=`${r} accepted, ${i} failed, ${c} unconfirmed, ${l} not attempted. Google may still process accepted sitemaps; indexing is not guaranteed.`;o=`Sitemap submission stopped after a batch request failed. ${d} ${u}`,Lt(o),Zn({title:`Sitemap resubmission partially completed`,detail:d,tone:`caution`,dedupeKey:`gsc:sitemap-submit:${e}`,dedupeMode:`replace`});return}}let t=n.length;Zn({title:i===0?`Sitemap submitted to Google`:`Some sitemap submissions need attention`,detail:i===0?`Google accepted the sitemap submission/refetch request; indexing is not guaranteed.`:`Google accepted ${r}/${t} sitemap submissions; ${i} failed. Indexing is not guaranteed.`,tone:i===0?`positive`:`caution`,dedupeKey:`gsc:sitemap-submit:${e}`,dedupeMode:`replace`}),qe(``)}catch(e){Lt(e instanceof Error?e.message:`Failed to submit sitemap to Google`)}finally{Ze(!1),Ge(null),await ln(),o&&Lt(o)}}async function fn(){Ze(!0);let t=Ae??[];try{let n=t.filter(e=>e.isSitemapsIndex),r=[];for(let t=0;t<n.length;t+=4)(await Promise.all(n.slice(t,t+4).map(async t=>{let n=Re[t.path];if(n)return n;let r=await rt(e,t.path);return ze(e=>({...e,[t.path]:r.sitemaps})),r.sitemaps}))).forEach((e,i)=>{r.push(...e.length>0?e.map(e=>e.path):[n[t+i].path])});await dn([...t.filter(e=>!e.isSitemapsIndex).map(e=>e.path),...r])}catch(e){Lt(e instanceof Error?e.message:`Failed to load sitemap files`),Ze(!1)}}async function pn(t){Ye(!0),Lt(null);try{await nt(e,`gsc`,t),await Qn(n,`google`),c(e=>e.map(e=>e.connectionType===`gsc`?{...e,sitemapUrl:t}:e)),Zn({title:`Default sitemap updated`,detail:t,tone:`positive`,dedupeKey:`gsc:sitemap-default:${e}`,dedupeMode:`replace`})}catch(e){Lt(e instanceof Error?e.message:`Failed to set the default sitemap`)}finally{Ye(!1)}}async function hn(t){try{await Qt.mutateAsync({projectName:e,projectLabel:e,opts:t?{sitemapUrl:t}:void 0})}catch{}}async function gn(){try{let t=(await n.fetchQuery({...$i({client:K,path:{name:e},query:{kind:wn[`gsc-sync`],limit:1}}),staleTime:$n}))[0];Ut(t?.status===et.failed&&t.error?`Last saved Search Console sync failed: ${ce(t.error)}`:null)}catch{Ut(`Saved Search Console sync status is unavailable.`)}}async function _n(){fe(!0),Lt(null);try{let[t,a]=await Promise.all([i||!r?Promise.resolve(null):mn().catch(()=>null),n.fetchQuery({...Mr({client:K,path:{name:e}}),staleTime:$n}).catch(()=>[])]);o(!!t?.google?.configured),c(a);let s=a.find(e=>e.connectionType===`gsc`);S(s?.propertyId??``),await Promise.all([!i&&s&&!s.propertyId?$t(s):Promise.resolve(),!i&&s?gn():Promise.resolve(),tn(),nn(),an(),on()])}finally{fe(!1)}}(0,Q.useEffect)(()=>{u([]),tt(!1),je(null),Ne(null),Fe([]),Ut(null),zt(null),Vt(null)},[e]),(0,Q.useEffect)(()=>{_n()},[e,t,r]),(0,Q.useEffect)(()=>{V(0),R(null),B(e=>e.startDate||e.endDate?{...e,startDate:``,endDate:``}:e),te(e=>e+1),nn()},[A]);let yn=(0,Q.useRef)(!1);(0,Q.useEffect)(()=>{yn.current?(V(0),pt.setPage(1),tn(0)):yn.current=!0},[ee]);function bn(e){let t=L===e?null:e;R(t),B(e=>({...e,startDate:t??``,endDate:t??``})),te(e=>e+1)}let xn=(0,Q.useRef)(!1);(0,Q.useEffect)(()=>{xn.current?(V(0),tn(0)):xn.current=!0},[dt]);async function Cn(){if(!a)Lt(`Google OAuth app credentials are not configured yet. Set them on the Settings page first.`);else{me(!0),Lt(null),Vt(null);try{let{authUrl:t,redirectUri:r}=await Sn(e,`gsc`);if(!t.startsWith(`https://accounts.google.com/`)){Lt(`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(),Vt(e?`Google connected. Refreshing access…`:`Refreshing Google connection…`);try{await Qn(n,`google`),await _n()}finally{Vt(null)}}};function u(e){if(e.source!==i||e.origin!==a||!e.data||typeof e.data!=`object`)return;let t=e.data;t.type===mu&&t.connectionType===`gsc`&&l(!0)}window.addEventListener(`message`,u),Vt(`Finish the Google consent flow in the popup. This page will refresh automatically.`),s=window.setInterval(()=>{i.closed&&l(!1)},1e3)}catch(e){Lt(e instanceof Error?e.message:`Failed to start OAuth flow`)}finally{me(!1)}}}async function Tn(){Lt(null),Vt(null);try{await At(e,`gsc`),await Qn(n,`google`),c(e=>e.filter(e=>e.connectionType!==`gsc`)),u([]),S(``)}catch(e){Lt(e instanceof Error?e.message:`Failed to disconnect`)}}async function Y(){if(x){ve(!0),Lt(null);try{await at(e,`gsc`,x),await Qn(n,`google`),c(e=>e.map(e=>e.connectionType===`gsc`?{...e,propertyId:x}:e)),Zn({title:`GSC property updated`,detail:`${e} is now linked to ${x}.`,tone:`positive`,dedupeKey:`gsc:property:${e}`,dedupeMode:`drop`})}catch(e){Lt(e instanceof Error?e.message:`Failed to save GSC property`)}finally{ve(!1)}}}async function En(){Lt(null),Vt(null);try{await Zt.mutateAsync({projectName:e,projectLabel:e,opts:{days:parseInt(E,10)||void 0,full:O||void 0}}),await Qn(n,`gsc`)}catch{}}async function Dn(){if(C.trim()){we(!0),Lt(null),Vt(null);try{let t=await yt(e,C.trim());await Qn(n,`gsc`),b(t),T(``),await an()}catch(e){Lt(e instanceof Error?e.message:`Failed to inspect URL`)}finally{we(!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`})]})}),Ht&&(0,$.jsx)(`p`,{role:`status`,className:`mb-3 text-copy-14 text-caution`,children:Ht}),Rt&&(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:Rt.title}),(0,$.jsx)(`p`,{className:`mt-0.5 text-caution-200/90`,children:Rt.message}),(Ko(Rt.enableUrl)||Ko(Rt.indexingApiUrl))&&(0,$.jsxs)(`div`,{className:`mt-2 flex flex-wrap gap-3`,children:[Ko(Rt.enableUrl)&&(0,$.jsx)(`a`,{href:Ko(Rt.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 ↗`}),Ko(Rt.indexingApiUrl)&&(0,$.jsx)(`a`,{href:Ko(Rt.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:()=>zt(null),children:`×`})]})}),It&&(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:[It,(0,$.jsx)(`button`,{type:`button`,className:`ml-2 text-negative-400 hover:text-negative-200`,onClick:()=>Lt(null),children:`×`})]}),Bt&&(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:[Bt,(0,$.jsx)(`button`,{type:`button`,className:`ml-2 text-positive-400 hover:text-positive-200`,onClick:()=>Vt(null),children:`×`})]}),de?(0,$.jsx)(`p`,{className:`text-copy-14 text-muted`,children:`Loading…`}):(0,$.jsxs)(`div`,{className:`space-y-3`,children:[Gt?(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:Gt.domain}),(0,$.jsx)(`span`,{className:`text-mono-700`,children:`·`}),(0,$.jsxs)(`span`,{children:[`Coverage measured`,` `,U?.lastInspectedAt?Pn(U.lastInspectedAt):`never`]}),!i&&(0,$.jsx)(`button`,{type:`button`,className:`ml-auto text-muted transition-colors hover:text-negative-400`,onClick:Yn(Tn),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:pe,onClick:Yn(Cn),children:pe?`Opening…`:`Connect Google Search Console`}):(0,$.jsx)(q,{type:`button`,variant:`outline`,size:`sm`,asChild:!0,children:(0,$.jsx)(M,{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:lu})}),(Gt||Xt)&&(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:`${gu(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 ${du.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)(Vc,{windows:uu,value:A,onChange:e=>{j(e),V(0),pt.setPage(1)},label:`Search Console time period`,formatOption:e=>e===`all`?`All`:e}),(0,$.jsx)(q,{type:`button`,variant:`outline`,size:`sm`,disabled:ye,onClick:()=>{V(0),pt.setPage(1),tn(0),nn()},children:ye?`Loading…`:`Apply filters`})]})]}),p&&p.daily.length>0&&(()=>{let{totals:e,daily:t,trends:n,periodComparison:r}=p,i=fu.filter(e=>N.includes(e.key)).map(e=>({dataKey:e.key,label:e.label,color:e.color,axisId:e.key,inverted:e.inverted,formatValue:e.format,trend:F?n?.[e.key]??null:null})),a=t=>e[t]??null,o=new Map(t.map(e=>[e.date,e])),s=t.length===0?[]:vn(t[0].date,t[t.length-1].date).map(e=>o.get(e)??{date:e});return(0,$.jsxs)(`div`,{className:`mt-3`,children:[(0,$.jsx)(`div`,{className:`grid grid-cols-2 gap-2 sm:grid-cols-4`,children:fu.map(e=>{let t=N.includes(e.key),n=a(e.key),i=n===null;return(0,$.jsxs)(`button`,{type:`button`,"aria-pressed":t,disabled:i,className:`rounded-md border px-3 py-2 text-left transition-colors ${t?`border-strong bg-surface-active`:`border-subtle bg-surface-subtle hover:bg-surface-hover`} ${i?`cursor-not-allowed opacity-50`:``}`,onClick:()=>{P(t=>t.includes(e.key)?t.length===1?t:t.filter(t=>t!==e.key):[...t,e.key])},children:[(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:`inline-block h-2 w-2 rounded-full`,style:{backgroundColor:t?e.color:`transparent`,border:`1px solid ${e.color}`}}),(0,$.jsx)(`span`,{className:`text-label-12 text-secondary`,children:e.label})]}),(0,$.jsx)(`span`,{className:`mt-0.5 block text-label-18 tabular-nums text-strong`,children:n===null?`—`:e.format(n)}),(0,$.jsx)(`span`,{className:`block text-label-12 tabular-nums text-muted`,children:hu(r,e.key,e.inverted)})]},e.key)})}),(0,$.jsx)(`div`,{className:`mt-2 flex items-center justify-end`,children:(0,$.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-1.5 text-label-12 text-secondary`,children:[(0,$.jsx)(`input`,{type:`checkbox`,className:`accent-mono-400`,checked:F,onChange:e=>I(e.target.checked)}),`Trend line`]})}),(0,$.jsx)(`div`,{className:`mt-1`,children:(0,$.jsx)(ra,{data:s,xKey:`date`,series:i,xTickFormatter:ia,labelFormatter:la,onSelectX:bn,selectedX:L})}),(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":L===e.date,onClick:()=>bn(e.date),children:[la(e.date),`: `,e.clicks,` clicks, `,e.impressions,` impressions`]},e.date))}),L&&(0,$.jsxs)(`div`,{className:`mt-1 flex items-center gap-2 text-label-12`,children:[(0,$.jsxs)(`span`,{className:`text-secondary`,children:[`Table showing `,la(L)]}),(0,$.jsxs)(`button`,{type:`button`,className:`text-link hover:underline`,onClick:()=>bn(L),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:z.startDate,onChange:e=>B(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:z.endDate,onChange:e=>B(t=>({...t,endDate:e.target.value}))}),(0,$.jsx)(us,{value:z.query,onChange:e=>B(t=>({...t,query:e})),label:`Filter search queries`,placeholder:`Contains query…`}),(0,$.jsx)(us,{value:z.page,onChange:e=>B(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(Hn).map(e=>(0,$.jsx)(`th`,{className:`text-right`,"aria-sort":ct?.key===e?ct.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:()=>{pt.setPage(1),lt(t=>t?.key===e?t.dir===`desc`?{key:e,dir:`asc`}:null:{key:e,dir:`desc`})},children:[Un[e],ct?.key===e?ct.dir===`desc`?` ↓`:` ↑`:``]})},e))]})}),(0,$.jsx)(`tbody`,{children:mt.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)(ls,{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:rn(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)(fs,{page:oe?pt.page:Math.floor(ne/25)+1,pageSize:25,visibleRows:mt.length,totalRows:oe?ie:void 0,hasNextPage:oe?void 0:H,disabled:ye,itemLabel:oe?`matches`:`rows`,onPageChange:e=>{if(oe){pt.setPage(e);return}let t=(e-1)*25;V(t),tn(t)}}),oe&&ie>=du?(0,$.jsxs)(`p`,{className:`mt-2 text-copy-13 text-muted`,children:[`Results are capped at `,du.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:[U&&U.notIndexed.length>0&&(0,$.jsx)(q,{type:`button`,variant:`outline`,size:`sm`,disabled:Pt,onClick:()=>void cn(),children:Pt?`Requesting…`:`Request indexing (${U.notIndexed.length})`}),(0,$.jsx)(q,{type:`button`,variant:`outline`,size:`sm`,disabled:Ee,onClick:()=>void on(!0),children:Ee?`Loading…`:`Reload saved coverage`})]})]}),U&&U.summary.total>0?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`mt-6 flex flex-col items-center`,children:(()=>{let e=U.summary.indexedShare??0,t=U.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:ca.trackSubtle,strokeWidth:`14`}),(0,$.jsx)(`circle`,{cx:`64`,cy:`64`,r:54,fill:`none`,stroke:fa.positiveDeep,strokeWidth:`14`,strokeDasharray:n,strokeDashoffset:r,strokeLinecap:`round`,transform:`rotate(-90 64 64)`,style:{transition:`stroke-dashoffset 0.6s ease`}}),U.summary.notIndexed>0&&(0,$.jsx)(`circle`,{cx:`64`,cy:`64`,r:54,fill:`none`,stroke:ca.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:rn(U.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:U.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:U.summary.notIndexed.toLocaleString()}),(0,$.jsxs)(`p`,{className:`text-label-12 normal-case text-muted`,children:[`Not indexed`,(U.reasonGroups??[]).length>0&&(0,$.jsxs)(`span`,{className:`ml-1 text-faint`,children:[`· `,(U.reasonGroups??[]).length,` `,(U.reasonGroups??[]).length===1?`reason`:`reasons`]})]})]})]}),U.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:U.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`?U.indexed.length:e===`notIndexed`?U.notIndexed.length:U.deindexed.length;return(0,$.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":st===e,className:`border-b-2 px-3 py-2 text-button-14 transition-colors ${st===e?`border-accent text-heading`:`border-transparent text-secondary hover:border-mono-600 hover:text-strong`}`,onClick:()=>{G(e),bt(null)},children:[e===`indexed`?`Indexed`:e===`notIndexed`?`Not Indexed`:`Deindexed`,` (`,t,`)`]},e)})}),(0,$.jsxs)(`div`,{className:`mt-3 overflow-x-auto`,children:[st===`indexed`&&U.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:kt.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))})]}),st===`notIndexed`&&!vt&&(U.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:(U.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:()=>bt(e.reason),onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),bt(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))})]}),st===`notIndexed`&&!vt&&(U.reasonGroups??[]).length===0&&U.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:jt.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))})]}),st===`notIndexed`&&vt&&(()=>{let e=(U.reasonGroups??[]).find(e=>e.reason===vt);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:()=>bt(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:Pt,onClick:()=>void sn(e.urls.map(e=>e.url)),children:Pt?`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:Nt.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:Pt,onClick:()=>void sn([e.url]),title:`Request indexing`,children:`Index`})})]},e.id))})]})]}):null})(),st===`deindexed`&&U.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:Mt.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}`))})]}),(st===`indexed`&&U.indexed.length===0||st===`notIndexed`&&!vt&&U.notIndexed.length===0||st===`deindexed`&&U.deindexed.length===0)&&(0,$.jsx)(`p`,{className:`text-copy-14 text-muted`,children:`No URLs in this category.`}),(0,$.jsx)(fs,{page:Dt,pageSize:pu,visibleRows:Math.min(pu,Tt.length-Ot),totalRows:Tt.length,onPageChange:St,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":it,onClick:()=>ot(e=>!e),children:[(0,$.jsx)(`span`,{children:`Coverage history`}),(0,$.jsx)(`span`,{children:it?`Hide snapshots`:gt.length>0?`View ${gt.length} snapshots`:`View history`})]}),(0,$.jsxs)(`p`,{className:`mt-1 text-copy-13 text-muted`,children:[`Current: `,U.summary.indexed.toLocaleString(),` indexed, `,U.summary.notIndexed.toLocaleString(),` not indexed.`,Ct&&(0,$.jsxs)($.Fragment,{children:[` Since the last snapshot: `,Ct.indexed>=0?`+`:``,Ct.indexed.toLocaleString(),` indexed, `,Ct.notIndexed>=0?`+`:``,Ct.notIndexed.toLocaleString(),` not indexed.`]})]}),it&&(0,$.jsx)(`div`,{className:`mt-3 overflow-x-auto`,children:gt.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:gt.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:Ee?`Loading coverage data…`:`No coverage data yet. Inspect your sitemap to populate this view.`})]}),!i&&(0,$.jsxs)($.Fragment,{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:`Sitemaps`}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`h3`,{children:`Sitemap operations`}),(0,$.jsx)(X,{text:`Submitting asks Google to refetch these sitemaps. Indexing is not guaranteed.`})]})]}),(0,$.jsx)(q,{type:`button`,variant:`outline`,size:`sm`,disabled:Oe||!Gt?.propertyId,onClick:()=>void ln(),children:Oe?`Loading…`:Ae===null?`Load from Google`:`Reload from Google`})]}),(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/sitemap.xml`,value:Ke,onChange:e=>qe(e.target.value),onKeyDown:e=>e.key===`Enter`&&void dn([Ke.trim()])}),(0,$.jsx)(q,{type:`button`,size:`sm`,disabled:!Kt||Xe||!Ke.trim(),onClick:()=>void dn([Ke.trim()]),children:Xe?`Submitting…`:`Submit sitemap to Google`})]}),(0,$.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(q,{type:`button`,size:`sm`,variant:`outline`,disabled:!Kt||Xe||qt.length===0,onClick:()=>void dn(qt),children:Xe?`Resubmitting…`:Yt}),(0,$.jsx)(q,{type:`button`,size:`sm`,variant:`outline`,disabled:!Kt||Xe||!Ae?.length,onClick:()=>void fn(),children:`Resubmit all files`}),Me&&(0,$.jsxs)(`span`,{className:`text-label-12 text-muted`,children:[`Top level: `,Me.indexes,` index`,Me.indexes===1?``:`es`,`, `,Me.files,` file`,Me.files===1?``:`s`]}),We&&(0,$.jsxs)(`span`,{className:`text-label-12 text-secondary`,children:[`Submitting `,We.completed,`/`,We.total]})]}),!Kt&&Gt&&(0,$.jsxs)(`div`,{className:`mt-2 flex items-center gap-2 text-label-12 text-caution`,children:[(0,$.jsx)(`span`,{children:`Reconnect to let Canonry submit sitemaps. Your current Canonry OAuth grant is read-only.`}),(0,$.jsx)(`button`,{type:`button`,className:`text-secondary underline hover:text-strong`,onClick:Yn(Cn),children:`Reconnect`})]}),Ae===null&&(0,$.jsx)(`p`,{className:`mt-3 text-copy-14 text-secondary`,children:`Load sitemaps from Google to view them and enable resubmission.`}),Ae&&(0,$.jsx)(`div`,{className:`mt-3 overflow-x-auto`,children:Ae.length>0?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(us,{value:He,onChange:e=>{Ue(e),ht.setPage(1)},label:`Filter sitemaps`,placeholder:`Filter sitemaps…`}),(0,$.jsxs)(`table`,{className:`data-table mt-3 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:`Type`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Google status`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Last submitted`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Last read`}),(0,$.jsx)(`th`,{className:`text-right`,children:`Discovered URLs`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Issues`}),(0,$.jsx)(`th`,{className:`text-left`,children:`Actions`})]})}),(0,$.jsx)(`tbody`,{children:ht.rows.flatMap(e=>{let t=_u(e),n=vu(e),r=yu(e),i=Re[e.path]??[],a=Ie.has(e.path);return[(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{className:`max-w-xs text-strong`,children:(0,$.jsx)(ls,{value:e.path})}),(0,$.jsx)(`td`,{className:`text-secondary`,children:e.isSitemapsIndex?(0,$.jsx)(`button`,{type:`button`,className:`text-secondary hover:text-strong`,"aria-expanded":a,"aria-label":`${a?`Collapse`:`Expand`} files in ${e.path}`,onClick:()=>void un(e.path),children:Be.has(e.path)?`Loading…`:`${a?`▾`:`▸`} Index${Re[e.path]?` (${i.length})`:``}`}):`Sitemap`}),(0,$.jsx)(`td`,{className:`text-secondary`,children:r}),(0,$.jsx)(`td`,{className:`text-secondary`,children:e.lastSubmitted?e.lastSubmitted.split(`T`)[0]:`—`}),(0,$.jsx)(`td`,{className:`text-secondary`,children:e.lastDownloaded?e.lastDownloaded.split(`T`)[0]:`—`}),(0,$.jsx)(`td`,{className:`text-right tabular-nums text-neutral`,children:t.toLocaleString()}),(0,$.jsx)(`td`,{className:`max-w-48 text-secondary`,children:n||`—`}),(0,$.jsx)(`td`,{children:(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,$.jsx)(`button`,{type:`button`,className:`text-button-14 text-secondary hover:text-strong`,disabled:!Kt||Xe,onClick:()=>void dn([e.path]),children:e.lastSubmitted?`Resubmit to Google`:`Submit to Google`}),Gt?.sitemapUrl===e.path?(0,$.jsx)(`span`,{className:`text-label-12 text-muted`,title:`Used when no sitemap URL is provided for Canonry GSC operations.`,children:`Default sitemap`}):(0,$.jsx)(`button`,{type:`button`,className:`text-button-14 text-secondary hover:text-strong`,disabled:Je,title:`Use this sitemap by default for Canonry GSC operations.`,onClick:()=>void pn(e.path),children:`Set as default`}),(0,$.jsx)(`button`,{type:`button`,className:`text-button-14 text-secondary hover:text-strong`,disabled:Qt.isPending,onClick:()=>void hn(e.path),children:`Inspect URLs`})]})})]},e.path),...e.isSitemapsIndex&&a?i.map(t=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{className:`max-w-xs pl-6 text-secondary`,children:(0,$.jsx)(ls,{value:t.path})}),(0,$.jsx)(`td`,{className:`text-secondary`,children:`File`}),(0,$.jsx)(`td`,{className:`text-secondary`,children:yu(t)}),(0,$.jsx)(`td`,{className:`text-secondary`,children:t.lastSubmitted?t.lastSubmitted.split(`T`)[0]:`—`}),(0,$.jsx)(`td`,{className:`text-secondary`,children:t.lastDownloaded?t.lastDownloaded.split(`T`)[0]:`—`}),(0,$.jsx)(`td`,{className:`text-right tabular-nums text-neutral`,children:_u(t).toLocaleString()}),(0,$.jsx)(`td`,{className:`text-secondary`,children:vu(t)||`—`}),(0,$.jsx)(`td`,{children:(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,$.jsx)(`button`,{type:`button`,className:`text-button-14 text-secondary hover:text-strong`,disabled:!Kt||Xe,onClick:()=>void dn([t.path]),children:`Resubmit`}),Gt?.sitemapUrl===t.path?(0,$.jsx)(`span`,{className:`text-label-12 text-muted`,title:`Used when no sitemap URL is provided for Canonry GSC operations.`,children:`Default sitemap`}):(0,$.jsx)(`button`,{type:`button`,className:`text-button-14 text-secondary hover:text-strong`,disabled:Je,title:`Use this sitemap by default for Canonry GSC operations.`,onClick:()=>void pn(t.path),children:`Set as default`}),(0,$.jsx)(`button`,{type:`button`,className:`text-button-14 text-secondary hover:text-strong`,disabled:Qt.isPending,onClick:()=>void hn(t.path),children:`Inspect URLs`})]})})]},`${e.path}:${t.path}`)):[]]})})]}),(0,$.jsx)(fs,{page:ht.page,pageSize:25,visibleRows:ht.rows.length,totalRows:ht.totalRows,onPageChange:ht.setPage,itemLabel:`sitemaps`})]}):(0,$.jsx)(`p`,{className:`text-copy-14 text-muted`,children:`No sitemaps found for this 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:`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:C,onChange:e=>T(e.target.value),onKeyDown:e=>e.key===`Enter`&&void Dn()}),(0,$.jsx)(q,{type:`button`,size:`sm`,disabled:Ce||!Gt?.propertyId||!C.trim(),onClick:Yn(Dn),children:Ce?`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:Bn(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:Pn(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:xe,onClick:()=>void an(!0),children:xe?`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:le,onChange:e=>ue(e.target.value)}),(0,$.jsx)(q,{type:`button`,size:`sm`,variant:`outline`,disabled:xe,onClick:()=>void an(!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:Bn(e.isMobileFriendly??null)}),(0,$.jsx)(`td`,{className:`text-secondary`,children:Pn(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:Pn(e.transitionDate)})]},`${e.url}:${e.transitionDate}`))})]})}):(0,$.jsx)(`p`,{className:`mt-3 text-copy-14 text-muted`,children:`No deindexed transitions recorded.`})]})]}),Gt&&!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:()=>{Qe||$t(Gt),tt(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 ${Qe?`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`})]})}),Qe&&(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:he||l.length===0,onChange:e=>S(e.target.value),children:l.length===0?(0,$.jsx)(`option`,{value:``,children:he?`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:he,onClick:()=>void $t(Gt,!0),children:he?`Refreshing…`:`Refresh properties`}),(0,$.jsx)(q,{type:`button`,size:`sm`,disabled:!x||_e,onClick:Yn(Y),children:_e?`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:E,onChange:e=>D(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:O,onChange:e=>k(e.target.checked)}),`Replace existing imported rows for the requested range`]})]}),(0,$.jsx)(q,{type:`button`,size:`sm`,disabled:Zt.isPending||!Gt.propertyId,onClick:Yn(En),children:Zt.isPending?`Queueing…`:`Queue sync`}),!Gt.propertyId&&(0,$.jsx)(`p`,{className:`text-copy-13 text-caution-400`,children:`Select a Search Console property before queueing a sync.`})]})]})]})})]})]})]})}var xu=new Set([`gbp-listing-discrepancy`,`gbp-lodging-gap`,`gbp-cta-gap`,`gbp-metric-drop`,`gbp-keyword-drop`]);function Su({projectName:e,projectId:t}){let n=w(),[r,i]=(0,Q.useState)(null),[a,o]=(0,Q.useState)(null),[s,c]=(0,Q.useState)(!1),l=E(Mr({client:K,path:{name:e}})),u=l.data?.find(e=>e.connectionType===`gbp`),d=!!u,f=r?{locationName:r}:void 0,p=E({...zr({client:K,path:{name:e}}),enabled:d}),m=E({...vi({client:K,path:{name:e},query:f}),enabled:d}),h=E({...Gi({client:K,path:{name:e},query:f}),enabled:d}),g=E({...mr({client:K,path:{name:e},query:f}),enabled:d}),_=E({...dr({client:K,path:{name:e},query:f}),enabled:d}),v=E({...kr({client:K,path:{name:e},query:f}),enabled:d}),y=E({queryKey:[`gbp-section-insights`,e],queryFn:()=>ye(e),enabled:d});function b(){Qn(n,`gbp`)}let x=T({...li(),onSuccess:n=>{Ho({id:n.runId,projectId:t,kind:wn[`gbp-sync`],projectLabel:e,sourceAction:`gbp-sync`}),Zn({title:`Business Profile sync started`,detail:`${e} will refresh when the sync completes.`,tone:`neutral`,dedupeKey:`gbp-sync:${e}`,dedupeMode:`replace`})}}),S=(0,Q.useSyncExternalStore)(Zo,ya,ya),C=Object.values(S.runs).some(e=>e.kind===wn[`gbp-sync`]&&e.projectId===t),D=x.isPending||C,O=T({...Ki(),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)),z=P.filter(e=>ee.has(e.locationName)),B=F.filter(e=>ee.has(e.locationName)),ne=new Set(j.map(e=>e.locationName)),V=r?M:M.filter(e=>ne.has(e.locationName)),H=!r&&j.length>1,re=(y.data??[]).filter(e=>!e.dismissed&&xu.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)(ss,{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:[re.length>0&&(0,$.jsxs)(`div`,{className:`mb-6 grid gap-2`,children:[(0,$.jsx)(`p`,{className:`eyebrow eyebrow-soft`,children:`Needs attention`}),re.map(e=>(0,$.jsx)(`div`,{className:[`surface-card insight-card`,zu(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)(qu,{performance:k.performance,freshness:k.freshness,timeseries:k.timeseries}),k?.profileCompleteness&&(0,$.jsx)(Cu,{summary:k.profileCompleteness}),R.length>0&&(0,$.jsx)(wu,{locations:R,lodging:te,places:B,placeActions:z,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:[rn(h.data.thresholdedPct,On.percent),` privacy-thresholded`]})]}),V.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`}),H&&(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:V.slice(0,25).map(e=>(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(`td`,{className:`text-neutral`,children:e.keyword}),H&&(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)(ss,{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 Cu({summary:e}){if(e.locationCount===0)return null;let t=e.locationCount,n=[{label:`Description`,value:`${e.withDescription}/${t}`,tone:Lu(e.withDescription,t,`caution`)},{label:`Hours`,value:`${e.withHours}/${t}`,tone:Lu(e.withHours,t,`caution`)},{label:`Phone`,value:`${e.withPrimaryPhone}/${t}`,tone:Lu(e.withPrimaryPhone,t,`caution`)},{label:`Service area`,value:`${e.withServiceArea}/${t}`,tone:Lu(e.withServiceArea,t,`neutral`)},{label:`Secondary categories`,value:`${e.withSecondaryCategories}/${t}`,detail:`${e.secondaryCategoryTotal} total`,tone:Lu(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 ${Ru(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 wu({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:Vu(e.openStatus)})]})]})}),(0,$.jsx)(`td`,{children:(0,$.jsx)(Eu,{location:e})}),(0,$.jsx)(`td`,{children:(0,$.jsx)(Du,{lodging:t})}),(0,$.jsx)(`td`,{children:(0,$.jsx)(ku,{place:n,mapsUri:e.mapsUri})}),(0,$.jsx)(`td`,{children:(0,$.jsx)(ju,{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)(Pu,{location:e,lodging:t,place:n,placeActions:r})})})]},e.id)})})]})})]})}function Tu(e){return[{label:`Description`,tone:Bu(e.description)?`positive`:`neutral`,value:Bu(e.description)?`set`:`not returned`},{label:`Hours`,tone:e.regularHours?`positive`:`neutral`,value:e.regularHours?`set`:`not returned`},{label:`Phone`,tone:Bu(e.primaryPhone)?`positive`:`neutral`,value:Bu(e.primaryPhone)?`set`:`not returned`},{label:`Website`,tone:Bu(e.websiteUri)?`positive`:`neutral`,value:Bu(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 Eu({location:e}){let t=Tu(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 Du({lodging:e}){return(0,$.jsx)(Nu,{...Ou(e)})}function Ou(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 ku({place:e,mapsUri:t}){return(0,$.jsx)(Nu,{...Au(e,t)})}function Au(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 ju({actions:e}){return(0,$.jsx)(Nu,{...Mu(e)})}function Mu(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 Nu({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 Pu({location:e,lodging:t,place:n,placeActions:r}){let i=t?Gu(t.attributes):[];return(0,$.jsxs)(`div`,{className:`grid gap-5 text-label-12 lg:grid-cols-3`,children:[(0,$.jsxs)(Fu,{title:`Owner profile · Business Information`,children:[(0,$.jsx)(Iu,{label:`Primary category`,value:e.primaryCategoryDisplayName??`Not returned`}),(0,$.jsx)(Iu,{label:`Secondary categories`,value:e.additionalCategories.length>0?e.additionalCategories.join(`, `):`Not returned`}),(0,$.jsx)(Iu,{label:`Description`,value:Bu(e.description)?e.description:`Not returned`}),(0,$.jsx)(Iu,{label:`Hours`,value:e.regularHours?`Returned by Google`:`Not returned`}),(0,$.jsx)(Iu,{label:`Service area`,value:e.serviceArea?`Returned by Google`:`Not returned`}),(0,$.jsx)(Iu,{label:`Phone`,value:e.primaryPhone??`Not returned`}),(0,$.jsx)(Iu,{label:`Website`,value:e.websiteUri??`Not returned`}),(0,$.jsx)(Iu,{label:`Open status`,value:Vu(e.openStatus)}),(0,$.jsx)(Iu,{label:`Opening date`,value:e.openingDate??`Not returned`})]}),(0,$.jsx)(Fu,{title:`Hotel data · Lodging API`,children:t?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Iu,{label:`Last checked`,value:Wu(t.syncedAt)}),(0,$.jsx)(Iu,{label:`Groups returned`,value:String(t.populatedGroupCount)}),(0,$.jsx)(Iu,{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)(Fu,{title:`Public listing + CTAs`,children:[n?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Iu,{label:`Places tier`,value:n.tier}),(0,$.jsx)(Iu,{label:`Last checked`,value:Wu(n.syncedAt)}),(0,$.jsx)(Iu,{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:[Hu(e.placeActionType),e.isPreferred?` · preferred`:``]}),(0,$.jsxs)(`span`,{className:`text-faint`,children:[Hu(e.providerType),e.uri?` · ${Uu(e.uri)}`:``]})]},e.placeActionLinkName))})})]})]})}function Fu({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 Iu({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 Lu(e,t,n){return e===t?`positive`:e===0?n:`caution`}function Ru(e){switch(e){case`positive`:return`text-positive`;case`caution`:return`text-caution`;case`negative`:return`text-negative`;case`neutral`:return`text-neutral`}}function zu(e){return e===`critical`||e===`high`?`insight-card-negative`:e===`medium`?`insight-card-caution`:``}function Bu(e){return typeof e==`string`&&e.trim().length>0}function Vu(e){return e?Hu(e):`Not returned`}function Hu(e){return e?e.toLowerCase().split(`_`).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `):`Unknown`}function Uu(e){try{return new URL(e).hostname.replace(/^www\./,``)}catch{return e}}function Wu(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString(void 0,{month:`short`,day:`numeric`,year:`numeric`})}function Gu(e){return Object.entries(e).filter(([e,t])=>e!==`name`&&e!==`metadata`&&Ku(t)).map(([e])=>Hu(e.replace(/([a-z])([A-Z])/g,`$1_$2`)))}function Ku(e){return e==null?!1:Array.isArray(e)?e.length>0:typeof e!=`object`||Object.keys(e).length>0}function qu({performance:e,freshness:t,timeseries:n}){let r=e.totals,i=Re.filter(e=>(r[e]??0)>0),a=Ke.filter(e=>(r[e]??0)>0),o=Object.keys(r).filter(e=>(r[e]??0)>0&&me(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 ${la(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)(Ju,{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:[we(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)(Ju,{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=>we(e)).join(`, `)]})]})}function Ju({data:e,metrics:t,kind:n,firstPending:r,lastDate:i}){return(0,$.jsx)(`div`,{className:`h-48 w-full`,children:(0,$.jsx)(R,{width:`100%`,height:`100%`,children:(0,$.jsxs)(ne,{data:e,margin:{top:8,right:8,bottom:0,left:0},children:[(0,$.jsx)(P,{stroke:ma,vertical:!1}),(0,$.jsx)(I,{dataKey:`date`,tick:da,tickLine:!1,axisLine:{stroke:ga},tickFormatter:ia,minTickGap:24}),(0,$.jsx)(z,{tick:da,tickLine:!1,axisLine:!1,allowDecimals:!1,width:36}),(0,$.jsx)(F,{...ha,labelFormatter:la,formatter:(e,t)=>[typeof e==`number`?e.toLocaleString():String(e??0),we(String(t??``))]}),(0,$.jsx)(te,{wrapperStyle:{fontSize:12,color:ca.text},formatter:e=>we(e)}),r&&i&&(0,$.jsx)(L,{x1:r,x2:i,fill:ca.surface,fillOpacity:.55,stroke:`none`,label:{value:`pending`,position:`insideTopRight`,fill:ca.textDim,fontSize:12}}),t.map((e,t)=>n===`line`?(0,$.jsx)(B,{type:`monotone`,dataKey:e,stroke:na[t%na.length],strokeWidth:2,dot:!1,isAnimationActive:!1},e):(0,$.jsx)(ee,{type:`monotone`,dataKey:e,stackId:`reach`,stroke:na[t%na.length],fill:na[t%na.length],fillOpacity:.25,strokeWidth:1.5,isAnimationActive:!1},e))]})})})}function Yu(e){return ua(sa(String(e)))}function Xu(e){return aa(sa(String(e)))}var Zu=25;function Qu(e){return typeof window>`u`?e:`${window.__CANONRY_CONFIG__?.basePath?.replace(/\/$/,``)??``}${e}`}function $u(e){return e.toLocaleString()}function ed(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 td(e){let t=e.filter(e=>e.kind===wn[`backlink-extract`]&&!Eo(e.status));return t.length===0?null:t.reduce((e,t)=>e.createdAt>t.createdAt?e:t)}function nd(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 rd({projectName:e}){let a=W(),[o,c]=(0,Q.useState)(null),[l,u]=(0,Q.useState)(null),[d,f]=(0,Q.useState)([]),[p,m]=(0,Q.useState)(null),[h,g]=(0,Q.useState)(null),[_,v]=(0,Q.useState)(null),[y,b]=(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,r,i,a]=await Promise.all([ot().catch(()=>null),Ce(e,{excludeCrawlers:!0}).catch(()=>null),Ge(e,{limit:Zu,offset:x,excludeCrawlers:!0}).catch(e=>{if(e instanceof bt&&e.code===`NOT_FOUND`)return null;throw e}),pe(e).catch(()=>[]),ke(e).catch(()=>[])]);m(t),c(n),u(r),f(i);let o=td(a);g(o)}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(!h)return;let e=h.id,t=!1,n=async()=>{try{let n=await ft(e);if(t)return;Eo(n.status)?(g(null),v(n),await k()):g(e=>e?.id===n.id?{...e,...n}:e)}catch{}},r=window.setInterval(()=>{n()},3e3);return()=>{t=!0,window.clearInterval(r)}},[h,k]),(0,Q.useEffect)(()=>{if(!h)return;let e=window.setInterval(()=>b(Date.now()),1e3);return()=>window.clearInterval(e)},[h]),(0,Q.useEffect)(()=>{if(!_||_.status===`failed`)return;let e=window.setTimeout(()=>v(null),1e4);return()=>window.clearTimeout(e)},[_]);async function A(){E(!0),O(null);try{let t=await St(e);g(t)}catch(e){e instanceof bt&&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=(0,Q.useMemo)(()=>d.slice().sort((e,t)=>e.queriedAt.localeCompare(t.queriedAt)).map(e=>({date:e.queriedAt,linkingDomains:e.totalLinkingDomains})),[d]),M=l?.rows??[],N=l?.total??0,P=o?.excludedLinkingDomains??0,L=Math.floor(x/Zu)+1;return(0,Q.useEffect)(()=>{x>0&&x>=N&&S(0)},[x,N]),(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})}),h&&(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:h.status}),(0,$.jsxs)(`span`,{className:`text-label-14 text-secondary tabular-nums`,children:[nd(h.startedAt??null,h.createdAt),` elapsed · refreshing every 3s`]}),(0,$.jsxs)(`span`,{className:`sr-only`,children:[`now=`,y]})]}),(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary mt-1`,children:`Refreshing this project from the current Common Crawl release.`})]})]})}),_&&!h&&(0,$.jsx)(Z,{className:`surface-card p-4 mb-4 ${_.status===`failed`?`bg-negative-soft`:`bg-positive-soft`}`,children:(0,$.jsxs)(`div`,{className:`flex items-start gap-3`,children:[_.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)(r,{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 ${_.status===`failed`?`text-negative`:`text-positive`}`,children:_.status===`failed`?`Extract failed`:`Extract complete`}),_.error?(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary mt-1`,children:Gn(_.error)}):_.status===`failed`?null:(0,$.jsx)(`p`,{className:`text-copy-14 text-secondary mt-1`,children:`Backlinks refreshed from the cached release.`})]})]})}),te()]});function te(){return C?(0,$.jsx)(Z,{className:`surface-card p-6`,children:(0,$.jsx)(`p`,{className:`text-copy-14 text-muted`,children:`Loading backlinks…`})}):B()}function B(){let e=o!==null&&o.totalLinkingDomains>0,r=_?.status===`failed`,i=o!==null&&o.totalLinkingDomains===0&&!r,c=p?.status===`ready`,l=p?.status===`failed`,u=p&&(p.status===`downloading`||p.status===`querying`||p.status===`queued`);return e?V((0,$.jsxs)($.Fragment,{children:[!Y()&&!a&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(q,{type:`button`,variant:`outline`,size:`sm`,disabled:T||h!==null,onClick:Yn(A),children:[(0,$.jsx)(s,{className:`h-4 w-4 mr-1.5`,"aria-hidden":!0}),h?`Extract running…`:T?`Queuing…`:`Re-run extract`]}),(0,$.jsx)(hs,{label:`About re-running`,children:`Re-queries the current release for this project without downloading it again.`})]}),!Y()&&!a&&(0,$.jsx)(q,{asChild:!0,type:`button`,variant:`outline`,size:`sm`,children:(0,$.jsx)(`a`,{href:Qu(`/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)(n,{className:`h-5 w-5`,"aria-hidden":!0})}),(0,$.jsxs)(`div`,{className:`flex-1`,children:[!p&&(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()&&!a&&(0,$.jsx)(`div`,{className:`mt-4`,children:(0,$.jsx)(q,{asChild:!0,type:`button`,size:`sm`,children:(0,$.jsx)(`a`,{href:Qu(`/backlinks`),children:`Set up backlinks`})})})]}),u&&(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 (`,p.status,p.phaseDetail?` — ${p.phaseDetail}`:``,`). Backlinks will appear here once it finishes.`]}),!Y()&&!a&&(0,$.jsx)(`div`,{className:`mt-4`,children:(0,$.jsx)(q,{asChild:!0,type:`button`,variant:`outline`,size:`sm`,children:(0,$.jsx)(`a`,{href:Qu(`/backlinks`),children:`View sync status`})})})]}),l&&(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:p.error??`The workspace release sync failed. Retry from the Backlinks admin page.`}),!Y()&&!a&&(0,$.jsx)(`div`,{className:`mt-4`,children:(0,$.jsx)(q,{asChild:!0,type:`button`,size:`sm`,children:(0,$.jsx)(`a`,{href:Qu(`/backlinks`),children:`Go to Backlinks admin`})})})]}),c&&!u&&!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:p.release}),` is ready. Run an extract for this project.`]}),!Y()&&!a&&(0,$.jsxs)(`div`,{className:`mt-4 flex items-center gap-3 flex-wrap`,children:[(0,$.jsxs)(q,{type:`button`,size:`sm`,disabled:T||h!==null,onClick:Yn(A),children:[(0,$.jsx)(t,{className:`h-4 w-4 mr-1.5`,"aria-hidden":!0}),h?`Extract running…`:T?`Queuing…`:`Run extract`]}),(0,$.jsx)(hs,{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()&&!a&&(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:Qu(`/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 `,o.targetDomain,`. Try a newer release or re-run this extract.`]}),!Y()&&!a&&(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:Qu(`/backlinks`),children:`Go to Backlinks admin`})}),(0,$.jsxs)(q,{type:`button`,variant:`outline`,size:`sm`,disabled:T||h!==null,onClick:Yn(A),children:[(0,$.jsx)(t,{className:`h-4 w-4 mr-1.5`,"aria-hidden":!0}),h?`Extract running…`:T?`Queuing…`:`Re-run extract`]}),(0,$.jsxs)(hs,{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:o.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 V(e){if(!o)return null;let t=`linking hosts`,n=`release`;return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`gauge-row`,children:[(0,$.jsxs)(`div`,{className:`metric-card`,children:[(0,$.jsx)(`p`,{className:`metric-card-eyebrow`,children:`Referring domains`}),(0,$.jsx)(`p`,{className:`metric-card-big-value`,children:(0,$.jsx)(`span`,{className:`text-primary`,children:$u(o.totalLinkingDomains)})}),(0,$.jsxs)(`p`,{className:`metric-card-sub`,children:[`unique domains linking to `,o.targetDomain]})]}),(0,$.jsxs)(`div`,{className:`metric-card`,children:[(0,$.jsxs)(`p`,{className:`metric-card-eyebrow`,children:[`Total `,t]}),(0,$.jsx)(`p`,{className:`metric-card-big-value`,children:(0,$.jsx)(`span`,{className:`text-primary`,children:$u(o.totalHosts)})}),(0,$.jsxs)(`p`,{className:`metric-card-sub`,children:[`aggregate `,t,` across referring domains`]})]}),(0,$.jsxs)(`div`,{className:`metric-card`,children:[(0,$.jsx)(`p`,{className:`metric-card-eyebrow`,children:`Top-10 concentration`}),(0,$.jsx)(`p`,{className:`metric-card-big-value`,children:(0,$.jsx)(`span`,{className:`text-primary`,children:rn(Number(o.top10HostsShare))})}),(0,$.jsxs)(`p`,{className:`metric-card-sub`,children:[`share of `,t,` from the 10 largest linking domains`]})]})]}),(0,$.jsxs)(`p`,{className:`text-copy-13 text-muted mt-2`,children:[(0,$.jsx)(`span`,{className:`text-secondary`,children:`Common Crawl`}),` · `,n,` `,(0,$.jsx)(`code`,{className:`text-secondary`,children:o.release}),` · queried `,ed(o.queriedAt),P>0&&(0,$.jsxs)($.Fragment,{children:[` · `,P,` excluded domain`,P===1?``:`s`]})]}),j.length>=2&&(0,$.jsxs)(Z,{className:`surface-card p-4 mt-4`,children:[(0,$.jsx)(`p`,{className:`eyebrow eyebrow-soft`,children:`Referring domains over time`}),(0,$.jsx)(`div`,{className:`h-40 mt-2`,children:(0,$.jsx)(R,{width:`100%`,height:`100%`,children:(0,$.jsxs)(ne,{data:j,margin:{top:8,right:12,bottom:0,left:12},children:[(0,$.jsx)(`defs`,{children:(0,$.jsxs)(`linearGradient`,{id:`bl-gradient`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,$.jsx)(`stop`,{offset:`0%`,stopColor:na[0],stopOpacity:.4}),(0,$.jsx)(`stop`,{offset:`100%`,stopColor:na[0],stopOpacity:0})]})}),(0,$.jsx)(I,{dataKey:`date`,tick:da,stroke:`var(--chart-axis, #2e2e2e)`,tickFormatter:Yu}),(0,$.jsx)(z,{tick:da,stroke:`var(--chart-axis, #2e2e2e)`,allowDecimals:!1}),(0,$.jsx)(F,{contentStyle:ha.contentStyle,labelStyle:ha.labelStyle,itemStyle:ha.itemStyle,labelFormatter:Xu}),(0,$.jsx)(ee,{type:`monotone`,dataKey:`linkingDomains`,name:`Referring domains`,stroke:na[0],fill:`url(#bl-gradient)`,strokeWidth:2})]})})})]}),(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:[M.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:$u(e.numHosts)})]},e.linkingDomain)),M.length===0&&(0,$.jsx)(`tr`,{children:(0,$.jsx)(`td`,{className:`px-4 py-4 text-label-14 text-muted`,colSpan:2,children:P>0&&N===0?`Every referring domain in this ${n} was a crawler/proxy host (${P} hidden).`:`No referring domains in this ${n}.`})})]})]})}),(0,$.jsx)(fs,{page:L,pageSize:Zu,visibleRows:M.length,totalRows:N,onPageChange:e=>S((e-1)*Zu)})]}),(0,$.jsx)(`div`,{className:`mt-4 flex items-center gap-3 flex-wrap`,children:e})]})}}var id={[G[`keyword-metrics`]]:`Search demand`,[G[`domain-intelligence`]]:`Domain comparison`,[G[`ranked-keywords`]]:`Searches you rank for`,[G[`market-rankings`]]:`Market rankings`,[G[`competitor-discovery`]]:`Organic competitors`,[G[`keyword-gaps`]]:`Search gaps`},ad={[je.shared]:`Shared`,[je.missing]:`Missing`,[je.outranked]:`Competitor ahead`},od=`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.`,sd={[H.queued]:`Queued`,[H.running]:`Refreshing`,[H.completed]:`Completed`,[H.partial]:`Partial results`,[H.failed]:`Failed`,[H.cancelled]:`Cancelled`,[H[`reconciliation-required`]]:`Needs review`},cd=25,ld=new Intl.NumberFormat(`en-US`,{maximumFractionDigits:1}),ud=new Intl.NumberFormat(`en-US`,{style:`currency`,currency:`USD`,maximumFractionDigits:2}),dd=Intl.DateTimeFormat().resolvedOptions().timeZone,fd=`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`,pd=`px-4 py-3 text-right align-top tabular-nums whitespace-nowrap`,md=`min-w-56 px-4 py-3 text-left align-top text-label-14`,hd=`Position on the page, counting maps and other blocks`;function gd(e){return e?.status===H.queued||e?.status===H.running}function _d({value:e,currency:t=!1}){return e===null?(0,$.jsx)(`span`,{className:`text-muted`,"aria-label":`Not supplied`,children:`—`}):(0,$.jsx)($.Fragment,{children:t?ud.format(e):ld.format(e)})}function vd({status:e}){let t=e===H.completed?`positive`:e===H.failed?`negative`:e===H.partial||e===H[`reconciliation-required`]?`caution`:`neutral`;return(0,$.jsx)(J,{tone:t,children:sd[e]})}function yd(e){let t=pn(e).split(`/`).at(-1)??e,n=tn.safeParse(t.replaceAll(`_`,`-`));return n.success?id[n.data]:t.replaceAll(/[-_]/g,` `)}function bd(e){return e===`mobile`?`phone results`:e===`desktop`?`computer results`:`device not specified by source`}function xd(e){return e.capabilities.includes(G[`market-rankings`])?`Market locations`:`Location ${e.locationCode}`}function Sd(e){return e.capabilities.includes(G[`market-rankings`])?`searches`:`tasks`}function Cd(e){return e.capability!==G[`market-rankings`]||![H.queued,H.running,H.completed].includes(e.status)}function wd(e,t){let n=e.capabilities.includes(G[`market-rankings`]);return`${t} ${t===1?n?`search`:`task`:Sd(e)}`}function Td(e,t){return Number.isFinite(Date.parse(e))?$t(Bt(e,t)):null}var Ed={[H.failed]:`Latest refresh failed`,[H.cancelled]:`Latest refresh cancelled`,[H[`reconciliation-required`]]:`Latest refresh needs review`};function Dd(e,t){let n=e&&e.id!==t?.id?Ed[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=`${wd(t,t.failedTasks)} failed`,n=t.capabilities.includes(G[`market-rankings`])?`Their queries show as Failed.`:`Open Activity for details.`;return{label:e,text:`${e}: ${t.failedTasks} of ${wd(t,t.taskCount)} in this refresh returned no results. ${n}`}}return t.status===H.partial?{label:`Partial results`,text:`Partial results: ${t.error??`some ${Sd(t)} returned only part of their results or did not run. Open Activity for details.`}`}:null}function Od({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:yd(e.dataset)})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`dt`,{className:`text-muted`,children:`Search engine`}),(0,$.jsxs)(`dd`,{children:[`Google · `,bd(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:Et(e.collectedAt,dd)})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`dt`,{className:`text-muted`,children:`Source updated`}),(0,$.jsx)(`dd`,{children:e.sourceUpdatedAt?fn(e.sourceUpdatedAt):`Not supplied`})]})]})}function kd({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)(Od,{source:t})]})]})}function Ad({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:Ts(e)}),(0,$.jsx)(q,{variant:`secondary`,className:`pointer-coarse:min-h-11`,onClick:t,children:`Retry`})]})}function jd({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 Md({projectName:e}){let t=O({strict:!1}),n=D(),r=E(qi({client:K,path:{name:e}})),i=E(_i({client:K,path:{name:e}})),a=E({...Or({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??a.data?.profileId,f=d?i.data?.profiles.find(e=>e.id===d):t.seoRunId?void 0:i.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=r.data?.access.canWrite===!0&&!Y()&&!W(),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]),r.error)return(0,$.jsx)(Ad,{error:r.error,retry:()=>{r.refetch()}});if(i.error)return(0,$.jsx)(Ad,{error:i.error,retry:()=>{i.refetch()}});if(!r.data||!i.data)return(0,$.jsx)(`p`,{role:`status`,className:`py-10 text-copy-14 text-secondary`,children:`Loading SEO data…`});let g=r.data.available&&r.data.connections.some(e=>e.capabilities.length>0),_=g&&r.data.connections.some(e=>e.capabilities.some(e=>r.data.scopes.some(t=>t.capabilities?.includes(e)??!0))),v=f&&r.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)(o,{"aria-hidden":`true`,className:`size-4`}),`New profile`]})]})]}),i.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:`${fd} min-w-0 sm:w-64`,children:[!f&&(0,$.jsx)(`option`,{value:``,disabled:!0,children:`Profile unavailable`}),i.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)(gf,{projectName:e,context:r.data,profile:s.profile,id:s.id,onClose:h,onSaved:e=>{p(e),requestAnimationFrame(()=>u.current?.focus())}},s.id),!W()&&!r.data.available&&i.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:r.data.reason??`Configure an SEO data provider to refresh saved profiles.`}),t.seoRunId&&a.error?(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsx)(Ad,{error:a.error,retry:()=>{a.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&&a.isPending?(0,$.jsx)(`p`,{role:`status`,className:`py-10 text-copy-14 text-secondary`,children:`Loading refresh…`}):f&&a.data&&a.data.profileId!==f.id?(0,$.jsxs)(jd,{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)(Nd,{projectName:e,profile:f,context:r.data,selectedRunId:t.seoRunId,onLatest:()=>p(f.id)},`${f.id}:${f.revision}:${t.seoRunId??``}`):!_&&i.data.profiles.length===0?(0,$.jsx)(jd,{title:g?`SEO scope unavailable`:`Configure an SEO data provider`,children:g?r.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)(jd,{title:`Profile unavailable`,children:`This saved profile is no longer available. Select another profile to view its data.`}):!s&&(0,$.jsx)(jd,{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 Nd({projectName:e,profile:t,context:n,selectedRunId:r,onLatest:a}){let o=w(),[s,c]=(0,Q.useState)(r?`activity`:t.capabilities.includes(G[`ranked-keywords`])?G[`ranked-keywords`]:t.capabilities.at(0)??`activity`),[l,u]=(0,Q.useState)(null),d=(0,Q.useRef)(null),f=(0,Q.useRef)(null),p={name:e},m=E({...or({client:K,path:p,query:{profileId:t.id,runId:r}}),refetchInterval:e=>gd(e.state.data?.latestRun)?2e3:!1}),h=T({...Yi({client:K}),meta:{skipGlobalErrorToast:!0}}),g=T({...lr({client:K}),meta:{skipGlobalErrorToast:!0}}),_=m.data?.latestRun,v=m.data?.evidenceRun,y=m.data?.evidenceRun?.capabilities??t.capabilities,b=s===`activity`||y.includes(s)?s:y.at(0)??`activity`,x=gd(_),C=h.isPending||g.isPending,D=n.access.canRun&&!Y()&&!W(),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=E({...ti({client:K,path:p,query:{kind:Ae[`seo-sync`]}}),retry:!1}),j=!A.isError&&A.data?.enabled&&A.data.nextRunAt?A.data.nextRunAt:null,M=j?Td(j,A.data?.timezone??`UTC`):null,N=v?.finishedAt&&(v.status===H.completed||v.status===H.partial)?Td(v.finishedAt,dd):null,P=x?null:Dd(_,v);return(0,Q.useEffect)(()=>{_&&(gd(_)?f.current=_.id:f.current===_.id&&(f.current=null,Qn(o,`seo`,{projectName:e,profileId:t.id})))},[_,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:x&&_?(0,$.jsxs)(`p`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(i,{className:`size-4 animate-spin`,"aria-hidden":`true`}),_.cancelRequested?`Cancellation requested`:sd[_.status],` · `,_.completedTasks,` of `,_.taskCount,` `,Sd(_),` completed`]}):(0,$.jsxs)(`p`,{children:[N&&v?.finishedAt?(0,$.jsxs)($.Fragment,{children:[`Updated `,(0,$.jsx)(`time`,{dateTime:v.finishedAt,title:Et(v.finishedAt,dd)??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:C||x||!n.available||!O,onClick:Yn(async()=>{if(!(!D||r||x||C)){u(null);try{if(!d.current){let e=await h.mutateAsync({path:p,body:{profileId:t.id}});if(e.availability!==tt.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 g.mutateAsync({path:p,body:d.current});d.current=null,gd(e)&&(f.current=e.id),await o.fetchQuery(or({client:K,path:p,query:{profileId:t.id}}))}catch(e){Os(e).code===`VALIDATION_ERROR`&&(d.current=null),u(Ts(e))}}}),children:[(0,$.jsx)(S,{"aria-hidden":`true`,className:`size-4 ${C?`animate-spin`:``}`}),C?`Starting refresh…`:x?`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,`.`]}),m.data?.evidenceRun&&m.data.evidenceRun.profileRevision!==t.revision&&(0,$.jsxs)(`p`,{role:`status`,className:`text-copy-14 text-secondary`,children:[`Saved data uses profile revision `,m.data.evidenceRun.profileRevision,` · `,xd(m.data.evidenceRun),` · `,m.data.evidenceRun.languageCode,`. The current profile has changed.`]}),!W()&&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.`}),m.error?(0,$.jsx)(Ad,{error:m.error,retry:()=>{m.refetch()}}):m.data?.summary&&(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`p`,{className:`mb-3 break-words text-copy-13 text-secondary`,children:[m.data.summary.target.value,m.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)(_d,{value:m.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)(_d,{value:m.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)(_d,{value:m.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:[...y,`activity`].map(e=>(0,$.jsx)(`button`,{type:`button`,"aria-pressed":b===e,className:`min-h-11 border-b-2 text-button-14 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-mono-400 ${b===e?`border-strong text-primary`:`border-transparent text-secondary hover:text-primary`}`,onClick:()=>c(e),children:e===`activity`?`Activity`:id[e]},e))}),b===`activity`?(0,$.jsx)(hf,{projectName:e,profileId:t.id,canRun:D,selectedRunId:r}):m.isPending?(0,$.jsx)(`p`,{role:`status`,className:`py-8 text-copy-14 text-secondary`,children:`Loading saved data…`}):m.data&&(0,$.jsx)(Pd,{projectName:e,profileId:t.id,runId:m.data.evidenceRunId,view:b,active:x,nextRefresh:M},`${t.id}:${b}:${m.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: `,W()?`Fictional demo data`:O?.label??`Source unavailable`,`. Google; `,bd(t.rankings?.device??`unspecified`),`.`]}),m.data?.evidenceRun&&(0,$.jsxs)(`p`,{children:[`Saved evidence: `,m.data.evidenceRun.scope.kind,m.data.evidenceRun.scope.key?` · ${m.data.evidenceRun.scope.key}`:``,m.data.evidenceRun.scope.expectedPlanRevision===void 0?``:` · plan revision ${m.data.evidenceRun.scope.expectedPlanRevision}`,`. `,xd(m.data.evidenceRun),` · `,m.data.evidenceRun.languageCode,` · profile revision `,m.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,`.`]}),m.data?.summary&&(0,$.jsx)(Od,{source:m.data.summary.provenance})]})]})]})}function Pd({projectName:e,profileId:t,runId:n,view:r,active:i,nextRefresh:a}){return r===G[`market-rankings`]?n?(0,$.jsx)(af,{projectName:e,profileId:t,runId:n,active:i}):(0,$.jsx)(jd,{title:`No market rankings yet`,children:a?`First refresh ${a}`:`Refresh this profile to rank its tracked queries in each market.`}):(0,$.jsx)(Fd,{projectName:e,profileId:t,runId:n,view:r,active:i})}function Fd({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:cd,offset:(a-1)*cd}},m=E({...Er(p),enabled:!!n&&r===G[`ranked-keywords`]}),h=E({...pr(p),enabled:!!n&&r===G[`keyword-metrics`]}),g=E({...Vr(p),enabled:!!n&&r===G[`domain-intelligence`]}),_=E({...ur({...p,query:{...p.query,sort:l}}),placeholderData:N,enabled:!!n&&r===G[`competitor-discovery`]}),v=E({...gr({...p,query:{...p.query,kind:s||void 0,sort:d}}),placeholderData:N,enabled:!!n&&r===G[`keyword-gaps`]}),y=r===G[`ranked-keywords`]?m:r===G[`keyword-metrics`]?h:r===G[`competitor-discovery`]?_:r===G[`keyword-gaps`]?v:g;return n?(0,$.jsxs)(`div`,{className:`space-y-3 pt-4`,children:[r===G[`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:`${fd} w-auto`,value:s,onChange:e=>{c(e.target.value),o(1)},children:[(0,$.jsx)(`option`,{value:``,children:`All comparisons`}),(0,$.jsx)(`option`,{value:je.missing,children:`Missing`}),(0,$.jsx)(`option`,{value:je.shared,children:`Shared`}),(0,$.jsx)(`option`,{value:je.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===G[`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)(Ad,{error:y.error,retry:()=>{y.refetch()}}):y.data?y.data.items.length===0?(0,$.jsx)(jd,{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":`${id[r]} table`,"aria-busy":y.isFetching,tabIndex:0,children:[r===G[`ranked-keywords`]&&m.data&&(0,$.jsx)(Bd,{rows:m.data.items}),r===G[`keyword-metrics`]&&h.data&&(0,$.jsx)(Vd,{rows:h.data.items}),r===G[`domain-intelligence`]&&g.data&&(0,$.jsx)(Hd,{rows:g.data.items}),r===G[`competitor-discovery`]&&_.data&&(0,$.jsx)(Rd,{rows:_.data.items,sort:l,onSort:e=>{u(e),o(1)}}),r===G[`keyword-gaps`]&&v.data&&(0,$.jsx)(zd,{rows:v.data.items,sort:d,onSort:e=>{f(e),o(1)}})]}),(0,$.jsx)(fs,{page:a,pageSize:cd,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 `,id[r].toLowerCase(),`…`]})]}):(0,$.jsxs)(jd,{title:`No saved data yet`,children:[`Refresh this profile to collect `,id[r].toLowerCase(),` for its saved scope.`]})}function Id({value:e}){return e===null?(0,$.jsx)(_d,{value:null}):(0,$.jsxs)($.Fragment,{children:[e>0?`+`:``,ld.format(e)]})}function Ld({label:e,sort:t,ascending:n,descending:r,align:i=`right`,onSort:a,help:o}){return(0,$.jsx)(rf,{label:e,align:i,sorted:t===n?`ascending`:t===r?`descending`:null,onSort:()=>a(t===n?r:n),help:o,showUnsorted:!0})}function Rd({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)(Ld,{label:`Competitor`,align:`left`,sort:t,ascending:ve.domain,descending:ve[`-domain`],onSort:n}),(0,$.jsx)(Ld,{label:`Shared searches`,sort:t,ascending:ve.shared,descending:ve[`-shared`],onSort:n}),(0,$.jsx)(Ld,{label:`Avg. position`,sort:t,ascending:ve.position,descending:ve[`-position`],onSort:n}),(0,$.jsx)(Ld,{label:`Est. organic traffic`,sort:t,ascending:ve.traffic,descending:ve[`-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:md,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:pd,children:(0,$.jsx)(_d,{value:e.sharedKeywords})}),(0,$.jsx)(`td`,{className:pd,children:(0,$.jsx)(_d,{value:e.averagePosition})}),(0,$.jsx)(`td`,{className:pd,children:(0,$.jsx)(_d,{value:e.estimatedOrganicTraffic})}),(0,$.jsx)(`td`,{className:`px-4 align-top`,children:(0,$.jsxs)(kd,{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)(_d,{value:e.organicKeywords})]}),(0,$.jsxs)(`p`,{children:[`Target: `,e.target.value,` · includes subdomains`]})]})})]},`${e.target.value}:${e.domain}:${t}`))})]})}function zd({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)(Ld,{label:`Search`,align:`left`,sort:t,ascending:un.keyword,descending:un[`-keyword`],onSort:n}),(0,$.jsx)(Ld,{label:`Comparison`,align:`left`,sort:t,ascending:un.kind,descending:un[`-kind`],onSort:n}),(0,$.jsx)(Ld,{label:`Your rank`,sort:t,ascending:un[`target-rank`],descending:un[`-target-rank`],onSort:n}),(0,$.jsx)(Ld,{label:`Competitor rank`,sort:t,ascending:un[`competitor-rank`],descending:un[`-competitor-rank`],onSort:n}),(0,$.jsx)(Ld,{label:`Rank gap`,sort:t,ascending:un[`rank-gap`],descending:un[`-rank-gap`],onSort:n,help:od}),(0,$.jsx)(Ld,{label:`Monthly searches`,sort:t,ascending:un.volume,descending:un[`-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:md,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===je.shared?`neutral`:`caution`,children:ad[e.kind]})}),(0,$.jsx)(`td`,{className:pd,children:e.kind===je.missing?(0,$.jsx)(`span`,{className:`text-secondary`,children:`Not found`}):(0,$.jsx)(_d,{value:e.targetRankOrganic})}),(0,$.jsx)(`td`,{className:pd,children:(0,$.jsx)(_d,{value:e.competitorRankOrganic})}),(0,$.jsx)(`td`,{className:pd,children:(0,$.jsx)(Id,{value:e.rankGap})}),(0,$.jsx)(`td`,{className:pd,children:(0,$.jsx)(_d,{value:e.searchVolume})}),(0,$.jsx)(`td`,{className:`px-4 align-top`,children:(0,$.jsxs)(kd,{label:`${e.keyword} against ${e.competitor.value}`,source:e.provenance,children:[(0,$.jsxs)(`p`,{children:[`Your ranking page: `,e.targetUrl?(0,$.jsx)(vo,{url:e.targetUrl}):`Not supplied`]}),(0,$.jsxs)(`p`,{children:[`Competitor’s ranking page: `,e.competitorUrl?(0,$.jsx)(vo,{url:e.competitorUrl}):`Not supplied`]}),(0,$.jsxs)(`p`,{children:[`Difficulty /100: `,(0,$.jsx)(_d,{value:e.keywordDifficulty})]}),(0,$.jsxs)(`p`,{children:[`CPC: `,(0,$.jsx)(_d,{value:e.cpcUsd,currency:!0})]})]})})]},`${e.target.value}:${e.competitor.value}:${e.keyword}:${t}`))})]})}function Bd({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:`${pd} text-label-13-strong`,children:`Position`}),(0,$.jsx)(`th`,{className:`${pd} text-label-13-strong`,children:`Monthly searches`}),(0,$.jsx)(`th`,{className:`${pd} text-label-13-strong`,children:`Est. traffic`}),(0,$.jsx)(`th`,{className:`${pd} 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:md,children:[(0,$.jsx)(`p`,{className:`text-primary`,children:e.keyword}),(0,$.jsx)(`p`,{className:`mt-1 text-copy-13 text-secondary`,children:(0,$.jsx)(ls,{value:e.url??e.target.value})})]}),(0,$.jsx)(`td`,{className:pd,children:(0,$.jsx)(_d,{value:e.rankOrganic})}),(0,$.jsx)(`td`,{className:pd,children:(0,$.jsx)(_d,{value:e.searchVolume})}),(0,$.jsx)(`td`,{className:pd,children:(0,$.jsx)(_d,{value:e.estimatedTraffic})}),(0,$.jsx)(`td`,{className:pd,children:(0,$.jsx)(_d,{value:e.keywordDifficulty})}),(0,$.jsx)(`td`,{className:`px-4 align-top`,children:(0,$.jsxs)(kd,{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:[hd,`: `,(0,$.jsx)(_d,{value:e.rankAbsolute})]}),(0,$.jsxs)(`p`,{children:[`CPC: `,(0,$.jsx)(_d,{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 Vd({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:`${pd} text-label-13-strong`,children:`Monthly searches`}),(0,$.jsx)(`th`,{className:`${pd} text-label-13-strong`,children:`CPC`}),(0,$.jsx)(`th`,{className:`${pd} 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:`${md} text-primary`,children:e.keyword}),(0,$.jsx)(`td`,{className:pd,children:(0,$.jsx)(_d,{value:e.searchVolume})}),(0,$.jsx)(`td`,{className:pd,children:(0,$.jsx)(_d,{value:e.cpcUsd,currency:!0})}),(0,$.jsx)(`td`,{className:pd,children:(0,$.jsx)(_d,{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)(kd,{label:e.keyword,source:e.provenance,children:[(0,$.jsxs)(`p`,{children:[`Ad competition: `,e.adCompetition===null?`Not supplied`:rn(e.adCompetition,On.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)(_d,{value:e.searchVolume})})]},`${e.year}-${e.month}`))})]})})]},`${e.keyword}:${t}`))})]})}function Hd({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:`${pd} text-label-13-strong`,children:`Searches ranked for`}),(0,$.jsx)(`th`,{className:`${pd} 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:md,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:pd,children:(0,$.jsx)(_d,{value:e.organicKeywords})}),(0,$.jsx)(`td`,{className:pd,children:(0,$.jsx)(_d,{value:e.estimatedOrganicTraffic})}),(0,$.jsx)(`td`,{className:`px-4 align-top`,children:(0,$.jsx)(kd,{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)(_d,{value:e.top1})}),(0,$.jsx)(`dt`,{children:`Positions 2–3`}),(0,$.jsx)(`dd`,{children:(0,$.jsx)(_d,{value:e.top2To3})}),(0,$.jsx)(`dt`,{children:`Positions 4–10`}),(0,$.jsx)(`dd`,{children:(0,$.jsx)(_d,{value:e.top4To10})}),(0,$.jsx)(`dt`,{children:`Positions 11–20`}),(0,$.jsx)(`dd`,{children:(0,$.jsx)(_d,{value:e.top11To20})}),(0,$.jsx)(`dt`,{children:`Est. traffic value`}),(0,$.jsx)(`dd`,{children:(0,$.jsx)(_d,{value:e.estimatedOrganicTrafficValueUsd,currency:!0})})]})})})]},`${e.target.value}:${t}`))})]})}var Ud=5,Wd=10,Gd=`all`;function Kd(e){return e===Gd?Gd:Vt.safeParse(e).data??null}var qd={column:`ranks11To20`,descending:!0},Jd={3:`sm:grid-cols-3`,4:`sm:grid-cols-4`,5:`sm:grid-cols-5`},Yd=`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`,Xd=`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 Zd(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 Qd(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 $d(e){let t=e.filter(e=>e.kind===mt.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 ef(e,t){return e.counts[t]}function tf(e){let t=e.descending?-1:1,n=e.column;return n===`label`?(e,n)=>t*(st(e.label,n.label)||st(e.key,n.key)):(e,r)=>t*(ef(e,n)-ef(r,n))||st(e.label,r.label)||st(e.key,r.key)}function nf(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 rf({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:`${Yd} ${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 af({projectName:e,profileId:t,runId:n,active:r}){let i=O({strict:!1}),a=D(),o=i.seoRegion,s=i.seoMarket,c=Kd(i.seoShow),l=Ct.safeParse(i.seoSort).data??Ze.rank,u=t=>{a({to:`/projects/$projectName/seo-data`,params:{projectName:e},search:e=>({...e,...t}),replace:!0})},d=(0,Q.useId)(),f=E(yi({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)(Ad,{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)(sf,{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)(jd,{title:`No rankings here`,children:[`This refresh has no rankings for this `,s===void 0?`region`:`market`,`.`]}):(0,$.jsx)(jd,{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=xe(m,p),b=c??(p.needsWork>0?De[`needs-work`]:Gd),x=h.length>1||h.some(e=>e.kind===mt.region),S=[`${ld.format(p.queries)} ${p.queries===1?`query`:`queries`}`,...p.partlyChecked>0?[`${ld.format(p.partlyChecked)} partly checked`]:[],...p.failed>0?[`${ld.format(p.failed)} failed`]:[],...p.cancelled>0?[`${ld.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 ${Jd[y.length+1]??`sm:grid-cols-5`}`,children:[y.map(e=>(0,$.jsx)(of,{label:e.label,help:Zd(e,m),value:p[e.count]},e.count)),(0,$.jsx)(of,{label:`Rival ahead`,help:Qd(m),value:p.rivalAhead,className:`sm:border-l sm:border-subtle sm:pl-5`})]})]}),x&&(0,$.jsx)(cf,{projectName:e,groups:h,bands:y},`groups\u0000${g}`),(0,$.jsx)(lf,{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===Ze.rank?void 0:e}),urlQ:i.seoQ??``,onQ:e=>u({seoQ:e||void 0}),onClear:()=>u({seoShow:Gd,seoQ:void 0})},`queries\u0000${g}`)]})}function of({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:ld.format(n)})]})}function sf({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)(M,{to:`/projects/$projectName/seo-data`,params:{projectName:e},search:e=>({...e,seoRegion:void 0,seoMarket:void 0}),className:Xd,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)(M,{to:`/projects/$projectName/seo-data`,params:{projectName:e},search:e=>({...e,seoMarket:void 0}),className:Xd,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 cf({projectName:e,groups:t,bands:n}){let r=D(),[i,a]=(0,Q.useState)(null),[o,s]=(0,Q.useState)(1),c=$d(t),l=(i===null?t:[...t].sort(tf(i))).slice((o-1)*Ud,o*Ud),u=i??(n.some(e=>e.count===qd.column)?qd:null),d=[{column:`queries`,label:`Queries`},...n.map(e=>({column:e.count,label:e.label})),{column:`rivalAhead`,label:`Rival ahead`}],f=e=>{let t=i??qd;a(t.column===e?{column:e,descending:!t.descending}:{column:e,descending:e!==`label`}),s(1)},p=e=>u?.column===e?u.descending?`descending`:`ascending`:null,m=e=>e.kind===mt.region?t=>({...t,seoRegion:e.key,seoMarket:void 0}):t=>({...t,seoMarket:e.key}),h=`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":h,tabIndex:0,children:(0,$.jsxs)(`table`,{className:`w-full text-label-14`,children:[(0,$.jsx)(`caption`,{className:`sr-only`,children:h}),(0,$.jsx)(`thead`,{className:`bg-surface text-label-13 text-secondary`,children:(0,$.jsxs)(`tr`,{children:[(0,$.jsx)(rf,{label:c.label,align:`left`,sorted:p(`label`),onSort:()=>f(`label`)}),d.map(e=>(0,$.jsx)(rf,{label:e.label,align:`right`,sorted:p(e.column),onSort:()=>f(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:m(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)(M,{to:`/projects/$projectName/seo-data`,params:{projectName:e},search:m(t),className:`rounded-sm text-primary hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-mono-400`,children:t.label})}),d.map(e=>(0,$.jsx)(`td`,{className:pd,children:ld.format(t.counts[e.column])},e.column)),(0,$.jsx)(`td`,{className:`px-4 py-3 text-right align-top`,children:(0,$.jsx)(g,{"aria-hidden":`true`,className:`ml-auto size-4 text-muted`})})]},`${t.kind}:${t.key}`))})]})}),(0,$.jsx)(fs,{page:o,pageSize:Ud,visibleRows:l.length,totalRows:t.length,onPageChange:s,itemLabel:c.plural,className:`text-label-13 [&_button]:min-h-11`})]})}function lf({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=nf(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,w=E({...jr({client:K,path:{name:e},query:{profileId:t,runId:n,regionKey:r,marketKey:i,outcome:c===Gd?void 0:c,q:v||void 0,sort:u,limit:Wd,offset:(C-1)*Wd}}),placeholderData:N}),T=[{value:De[`needs-work`],label:`Needs work`,count:a.needsWork},...o.map(e=>({value:e.filter,label:e.label,count:a[e.count]})),{value:De[`rival-ahead`],label:`Rival ahead`,count:a.rivalAhead},{value:De[`partly-checked`],label:`Partly checked`,count:a.partlyChecked},{value:De.failed,label:`Failed`,count:a.failed},{value:De.cancelled,label:`Not searched`,count:a.cancelled},{value:Gd,label:`All`,count:a.queries}],D=[De[`partly-checked`],De.failed,De.cancelled],O=T.filter(e=>e.value===c||e.count>0||!D.includes(e.value)),k=O.find(e=>e.value===c)?.label??`All`,A=u===Ze.rank?`ascending`:u===Ze[`-rank`]?`descending`:null,j=u===Ze.query?`ascending`:u===Ze[`-query`]?`descending`:null,M=w.data?.items??[],P=s===null?`not ranked`:`not in the top ${s}`,F=!w.data||w.isPlaceholderData?null:w.data.total===0?`No queries match`:`${ld.format(w.data.total)} ${w.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:`${fd} min-w-0 sm:w-56`,children:O.map(e=>(0,$.jsxs)(`option`,{value:e.value,children:[e.label,` (`,ld.format(e.count),`)`]},e.value))})]}),(0,$.jsx)(us,{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}),w.error?(0,$.jsx)(Ad,{error:w.error,retry:()=>{w.refetch()}}):w.data?w.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 ${w.isPlaceholderData?`opacity-60`:``}`,role:`region`,"aria-label":`Queries`,"aria-busy":w.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)(rf,{label:`Query`,align:`left`,sorted:j,onSort:()=>d(u===Ze.query?Ze[`-query`]:Ze.query)}),(0,$.jsx)(rf,{label:`Google rank`,align:`right`,sorted:A,onSort:()=>d(u===Ze.rank?Ze[`-rank`]:Ze.rank)}),(0,$.jsx)(`th`,{className:`px-4 py-3 text-left text-label-13-strong whitespace-nowrap`,children:`Top rival`}),(0,$.jsx)(`th`,{className:`${pd} text-label-13-strong`,children:`Rival rank`}),(0,$.jsx)(`th`,{className:`${pd} text-label-13-strong`,children:(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[`Rank gap`,(0,$.jsx)(X,{text:od,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:M.map((e,t)=>(0,$.jsx)(uf,{row:e,requested:s},`${e.marketKey}\u0000${e.queryId??e.queryText}\u0000${t}`))})]})}),(0,$.jsx)(fs,{page:C,pageSize:Wd,visibleRows:M.length,totalRows:w.data.total,onPageChange:e=>S({filterKey:b,page:e}),disabled:w.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 uf({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:md,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:pd,children:(0,$.jsx)(ff,{row:e,requested:t})}),(0,$.jsx)(`td`,{className:`px-4 py-3 align-top text-label-13`,children:(0,$.jsx)(pf,{row:e})}),(0,$.jsx)(`td`,{className:pd,children:(0,$.jsx)(_d,{value:e.topCompetitor?.rankOrganic??null})}),(0,$.jsx)(`td`,{className:pd,children:(0,$.jsx)(Id,{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)(mf,{row:e,requested:t})})})]})}function df(e){return e.outcome===ut.failed||e.outcome===ut.cancelled}function ff({row:e,requested:t}){return e.outcome===ut.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===ut.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===ut[`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 pf({row:e}){if(df(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 mf({row:e,requested:t}){let n=`text-muted`,r=`mt-0.5 text-primary`,i=e.outcome===ut.failed?`No result: the search failed`:e.outcome===ut.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)(vo,{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:hd}),(0,$.jsx)(`p`,{className:`${r} tabular-nums`,children:(0,$.jsx)(_d,{value:e.rankAbsolute})})]}),e.searchStatus===gt.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}`]})]}),!df(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)(Od,{source:e.provenance})})]})}function hf({projectName:e,profileId:t,canRun:n,selectedRunId:r}){let[i,a]=(0,Q.useState)(r??null),[o,s]=(0,Q.useState)(null),c=E({...Nr({client:K,path:{name:e},query:{profileId:t}}),refetchInterval:e=>e.state.data?.runs.some(gd)?2e3:!1}),l=E({...Or({client:K,path:{name:e,id:i??``}}),enabled:!!i,refetchInterval:e=>gd(e.state.data)?2e3:!1}),u=T({...Lr({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(Ts(e))}}};if(c.error)return(0,$.jsx)(`div`,{className:`py-4`,children:(0,$.jsx)(Ad,{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)(vd,{status:e.status}),(0,$.jsx)(`span`,{className:`text-label-14`,children:Et(e.createdAt,dd)})]}),(0,$.jsxs)(`p`,{className:`text-copy-13 text-secondary`,children:[e.completedTasks,` of `,e.taskCount,` `,Sd(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&&gd(e)&&(0,$.jsx)(q,{variant:`secondary`,className:`pointer-coarse:min-h-11`,disabled:u.isPending||e.cancelRequested,onClick:Yn(()=>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,` · `,xd(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)(Ad,{error:l.error,retry:()=>{l.refetch()}}):l.data?l.data.tasks.some(Cd)&&(0,$.jsx)(`ul`,{className:`space-y-3`,children:l.data.tasks.filter(Cd).map(e=>(0,$.jsxs)(`li`,{children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,$.jsxs)(`span`,{children:[id[e.capability],e.searchText===null?e.target?` · ${e.target.value}`:``:` · “${e.searchText}” from ${e.locationLabel??`its market`}`,e.comparison?` · ${e.comparison.competitor.value} · ${ad[e.comparison.mode]} searches`:``,e.retried?` · retried once`:``]}),(0,$.jsx)(vd,{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)(jd,{title:`No refreshes yet`,children:`Refresh this profile to collect its first saved results.`})}function gf({projectName:e,context:t,profile:n,id:r,onClose:i,onSaved:a}){let o=w(),[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??[G[`ranked-keywords`]]),[p,m]=(0,Q.useState)(n?.targets??[{kind:yn.domain,value:``,includeSubdomains:!0}]),[h,g]=(0,Q.useState)(n?.competitors?.map(e=>e.value).join(`
2
2
  `)??``),[_,v]=(0,Q.useState)(n?.keywords.join(`
3
3
  `)??``),[y,x]=(0,Q.useState)(n?.locationCode.toString()??``),[S,C]=(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=T({...Ar({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(G[`keyword-gaps`]),R=L||I.includes(G[`competitor-discovery`]),ee=I.some(e=>e!==G[`keyword-metrics`]),te=I.includes(G[`ranked-keywords`])||R,z=(0,Q.useId)(),B=I.includes(G[`market-rankings`]),ne=e=>e===G[`market-rankings`]?!n?.rankings||I.some(e=>e!==G[`market-rankings`]):B,V=F.includes(G[`market-rankings`])?n?.rankings?`Market rankings use their own profile.`:`Set up market rankings with the CLI or API.`:null,H=async()=>{if(!t.access.canWrite||Y()||W()||M.isPending)return;if(!P){j(`Choose a measurement scope.`);return}if(R&&p.some(e=>e.kind!==yn.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:_.split(`
4
4
  `).map(e=>e.trim()).filter(Boolean),locationCode:Number(y),languageCode:S,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(G[`market-rankings`])&&n?.rankings?{rankings:n.rankings}:{},...L?{competitors:h.split(`