@ainyc/canonry 1.28.1 → 1.28.2
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.
|
@@ -233,7 +233,7 @@ spec:
|
|
|
233
233
|
keywords: []`,value:t,onChange:v=>s(v.target.value)}),c.length>0&&o.jsx("ul",{className:"mt-2 space-y-1",children:c.map((v,y)=>o.jsx("li",{className:"text-emerald-400 text-sm",children:v},y))}),f.length>0&&o.jsx("ul",{className:"mt-2 space-y-1",children:f.map((v,y)=>o.jsx("li",{className:"text-rose-400 text-sm",children:v},y))}),o.jsx("div",{className:"mt-3",children:o.jsx(oe,{type:"button",disabled:!t.trim()||a,onClick:p,children:a?"Applying...":"Apply"})})]})}function G3(){const{dashboard:e,isLoading:t,refetch:s}=Oa();if(!e||t)return o.jsxs("div",{className:"page-skeleton",children:[o.jsxs("div",{className:"page-skeleton-header",children:[o.jsx("div",{className:"skeleton-text h-6 w-28"}),o.jsx("div",{className:"skeleton-text-sm w-40"})]}),o.jsxs("div",{className:"rounded-xl border border-zinc-800/60 bg-zinc-900/30 overflow-hidden",children:[o.jsx("div",{className:"p-3 border-b border-zinc-800/60 flex gap-8",children:["Name","Domain","Visibility","Last run","Country"].map(E=>o.jsx("div",{className:"skeleton-text-sm w-16"},E))}),[1,2,3].map(E=>o.jsxs("div",{className:"p-3 border-b border-zinc-800/40 flex gap-8 items-center",children:[o.jsxs("div",{className:"flex-1 space-y-1",children:[o.jsx("div",{className:"skeleton-text w-28"}),o.jsx("div",{className:"skeleton-text-sm w-16"})]}),o.jsx("div",{className:"skeleton-text w-24"}),o.jsx("div",{className:"skeleton h-5 w-14 rounded-full"}),o.jsx("div",{className:"skeleton h-5 w-16 rounded-full"}),o.jsx("div",{className:"skeleton-text-sm w-8"})]},E))]})]});const a=e.projects,r=Ii(),[c,u]=w.useState(!1),[f,m]=w.useState(""),[p,v]=w.useState(""),[y,x]=w.useState(""),[b,N]=w.useState("US"),[S,C]=w.useState("en"),[k,A]=w.useState(!1),[R,z]=w.useState(null),O=f.toLowerCase().replace(/[^a-z0-9-]/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,""),M=async()=>{if(!(!O||!y)){A(!0),z(null);try{const E=await Gu(O,{displayName:p||f,canonicalDomain:y,country:b,language:S});Ke({title:"Project created",detail:`${E.displayName||E.name} is ready to configure.`,tone:"positive",dedupeKey:`project:create:${E.name}`,dedupeMode:"drop"}),s(),m(""),v(""),x(""),N("US"),C("en"),u(!1),r({to:"/projects/$projectId",params:{projectId:E.id}})}catch(E){z(E instanceof Error?E.message:"Failed to create project")}finally{A(!1)}}};return o.jsxs("div",{className:"page-container",children:[o.jsxs("div",{className:"page-header",children:[o.jsxs("div",{className:"page-header-left",children:[o.jsx("h1",{className:"page-title",children:"Projects"}),o.jsxs("p",{className:"page-subtitle",children:[a.length," project",a.length!==1?"s":""," tracked"]})]}),o.jsx("div",{className:"page-header-right",children:o.jsxs(oe,{type:"button",onClick:()=>u(E=>!E),children:[o.jsx(Jx,{className:"size-4 mr-1.5"}),"Add project"]})})]}),c?o.jsxs(Le,{className:"surface-card mb-6",children:[o.jsx("div",{className:"section-head",children:o.jsxs("div",{children:[o.jsx("p",{className:"eyebrow eyebrow-soft",children:"New project"}),o.jsx("h2",{className:"text-sm font-medium text-zinc-200",children:"Create a new monitoring project"})]})}),o.jsxs("div",{className:"compact-stack mt-4",children:[o.jsxs("div",{className:"setup-field-row",children:[o.jsxs("div",{className:"setup-field",children:[o.jsx("label",{className:"setup-label",htmlFor:"new-project-name",children:"Project name"}),o.jsx("input",{id:"new-project-name",className:"setup-input",type:"text",placeholder:"my-project",value:f,onChange:E=>m(E.target.value)}),O&&O!==f?o.jsxs("p",{className:"supporting-copy",children:["Slug: ",O]}):null]}),o.jsxs("div",{className:"setup-field",children:[o.jsx("label",{className:"setup-label",htmlFor:"new-display-name",children:"Display name"}),o.jsx("input",{id:"new-display-name",className:"setup-input",type:"text",placeholder:"My Project",value:p,onChange:E=>v(E.target.value)})]})]}),o.jsxs("div",{className:"setup-field",children:[o.jsx("label",{className:"setup-label",htmlFor:"new-domain",children:"Canonical domain"}),o.jsx("input",{id:"new-domain",className:"setup-input",type:"text",placeholder:"example.com",value:y,onChange:E=>x(E.target.value)})]}),o.jsxs("div",{className:"setup-field-row",children:[o.jsxs("div",{className:"setup-field",children:[o.jsx("label",{className:"setup-label",htmlFor:"new-country",children:"Country"}),o.jsx("input",{id:"new-country",className:"setup-input",type:"text",placeholder:"US",maxLength:2,value:b,onChange:E=>N(E.target.value.toUpperCase())})]}),o.jsxs("div",{className:"setup-field",children:[o.jsx("label",{className:"setup-label",htmlFor:"new-language",children:"Language"}),o.jsx("input",{id:"new-language",className:"setup-input",type:"text",placeholder:"en",maxLength:5,value:S,onChange:E=>C(E.target.value.toLowerCase())})]})]})]}),R?o.jsx("p",{className:"text-rose-400 text-sm mt-3",children:R}):null,o.jsxs("div",{className:"flex items-center gap-3 mt-4",children:[o.jsx(oe,{type:"button",disabled:!O||!y||k,onClick:M,children:k?"Creating...":"Create project"}),o.jsx(oe,{type:"button",variant:"ghost",onClick:()=>u(!1),children:"Cancel"})]})]}):null,a.length>0?o.jsx("div",{className:"data-table-wrapper",children:o.jsxs("table",{className:"data-table",children:[o.jsx("thead",{children:o.jsxs("tr",{children:[o.jsx("th",{children:"Name"}),o.jsx("th",{children:"Domain"}),o.jsx("th",{children:"Visibility"}),o.jsx("th",{children:"Last run"}),o.jsx("th",{className:"text-right",children:"Country"})]})}),o.jsx("tbody",{children:a.map(E=>{const L=E.recentRuns[0];return o.jsxs("tr",{className:"cursor-pointer",onClick:()=>r({to:"/projects/$projectId",params:{projectId:E.project.id}}),children:[o.jsxs("td",{children:[o.jsx(St,{to:"/projects/$projectId",params:{projectId:E.project.id},className:"text-zinc-100 font-medium hover:underline",onClick:U=>U.stopPropagation(),children:E.project.displayName||E.project.name}),o.jsx("p",{className:"text-[11px] text-zinc-500",children:E.project.name})]}),o.jsx("td",{className:"text-zinc-400",children:E.project.canonicalDomain}),o.jsx("td",{children:o.jsx(lt,{tone:E.visibilitySummary.tone,children:E.visibilitySummary.value})}),o.jsx("td",{className:"text-zinc-500 text-sm",children:L?o.jsx(Ju,{status:L.status}):o.jsx("span",{className:"text-zinc-600",children:"No runs"})}),o.jsx("td",{className:"text-right text-zinc-500",children:E.project.country})]},E.project.id)})})]})}):c?null:o.jsxs(Le,{className:"surface-card empty-card",children:[o.jsx("h3",{children:"No projects yet"}),o.jsx("p",{className:"supporting-copy",children:"Create your first monitoring project to start tracking AI visibility."}),o.jsxs(oe,{type:"button",onClick:()=>u(!0),children:[o.jsx(Jx,{className:"size-4 mr-1.5"}),"Add project"]})]}),o.jsx(K3,{onApplied:()=>{s()}})]})}function ws({text:e}){return o.jsxs("span",{className:"info-tooltip-wrapper",children:[o.jsxs("svg",{className:"info-tooltip-icon",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",children:[o.jsx("circle",{cx:"8",cy:"8",r:"7",stroke:"currentColor",strokeWidth:"1.5"}),o.jsx("path",{d:"M8 7v4M8 5.5v0",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})]}),o.jsx("span",{className:"info-tooltip-bubble",role:"tooltip",children:e})]})}function UN({run:e}){const{openRun:t}=Gr();return o.jsxs("article",{className:"run-row",children:[o.jsxs("div",{className:"run-row-main",children:[o.jsxs("div",{className:"run-row-head",children:[o.jsxs("div",{children:[o.jsx("p",{className:"run-row-title",children:e.summary}),o.jsxs("p",{className:"run-row-subtitle",children:[e.projectName,e.location?` · ${e.location}`:""," · ",e.kindLabel]})]}),o.jsx(Ju,{status:e.status})]}),o.jsx("p",{className:"run-row-detail",children:e.statusDetail})]}),o.jsxs("dl",{className:"run-row-meta",children:[o.jsxs("div",{children:[o.jsx("dt",{children:"Started"}),o.jsx("dd",{children:e.startedAt})]}),o.jsxs("div",{children:[o.jsx("dt",{children:"Duration"}),o.jsx("dd",{children:e.duration})]}),o.jsxs("div",{children:[o.jsx("dt",{children:"Trigger"}),o.jsx("dd",{children:e.triggerLabel})]})]}),o.jsx(oe,{variant:"outline",size:"sm",type:"button",onClick:()=>t(e.id),children:"View run"})]})}function IN({value:e,label:t,delta:s,tone:a,description:r,tooltip:c,isNumeric:u=!0,progress:f}){const v=2*Math.PI*48,y=Number.parseInt(e,10),x=typeof f=="number"&&Number.isFinite(f)?Math.min(Math.max(f,0),1):u&&!Number.isNaN(y)?Math.min(y/100,1):.5,b=v*(1-x);return o.jsxs("div",{className:"score-gauge",children:[o.jsxs("div",{className:"gauge-ring-wrapper",children:[o.jsxs("svg",{className:"gauge-ring",viewBox:"0 0 120 120","aria-hidden":"true",children:[o.jsx("circle",{className:"gauge-bg",cx:"60",cy:"60",r:48,strokeWidth:6}),o.jsx("circle",{className:`gauge-fill gauge-fill-${a}`,cx:"60",cy:"60",r:48,strokeWidth:6,strokeDasharray:v,strokeDashoffset:b,transform:"rotate(-90 60 60)"})]}),o.jsx("div",{className:"gauge-center",children:o.jsx("span",{className:u?"gauge-value":"gauge-value-text",children:e.split(" / ")[0]})})]}),o.jsxs("p",{className:"gauge-label",children:[t,c&&o.jsx(ws,{text:c})]}),o.jsx("p",{className:"gauge-delta",children:s}),o.jsx("p",{className:"gauge-description",children:r})]})}function uS({history:e,maxDots:t=12}){const s=e.slice(-t);if(s.length===0)return o.jsx("span",{className:"text-[11px] text-zinc-600",children:"No data"});const a={cited:"bg-emerald-400","not-cited":"bg-zinc-600",lost:"bg-rose-400",emerging:"bg-amber-400 ring-1 ring-amber-300/60"},r=new Date(s[0].createdAt).toLocaleDateString(void 0,{month:"short",day:"numeric"}),c=new Date(s[s.length-1].createdAt).toLocaleDateString(void 0,{month:"short",day:"numeric"});return o.jsxs("div",{className:"flex items-center gap-1",children:[o.jsx("span",{className:"text-[9px] text-zinc-600 shrink-0",children:r}),o.jsx("div",{className:"flex items-center gap-[3px]",title:`${s.length} runs`,children:s.map((u,f)=>o.jsx("div",{className:`h-2.5 w-2.5 rounded-sm ${a[u.citationState]??"bg-zinc-700"} ${u.model&&f>0&&s[f-1]?.model&&s[f-1].model!==u.model?"ring-1 ring-amber-300/80 ring-offset-1 ring-offset-zinc-950":""}`,title:[u.citationState,new Date(u.createdAt).toLocaleDateString(),u.model?`model ${u.model}`:null,u.model&&f>0&&s[f-1]?.model&&s[f-1].model!==u.model?"model changed":null].filter(Boolean).join(" — ")},f))}),o.jsx("span",{className:"text-[9px] text-zinc-600 shrink-0",children:c})]})}function F3(e){const t=new Map;for(const a of e)for(const r of a.runHistory){const c=t.get(r.createdAt);c?c.states.push(r.citationState):t.set(r.createdAt,{states:[r.citationState],runId:r.runId})}return[...t.entries()].sort(([a],[r])=>a.localeCompare(r)).map(([a,{states:r,runId:c}])=>({runId:c,createdAt:a,citationState:r.includes("cited")?"cited":r.includes("emerging")?"emerging":"not-cited"}))}function Z3({evidence:e}){const{openEvidence:t}=Gr(),[s,a]=w.useState(new Set),r=w.useMemo(()=>{const u=new Map;for(const f of e){const m=u.get(f.keyword)??[];u.set(f.keyword,[...m,f])}return[...u.entries()].map(([f,m])=>({phrase:f,items:m}))},[e]),c=u=>{a(f=>{const m=new Set(f);return m.has(u)?m.delete(u):m.add(u),m})};return o.jsx("div",{className:"evidence-table-wrap",children:o.jsxs("table",{className:"evidence-table",children:[o.jsx("thead",{children:o.jsxs("tr",{children:[o.jsx("th",{style:{width:"2rem"}}),o.jsx("th",{children:"Key Phrase"}),o.jsx("th",{children:"Status"}),o.jsx("th",{children:"Citation History"}),o.jsx("th",{children:"Change"}),o.jsx("th",{})]})}),o.jsx("tbody",{children:r.map(({phrase:u,items:f})=>{const m=s.has(u),p=f.map(N=>N.citationState),v=p.includes("cited")?"cited":p.includes("emerging")?"emerging":p.includes("lost")?"lost":p.every(N=>N==="pending")?"pending":"not-cited",y=F3(f),x=f.filter(N=>N.citationState==="cited"||N.citationState==="emerging").length,b=(()=>{if(y.length===0)return"Awaiting first run";if(y.length===1)return"First observation";const N=y[y.length-1].citationState,S=y[y.length-2].citationState;if(S!=="cited"&&N==="cited")return"Newly cited";if(S==="cited"&&N!=="cited")return"Lost since last run";let C=0;for(let k=y.length-1;k>=0&&y[k].citationState===N;k--)C++;return N==="cited"?C<=1?"Cited in latest run":`Cited for ${C} runs`:C<=1?"Not cited in latest run":`Not cited across ${C} runs`})();return o.jsxs(w.Fragment,{children:[o.jsxs("tr",{className:"evidence-phrase-row cursor-pointer hover:bg-zinc-800/40",onClick:()=>c(u),"aria-expanded":m,children:[o.jsx("td",{children:o.jsx(Fu,{size:14,className:`transition-transform duration-150 text-zinc-500 ${m?"rotate-90":""}`})}),o.jsx("td",{className:"evidence-keyword-cell",children:o.jsxs("div",{children:[o.jsx("span",{className:"font-medium text-zinc-100",children:u}),o.jsx("div",{className:"flex flex-wrap gap-1 mt-1",children:f.map(N=>o.jsx(al,{provider:N.provider},N.id))})]})}),o.jsx("td",{children:o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(Bm,{state:v}),o.jsxs("span",{className:"text-[11px] text-zinc-500",children:[x,"/",f.length]})]})}),o.jsx("td",{children:o.jsx(uS,{history:y})}),o.jsx("td",{className:"evidence-change-cell",children:b}),o.jsx("td",{})]}),m&&f.map(N=>o.jsxs("tr",{className:"bg-zinc-900/30",children:[o.jsx("td",{}),o.jsx("td",{className:"evidence-keyword-cell pl-5",children:o.jsx(al,{provider:N.provider})}),o.jsx("td",{children:o.jsx(Bm,{state:N.citationState})}),o.jsx("td",{children:o.jsx(uS,{history:N.runHistory})}),o.jsx("td",{className:"evidence-change-cell",children:N.changeLabel}),o.jsx("td",{children:o.jsx(oe,{variant:"ghost",size:"sm",type:"button",onClick:S=>{S.stopPropagation(),t(N.id)},children:"View"})})]},N.id))]},u)})})]})})}function V3({competitors:e}){return e.length===0?o.jsx("p",{className:"text-sm text-zinc-500",children:"No competitors configured. Add competitors to track overlap."}):o.jsx("div",{className:"competitor-table-wrap",children:o.jsxs("table",{className:"competitor-table",children:[o.jsx("thead",{children:o.jsxs("tr",{children:[o.jsx("th",{children:"Domain"}),o.jsx("th",{children:"Pressure"}),o.jsx("th",{children:"Citations"}),o.jsx("th",{children:"Key Phrases"})]})}),o.jsx("tbody",{children:e.map(t=>o.jsxs("tr",{children:[o.jsx("td",{className:"font-medium text-zinc-100",children:t.domain}),o.jsx("td",{children:o.jsx(lt,{tone:qR(t.pressureLabel),children:t.pressureLabel})}),o.jsx("td",{className:"text-zinc-300 tabular-nums",children:t.totalKeywords>0?`${t.citationCount} / ${t.totalKeywords}`:"—"}),o.jsx("td",{className:"text-zinc-500 text-xs",children:t.citedKeywords.length>0?t.citedKeywords.join(", "):"Not cited"})]},t.id))})]})})}const Q3=["7d","30d","90d","all"],Y3=["gap","cited","uncited"],BN={forum:"bg-amber-500",social:"bg-blue-500",news:"bg-zinc-400",reference:"bg-purple-500",blog:"bg-emerald-500",ecommerce:"bg-orange-500",video:"bg-red-500",academic:"bg-cyan-500",other:"bg-zinc-600"};function J3({projectName:e}){const[t,s]=w.useState("30d"),[a,r]=w.useState(null),[c,u]=w.useState(null),[f,m]=w.useState(null),[p,v]=w.useState(null),[y,x]=w.useState(!0);return w.useEffect(()=>{let b=!1;return x(!0),Promise.all([D2(e,t),M2(e,t),$2(e,t)]).then(([N,S,C])=>{b||(r(N),u(S),m(C),x(!1))}).catch(()=>{b||x(!1)}),()=>{b=!0}},[e,t]),y&&!a?o.jsx("p",{className:"text-sm text-zinc-500 py-8 text-center",children:"Loading analytics…"}):o.jsxs(o.Fragment,{children:[o.jsxs("section",{children:[o.jsxs("div",{className:"flex items-center justify-between mb-4",children:[o.jsxs("div",{children:[o.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-wider text-zinc-500 mb-1",children:"Citation Metrics"}),o.jsxs("h2",{className:"text-base font-semibold text-zinc-50 flex items-center gap-1.5",children:["Citation Rate Trends ",o.jsx(ws,{text:"Citation rate over time across all runs within the selected window. Each data point represents the percentage of queries where your brand was cited by AI providers."})]})]}),o.jsx("div",{className:"flex gap-1",children:Q3.map(b=>o.jsx("button",{type:"button",className:`px-3 py-1 text-xs rounded-full border transition-colors ${t===b?"bg-zinc-700 border-zinc-600 text-zinc-50":"border-zinc-800 text-zinc-400 hover:border-zinc-700 hover:text-zinc-300"}`,onClick:()=>s(b),children:b==="all"?"All":b},b))})]}),a&&o.jsxs("div",{className:"space-y-4",children:[o.jsxs("div",{className:"flex items-center gap-6",children:[o.jsx(IN,{value:`${Math.round(a.overall.citationRate*100)}`,label:"Citation Rate",delta:`${a.overall.cited} / ${a.overall.total}`,tone:a.trend==="improving"?"positive":a.trend==="declining"?"negative":"neutral",description:`Trend: ${a.trend}`,isNumeric:!0}),o.jsxs("div",{className:"flex-1 space-y-3",children:[o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx("span",{className:"text-xs text-zinc-500",children:"Trend"}),o.jsx(lt,{tone:a.trend==="improving"?"positive":a.trend==="declining"?"negative":"neutral",children:a.trend})]}),Object.keys(a.byProvider).length>0&&o.jsxs("table",{className:"w-full text-sm",children:[o.jsx("thead",{children:o.jsxs("tr",{className:"text-[10px] uppercase tracking-wider text-zinc-500",children:[o.jsx("th",{className:"text-left py-1 font-medium",children:"Provider"}),o.jsx("th",{className:"text-right py-1 font-medium",children:"Rate"}),o.jsx("th",{className:"text-right py-1 font-medium",children:"Cited / Total"})]})}),o.jsx("tbody",{children:Object.entries(a.byProvider).map(([b,N])=>o.jsxs("tr",{className:"border-t border-zinc-800/40",children:[o.jsx("td",{className:"py-1.5 text-zinc-300",children:b}),o.jsxs("td",{className:"py-1.5 text-right text-zinc-200",children:[(N.citationRate*100).toFixed(1),"%"]}),o.jsxs("td",{className:"py-1.5 text-right text-zinc-400",children:[N.cited," / ",N.total]})]},b))})]})]})]}),a.buckets.length>=1&&o.jsx(X3,{buckets:a.buckets,keywordChanges:a.keywordChanges??[]})]})]}),o.jsx("div",{className:"page-section-divider"}),o.jsxs("section",{children:[o.jsx("div",{className:"flex items-center justify-between mb-4",children:o.jsxs("div",{children:[o.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-wider text-zinc-500 mb-1",children:"Opportunity Analysis"}),o.jsxs("h2",{className:"text-base font-semibold text-zinc-50 flex items-center gap-1.5",children:["Brand Gap Analysis ",o.jsx(ws,{text:"Classification based on the most recent completed run. Cited: your brand appeared in the AI answer. Gap: a competitor was cited but you were not. Not Cited: neither mentioned. Consistency shows how often each key phrase was cited across all runs in the selected window."})]})]})}),c&&o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"flex gap-1 mb-4",children:Y3.map(b=>{const N=b==="cited"?c.cited.length:b==="gap"?c.gap.length:c.uncited.length,S=p===b;return o.jsxs("button",{type:"button",className:`px-3 py-1 text-xs rounded-full border transition-colors ${S?b==="gap"?"bg-amber-900/40 border-amber-700/60 text-amber-300":b==="cited"?"bg-emerald-900/40 border-emerald-700/60 text-emerald-300":"bg-zinc-800/40 border-zinc-700 text-zinc-300":"border-zinc-800 text-zinc-400 hover:border-zinc-700"}`,onClick:()=>v(S?null:b),children:[b==="gap"?"Gap":b==="cited"?"Cited":"Not Cited"," (",N,")"]},b)})}),o.jsx(W3,{gaps:c,filter:p})]})]}),o.jsx("div",{className:"page-section-divider"}),o.jsxs("section",{children:[o.jsxs("div",{className:"mb-4",children:[o.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-wider text-zinc-500 mb-1",children:"Source Intelligence"}),o.jsxs("h2",{className:"text-base font-semibold text-zinc-50 flex items-center gap-1.5",children:["Source Origin Breakdown ",o.jsx(ws,{text:"Aggregated across all runs in the selected window. Shows what types of websites AI engines cite as grounding sources. More runs = more statistically meaningful breakdown."})]})]}),f&&f.overall.length>0&&o.jsxs("div",{className:"space-y-4",children:[o.jsx(e$,{categories:f.overall}),o.jsxs("table",{className:"w-full text-sm",children:[o.jsx("thead",{children:o.jsxs("tr",{className:"text-[10px] uppercase tracking-wider text-zinc-500",children:[o.jsx("th",{className:"text-left py-1 font-medium",children:"Category"}),o.jsx("th",{className:"text-right py-1 font-medium",children:"Count"}),o.jsx("th",{className:"text-right py-1 font-medium",children:"%"}),o.jsx("th",{className:"text-left py-1 pl-4 font-medium",children:"Top Sources"})]})}),o.jsx("tbody",{children:f.overall.map(b=>o.jsxs("tr",{className:"border-t border-zinc-800/40",children:[o.jsxs("td",{className:"py-1.5 text-zinc-300 flex items-center gap-2",children:[o.jsx("span",{className:`inline-block w-2 h-2 rounded-full ${BN[b.category]??"bg-zinc-600"}`}),b.label]}),o.jsx("td",{className:"py-1.5 text-right text-zinc-200",children:b.count}),o.jsxs("td",{className:"py-1.5 text-right text-zinc-400",children:[(b.percentage*100).toFixed(1),"%"]}),o.jsx("td",{className:"py-1.5 pl-4 text-zinc-500 text-xs truncate max-w-[200px]",children:b.topDomains.slice(0,3).map(N=>N.domain).join(", ")})]},b.category))})]})]}),f&&f.overall.length===0&&o.jsx("p",{className:"text-sm text-zinc-500 py-4",children:"No source data available. Run a visibility sweep first."})]})]})}function X3({buckets:e,keywordChanges:t}){const[s,a]=w.useState(null),r=600,c=140,u={top:30,right:10,bottom:20,left:40},f=r-u.left-u.right,m=c-u.top-u.bottom,p=1,v=e.map((b,N)=>{const S=u.left+(e.length>1?N/(e.length-1)*f:f/2),C=u.top+m-b.citationRate/p*m;return{x:S,y:C}}),y=w.useMemo(()=>{if(!t||t.length===0||e.length<2)return[];const b=new Date(e[0].startDate).getTime(),S=new Date(e[e.length-1].startDate).getTime()-b;return S<=0?[]:t.map(C=>{const A=(new Date(C.date).getTime()-b)/S;return A<0||A>1?null:{...C,x:u.left+A*f}}).filter(C=>C!==null)},[e,t,u.left,f]),x=v.map(b=>`${b.x},${b.y}`).join(" ");return o.jsxs("div",{className:"surface-card rounded-lg p-3 border border-zinc-800/60",children:[o.jsx("p",{className:"text-[10px] text-zinc-500 mb-1 flex items-center gap-1",children:"kp = key phrases tracked in this window"}),o.jsxs("svg",{viewBox:`0 0 ${r} ${c}`,className:"w-full h-auto","aria-label":"Citation rate trend chart",onMouseLeave:()=>a(null),children:[o.jsxs("text",{x:u.left-4,y:u.top+4,textAnchor:"end",className:"fill-zinc-500",fontSize:"9",children:[(p*100).toFixed(0),"%"]}),o.jsx("text",{x:u.left-4,y:u.top+m+4,textAnchor:"end",className:"fill-zinc-500",fontSize:"9",children:"0%"}),o.jsx("line",{x1:u.left,y1:u.top+m,x2:u.left+f,y2:u.top+m,stroke:"currentColor",className:"text-zinc-800",strokeWidth:"0.5"}),o.jsx("polyline",{fill:"none",stroke:"currentColor",className:"text-emerald-500",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",points:x}),y.map((b,N)=>o.jsxs("g",{children:[o.jsx("line",{x1:b.x,y1:u.top,x2:b.x,y2:u.top+m,stroke:"currentColor",className:"text-zinc-600",strokeWidth:"0.5",strokeDasharray:"4 2"}),o.jsx("text",{x:b.x,y:u.top-6,textAnchor:"middle",className:"fill-zinc-500",fontSize:"7",fontWeight:"500",children:b.label})]},`kw-change-${N}`)),s!==null&&o.jsx("line",{x1:v[s].x,y1:u.top,x2:v[s].x,y2:u.top+m,stroke:"currentColor",className:"text-zinc-600",strokeWidth:"0.5",strokeDasharray:"3 2"}),e.map((b,N)=>{const{x:S,y:C}=v[N],k=s===N;return o.jsxs("g",{children:[o.jsx("circle",{cx:S,cy:C,r:"10",fill:"transparent",onMouseEnter:()=>a(N),style:{cursor:"pointer"}}),o.jsx("circle",{cx:S,cy:C,r:k?5:3,className:k?"fill-emerald-400":"fill-emerald-500"})]},N)}),s!==null&&(()=>{const b=e[s],{x:N,y:S}=v[s],C=`${(b.citationRate*100).toFixed(1)}%`,k=b.keywordCount?`${b.keywordCount} kp`:"",A=56,R=30,z=Math.max(u.left,Math.min(N-A/2,r-u.right-A)),O=S-R-8;return o.jsxs("g",{children:[o.jsx("rect",{x:z,y:O,width:A,height:R,rx:"4",className:"fill-zinc-800",stroke:"currentColor",strokeWidth:"0.5"}),o.jsx("text",{x:z+A/2,y:O+13,textAnchor:"middle",className:"fill-zinc-50",fontSize:"11",fontWeight:"600",children:C}),k&&o.jsx("text",{x:z+A/2,y:O+24,textAnchor:"middle",className:"fill-zinc-400",fontSize:"8",children:k})]})})(),e.map((b,N)=>({b,i:N})).filter(({i:b})=>b===0||b===e.length-1||e.length<=7).map(({b,i:N})=>{const S=v[N].x;return o.jsx("text",{x:S,y:c-2,textAnchor:"middle",className:"fill-zinc-500",fontSize:"8",children:b.startDate.slice(5,10)},N)})]})]})}function W3({gaps:e,filter:t}){const s=w.useMemo(()=>{const a=[...e.gap.map(r=>({...r,_sort:0})),...e.cited.map(r=>({...r,_sort:1})),...e.uncited.map(r=>({...r,_sort:2}))];return t?a.filter(r=>r.category===t):a.sort((r,c)=>r._sort-c._sort)},[e,t]);return s.length===0?o.jsxs("p",{className:"text-sm text-zinc-500 py-4",children:["No key phrases found",t?` with status "${t}"`:"","."]}):o.jsxs("table",{className:"w-full text-sm",children:[o.jsx("thead",{children:o.jsxs("tr",{className:"text-[10px] uppercase tracking-wider text-zinc-500",children:[o.jsx("th",{className:"text-left py-1 font-medium",children:"Keyword"}),o.jsx("th",{className:"text-left py-1 font-medium",children:"Status"}),o.jsx("th",{className:"text-left py-1 font-medium",children:"Providers Citing"}),o.jsx("th",{className:"text-left py-1 font-medium",children:"Competitors Citing"}),o.jsx("th",{className:"text-right py-1 font-medium",children:"Consistency"})]})}),o.jsx("tbody",{children:s.map(a=>{const r=a.category==="cited"?"positive":a.category==="gap"?"caution":"neutral";return o.jsxs("tr",{className:`border-t border-zinc-800/40 ${a.category==="gap"?"border-l-2 border-l-amber-600/60":""}`,children:[o.jsx("td",{className:"py-1.5 text-zinc-200",children:a.keyword}),o.jsx("td",{className:"py-1.5",children:o.jsx(lt,{tone:r,children:a.category==="gap"?"Gap":a.category==="cited"?"Cited":"Not Cited"})}),o.jsx("td",{className:"py-1.5 text-zinc-400 text-xs",children:a.providers.length>0?a.providers.join(", "):"—"}),o.jsx("td",{className:"py-1.5 text-zinc-400 text-xs",children:a.competitorsCiting.length>0?a.competitorsCiting.join(", "):"—"}),o.jsx("td",{className:"py-1.5 text-right text-zinc-400 text-xs",children:a.consistency.totalRuns>0?`${a.consistency.citedRuns}/${a.consistency.totalRuns} runs`:"—"})]},a.keywordId)})})]})}function e$({categories:e}){const t=e.reduce((s,a)=>s+a.count,0);return t===0?null:o.jsx("div",{className:"flex rounded-full overflow-hidden h-3 bg-zinc-800","aria-label":"Source category distribution",children:e.map(s=>{const a=s.count/t*100;return a<.5?null:o.jsx("div",{className:`${BN[s.category]??"bg-zinc-600"} transition-all`,style:{width:`${a}%`},title:`${s.label}: ${(s.percentage*100).toFixed(1)}%`},s.category)})})}function fm(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toLocaleString()}function t$(e){const t=Date.now()-new Date(e).getTime(),s=Math.floor(t/6e4);if(s<1)return"just now";if(s<60)return`${s}m ago`;const a=Math.floor(s/60);return a<24?`${a}h ago`:`${Math.floor(a/24)}d ago`}function n$({projectName:e}){const[t,s]=w.useState(null),[a,r]=w.useState(null),[c,u]=w.useState(!0),[f,m]=w.useState(!1),[p,v]=w.useState(!1),[y,x]=w.useState(null),[b,N]=w.useState(null),[S,C]=w.useState("sessions"),[k,A]=w.useState("desc");function R(U){u(!0),Fx(e).then(X=>{if(!U.current)return s(X),X.connected?Zx(e):null}).then(X=>{U.current||(X&&r(X),u(!1))}).catch(X=>{U.current||(x(X instanceof Error?X.message:"Failed to load GA4 data"),u(!1))})}w.useEffect(()=>{const U={current:!1};return R(U),()=>{U.current=!0}},[e]);async function z(){m(!0),x(null),N(null);try{const U=await oj(e);N(`Synced ${U.rowCount.toLocaleString()} rows (${U.days} days)`);const X=await Zx(e);r(X);const Q=await Fx(e);s(Q)}catch(U){x(U instanceof Error?U.message:"Sync failed")}finally{m(!1)}}async function O(){v(!0),x(null),N(null);try{await U2(e),s({connected:!1,propertyId:null,clientEmail:null,lastSyncedAt:null,createdAt:null,updatedAt:null}),r(null),N("GA4 disconnected")}catch(U){x(U instanceof Error?U.message:"Disconnect failed")}finally{v(!1)}}function M(U){S===U?A(X=>X==="desc"?"asc":"desc"):(C(U),A("desc"))}const E=w.useMemo(()=>a?.topPages?[...a.topPages].sort((U,X)=>{const Q=U[S],ee=X[S];return typeof Q=="string"&&typeof ee=="string"?k==="asc"?Q.localeCompare(ee):ee.localeCompare(Q):k==="asc"?Q-ee:ee-Q}):[],[a?.topPages,S,k]);if(c&&!t)return o.jsx("p",{className:"text-sm text-zinc-500 py-8 text-center",children:"Loading traffic data…"});if(!t?.connected)return o.jsx(s$,{projectName:e,onConnected:()=>R({current:!1})});const L=a&&a.totalSessions>0?Math.round(a.totalOrganicSessions/a.totalSessions*100):0;return o.jsxs(o.Fragment,{children:[y&&o.jsx("div",{className:"mb-4 px-4 py-2 rounded-lg bg-rose-900/20 border border-rose-800/60 text-sm text-rose-300",children:y}),b&&o.jsx("div",{className:"mb-4 px-4 py-2 rounded-lg bg-emerald-900/20 border border-emerald-800/60 text-sm text-emerald-300",children:b}),o.jsxs("div",{className:"flex items-center justify-between mb-6",children:[o.jsxs("div",{className:"flex items-center gap-3",children:[o.jsx("span",{className:"inline-block w-2 h-2 rounded-full bg-emerald-500"}),o.jsxs("span",{className:"text-xs text-zinc-400",children:["Property ",o.jsx("span",{className:"text-zinc-300",children:t.propertyId}),t.clientEmail&&o.jsxs(o.Fragment,{children:[" · ",o.jsx("span",{className:"text-zinc-500",children:t.clientEmail})]})]})]}),o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsxs(oe,{variant:"outline",size:"sm",disabled:f,onClick:z,children:[o.jsx(Xx,{className:`w-3.5 h-3.5 mr-1.5 ${f?"animate-spin":""}`}),f?"Syncing…":"Sync"]}),o.jsxs(oe,{variant:"ghost",size:"sm",className:"text-rose-400 hover:text-rose-300",disabled:p,onClick:O,children:[o.jsx(CE,{className:"w-3.5 h-3.5 mr-1.5"}),"Disconnect"]})]})]}),o.jsxs("section",{children:[o.jsxs("div",{className:"mb-4",children:[o.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-wider text-zinc-500 mb-1",children:"Traffic Overview"}),o.jsxs("h2",{className:"text-base font-semibold text-zinc-50 flex items-center gap-1.5",children:["Site Traffic",o.jsx(ws,{text:"Aggregated traffic metrics from Google Analytics 4. Sessions and users are summed across all synced dates. Organic sessions are Google organic search sessions specifically."})]})]}),a?o.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[o.jsx(hm,{value:fm(a.totalSessions),label:"Total Sessions",subtitle:a.totalSessions.toLocaleString(),tone:"neutral"}),o.jsx(hm,{value:fm(a.totalOrganicSessions),label:"Organic Sessions",subtitle:`${L}% of total`,tone:"positive"}),o.jsx(hm,{value:fm(a.totalUsers),label:"Total Users",subtitle:a.totalUsers.toLocaleString(),tone:"neutral"})]}):o.jsxs("div",{className:"surface-card rounded-lg p-6 text-center border border-zinc-800/60",children:[o.jsx("p",{className:"text-sm text-zinc-400 mb-3",children:"No traffic data yet."}),o.jsxs(oe,{variant:"outline",size:"sm",disabled:f,onClick:z,children:[o.jsx(Xx,{className:`w-3.5 h-3.5 mr-1.5 ${f?"animate-spin":""}`}),"Sync from GA4"]})]})]}),a&&a.topPages.length>0&&o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"page-section-divider"}),o.jsxs("section",{children:[o.jsxs("div",{className:"mb-4",children:[o.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-wider text-zinc-500 mb-1",children:"Page Performance"}),o.jsxs("h2",{className:"text-base font-semibold text-zinc-50 flex items-center gap-1.5",children:["Top Landing Pages",o.jsx(ws,{text:"Landing pages ranked by session volume. Click column headers to sort. Organic % shows the share of sessions coming from Google organic search."})]})]}),o.jsx("div",{className:"overflow-x-auto",children:o.jsxs("table",{className:"w-full text-sm",children:[o.jsx("thead",{children:o.jsxs("tr",{className:"text-[10px] uppercase tracking-wider text-zinc-500",children:[o.jsx(au,{label:"Landing Page",sortKey:"landingPage",current:S,dir:k,onSort:M,align:"left"}),o.jsx(au,{label:"Sessions",sortKey:"sessions",current:S,dir:k,onSort:M,align:"right"}),o.jsx(au,{label:"Organic",sortKey:"organicSessions",current:S,dir:k,onSort:M,align:"right"}),o.jsx("th",{className:"text-right py-1 font-medium",children:"Organic %"}),o.jsx(au,{label:"Users",sortKey:"users",current:S,dir:k,onSort:M,align:"right"})]})}),o.jsx("tbody",{children:E.map(U=>o.jsx(a$,{page:U},U.landingPage))})]})})]})]}),o.jsxs("div",{className:"mt-6 flex items-center justify-between text-xs text-zinc-500",children:[o.jsx("span",{children:a?.lastSyncedAt?`Last synced ${t$(a.lastSyncedAt)}`:"Never synced"}),o.jsx("span",{children:a?`${a.topPages.length} pages shown`:""})]})]})}function s$({projectName:e,onConnected:t}){const[s,a]=w.useState(""),[r,c]=w.useState(null),[u,f]=w.useState(null),[m,p]=w.useState(!1),[v,y]=w.useState(null),x=w.useRef(null),b=w.useCallback(S=>{const C=S.target.files?.[0];if(!C)return;y(null),c(C.name);const k=new FileReader;k.onload=()=>{const A=k.result;try{const R=JSON.parse(A);if(!R.client_email||!R.private_key){y("JSON file is missing required fields: client_email and private_key. Make sure you downloaded a service account key (not an OAuth client)."),f(null);return}f(A)}catch{y("File is not valid JSON. Please upload a service account key file (.json) downloaded from Google Cloud Console."),f(null)}},k.onerror=()=>{y("Failed to read file."),f(null)},k.readAsText(C)},[]);async function N(){if(y(null),!s.trim()){y("Property ID is required.");return}if(!u){y("Please upload a service account key file.");return}p(!0);try{await P2(e,{propertyId:s.trim(),keyJson:u});try{await oj(e)}catch{}t()}catch(S){y(S instanceof Error?S.message:"Failed to connect GA4")}finally{p(!1)}}return o.jsxs(Le,{className:"surface-card p-6",children:[o.jsx("h3",{className:"text-base font-semibold text-zinc-50 mb-1",children:"Connect Google Analytics 4"}),o.jsx("p",{className:"text-sm text-zinc-400 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."}),v&&o.jsx("div",{className:"mb-4 px-4 py-2 rounded-lg bg-rose-900/20 border border-rose-800/60 text-sm text-rose-300",children:v}),o.jsxs("div",{className:"mb-4",children:[o.jsx("label",{htmlFor:"ga4-property-id",className:"block text-xs font-medium text-zinc-400 mb-1.5",children:"GA4 Property ID"}),o.jsx("input",{id:"ga4-property-id",type:"text",placeholder:"e.g. 123456789",value:s,onChange:S=>a(S.target.value),className:"w-full rounded-lg bg-zinc-900/60 border border-zinc-800/60 px-3 py-2 text-sm text-zinc-200 placeholder:text-zinc-600 focus:outline-none focus:ring-1 focus:ring-zinc-600"}),o.jsx("p",{className:"mt-1 text-[11px] text-zinc-500",children:"Find this in GA4 → Admin → Property Settings. It's a numeric ID, not the Measurement ID (G-XXXXXX)."})]}),o.jsxs("div",{className:"mb-5",children:[o.jsx("label",{className:"block text-xs font-medium text-zinc-400 mb-1.5",children:"Service Account Key File"}),o.jsx("input",{ref:x,type:"file",accept:".json,application/json",onChange:b,className:"hidden"}),o.jsxs("button",{type:"button",onClick:()=>x.current?.click(),className:"flex items-center gap-2 w-full rounded-lg bg-zinc-900/60 border border-zinc-800/60 border-dashed px-4 py-3 text-sm text-zinc-400 hover:border-zinc-600 hover:text-zinc-300 transition-colors cursor-pointer",children:[o.jsx(zE,{className:"w-4 h-4 shrink-0"}),r?o.jsx("span",{className:"text-zinc-200 truncate",children:r}):o.jsx("span",{children:"Upload .json key file"})]}),o.jsxs("p",{className:"mt-1 text-[11px] text-zinc-500",children:["Download from Google Cloud Console → IAM & Admin → Service Accounts → Keys → Add Key → JSON. The service account must have ",o.jsx("span",{className:"text-zinc-400",children:"Viewer"})," access on the GA4 property."]})]}),o.jsx(oe,{variant:"default",size:"sm",disabled:m||!s.trim()||!u,onClick:N,children:m?"Connecting & syncing…":"Connect GA4"})]})}function au({label:e,sortKey:t,current:s,dir:a,onSort:r,align:c}){const u=s===t;return o.jsxs("th",{className:`py-1 font-medium cursor-pointer select-none hover:text-zinc-300 transition-colors ${c==="right"?"text-right":"text-left"}`,onClick:()=>r(t),children:[e,u&&o.jsx("span",{className:"ml-0.5",children:a==="asc"?"↑":"↓"})]})}const i$={positive:"text-emerald-400",caution:"text-amber-400",negative:"text-rose-400",neutral:"text-zinc-50"};function hm({value:e,label:t,subtitle:s,tone:a}){return o.jsxs("div",{className:"rounded-lg bg-zinc-900/30 border border-zinc-800/60 px-5 py-4",children:[o.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-wider text-zinc-500 mb-1",children:t}),o.jsx("p",{className:`text-2xl font-bold tabular-nums ${i$[a]}`,children:e}),o.jsx("p",{className:"text-xs text-zinc-500 mt-1",children:s})]})}function a$({page:e}){const t=e.sessions>0?(e.organicSessions/e.sessions*100).toFixed(1):"0.0";return o.jsxs("tr",{className:"border-t border-zinc-800/40",children:[o.jsx("td",{className:"py-1.5 text-zinc-300 max-w-[400px] truncate",title:e.landingPage,children:e.landingPage}),o.jsx("td",{className:"py-1.5 text-right text-zinc-200 tabular-nums",children:e.sessions.toLocaleString()}),o.jsx("td",{className:"py-1.5 text-right text-emerald-400 tabular-nums",children:e.organicSessions.toLocaleString()}),o.jsxs("td",{className:"py-1.5 text-right text-zinc-400 tabular-nums",children:[t,"%"]}),o.jsx("td",{className:"py-1.5 text-right text-zinc-200 tabular-nums",children:e.users.toLocaleString()})]})}function bl(e){e.invalidateQueries({queryKey:Vn.runs.all}),e.invalidateQueries({queryKey:Vn.projects.all})}function r$(e){return e==="gsc-sync"?"GSC sync queued":e==="inspect-sitemap"?"Sitemap inspection queued":"Visibility sweep queued"}function o$(e,t){const s=e??"Project";return t==="gsc-sync"?`${s} will refresh after the sync completes.`:t==="inspect-sitemap"?`${s} will notify you when sitemap inspection finishes.`:`${s} will notify you when the run finishes.`}function gd(e,t){fj({id:e.id,projectId:e.projectId,kind:e.kind,projectLabel:t.projectLabel,sourceAction:t.sourceAction,lastAnnouncedStatus:"queued"}),Ke({title:r$(e.kind),detail:o$(t.projectLabel,e.kind),tone:"neutral",dedupeKey:`run:${e.id}`,dedupeMode:"replace"})}function l$(e){const t=e.filter(r=>r.status!=="conflict"),s=e.filter(r=>r.status==="conflict");if(t.length===0){Ke({title:"No runs queued",detail:s.length>0?`${s.length} project${s.length===1?"":"s"} already had a run in progress.`:"No projects were available to queue.",tone:"caution",durationMs:8e3,dedupeKey:"run-all:conflict",dedupeMode:"replace"});return}for(const r of t)fj({id:r.id,projectId:r.projectId,kind:r.kind,projectLabel:r.projectName,sourceAction:"run-all",lastAnnouncedStatus:"queued"});const a=$E({runIds:t.map(r=>r.id),queuedCount:t.length,skippedCount:s.length});Ke({title:"Run-all batch queued",detail:s.length>0?`${t.length} project${t.length===1?"":"s"} queued, ${s.length} skipped because a run is already active.`:`${t.length} project${t.length===1?"":"s"} queued.`,tone:s.length>0?"caution":"neutral",dedupeKey:`batch:${a}`,dedupeMode:"replace"})}function yd(e,t){if(e instanceof ku&&e.code==="RUN_IN_PROGRESS"){Ke({title:"Run already in progress",detail:t?.projectLabel?`${t.projectLabel} already has an active run. Wait for it to finish, then retry.`:"This project already has an active run. Wait for it to finish, then retry.",tone:"caution",durationMs:8e3,dedupeKey:`run-in-progress:${t?.projectKey??"project"}:${t?.sourceAction??"run"}`,dedupeMode:"replace"});return}Ke({title:e instanceof Error?e.message:"Failed to queue run",tone:"negative"})}function qN(){const e=Pi();return hl({meta:{skipGlobalErrorToast:!0},mutationFn:({projectName:t,opts:s})=>Q_(t,s),onSuccess:(t,s)=>{bl(e),gd(t,{projectLabel:s.projectLabel??s.projectName,sourceAction:s.sourceAction})},onError:(t,s)=>{yd(t,{projectKey:s.projectName,projectLabel:s.projectLabel??s.projectName,sourceAction:s.sourceAction})}})}function c$(){const e=Pi();return hl({meta:{skipGlobalErrorToast:!0},mutationFn:t=>m2(t),onSuccess:t=>{bl(e),l$(t)},onError:t=>{Ke({title:t instanceof Error?t.message:"Failed to queue runs",tone:"negative"})}})}function u$(){const e=Pi();return hl({meta:{skipGlobalErrorToast:!0},mutationFn:({projectName:t,opts:s})=>sj(t,s),onSuccess:(t,s)=>{bl(e),gd(t,{projectLabel:s.projectLabel??s.projectName,sourceAction:"gsc-sync"})},onError:(t,s)=>{yd(t,{projectKey:s.projectName,projectLabel:s.projectLabel??s.projectName,sourceAction:"gsc-sync"})}})}function d$(){const e=Pi();return hl({meta:{skipGlobalErrorToast:!0},mutationFn:({projectName:t})=>z2(t),onSuccess:(t,s)=>{bl(e),gd(t.run,{projectLabel:s.projectLabel??s.projectName,sourceAction:"discover-sitemaps"})},onError:(t,s)=>{yd(t,{projectKey:s.projectName,projectLabel:s.projectLabel??s.projectName,sourceAction:"discover-sitemaps"})}})}function f$(){const e=Pi();return hl({meta:{skipGlobalErrorToast:!0},mutationFn:({projectName:t,opts:s})=>C2(t,s),onSuccess:(t,s)=>{bl(e),gd(t,{projectLabel:s.projectLabel??s.projectName,sourceAction:"inspect-sitemap"})},onError:(t,s)=>{yd(t,{projectKey:s.projectName,projectLabel:s.projectLabel??s.projectName,sourceAction:"inspect-sitemap"})}})}function h$({projectName:e}){const[t,s]=w.useState(!1),[a,r]=w.useState([]),[c,u]=w.useState([]),[f,m]=w.useState([]),[p,v]=w.useState([]),[y,x]=w.useState([]),[b,N]=w.useState(null),[S,C]=w.useState(""),[k,A]=w.useState(""),[R,z]=w.useState("30"),[O,M]=w.useState(!1),[E,L]=w.useState({startDate:"",endDate:"",query:"",page:"",limit:"20"}),[U,X]=w.useState(""),[Q,ee]=w.useState(!0),[ue,ze]=w.useState(!1),[je,K]=w.useState(!1),[ae,me]=w.useState(!1),[V,H]=w.useState(!1),[T,B]=w.useState(!1),[se,le]=w.useState(!1),[J,fe]=w.useState(null),[ye,_e]=w.useState(!1),[ge,Ze]=w.useState(!1),[et,de]=w.useState(null),[Ve,at]=w.useState(""),[Zt,$t]=w.useState(!1),[Dn,nn]=w.useState(!1),[_t,re]=w.useState("indexed"),[Ge,gt]=w.useState([]),[Vt,Qe]=w.useState(null),[De,Ye]=w.useState(!1),[Nt,Be]=w.useState(null),[Da,pn]=w.useState(null),nt=a.find(I=>I.connectionType==="gsc"),Yr=f.length>0||p.length>0||y.length>0,ts=u$(),ht=d$(),gn=f$();async function ce(I){if(!I){u([]),C("");return}K(!0);try{const{sites:he}=await y2(e);u(he),C(I.propertyId??he[0]?.siteUrl??"")}catch(he){u([]),Be(he instanceof Error?he.message:"Failed to load Search Console properties")}finally{K(!1)}}async function kn(){H(!0);try{const I=await b2(e,{startDate:E.startDate||void 0,endDate:E.endDate||void 0,query:E.query||void 0,page:E.page||void 0,limit:parseInt(E.limit,10)||20});m(I)}catch(I){m([]),Be(I instanceof Error?I.message:"Failed to load GSC performance data")}finally{H(!1)}}async function Ma(){B(!0);try{const[I,he]=await Promise.all([j2(e,{url:U.trim()||void 0,limit:20}),w2(e)]);v(I),x(he)}catch(I){v([]),x([]),Be(I instanceof Error?I.message:"Failed to load GSC inspection history")}finally{B(!1)}}async function jl(){_e(!0);try{const[I,he]=await Promise.all([jp(e),N2(e).catch(()=>[])]);fe(I),gt(he)}catch(I){fe(null),gt([]),Be(I instanceof Error?I.message:"Failed to load coverage data")}finally{_e(!1)}}async function Ki(I){Ye(!0),Be(null);try{const he=await Kx(e,{urls:I}),{succeeded:xt,failed:Ht,total:ln}=he.summary;Ke({title:"Indexing requested",detail:Ht===0?`${xt} URL${xt!==1?"s":""} submitted for indexing.`:`${xt}/${ln} submitted successfully, ${Ht} failed.`,tone:Ht===0?"positive":"caution",dedupeKey:`gsc:indexing:${e}`,dedupeMode:"replace"})}catch(he){Be(he instanceof Error?he.message:"Failed to request indexing")}finally{Ye(!1)}}async function $a(){Ye(!0),Be(null);try{const I=await Kx(e,{urls:[],allUnindexed:!0}),{succeeded:he,failed:xt,total:Ht}=I.summary;Ke({title:"Indexing requested",detail:xt===0?`${he} unindexed URL${he!==1?"s":""} submitted for indexing.`:`${he}/${Ht} submitted successfully, ${xt} failed.`,tone:xt===0?"positive":"caution",dedupeKey:`gsc:indexing-all:${e}`,dedupeMode:"replace"})}catch(I){Be(I instanceof Error?I.message:"Failed to request indexing")}finally{Ye(!1)}}async function Cs(){if(Ve.trim()){$t(!0),Be(null);try{await x2(e,"gsc",Ve.trim()),r(I=>I.map(he=>he.connectionType==="gsc"?{...he,sitemapUrl:Ve.trim()}:he)),Ke({title:"Sitemap URL saved",detail:`${e} will use the updated sitemap URL.`,tone:"positive",dedupeKey:`gsc:sitemap:${e}`,dedupeMode:"drop"}),at("")}catch(I){Be(I instanceof Error?I.message:"Failed to save sitemap URL")}finally{$t(!1)}}}async function hs(){Be(null);try{const I=await ht.mutateAsync({projectName:e,projectLabel:e});de(I.sitemaps),r(he=>he.map(xt=>xt.connectionType==="gsc"?{...xt,sitemapUrl:I.primarySitemapUrl}:xt))}catch{}}async function Pa(){Ze(!0),Be(null);try{const I=await k2(e);de(I.sitemaps),I.sitemaps.length===0&&pn("No sitemaps found in this GSC property. Submit a sitemap in Google Search Console first.")}catch(I){Be(I instanceof Error?I.message:"Failed to list sitemaps")}finally{Ze(!1)}}async function Ys(){ee(!0),Be(null);try{const[I,he]=await Promise.all([Sp().catch(()=>null),nj(e).catch(()=>[])]);s(!!I?.google?.configured),r(he);const xt=he.find(Ht=>Ht.connectionType==="gsc");await Promise.all([ce(xt),kn(),Ma(),jl()])}finally{ee(!1)}}w.useEffect(()=>{Ys()},[e]);async function xd(){if(!t){Be("Google OAuth app credentials are not configured yet. Set them on the Settings page first.");return}ze(!0),Be(null),pn(null);try{const{authUrl:I}=await p2(e,"gsc");if(!I.startsWith("https://accounts.google.com/")){Be("Unexpected OAuth redirect URL. Please try again.");return}const he=window.open(I,"_blank","width=600,height=700");if(!he){window.location.assign(I);return}pn("Finish the Google consent flow in the popup, then close it to refresh this project.");const xt=window.setInterval(()=>{he.closed&&(window.clearInterval(xt),pn(null),Ys())},1e3)}catch(I){Be(I instanceof Error?I.message:"Failed to start OAuth flow")}finally{ze(!1)}}async function wl(){Be(null),pn(null);try{await g2(e,"gsc"),r(I=>I.filter(he=>he.connectionType!=="gsc")),u([]),C("")}catch(I){Be(I instanceof Error?I.message:"Failed to disconnect")}}async function Jr(){if(S){me(!0),Be(null);try{await v2(e,"gsc",S),r(I=>I.map(he=>he.connectionType==="gsc"?{...he,propertyId:S}:he)),Ke({title:"GSC property updated",detail:`${e} is now linked to ${S}.`,tone:"positive",dedupeKey:`gsc:property:${e}`,dedupeMode:"drop"})}catch(I){Be(I instanceof Error?I.message:"Failed to save GSC property")}finally{me(!1)}}}async function Gi(){Be(null),pn(null);try{await ts.mutateAsync({projectName:e,projectLabel:e,opts:{days:parseInt(R,10)||void 0,full:O||void 0}})}catch{}}async function Nl(){if(k.trim()){le(!0),Be(null),pn(null);try{const I=await S2(e,k.trim());N(I),A(""),await Ma()}catch(I){Be(I instanceof Error?I.message:"Failed to inspect URL")}finally{le(!1)}}}return o.jsxs("section",{className:"page-section-divider",children:[o.jsxs("div",{className:"section-head section-head-inline",children:[o.jsxs("div",{children:[o.jsx("p",{className:"eyebrow eyebrow-soft",children:"Search Console"}),o.jsx("h2",{children:"Google Search Console"})]}),o.jsx("div",{className:"flex items-center gap-2",children:nt&&o.jsx(oe,{type:"button",variant:"outline",size:"sm",disabled:V,onClick:()=>{kn()},children:V?"Refreshing…":"Refresh data"})})]}),Nt&&o.jsxs("div",{className:"mb-3 rounded-lg border border-rose-800/40 bg-rose-950/20 px-3 py-2 text-sm text-rose-300",children:[Nt,o.jsx("button",{type:"button",className:"ml-2 text-rose-400 hover:text-rose-200",onClick:()=>Be(null),children:"×"})]}),Da&&o.jsxs("div",{className:"mb-3 rounded-lg border border-emerald-800/40 bg-emerald-950/20 px-3 py-2 text-sm text-emerald-300",children:[Da,o.jsx("button",{type:"button",className:"ml-2 text-emerald-400 hover:text-emerald-200",onClick:()=>pn(null),children:"×"})]}),Q?o.jsx("p",{className:"text-sm text-zinc-500",children:"Loading…"}):o.jsxs("div",{className:"space-y-3",children:[o.jsxs(Le,{className:"surface-card",children:[o.jsxs("div",{className:"section-head section-head-inline",children:[o.jsxs("div",{children:[o.jsx("p",{className:"eyebrow eyebrow-soft",children:"Connection"}),o.jsx("h3",{children:"Domain authorization"})]}),o.jsx(lt,{tone:nt?"positive":t?"caution":"negative",children:nt?"Connected":t?"Ready to connect":"App credentials missing"})]}),nt?o.jsxs("div",{className:"mt-3 space-y-3",children:[o.jsxs("div",{className:"rounded-lg border border-zinc-800/60 bg-zinc-900/30 px-4 py-3",children:[o.jsxs("div",{className:"flex items-center gap-3",children:[o.jsx("span",{className:"h-2 w-2 rounded-full bg-emerald-500"}),o.jsx("span",{className:"text-sm text-zinc-200",children:"Authorized for this project domain"}),o.jsx("span",{className:"text-xs text-zinc-500",children:nt.domain}),o.jsx("button",{type:"button",className:"ml-auto text-xs text-zinc-500 hover:text-rose-400 transition-colors",onClick:wl,children:"Disconnect"})]}),o.jsxs("p",{className:"mt-2 text-xs text-zinc-500",children:["Canonry stores OAuth tokens per canonical domain. This project currently maps to ",o.jsx("code",{children:nt.domain}),"."]})]}),o.jsxs("div",{className:"grid gap-3 lg:grid-cols-2",children:[o.jsxs("div",{className:"rounded-lg border border-zinc-800/60 bg-zinc-900/20 p-3",children:[o.jsx("p",{className:"text-xs uppercase tracking-wide text-zinc-500",children:"Selected property"}),o.jsx("p",{className:"mt-1 text-sm text-zinc-200",children:nt.propertyId??"No property selected yet"})]}),o.jsxs("div",{className:"rounded-lg border border-zinc-800/60 bg-zinc-900/20 p-3",children:[o.jsx("p",{className:"text-xs uppercase tracking-wide text-zinc-500",children:"Last auth update"}),o.jsx("p",{className:"mt-1 text-sm text-zinc-200",children:ls(nt.updatedAt)})]})]})]}):o.jsxs("div",{className:"mt-3 rounded-lg border border-zinc-800/60 bg-zinc-900/30 px-4 py-5",children:[o.jsx("p",{className:"text-sm text-zinc-300",children:t?"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."}),o.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[t?o.jsx(oe,{type:"button",variant:"outline",size:"sm",disabled:ue,onClick:xd,children:ue?"Opening…":"Connect Google Search Console"}):o.jsx(oe,{type:"button",variant:"outline",size:"sm",asChild:!0,children:o.jsx(St,{to:"/settings",children:"Open Settings"})}),!t&&o.jsx("p",{className:"text-xs text-zinc-500",children:"The same Google OAuth app credentials are shared across all projects."})]})]})]}),nt&&!nt.sitemapUrl&&o.jsx("div",{className:"rounded-lg border border-amber-800/40 bg-amber-950/20 px-4 py-3",children:o.jsxs("div",{className:"flex items-start gap-3",children:[o.jsx("span",{className:"mt-0.5 text-amber-400",children:o.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",className:"h-5 w-5","aria-hidden":"true",children:o.jsx("path",{fillRule:"evenodd",d:"M8.485 2.495c.673-1.167 2.357-1.167 3.03 0l6.28 10.875c.673 1.167-.17 2.625-1.516 2.625H3.72c-1.347 0-2.189-1.458-1.515-2.625L8.485 2.495zM10 6a.75.75 0 01.75.75v3.5a.75.75 0 01-1.5 0v-3.5A.75.75 0 0110 6zm0 9a1 1 0 100-2 1 1 0 000 2z",clipRule:"evenodd"})})}),o.jsxs("div",{className:"flex-1 min-w-0",children:[o.jsx("p",{className:"text-sm font-medium text-amber-300",children:"Set your sitemap URL"}),o.jsx("p",{className:"mt-1 text-xs text-amber-400/70",children:"Canonry uses your sitemap to discover URLs for index coverage inspection. Auto-discover from GSC or enter it manually."}),o.jsxs("div",{className:"mt-2 flex flex-col gap-2",children:[o.jsxs("div",{className:"flex flex-col gap-2 lg:flex-row",children:[o.jsx(oe,{type:"button",size:"sm",disabled:ht.isPending||!nt.propertyId,onClick:hs,children:ht.isPending?"Discovering…":"Auto-discover from GSC"}),o.jsx("span",{className:"self-center text-xs text-amber-400/60",children:"or enter manually:"})]}),o.jsxs("div",{className:"flex flex-col gap-2 lg:flex-row",children:[o.jsx("input",{className:"flex-1 rounded border border-amber-800/40 bg-transparent px-2 py-1.5 text-sm text-zinc-200 placeholder-zinc-500 focus:border-amber-600 focus:outline-none",type:"url",placeholder:"https://example.com/sitemap.xml",value:Ve,onChange:I=>at(I.target.value),onKeyDown:I=>I.key==="Enter"&&void Cs()}),o.jsx(oe,{type:"button",size:"sm",variant:"outline",disabled:Zt||!Ve.trim(),onClick:Cs,children:Zt?"Saving…":"Save sitemap URL"})]})]})]})]})}),(nt||Yr)&&o.jsxs(o.Fragment,{children:[o.jsxs(Le,{className:"surface-card",children:[o.jsxs("div",{className:"section-head section-head-inline",children:[o.jsxs("div",{children:[o.jsx("p",{className:"eyebrow eyebrow-soft",children:"Coverage"}),o.jsx("h3",{children:"Index coverage"})]}),o.jsxs("div",{className:"flex items-center gap-2",children:[J&&J.notIndexed.length>0&&o.jsx(oe,{type:"button",variant:"outline",size:"sm",disabled:De,onClick:()=>{$a()},children:De?"Requesting…":`Request indexing (${J.notIndexed.length})`}),o.jsx(oe,{type:"button",variant:"outline",size:"sm",disabled:ye,onClick:()=>{jl()},children:ye?"Loading…":"Refresh coverage"})]})]}),J&&J.summary.total>0?o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"mt-6 flex flex-col items-center",children:(()=>{const I=J.summary.indexed+J.summary.notIndexed,he=I>0?J.summary.indexed/I:0,xt=I>0?J.summary.notIndexed/I:0,Ht=54,ln=2*Math.PI*Ht,Ua=ln*(1-he),ms=ln*xt,cn=ln*he;return o.jsxs(o.Fragment,{children:[o.jsxs("div",{className:"relative h-48 w-48",children:[o.jsxs("svg",{viewBox:"0 0 128 128",className:"h-full w-full","aria-hidden":"true",children:[o.jsx("circle",{cx:"64",cy:"64",r:Ht,fill:"none",stroke:"rgba(255,255,255,0.04)",strokeWidth:"14"}),o.jsx("circle",{cx:"64",cy:"64",r:Ht,fill:"none",stroke:"#10b981",strokeWidth:"14",strokeDasharray:ln,strokeDashoffset:Ua,strokeLinecap:"round",transform:"rotate(-90 64 64)",style:{transition:"stroke-dashoffset 0.6s ease"}}),J.summary.notIndexed>0&&o.jsx("circle",{cx:"64",cy:"64",r:Ht,fill:"none",stroke:"#52525b",strokeWidth:"14",strokeDasharray:`${ms} ${ln-ms}`,strokeDashoffset:-cn,transform:"rotate(-90 64 64)",style:{transition:"stroke-dasharray 0.6s ease, stroke-dashoffset 0.6s ease"}})]}),o.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center",children:[o.jsxs("span",{className:"text-3xl font-bold tabular-nums text-zinc-50",children:[(he*100).toFixed(0),"%"]}),o.jsx("span",{className:"text-xs uppercase tracking-widest text-zinc-500 mt-0.5",children:"Indexed"})]})]}),o.jsxs("div",{className:"mt-4 flex items-center justify-center gap-8",children:[o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx("span",{className:"inline-block h-2.5 w-2.5 rounded-full bg-emerald-500"}),o.jsxs("div",{children:[o.jsx("p",{className:"text-2xl font-semibold tabular-nums text-zinc-50",children:J.summary.indexed.toLocaleString()}),o.jsx("p",{className:"text-[11px] uppercase tracking-wide text-zinc-500",children:"Indexed"})]})]}),o.jsx("div",{className:"h-8 w-px bg-zinc-800"}),o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx("span",{className:"inline-block h-2.5 w-2.5 rounded-full bg-zinc-500"}),o.jsxs("div",{children:[o.jsx("p",{className:"text-2xl font-semibold tabular-nums text-zinc-50",children:J.summary.notIndexed.toLocaleString()}),o.jsxs("p",{className:"text-[11px] uppercase tracking-wide text-zinc-500",children:["Not indexed",(J.reasonGroups??[]).length>0&&o.jsxs("span",{className:"ml-1 text-zinc-600",children:["· ",(J.reasonGroups??[]).length," ",(J.reasonGroups??[]).length===1?"reason":"reasons"]})]})]})]}),J.summary.deindexed>0&&o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"h-8 w-px bg-zinc-800"}),o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx("span",{className:"inline-block h-2.5 w-2.5 rounded-full bg-rose-500"}),o.jsxs("div",{children:[o.jsx("p",{className:"text-2xl font-semibold tabular-nums text-zinc-50",children:J.summary.deindexed.toLocaleString()}),o.jsx("p",{className:"text-[11px] uppercase tracking-wide text-zinc-500",children:"Deindexed"})]})]})]})]})]})})()}),o.jsx("div",{className:"mt-3 flex gap-1",children:["indexed","notIndexed","deindexed"].map(I=>{const he=I==="indexed"?J.indexed.length:I==="notIndexed"?J.notIndexed.length:J.deindexed.length,xt=I==="indexed"?"Indexed":I==="notIndexed"?"Not Indexed":"Deindexed";return o.jsxs("button",{type:"button",className:`rounded-full px-3 py-1 text-xs font-medium transition-colors ${_t===I?"bg-zinc-700 text-zinc-100":"text-zinc-400 hover:bg-zinc-800 hover:text-zinc-200"}`,onClick:()=>{re(I),Qe(null)},children:[xt," (",he,")"]},I)})}),o.jsxs("div",{className:"mt-3 overflow-x-auto",children:[_t==="indexed"&&J.indexed.length>0&&o.jsxs("table",{className:"data-table w-full text-sm",children:[o.jsx("thead",{children:o.jsxs("tr",{children:[o.jsx("th",{className:"text-left",children:"URL"}),o.jsx("th",{className:"text-left",children:"Verdict"}),o.jsx("th",{className:"text-left",children:"Last Crawl"}),o.jsx("th",{className:"text-left",children:"Mobile"})]})}),o.jsx("tbody",{children:J.indexed.map(I=>o.jsxs("tr",{children:[o.jsx("td",{className:"max-w-sm truncate text-zinc-200",children:I.url}),o.jsx("td",{className:"text-zinc-400",children:I.verdict??"Unknown"}),o.jsx("td",{className:"text-zinc-400",children:I.crawlTime?I.crawlTime.split("T")[0]:"—"}),o.jsx("td",{className:"text-zinc-400",children:I.isMobileFriendly===!0?"Yes":I.isMobileFriendly===!1?"No":"—"})]},I.id))})]}),_t==="notIndexed"&&!Vt&&(J.reasonGroups??[]).length>0&&o.jsxs("table",{className:"data-table w-full text-sm",children:[o.jsx("thead",{children:o.jsxs("tr",{children:[o.jsx("th",{className:"text-left",children:"Reason"}),o.jsx("th",{className:"text-right",children:"Pages"})]})}),o.jsx("tbody",{children:(J.reasonGroups??[]).map(I=>o.jsxs("tr",{className:"cursor-pointer hover:bg-zinc-800/40",onClick:()=>Qe(I.reason),children:[o.jsx("td",{className:"text-zinc-200",children:I.reason}),o.jsx("td",{className:"text-right tabular-nums text-zinc-400",children:I.count})]},I.reason))})]}),_t==="notIndexed"&&!Vt&&(J.reasonGroups??[]).length===0&&J.notIndexed.length>0&&o.jsxs("table",{className:"data-table w-full text-sm",children:[o.jsx("thead",{children:o.jsxs("tr",{children:[o.jsx("th",{className:"text-left",children:"URL"}),o.jsx("th",{className:"text-left",children:"Indexing State"}),o.jsx("th",{className:"text-left",children:"Coverage"})]})}),o.jsx("tbody",{children:J.notIndexed.map(I=>o.jsxs("tr",{children:[o.jsx("td",{className:"max-w-sm truncate text-zinc-200",children:I.url}),o.jsx("td",{className:"text-zinc-400",children:I.indexingState??"Unknown"}),o.jsx("td",{className:"text-zinc-400",children:I.coverageState??"Unknown"})]},I.id))})]}),_t==="notIndexed"&&Vt&&(()=>{const I=(J.reasonGroups??[]).find(he=>he.reason===Vt);return I?o.jsxs("div",{children:[o.jsx("div",{className:"flex items-center gap-2 mb-3",children:o.jsx("button",{type:"button",className:"text-xs text-zinc-400 hover:text-zinc-200 transition-colors",onClick:()=>Qe(null),children:"\\u2190 Back to reasons"})}),o.jsxs("div",{className:"mb-3 flex items-center justify-between rounded-lg border border-zinc-800/60 bg-zinc-900/20 p-3",children:[o.jsxs("div",{children:[o.jsx("p",{className:"text-sm font-medium text-zinc-200",children:I.reason}),o.jsxs("p",{className:"mt-1 text-xs text-zinc-500",children:[I.count," affected page",I.count!==1?"s":""]})]}),o.jsx(oe,{type:"button",variant:"outline",size:"sm",disabled:De,onClick:()=>{Ki(I.urls.map(he=>he.url))},children:De?"Requesting…":`Request indexing (${I.count})`})]}),o.jsxs("table",{className:"data-table w-full text-sm",children:[o.jsx("thead",{children:o.jsxs("tr",{children:[o.jsx("th",{className:"text-left",children:"URL"}),o.jsx("th",{className:"text-left",children:"Last Crawl"}),o.jsx("th",{className:"w-8"})]})}),o.jsx("tbody",{children:I.urls.map(he=>o.jsxs("tr",{children:[o.jsx("td",{className:"max-w-sm truncate text-zinc-200",children:he.url}),o.jsx("td",{className:"text-zinc-400",children:he.crawlTime?he.crawlTime.split("T")[0]:"—"}),o.jsx("td",{children:o.jsx("button",{type:"button",className:"text-xs text-zinc-500 hover:text-zinc-200 transition-colors",disabled:De,onClick:()=>{Ki([he.url])},title:"Request indexing",children:"Index"})})]},he.id))})]})]}):null})(),_t==="deindexed"&&J.deindexed.length>0&&o.jsxs("table",{className:"data-table w-full text-sm",children:[o.jsx("thead",{children:o.jsxs("tr",{children:[o.jsx("th",{className:"text-left",children:"URL"}),o.jsx("th",{className:"text-left",children:"Previous"}),o.jsx("th",{className:"text-left",children:"Current"}),o.jsx("th",{className:"text-left",children:"Detected"})]})}),o.jsx("tbody",{children:J.deindexed.map((I,he)=>o.jsxs("tr",{children:[o.jsx("td",{className:"max-w-sm truncate text-zinc-200",children:I.url}),o.jsx("td",{className:"text-zinc-400",children:I.previousState}),o.jsx("td",{className:"text-zinc-400",children:I.currentState}),o.jsx("td",{className:"text-zinc-400",children:I.transitionDate.split("T")[0]})]},`${I.url}-${he}`))})]}),(_t==="indexed"&&J.indexed.length===0||_t==="notIndexed"&&!Vt&&J.notIndexed.length===0||_t==="deindexed"&&J.deindexed.length===0)&&o.jsx("p",{className:"text-sm text-zinc-500",children:"No URLs in this category."})]})]}):o.jsx("p",{className:"mt-3 text-sm text-zinc-500",children:ye?"Loading coverage data…":"No coverage data yet. Inspect your sitemap to populate this view."})]}),o.jsxs(Le,{className:"surface-card",children:[o.jsxs("div",{className:"section-head section-head-inline",children:[o.jsxs("div",{children:[o.jsx("p",{className:"eyebrow eyebrow-soft",children:"Performance"}),o.jsx("h3",{children:"Search performance"})]}),o.jsx(oe,{type:"button",variant:"outline",size:"sm",disabled:V,onClick:()=>{kn()},children:V?"Loading…":"Apply filters"})]}),f.length>0&&(()=>{const I=new Map;for(const Me of f){const Je=I.get(Me.date);Je?(Je.clicks+=Me.clicks,Je.impressions+=Me.impressions):I.set(Me.date,{clicks:Me.clicks,impressions:Me.impressions})}const he=[...I.entries()].sort(([Me],[Je])=>Me.localeCompare(Je));if(he.length===0)return null;const xt=Math.max(...he.map(([,Me])=>Me.impressions),1),Ht=he.reduce((Me,[,Je])=>Me+Je.clicks,0),ln=he.reduce((Me,[,Je])=>Me+Je.impressions,0),Ua=ln>0?(Ht/ln*100).toFixed(1):"0.0",ms=700,cn=220,st={top:12,bottom:36,left:48,right:12},sn=ms-st.left-st.right,zn=cn-st.top-st.bottom,ks=sn/he.length,Ia=Math.max(Math.min(ks*.35,24),4),Cl=Math.max(Ia*.15,1),kl=Me=>{if(Me<=0)return 1;const Je=Math.pow(10,Math.floor(Math.log10(Me))),it=Me/Je,ns=it<=1.5?1.5:it<=3?3:it<=5?5:10;return Math.ceil(ns*Je)},ps=4,Js=Math.ceil(kl(xt)/ps)*ps,Xs=Array.from({length:ps+1},(Me,Je)=>Js/ps*Je),Ws=Me=>Me>=1e3?`${(Me/1e3).toFixed(Me>=1e4?0:1)}k`:String(Me);return o.jsxs("div",{className:"mt-3",children:[o.jsxs("div",{className:"flex items-center gap-5 mb-2",children:[o.jsxs("div",{className:"flex items-center gap-1.5",children:[o.jsx("span",{className:"inline-block h-2.5 w-2.5 rounded-sm bg-emerald-500"}),o.jsxs("span",{className:"text-xs text-zinc-400",children:["Clicks ",o.jsx("span",{className:"text-zinc-200 tabular-nums font-medium",children:Ht.toLocaleString()})]})]}),o.jsxs("div",{className:"flex items-center gap-1.5",children:[o.jsx("span",{className:"inline-block h-2.5 w-2.5 rounded-sm bg-blue-500"}),o.jsxs("span",{className:"text-xs text-zinc-400",children:["Impressions ",o.jsx("span",{className:"text-zinc-200 tabular-nums font-medium",children:ln.toLocaleString()})]})]}),o.jsxs("span",{className:"text-xs text-zinc-500",children:["CTR ",o.jsxs("span",{className:"text-amber-400 tabular-nums font-medium",children:[Ua,"%"]})]})]}),o.jsx("div",{className:"relative w-full",style:{aspectRatio:`${ms} / ${cn}`},children:o.jsxs("svg",{viewBox:`0 0 ${ms} ${cn}`,className:"h-full w-full",children:[Xs.map((Me,Je)=>{const it=st.top+zn-Me/Js*zn;return o.jsxs("g",{children:[o.jsx("line",{x1:st.left,y1:it,x2:ms-st.right,y2:it,stroke:"rgba(255,255,255,0.06)",strokeWidth:"1"}),o.jsx("text",{x:st.left-6,y:it+3.5,textAnchor:"end",fill:"#a1a1aa",fontSize:"10",fontFamily:"inherit",children:Ws(Me)})]},`t-${Je}`)}),he.map(([Me,Je],it)=>{const ns=st.left+ks*it+ks/2,Fi=Je.impressions/Js*zn,gs=Je.clicks/Js*zn;return o.jsxs("g",{children:[o.jsx("title",{children:`${Me}
|
|
234
234
|
Clicks: ${Je.clicks}
|
|
235
235
|
Impressions: ${Je.impressions}
|
|
236
|
-
CTR: ${Je.impressions>0?(Je.clicks/Je.impressions*100).toFixed(1):0}%`}),o.jsx("rect",{x:ns-Ia-Cl/2,y:st.top+zn-Fi,width:Ia,height:Math.max(Fi,1),rx:2,fill:"#3b82f6",opacity:.85}),o.jsx("rect",{x:ns+Cl/2,y:st.top+zn-gs,width:Ia,height:Math.max(gs,1),rx:2,fill:"#10b981",opacity:.85})]},Me)}),(()=>{const Me=Math.min(he.length,7);return Array.from({length:Me},(Je,it)=>{const ns=he.length===1?0:Math.round(it/(Me-1)*(he.length-1)),Fi=st.left+ks*ns+ks/2;return o.jsx("text",{x:Fi,y:cn-8,textAnchor:"middle",fill:"#71717a",fontSize:"10",fontFamily:"inherit",children:he[ns][0].slice(5)},`xl-${ns}`)})})()]})})]})})(),o.jsxs("div",{className:"mt-3 grid gap-2 lg:grid-cols-5",children:[o.jsx("input",{className:"rounded border border-zinc-700 bg-transparent px-2 py-1.5 text-sm text-zinc-200 placeholder-zinc-600 focus:border-zinc-500 focus:outline-none",type:"date",value:E.startDate,onChange:I=>L(he=>({...he,startDate:I.target.value}))}),o.jsx("input",{className:"rounded border border-zinc-700 bg-transparent px-2 py-1.5 text-sm text-zinc-200 placeholder-zinc-600 focus:border-zinc-500 focus:outline-none",type:"date",value:E.endDate,onChange:I=>L(he=>({...he,endDate:I.target.value}))}),o.jsx("input",{className:"rounded border border-zinc-700 bg-transparent px-2 py-1.5 text-sm text-zinc-200 placeholder-zinc-600 focus:border-zinc-500 focus:outline-none",type:"text",placeholder:"Filter query",value:E.query,onChange:I=>L(he=>({...he,query:I.target.value}))}),o.jsx("input",{className:"rounded border border-zinc-700 bg-transparent px-2 py-1.5 text-sm text-zinc-200 placeholder-zinc-600 focus:border-zinc-500 focus:outline-none",type:"text",placeholder:"Filter page",value:E.page,onChange:I=>L(he=>({...he,page:I.target.value}))}),o.jsx("input",{className:"rounded border border-zinc-700 bg-transparent px-2 py-1.5 text-sm text-zinc-200 placeholder-zinc-600 focus:border-zinc-500 focus:outline-none",type:"number",min:"1",placeholder:"Limit",value:E.limit,onChange:I=>L(he=>({...he,limit:I.target.value}))})]}),f.length>0?o.jsx("div",{className:"mt-3 overflow-x-auto",children:o.jsxs("table",{className:"data-table w-full text-sm",children:[o.jsx("thead",{children:o.jsxs("tr",{children:[o.jsx("th",{className:"text-left",children:"Date"}),o.jsx("th",{className:"text-left",children:"Query"}),o.jsx("th",{className:"text-left",children:"Page"}),o.jsx("th",{className:"text-right",children:"Clicks"}),o.jsx("th",{className:"text-right",children:"Impressions"}),o.jsx("th",{className:"text-right",children:"CTR"}),o.jsx("th",{className:"text-right",children:"Position"})]})}),o.jsx("tbody",{children:f.map((I,he)=>o.jsxs("tr",{children:[o.jsx("td",{className:"text-zinc-400",children:I.date}),o.jsx("td",{className:"max-w-xs truncate text-zinc-200",children:I.query}),o.jsx("td",{className:"max-w-xs truncate text-zinc-400",children:I.page}),o.jsx("td",{className:"text-right tabular-nums text-zinc-300",children:I.clicks.toLocaleString()}),o.jsx("td",{className:"text-right tabular-nums text-zinc-400",children:I.impressions.toLocaleString()}),o.jsxs("td",{className:"text-right tabular-nums text-zinc-400",children:[(I.ctr*100).toFixed(1),"%"]}),o.jsx("td",{className:"text-right tabular-nums text-zinc-400",children:I.position.toFixed(1)})]},`${I.date}:${I.query}:${I.page}:${he}`))})]})}):o.jsx("p",{className:"mt-3 text-sm text-zinc-500",children:"No performance rows match the current filters yet."})]}),o.jsxs(Le,{className:"surface-card",children:[o.jsx("div",{className:"section-head",children:o.jsxs("div",{children:[o.jsx("p",{className:"eyebrow eyebrow-soft",children:"Inspection"}),o.jsx("h3",{children:"Inspect a URL"})]})}),o.jsxs("div",{className:"mt-3 flex flex-col gap-2 lg:flex-row",children:[o.jsx("input",{className:"flex-1 rounded border border-zinc-700 bg-transparent px-2 py-1.5 text-sm text-zinc-200 placeholder-zinc-600 focus:border-zinc-500 focus:outline-none",type:"url",placeholder:"https://example.com/page",value:k,onChange:I=>A(I.target.value),onKeyDown:I=>I.key==="Enter"&&void Nl()}),o.jsx(oe,{type:"button",size:"sm",disabled:se||!nt?.propertyId||!k.trim(),onClick:Nl,children:se?"Inspecting…":"Inspect URL"})]}),b&&o.jsxs("div",{className:"mt-3 grid gap-3 md:grid-cols-2 xl:grid-cols-4",children:[o.jsxs("div",{className:"rounded-lg border border-zinc-800/60 bg-zinc-900/20 p-3",children:[o.jsx("p",{className:"text-xs uppercase tracking-wide text-zinc-500",children:"Indexing state"}),o.jsx("p",{className:"mt-1 text-sm text-zinc-200",children:b.indexingState??"Unknown"})]}),o.jsxs("div",{className:"rounded-lg border border-zinc-800/60 bg-zinc-900/20 p-3",children:[o.jsx("p",{className:"text-xs uppercase tracking-wide text-zinc-500",children:"Verdict"}),o.jsx("p",{className:"mt-1 text-sm text-zinc-200",children:b.verdict??"Unknown"})]}),o.jsxs("div",{className:"rounded-lg border border-zinc-800/60 bg-zinc-900/20 p-3",children:[o.jsx("p",{className:"text-xs uppercase tracking-wide text-zinc-500",children:"Mobile friendly"}),o.jsx("p",{className:"mt-1 text-sm text-zinc-200",children:Wx(b.isMobileFriendly)})]}),o.jsxs("div",{className:"rounded-lg border border-zinc-800/60 bg-zinc-900/20 p-3",children:[o.jsx("p",{className:"text-xs uppercase tracking-wide text-zinc-500",children:"Last crawl"}),o.jsx("p",{className:"mt-1 text-sm text-zinc-200",children:ls(b.crawlTime)})]})]})]}),o.jsxs(Le,{className:"surface-card",children:[o.jsxs("div",{className:"section-head section-head-inline",children:[o.jsxs("div",{children:[o.jsx("p",{className:"eyebrow eyebrow-soft",children:"History"}),o.jsx("h3",{children:"Inspection log"})]}),o.jsx(oe,{type:"button",variant:"outline",size:"sm",disabled:T,onClick:()=>{Ma()},children:T?"Loading…":"Refresh history"})]}),o.jsxs("div",{className:"mt-3 flex flex-col gap-2 lg:flex-row",children:[o.jsx("input",{className:"flex-1 rounded border border-zinc-700 bg-transparent px-2 py-1.5 text-sm text-zinc-200 placeholder-zinc-600 focus:border-zinc-500 focus:outline-none",type:"text",placeholder:"Filter exact URL",value:U,onChange:I=>X(I.target.value)}),o.jsx(oe,{type:"button",size:"sm",variant:"outline",disabled:T,onClick:()=>{Ma()},children:"Apply filter"})]}),p.length>0?o.jsx("div",{className:"mt-3 overflow-x-auto",children:o.jsxs("table",{className:"data-table w-full text-sm",children:[o.jsx("thead",{children:o.jsxs("tr",{children:[o.jsx("th",{className:"text-left",children:"URL"}),o.jsx("th",{className:"text-left",children:"Indexing"}),o.jsx("th",{className:"text-left",children:"Verdict"}),o.jsx("th",{className:"text-left",children:"Coverage"}),o.jsx("th",{className:"text-left",children:"Mobile"}),o.jsx("th",{className:"text-left",children:"Inspected"})]})}),o.jsx("tbody",{children:p.map(I=>o.jsxs("tr",{children:[o.jsx("td",{className:"max-w-sm truncate text-zinc-200",children:I.url}),o.jsx("td",{className:"text-zinc-300",children:I.indexingState??"Unknown"}),o.jsx("td",{className:"text-zinc-400",children:I.verdict??"Unknown"}),o.jsx("td",{className:"text-zinc-400",children:I.coverageState??"Unknown"}),o.jsx("td",{className:"text-zinc-400",children:Wx(I.isMobileFriendly)}),o.jsx("td",{className:"text-zinc-400",children:ls(I.inspectedAt)})]},I.id))})]})}):o.jsx("p",{className:"mt-3 text-sm text-zinc-500",children:"No inspection history yet."})]}),o.jsxs(Le,{className:"surface-card",children:[o.jsx("div",{className:"section-head",children:o.jsxs("div",{children:[o.jsx("p",{className:"eyebrow eyebrow-soft",children:"Deindexed"}),o.jsx("h3",{children:"Recent indexing losses"})]})}),y.length>0?o.jsx("div",{className:"mt-3 overflow-x-auto",children:o.jsxs("table",{className:"data-table w-full text-sm",children:[o.jsx("thead",{children:o.jsxs("tr",{children:[o.jsx("th",{className:"text-left",children:"URL"}),o.jsx("th",{className:"text-left",children:"Previous"}),o.jsx("th",{className:"text-left",children:"Current"}),o.jsx("th",{className:"text-left",children:"Changed at"})]})}),o.jsx("tbody",{children:y.map(I=>o.jsxs("tr",{children:[o.jsx("td",{className:"max-w-sm truncate text-zinc-200",children:I.url}),o.jsx("td",{className:"text-zinc-400",children:I.previousState??"Unknown"}),o.jsx("td",{className:"text-zinc-300",children:I.currentState??"Unknown"}),o.jsx("td",{className:"text-zinc-400",children:ls(I.transitionDate)})]},`${I.url}:${I.transitionDate}`))})]})}):o.jsx("p",{className:"mt-3 text-sm text-zinc-500",children:"No deindexed transitions recorded."})]})]}),nt&&o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"border-t border-zinc-800/60 pt-3",children:o.jsxs("button",{type:"button",className:"flex w-full items-center gap-2 text-left",onClick:()=>nn(I=>!I),children:[o.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",className:`h-4 w-4 text-zinc-500 transition-transform ${Dn?"rotate-90":""}`,"aria-hidden":"true",children:o.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"})}),o.jsx("span",{className:"text-xs uppercase tracking-wide text-zinc-500",children:"Setup & Configuration"})]})}),Dn&&o.jsxs("div",{className:"space-y-3",children:[o.jsxs("div",{className:"grid gap-3 xl:grid-cols-2",children:[o.jsxs(Le,{className:"surface-card",children:[o.jsx("div",{className:"section-head",children:o.jsxs("div",{children:[o.jsx("p",{className:"eyebrow eyebrow-soft",children:"Property"}),o.jsx("h3",{children:"Pick the Search Console property"})]})}),o.jsxs("div",{className:"mt-3 space-y-2",children:[o.jsx("label",{className:"text-xs text-zinc-500",htmlFor:`gsc-property-${e}`,children:"Property URL"}),o.jsx("select",{id:`gsc-property-${e}`,className:"w-full rounded border border-zinc-700 bg-transparent px-2 py-1.5 text-sm text-zinc-200 focus:border-zinc-500 focus:outline-none",value:S,disabled:je||c.length===0,onChange:I=>C(I.target.value),children:c.length===0?o.jsx("option",{value:"",children:je?"Loading properties…":"No properties available"}):c.map(I=>o.jsxs("option",{value:I.siteUrl,children:[I.siteUrl," · ",I.permissionLevel]},I.siteUrl))}),o.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[o.jsx(oe,{type:"button",size:"sm",variant:"outline",disabled:je,onClick:()=>{ce(nt)},children:je?"Refreshing…":"Refresh properties"}),o.jsx(oe,{type:"button",size:"sm",disabled:!S||ae,onClick:Jr,children:ae?"Saving…":"Save property"})]}),o.jsx("p",{className:"text-xs text-zinc-500",children:"The selected property is used for future syncs and URL inspections for this project."})]})]}),o.jsxs(Le,{className:"surface-card",children:[o.jsx("div",{className:"section-head",children:o.jsxs("div",{children:[o.jsx("p",{className:"eyebrow eyebrow-soft",children:"Sync"}),o.jsx("h3",{children:"Import GSC performance data"})]})}),o.jsxs("div",{className:"mt-3 space-y-3",children:[o.jsxs("div",{className:"grid gap-3 sm:grid-cols-[160px_1fr]",children:[o.jsxs("div",{children:[o.jsx("label",{className:"text-xs text-zinc-500",htmlFor:`gsc-sync-days-${e}`,children:"Days"}),o.jsx("input",{id:`gsc-sync-days-${e}`,type:"number",min:"1",className:"mt-0.5 w-full rounded border border-zinc-700 bg-transparent px-2 py-1.5 text-sm text-zinc-200 placeholder-zinc-600 focus:border-zinc-500 focus:outline-none",value:R,onChange:I=>z(I.target.value)})]}),o.jsxs("label",{className:"flex items-center gap-2 rounded border border-zinc-800/60 bg-zinc-900/20 px-3 py-2 text-sm text-zinc-300",children:[o.jsx("input",{type:"checkbox",checked:O,onChange:I=>M(I.target.checked)}),"Replace existing imported rows for the requested range"]})]}),o.jsx(oe,{type:"button",size:"sm",disabled:ts.isPending||!nt.propertyId,onClick:Gi,children:ts.isPending?"Queueing…":"Queue sync"}),!nt.propertyId&&o.jsx("p",{className:"text-xs text-amber-400",children:"Select a Search Console property before queueing a sync."})]})]})]}),o.jsxs(Le,{className:"surface-card",children:[o.jsx("div",{className:"section-head",children:o.jsxs("div",{children:[o.jsx("p",{className:"eyebrow eyebrow-soft",children:"Sitemap"}),o.jsx("h3",{children:"Sitemap configuration"})]})}),o.jsxs("div",{className:"mt-3 space-y-3",children:[nt.sitemapUrl&&o.jsxs("div",{className:"rounded-lg border border-zinc-800/60 bg-zinc-900/20 p-3",children:[o.jsx("p",{className:"text-xs uppercase tracking-wide text-zinc-500",children:"Current sitemap URL"}),o.jsx("p",{className:"mt-1 text-sm text-zinc-200 break-all",children:nt.sitemapUrl})]}),o.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[o.jsx(oe,{type:"button",size:"sm",variant:"outline",disabled:ge||!nt.propertyId,onClick:()=>{Pa()},children:ge?"Loading…":"Browse sitemaps from GSC"}),o.jsx(oe,{type:"button",size:"sm",variant:"outline",disabled:ht.isPending||!nt.propertyId,onClick:hs,children:ht.isPending?"Discovering…":"Auto-discover and queue inspection"})]}),o.jsx("p",{className:"text-xs text-zinc-500",children:"Browse lists available sitemaps without queueing a run. Auto-discover saves the primary sitemap and queues an inspection."}),et&&et.length>0&&o.jsxs("div",{className:"rounded-lg border border-zinc-800/60 bg-zinc-900/20 p-3 space-y-2",children:[o.jsxs("p",{className:"text-xs uppercase tracking-wide text-zinc-500",children:["Sitemaps (",et.length,")"]}),et.map(I=>{const he=I.contents?.[0];return o.jsxs("div",{className:"flex items-start justify-between gap-2 text-xs",children:[o.jsxs("div",{children:[o.jsx("p",{className:"text-zinc-200 break-all",children:I.path}),I.lastSubmitted&&o.jsxs("p",{className:"text-zinc-500",children:["Submitted: ",I.lastSubmitted.split("T")[0]]})]}),o.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[he&&o.jsxs("div",{className:"text-right",children:[o.jsxs("p",{className:"text-zinc-300",children:[he.indexed," / ",he.submitted]}),o.jsx("p",{className:"text-zinc-500",children:"indexed"})]}),o.jsx("button",{type:"button",className:"text-xs text-zinc-400 hover:text-zinc-200 transition-colors",onClick:()=>at(I.path),children:"Use"})]})]},I.path)})]}),o.jsxs("div",{className:"flex flex-col gap-2 lg:flex-row",children:[o.jsx("input",{className:"flex-1 rounded border border-zinc-700 bg-transparent px-2 py-1.5 text-sm text-zinc-200 placeholder-zinc-600 focus:border-zinc-500 focus:outline-none",type:"url",placeholder:nt.sitemapUrl?"Update sitemap URL…":"https://example.com/sitemap.xml",value:Ve,onChange:I=>at(I.target.value),onKeyDown:I=>I.key==="Enter"&&Ve.trim()&&void Cs()}),o.jsx(oe,{type:"button",size:"sm",disabled:Zt||!Ve.trim(),onClick:Cs,children:Zt?"Saving…":nt.sitemapUrl?"Update":"Save"})]}),o.jsxs("div",{className:"flex flex-col gap-2 lg:flex-row",children:[o.jsx("input",{className:"flex-1 rounded border border-zinc-700 bg-transparent px-2 py-1.5 text-sm text-zinc-200 placeholder-zinc-600 focus:border-zinc-500 focus:outline-none",type:"url",placeholder:"Sitemap URL for inspection (leave empty for saved default)",id:`gsc-sitemap-inspect-${e}`}),o.jsx(oe,{type:"button",size:"sm",variant:"outline",disabled:gn.isPending||!nt.propertyId,onClick:async()=>{const he=document.getElementById(`gsc-sitemap-inspect-${e}`)?.value?.trim()||nt.sitemapUrl||void 0;Be(null),pn(null);try{await gn.mutateAsync({projectName:e,projectLabel:e,opts:{sitemapUrl:he}})}catch{}},children:gn.isPending?"Queueing…":"Inspect sitemap"})]}),!nt.propertyId&&o.jsx("p",{className:"text-xs text-amber-400",children:"Select a Search Console property first."})]})]})]})]})]})]})}function m$({project:e,onUpdateProject:t,onRefresh:s}){const[a,r]=w.useState(!1),[c,u]=w.useState(!1),[f,m]=w.useState(null),[p,v]=w.useState(e.displayName),[y,x]=w.useState(e.canonicalDomain),[b,N]=w.useState(e.country),[S,C]=w.useState(e.language),[k,A]=w.useState(e.ownedDomains??[]),[R,z]=w.useState(""),[O,M]=w.useState(null),[E,L]=w.useState(!1),[U,X]=w.useState(!1),[Q,ee]=w.useState(""),[ue,ze]=w.useState(""),[je,K]=w.useState(""),[ae,me]=w.useState(""),[V,H]=w.useState("");w.useEffect(()=>{a||(v(e.displayName),x(e.canonicalDomain),N(e.country),C(e.language),A(e.ownedDomains??[]))},[e,a]);function T(){r(!1),m(null),v(e.displayName),x(e.canonicalDomain),N(e.country),C(e.language),A(e.ownedDomains??[]),z("")}function B(){const de=R.trim();de&&(k.includes(de)||A([...k,de]),z(""))}function se(de){A(k.filter(Ve=>Ve!==de))}async function le(){if(!(!p.trim()||!y.trim()||!b.trim()||!S.trim())){u(!0),m(null);try{await t(e.name,{displayName:p.trim(),canonicalDomain:y.trim(),ownedDomains:k,country:b.trim(),language:S.trim()}),r(!1),Ke({title:"Project settings saved",detail:`${p.trim()} was updated.`,tone:"positive",dedupeKey:`project:update:${e.name}`,dedupeMode:"replace"})}catch(de){m(de instanceof Error?de.message:"Failed to save")}finally{u(!1)}}}async function J(){const de=Q.trim(),Ve=ue.trim(),at=je.trim(),Zt=ae.trim();if(!(!de||!Ve||!at||!Zt)){L(!0),M(null);try{const $t={label:de,city:Ve,region:at,country:Zt};V.trim()&&($t.timezone=V.trim()),await Y_(e.name,$t),s(),ee(""),ze(""),K(""),me(""),H(""),X(!1),Ke({title:"Location added",detail:`${de} is now available for ${e.name}.`,tone:"positive",dedupeKey:`project:location:add:${e.name}:${de}`,dedupeMode:"drop"})}catch($t){M($t instanceof Error?$t.message:"Failed to add location")}finally{L(!1)}}}async function fe(de){L(!0),M(null);try{await J_(e.name,de),s(),Ke({title:"Location removed",detail:`${de} was removed from ${e.name}.`,tone:"positive",dedupeKey:`project:location:remove:${e.name}:${de}`,dedupeMode:"drop"})}catch(Ve){M(Ve instanceof Error?Ve.message:"Failed to remove location")}finally{L(!1)}}async function ye(de){L(!0),M(null);try{await X_(e.name,de),s(),Ke({title:"Default location updated",detail:`${de} is now the default for ${e.name}.`,tone:"positive",dedupeKey:`project:location:default:${e.name}`,dedupeMode:"replace"})}catch(Ve){M(Ve instanceof Error?Ve.message:"Failed to set default location")}finally{L(!1)}}const _e=p!==e.displayName||y!==e.canonicalDomain||b!==e.country||S!==e.language||JSON.stringify(k)!==JSON.stringify(e.ownedDomains??[]),ge="w-full rounded border border-zinc-700 bg-transparent px-2 py-1.5 text-sm text-zinc-200 placeholder-zinc-600 focus:border-zinc-500 focus:outline-none",Ze="block text-xs font-medium text-zinc-400 mb-1",et=Q.trim()&&ue.trim()&&je.trim()&&ae.trim();return o.jsxs("section",{className:"page-section-divider",children:[o.jsxs("div",{className:"section-head section-head-inline",children:[o.jsxs("div",{children:[o.jsx("p",{className:"eyebrow eyebrow-soft",children:"Configuration"}),o.jsx("h2",{children:"Project settings"})]}),!a&&o.jsx(oe,{type:"button",variant:"outline",size:"sm",onClick:()=>r(!0),children:"Edit settings"})]}),f&&o.jsxs("div",{className:"mb-3 rounded-lg border border-rose-800/40 bg-rose-950/20 px-3 py-2 text-sm text-rose-300",children:[f,o.jsx("button",{type:"button",className:"ml-2 text-rose-400 hover:text-rose-200",onClick:()=>m(null),children:"×"})]}),a?o.jsxs("div",{className:"rounded-lg border border-zinc-800 bg-zinc-900/40 p-4 space-y-4",children:[o.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[o.jsxs("div",{children:[o.jsx("label",{className:Ze,children:"Display name"}),o.jsx("input",{className:ge,type:"text",value:p,onChange:de=>v(de.target.value),placeholder:"My Project"})]}),o.jsxs("div",{children:[o.jsx("label",{className:Ze,children:"Canonical domain"}),o.jsx("input",{className:ge,type:"text",value:y,onChange:de=>x(de.target.value),placeholder:"example.com"})]}),o.jsxs("div",{children:[o.jsx("label",{className:Ze,children:"Country"}),o.jsx("input",{className:ge,type:"text",value:b,onChange:de=>N(de.target.value),placeholder:"US",maxLength:2})]}),o.jsxs("div",{children:[o.jsx("label",{className:Ze,children:"Language"}),o.jsx("input",{className:ge,type:"text",value:S,onChange:de=>C(de.target.value),placeholder:"en"})]})]}),o.jsxs("div",{children:[o.jsx("label",{className:Ze,children:"Owned domains"}),o.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:k.map(de=>o.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full border border-zinc-700/60 bg-zinc-800/40 px-2 py-0.5 text-xs text-zinc-300",children:[de,o.jsx("button",{type:"button",className:"ml-0.5 text-zinc-500 hover:text-zinc-200 transition-colors",onClick:()=>se(de),"aria-label":`Remove ${de}`,children:"×"})]},de))}),o.jsxs("div",{className:"flex gap-2",children:[o.jsx("input",{className:`${ge} flex-1`,type:"text",placeholder:"docs.example.com",value:R,onChange:de=>z(de.target.value),onKeyDown:de=>de.key==="Enter"&&(de.preventDefault(),B())}),o.jsx(oe,{type:"button",variant:"outline",size:"sm",disabled:!R.trim(),onClick:B,children:"Add"})]})]}),o.jsxs("div",{className:"flex items-center gap-2 pt-2 border-t border-zinc-800/60",children:[o.jsx(oe,{type:"button",disabled:c||!_e||!p.trim()||!y.trim(),onClick:le,children:c?"Saving...":"Save changes"}),o.jsx(oe,{type:"button",variant:"outline",disabled:c,onClick:T,children:"Cancel"})]})]}):o.jsx("div",{className:"rounded-lg border border-zinc-800/60 bg-zinc-900/30 overflow-hidden",children:o.jsx("table",{className:"w-full text-sm",children:o.jsxs("tbody",{children:[o.jsxs("tr",{className:"border-b border-zinc-800/40",children:[o.jsx("td",{className:"px-4 py-2.5 text-zinc-500 font-medium w-40",children:"Display name"}),o.jsx("td",{className:"px-4 py-2.5 text-zinc-200",children:e.displayName||"—"})]}),o.jsxs("tr",{className:"border-b border-zinc-800/40",children:[o.jsx("td",{className:"px-4 py-2.5 text-zinc-500 font-medium",children:"Canonical domain"}),o.jsx("td",{className:"px-4 py-2.5 text-zinc-200",children:e.canonicalDomain})]}),o.jsxs("tr",{className:"border-b border-zinc-800/40",children:[o.jsx("td",{className:"px-4 py-2.5 text-zinc-500 font-medium",children:"Owned domains"}),o.jsx("td",{className:"px-4 py-2.5",children:(e.ownedDomains??[]).length>0?o.jsx("div",{className:"flex flex-wrap gap-1.5",children:e.ownedDomains.map(de=>o.jsx("span",{className:"rounded-full border border-zinc-700/60 bg-zinc-800/40 px-2 py-0.5 text-xs text-zinc-300",children:de},de))}):o.jsx("span",{className:"text-zinc-500",children:"—"})})]}),o.jsxs("tr",{className:"border-b border-zinc-800/40",children:[o.jsx("td",{className:"px-4 py-2.5 text-zinc-500 font-medium",children:"Country"}),o.jsx("td",{className:"px-4 py-2.5 text-zinc-200",children:e.country})]}),o.jsxs("tr",{className:"border-b border-zinc-800/40",children:[o.jsx("td",{className:"px-4 py-2.5 text-zinc-500 font-medium",children:"Language"}),o.jsx("td",{className:"px-4 py-2.5 text-zinc-200",children:e.language})]}),o.jsxs("tr",{children:[o.jsx("td",{className:"px-4 py-2.5 text-zinc-500 font-medium align-top pt-3",children:"Locations"}),o.jsxs("td",{className:"px-4 py-2.5",children:[O&&o.jsxs("div",{className:"mb-2 rounded border border-rose-800/40 bg-rose-950/20 px-2 py-1 text-xs text-rose-300",children:[O,o.jsx("button",{type:"button",className:"ml-1 text-rose-400 hover:text-rose-200",onClick:()=>M(null),children:"×"})]}),(e.locations??[]).length>0?o.jsxs("table",{className:"w-full text-xs mb-2",children:[o.jsx("thead",{children:o.jsxs("tr",{className:"text-zinc-600",children:[o.jsx("th",{className:"text-left pb-1 font-medium pr-3",children:"Label"}),o.jsx("th",{className:"text-left pb-1 font-medium pr-3",children:"City"}),o.jsx("th",{className:"text-left pb-1 font-medium pr-3",children:"Region"}),o.jsx("th",{className:"text-left pb-1 font-medium pr-3",children:"Country"}),o.jsx("th",{className:"text-left pb-1 font-medium pr-3",children:"Timezone"}),o.jsx("th",{className:"pb-1"})]})}),o.jsx("tbody",{children:e.locations.map(de=>o.jsxs("tr",{className:"border-t border-zinc-800/30",children:[o.jsx("td",{className:"py-1.5 pr-3",children:o.jsxs("span",{className:`inline-flex items-center gap-1 rounded-full border px-1.5 py-0.5 text-[10px] font-medium ${de.label===e.defaultLocation?"border-emerald-700/60 bg-emerald-950/30 text-emerald-300":"border-zinc-700/60 bg-zinc-800/40 text-zinc-300"}`,children:[de.label,de.label===e.defaultLocation?" ★":""]})}),o.jsx("td",{className:"py-1.5 pr-3 text-zinc-300",children:de.city}),o.jsx("td",{className:"py-1.5 pr-3 text-zinc-300",children:de.region}),o.jsx("td",{className:"py-1.5 pr-3 text-zinc-300",children:de.country}),o.jsx("td",{className:"py-1.5 pr-3 text-zinc-500",children:de.timezone??"—"}),o.jsx("td",{className:"py-1.5",children:o.jsxs("div",{className:"flex items-center gap-1.5",children:[de.label!==e.defaultLocation&&o.jsx("button",{type:"button",disabled:E,onClick:()=>ye(de.label),className:"text-[10px] text-zinc-500 hover:text-emerald-400 transition-colors disabled:opacity-40","aria-label":`Set ${de.label} as default location`,children:"Set default"}),o.jsx("button",{type:"button",disabled:E,onClick:()=>fe(de.label),className:"text-[10px] text-zinc-500 hover:text-rose-400 transition-colors disabled:opacity-40","aria-label":`Remove location ${de.label}`,children:"Remove"})]})})]},de.label))})]}):o.jsx("p",{className:"text-zinc-500 text-xs mb-2",children:"No locations configured"}),U?o.jsxs("div",{className:"mt-2 rounded border border-zinc-800 bg-zinc-900/50 p-3 space-y-2",children:[o.jsx("p",{className:"text-[10px] font-medium uppercase tracking-wide text-zinc-500",children:"Add location"}),o.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[o.jsxs("div",{children:[o.jsx("label",{className:"block text-[10px] text-zinc-500 mb-0.5",children:"Label *"}),o.jsx("input",{className:ge,type:"text",value:Q,onChange:de=>ee(de.target.value),placeholder:"nyc"})]}),o.jsxs("div",{children:[o.jsx("label",{className:"block text-[10px] text-zinc-500 mb-0.5",children:"City *"}),o.jsx("input",{className:ge,type:"text",value:ue,onChange:de=>ze(de.target.value),placeholder:"New York"})]}),o.jsxs("div",{children:[o.jsx("label",{className:"block text-[10px] text-zinc-500 mb-0.5",children:"Region *"}),o.jsx("input",{className:ge,type:"text",value:je,onChange:de=>K(de.target.value),placeholder:"NY"})]}),o.jsxs("div",{children:[o.jsx("label",{className:"block text-[10px] text-zinc-500 mb-0.5",children:"Country *"}),o.jsx("input",{className:ge,type:"text",value:ae,onChange:de=>me(de.target.value),placeholder:"US",maxLength:2})]}),o.jsxs("div",{className:"col-span-2",children:[o.jsx("label",{className:"block text-[10px] text-zinc-500 mb-0.5",children:"Timezone (optional)"}),o.jsx("input",{className:ge,type:"text",value:V,onChange:de=>H(de.target.value),placeholder:"America/New_York"})]})]}),o.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[o.jsx(oe,{type:"button",size:"sm",disabled:E||!et,onClick:J,children:E?"Adding...":"Add location"}),o.jsx(oe,{type:"button",size:"sm",variant:"outline",disabled:E,onClick:()=>{X(!1),M(null)},children:"Cancel"})]})]}):o.jsx(oe,{type:"button",size:"sm",variant:"outline",onClick:()=>X(!0),children:"+ Add location"})]})]})]})})})]})}const p$=[{value:"daily",label:"Every day"},{value:"weekly@mon",label:"Every Monday"},{value:"weekly@wed",label:"Every Wednesday"},{value:"weekly@fri",label:"Every Friday"},{value:"twice-daily",label:"Twice a day (6am & 6pm)"},{value:"custom",label:"Custom cron expression"}],dS=["UTC","America/New_York","America/Chicago","America/Denver","America/Los_Angeles","America/Toronto","America/Vancouver","Europe/London","Europe/Paris","Europe/Berlin","Asia/Tokyo","Asia/Shanghai","Asia/Singapore","Australia/Sydney"];function g$({projectName:e}){const[t,s]=w.useState("loading"),[a,r]=w.useState(!1),[c,u]=w.useState("daily"),[f,m]=w.useState(6),[p,v]=w.useState(""),[y,x]=w.useState("UTC"),[b,N]=w.useState(!1),[S,C]=w.useState(""),[k,A]=w.useState(!1),[R,z]=w.useState(!1),[O,M]=w.useState(null);w.useEffect(()=>{r2(e).then(s).catch(()=>s(null))},[e]);const E=()=>{if(t&&t!=="loading"){const Q=AE(t.preset??null,t.cronExpr);u(Q.freq),m(Q.hour),v(Q.customCron);const ee=dS.includes(t.timezone);x(ee?t.timezone:"Other"),N(!ee),C(ee?"":t.timezone)}else u("daily"),m(6),v(""),x("UTC"),N(!1),C("");M(null),r(!0)},L=async()=>{A(!0),M(null);try{const ee={timezone:b?S.trim()||"UTC":y};c==="custom"?ee.cron=p.trim():ee.preset=RE(c,f);const ue=await qx(e,ee);s(ue),r(!1),Ke({title:"Schedule saved",detail:Gh(ue.preset??null,ue.cronExpr,ue.timezone),tone:"positive",dedupeKey:`schedule:${e}`,dedupeMode:"replace"})}catch(Q){M(Q instanceof Error?Q.message:"Failed to save schedule")}finally{A(!1)}},U=async()=>{if(!(!t||t==="loading")){A(!0),M(null);try{const Q={timezone:t.timezone,enabled:!t.enabled};t.preset?Q.preset=t.preset:Q.cron=t.cronExpr;const ee=await qx(e,Q);s(ee),Ke({title:ee.enabled?"Schedule resumed":"Schedule paused",detail:Gh(ee.preset??null,ee.cronExpr,ee.timezone),tone:"positive",dedupeKey:`schedule:toggle:${e}`,dedupeMode:"replace"})}catch(Q){M(Q instanceof Error?Q.message:"Failed to update schedule")}finally{A(!1)}}},X=async()=>{z(!0),M(null);try{await o2(e),s(null),r(!1),Ke({title:"Schedule removed",detail:`${e} will no longer run automatically.`,tone:"positive",dedupeKey:`schedule:remove:${e}`,dedupeMode:"drop"})}catch(Q){M(Q instanceof Error?Q.message:"Failed to remove schedule")}finally{z(!1)}};return o.jsxs("section",{className:"page-section-divider",children:[o.jsxs("div",{className:"section-head section-head-inline",children:[o.jsxs("div",{children:[o.jsx("p",{className:"eyebrow eyebrow-soft",children:"Automation"}),o.jsx("h2",{children:"Scheduled runs"})]}),t!=="loading"&&!a&&o.jsx(oe,{type:"button",variant:"outline",size:"sm",onClick:E,children:t?"Edit schedule":"+ Set schedule"})]}),t==="loading"&&o.jsx("p",{className:"supporting-copy",children:"Loading..."}),t!=="loading"&&!a&&t===null&&o.jsx(Le,{className:"surface-card compact-card",children:o.jsx("p",{className:"supporting-copy",children:"No schedule configured. Set one to automatically trigger visibility sweeps."})}),t!=="loading"&&!a&&t!==null&&o.jsxs(Le,{className:"surface-card compact-card",children:[o.jsxs("div",{className:"flex items-start justify-between gap-4",children:[o.jsxs("div",{className:"space-y-1",children:[o.jsx("p",{className:"text-sm font-medium text-zinc-200",children:Gh(t.preset??null,t.cronExpr,t.timezone)}),o.jsxs("p",{className:"text-xs text-zinc-500",children:["Cron: ",o.jsx("span",{className:"font-mono",children:t.cronExpr})]}),t.nextRunAt&&o.jsxs("p",{className:"text-xs text-zinc-500",children:["Next run: ",new Date(t.nextRunAt).toLocaleString()]}),t.lastRunAt&&o.jsxs("p",{className:"text-xs text-zinc-500",children:["Last run: ",new Date(t.lastRunAt).toLocaleString()]})]}),o.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[o.jsx(lt,{tone:t.enabled?"positive":"neutral",children:t.enabled?"Active":"Paused"}),o.jsx(oe,{type:"button",variant:"outline",size:"sm",disabled:k,onClick:U,children:t.enabled?"Pause":"Resume"}),o.jsx(oe,{type:"button",variant:"ghost",size:"sm",disabled:R,onClick:X,children:R?"Removing...":"Remove"})]})]}),O&&o.jsx("p",{className:"text-rose-400 text-sm mt-2",children:O})]}),a&&o.jsxs("div",{className:"rounded-lg border border-zinc-800 bg-zinc-900/40 p-4 space-y-3",children:[o.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[o.jsxs("div",{className:"space-y-1.5",children:[o.jsx("label",{className:"text-xs font-medium text-zinc-400",children:"Frequency"}),o.jsx("select",{className:"w-full rounded border border-zinc-700 bg-zinc-900 px-2 py-1.5 text-sm text-zinc-200 focus:border-zinc-500 focus:outline-none",value:c,onChange:Q=>u(Q.target.value),children:p$.map(Q=>o.jsx("option",{value:Q.value,children:Q.label},Q.value))})]}),o.jsxs("div",{className:"space-y-1.5",children:[o.jsx("label",{className:"text-xs font-medium text-zinc-400",children:"Time"}),o.jsx("select",{className:"w-full rounded border border-zinc-700 bg-zinc-900 px-2 py-1.5 text-sm text-zinc-200 focus:border-zinc-500 focus:outline-none disabled:opacity-40",value:f,disabled:c==="twice-daily"||c==="custom",onChange:Q=>m(parseInt(Q.target.value)),children:Array.from({length:24},(Q,ee)=>o.jsx("option",{value:ee,children:Am(ee)},ee))})]})]}),c==="custom"&&o.jsxs("div",{className:"space-y-1.5",children:[o.jsx("label",{className:"text-xs font-medium text-zinc-400",children:"Cron expression"}),o.jsx("input",{className:"w-full rounded border border-zinc-700 bg-transparent px-2 py-1.5 text-sm text-zinc-200 placeholder-zinc-600 font-mono focus:border-zinc-500 focus:outline-none",type:"text",placeholder:"0 9 * * 1-5",value:p,onChange:Q=>v(Q.target.value)})]}),o.jsxs("div",{className:"space-y-1.5",children:[o.jsx("label",{className:"text-xs font-medium text-zinc-400",children:"Timezone"}),o.jsxs("select",{className:"w-full rounded border border-zinc-700 bg-zinc-900 px-2 py-1.5 text-sm text-zinc-200 focus:border-zinc-500 focus:outline-none",value:b?"Other":y,onChange:Q=>{Q.target.value==="Other"?(N(!0),x("Other")):(N(!1),x(Q.target.value))},children:[dS.map(Q=>o.jsx("option",{value:Q,children:Q},Q)),o.jsx("option",{value:"Other",children:"Other (enter manually)\\u2026"})]}),b&&o.jsx("input",{className:"w-full rounded border border-zinc-700 bg-transparent px-2 py-1.5 text-sm text-zinc-200 placeholder-zinc-600 focus:border-zinc-500 focus:outline-none",type:"text",placeholder:"e.g. America/New_York",value:S,onChange:Q=>C(Q.target.value)})]}),O&&o.jsx("p",{className:"text-rose-400 text-sm",children:O}),o.jsxs("div",{className:"flex gap-2 justify-end",children:[o.jsx(oe,{type:"button",variant:"outline",size:"sm",onClick:()=>{r(!1),M(null)},children:"Cancel"}),o.jsx(oe,{type:"button",size:"sm",disabled:k||c==="custom"&&!p.trim(),onClick:L,children:k?"Saving...":"Save schedule"})]})]})]})}const y$=[{value:"citation.lost",label:"Citation lost"},{value:"citation.gained",label:"Citation gained"},{value:"run.completed",label:"Run completed"},{value:"run.failed",label:"Run failed"}];function v$({projectName:e}){const[t,s]=w.useState("loading"),[a,r]=w.useState(!1),[c,u]=w.useState(""),[f,m]=w.useState(["citation.lost","citation.gained"]),[p,v]=w.useState(!1),[y,x]=w.useState(null),[b,N]=w.useState({});w.useEffect(()=>{l2(e).then(s).catch(()=>s([]))},[e]);const S=R=>{m(z=>z.includes(R)?z.filter(O=>O!==R):[...z,R])},C=async()=>{if(!(!c.trim()||f.length===0)){v(!0),x(null);try{const R=await c2(e,{channel:"webhook",url:c.trim(),events:f});s(z=>z==="loading"?[R]:[...z,R]),u(""),m(["citation.lost","citation.gained"]),r(!1),Ke({title:"Webhook added",detail:`Notifications will be sent to ${R.url}.`,tone:"positive",dedupeKey:`notification:add:${e}`,dedupeMode:"drop"})}catch(R){x(R instanceof Error?R.message:"Failed to add webhook")}finally{v(!1)}}},k=async R=>{try{await u2(e,R),s(z=>z==="loading"?z:z.filter(O=>O.id!==R)),Ke({title:"Webhook removed",detail:`${e} no longer sends notifications to this endpoint.`,tone:"positive",dedupeKey:`notification:remove:${e}:${R}`,dedupeMode:"drop"})}catch(z){x(z instanceof Error?z.message:"Failed to remove webhook")}},A=async R=>{N(z=>({...z,[R]:{state:"testing"}}));try{const z=await d2(e,R);N(O=>({...O,[R]:{state:z.ok?"ok":"fail",status:z.status}})),z.ok&&Ke({title:"Test notification sent",detail:`Webhook returned status ${z.status}.`,tone:"positive",dedupeKey:`notification:test:${e}:${R}`,dedupeMode:"replace"})}catch{N(z=>({...z,[R]:{state:"fail"}}))}};return o.jsxs("section",{className:"page-section-divider",children:[o.jsxs("div",{className:"section-head section-head-inline",children:[o.jsxs("div",{children:[o.jsx("p",{className:"eyebrow eyebrow-soft",children:"Automation"}),o.jsx("h2",{children:"Notifications"})]}),t!=="loading"&&o.jsx(oe,{type:"button",variant:"outline",size:"sm",onClick:()=>{r(!a),x(null)},children:a?"Cancel":"+ Add webhook"})]}),a&&o.jsxs("div",{className:"mb-3 rounded-lg border border-zinc-800 bg-zinc-900/40 p-4 space-y-3",children:[o.jsxs("div",{className:"space-y-1.5",children:[o.jsx("label",{className:"text-xs font-medium text-zinc-400",children:"Webhook URL"}),o.jsx("input",{className:"w-full rounded border border-zinc-700 bg-transparent px-2 py-1.5 text-sm text-zinc-200 placeholder-zinc-600 focus:border-zinc-500 focus:outline-none",type:"url",placeholder:"https://hooks.example.com/canonry",value:c,onChange:R=>u(R.target.value)})]}),o.jsxs("div",{className:"space-y-1.5",children:[o.jsx("label",{className:"text-xs font-medium text-zinc-400",children:"Trigger on"}),o.jsx("div",{className:"flex flex-wrap gap-3",children:y$.map(R=>o.jsxs("label",{className:"flex items-center gap-1.5 cursor-pointer select-none",children:[o.jsx("input",{type:"checkbox",className:"rounded border-zinc-600 bg-zinc-800",checked:f.includes(R.value),onChange:()=>S(R.value)}),o.jsx("span",{className:"text-sm text-zinc-300",children:R.label})]},R.value))})]}),y&&o.jsx("p",{className:"text-rose-400 text-sm",children:y}),o.jsxs("div",{className:"flex gap-2 justify-end",children:[o.jsx(oe,{type:"button",variant:"outline",size:"sm",onClick:()=>{r(!1),x(null)},children:"Cancel"}),o.jsx(oe,{type:"button",size:"sm",disabled:p||!c.trim()||f.length===0,onClick:C,children:p?"Adding...":"Add webhook"})]})]}),t==="loading"&&o.jsx("p",{className:"supporting-copy",children:"Loading..."}),t!=="loading"&&t.length===0&&!a&&o.jsx(Le,{className:"surface-card compact-card",children:o.jsx("p",{className:"supporting-copy",children:"No webhooks configured. Add one to get alerted when citations change or runs complete."})}),t!=="loading"&&t.length>0&&o.jsxs("div",{className:"evidence-table-wrap",children:[o.jsxs("table",{className:"evidence-table",children:[o.jsx("thead",{children:o.jsxs("tr",{children:[o.jsx("th",{children:"Endpoint"}),o.jsx("th",{children:"Events"}),o.jsx("th",{children:"Status"}),o.jsx("th",{})]})}),o.jsx("tbody",{children:t.map(R=>o.jsxs("tr",{children:[o.jsx("td",{className:"evidence-keyword-cell",children:o.jsx("span",{className:"font-mono text-xs text-zinc-300 break-all",title:R.urlHost,children:R.urlDisplay??R.url})}),o.jsx("td",{children:o.jsx("div",{className:"flex flex-wrap gap-1",children:R.events.map(z=>o.jsx("span",{className:"inline-flex items-center rounded-full border border-zinc-700 bg-zinc-800/60 px-2 py-0.5 text-[10px] font-medium text-zinc-400 uppercase tracking-wide",children:z.replace("."," ")},z))})}),o.jsx("td",{children:o.jsx(lt,{tone:R.enabled?"positive":"neutral",children:R.enabled?"Active":"Paused"})}),o.jsx("td",{children:o.jsxs("div",{className:"flex items-center gap-1 justify-end",children:[b[R.id]&&(()=>{const z=b[R.id],O=z.state==="testing"?"Sending…":z.state==="ok"?`Delivered${z.status?` (${z.status})`:""}`:`Failed${z.status?` (${z.status})`:""}`;return o.jsx(lt,{tone:z.state==="ok"?"positive":z.state==="fail"?"negative":"neutral",children:O})})(),o.jsx(oe,{variant:"ghost",size:"sm",type:"button",disabled:b[R.id]?.state==="testing",onClick:()=>A(R.id),children:"Test"}),o.jsx(oe,{variant:"ghost",size:"sm",type:"button",onClick:()=>k(R.id),children:"Remove"})]})})]},R.id))})]}),y&&o.jsx("p",{className:"text-rose-400 text-sm mt-2",children:y})]})]})}function fS({eyebrow:e,title:t,status:s,tone:a,targetLabel:r,targetValue:c,coverageValue:u,note:f,updatedAt:m,active:p,onClick:v}){return o.jsxs("button",{type:"button",onClick:v,className:`surface-card w-full text-left transition-colors ${p?"border-zinc-200 bg-zinc-900/50":"hover:border-zinc-700 hover:bg-zinc-900/40"}`,children:[o.jsxs("div",{className:"section-head",children:[o.jsxs("div",{className:"min-w-0",children:[o.jsx("p",{className:"eyebrow eyebrow-soft",children:e}),o.jsx("h3",{children:t})]}),o.jsx(lt,{tone:a,children:s})]}),o.jsxs("div",{className:"mt-4 grid gap-3 sm:grid-cols-2",children:[o.jsxs("div",{className:"rounded-lg border border-zinc-800/60 bg-zinc-900/20 p-3",children:[o.jsx("p",{className:"text-xs uppercase tracking-wide text-zinc-500",children:r}),o.jsx("p",{className:"mt-1 truncate text-sm text-zinc-200",children:c})]}),o.jsxs("div",{className:"rounded-lg border border-zinc-800/60 bg-zinc-900/20 p-3",children:[o.jsx("p",{className:"text-xs uppercase tracking-wide text-zinc-500",children:"Coverage"}),o.jsx("p",{className:"mt-1 text-sm text-zinc-200",children:u})]})]}),o.jsxs("div",{className:"mt-3 flex flex-col gap-1 text-xs text-zinc-500 sm:flex-row sm:items-center sm:justify-between",children:[o.jsx("span",{children:f}),o.jsx("span",{children:m?`Updated ${ls(m)}`:"No recent sync yet"})]})]})}function ru({label:e,value:t,tone:s}){const a=s==="positive"?"text-emerald-400":s==="negative"?"text-rose-400":"text-zinc-200";return o.jsxs("div",{className:"rounded-lg border border-zinc-800/60 bg-zinc-900/20 p-3",children:[o.jsx("p",{className:"text-xs uppercase tracking-wide text-zinc-500",children:e}),o.jsx("p",{className:`mt-2 text-2xl font-semibold ${a}`,children:t})]})}function x$({projectName:e}){const[t,s]=w.useState(null),[a,r]=w.useState([]),[c,u]=w.useState(null),[f,m]=w.useState([]),[p,v]=w.useState([]),[y,x]=w.useState(null),[b,N]=w.useState(""),[S,C]=w.useState(""),[k,A]=w.useState(""),[R,z]=w.useState(!0),[O,M]=w.useState(!1),[E,L]=w.useState(null),[U,X]=w.useState("coverage");w.useEffect(()=>{Q()},[e]);async function Q(){z(!0),L(null);try{const V=await ij(e);if(s(V),V.connected){const[H,T,B]=await Promise.all([wp(e).catch(()=>null),aj(e).catch(()=>[]),O2(e).catch(()=>[])]);H&&u(H),m(T),v(B)}}catch(V){L(V instanceof Error?V.message:"Failed to load Bing data")}finally{z(!1)}}async function ee(){if(S.trim()){L(null);try{const V=await E2(e,S.trim());C(""),V.availableSites.length>0&&r(V.availableSites),await Q()}catch(V){L(V instanceof Error?V.message:"Failed to connect")}}}async function ue(){try{await R2(e),s(null),r([]),u(null),m([]),v([]),x(null),A(""),L(null)}catch(V){L(V instanceof Error?V.message:"Failed to disconnect")}}async function ze(){if(k)try{await T2(e,k),await Q()}catch(V){L(V instanceof Error?V.message:"Failed to set site")}}async function je(){if(b.trim())try{const V=await rj(e,b.trim());x(V),m(H=>[V,...H])}catch(V){L(V instanceof Error?V.message:"Inspection failed")}}async function K(V){M(!0),L(null);try{const H=await Gx(e,{urls:[V]}),{succeeded:T,failed:B,total:se}=H.summary;Ke({title:"Bing submission requested",detail:B===0?`${T} URL submitted to Bing.`:`${T}/${se} submitted successfully, ${B} failed.`,tone:B===0?"positive":"caution",dedupeKey:`bing:indexing:${e}:${V}`,dedupeMode:"replace"})}catch(H){const T=H instanceof Error?H.message:"Submission failed";L(T),Ke({title:"Bing submission failed",detail:T,tone:"negative",dedupeKey:`bing:indexing:${e}:${V}`,dedupeMode:"replace"})}finally{M(!1)}}async function ae(){M(!0),L(null),Ke({title:"Submitting URLs to Bing",detail:"Requesting indexing for all currently unindexed URLs.",tone:"neutral",dedupeKey:`bing:indexing-all:${e}`,dedupeMode:"replace"});try{const V=await Gx(e,{allUnindexed:!0}),{succeeded:H,failed:T,total:B}=V.summary;Ke({title:"Bing submissions requested",detail:T===0?`${H}/${B} URL${B!==1?"s":""} submitted to Bing.`:`${H}/${B} submitted successfully, ${T} failed.`,tone:T===0?"positive":"caution",dedupeKey:`bing:indexing-all:${e}`,dedupeMode:"replace"})}catch(V){const H=V instanceof Error?V.message:"Batch submission failed";L(H),Ke({title:"Bing submissions failed",detail:H,tone:"negative",dedupeKey:`bing:indexing-all:${e}`,dedupeMode:"replace"})}finally{M(!1)}}if(R)return o.jsx(Le,{className:"surface-card",children:o.jsx("div",{className:"text-sm text-zinc-400",children:"Loading Bing data..."})});if(!t?.connected)return o.jsxs(Le,{className:"surface-card",children:[o.jsxs("div",{className:"section-head section-head-inline",children:[o.jsxs("div",{children:[o.jsx("p",{className:"eyebrow eyebrow-soft",children:"Connection"}),o.jsx("h3",{children:"Domain authorization"})]}),o.jsx(lt,{tone:"caution",children:"Not connected"})]}),o.jsx("p",{className:"text-sm text-zinc-300",children:"Connect Bing Webmaster Tools to inspect URLs, monitor index coverage, and submit pages for indexing."}),o.jsxs("div",{className:"mt-3",children:[o.jsx("label",{className:"text-xs text-zinc-500",htmlFor:"bing-api-key",children:"API Key"}),o.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[o.jsx("input",{id:"bing-api-key",type:"password",className:"flex-1 rounded border border-zinc-700 bg-transparent px-2 py-1.5 text-sm text-zinc-200 placeholder-zinc-600 focus:border-zinc-500 focus:outline-none",placeholder:"Bing Webmaster Tools API key",value:S,onChange:V=>C(V.target.value),onKeyDown:V=>V.key==="Enter"&&ee()}),o.jsx(oe,{size:"sm",disabled:!S.trim(),onClick:ee,children:"Connect"})]}),o.jsxs("p",{className:"mt-1 text-[11px] text-zinc-500",children:["Get your API key from"," ",o.jsx("a",{href:"https://www.bing.com/webmasters/",target:"_blank",rel:"noopener noreferrer",className:"text-zinc-400 hover:text-zinc-300 underline underline-offset-2",children:"Bing Webmaster Tools"})]})]}),E&&o.jsx("p",{className:"mt-3 text-xs text-rose-400",children:E})]});if(!t.siteUrl)return o.jsxs(Le,{className:"surface-card",children:[o.jsxs("div",{className:"section-head section-head-inline",children:[o.jsxs("div",{children:[o.jsx("p",{className:"eyebrow eyebrow-soft",children:"Connection"}),o.jsx("h3",{children:"Domain authorization"})]}),o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(lt,{tone:"positive",children:"Connected"}),o.jsx(oe,{size:"sm",variant:"ghost",onClick:ue,children:"Disconnect"})]})]}),o.jsxs("div",{className:"space-y-3",children:[o.jsxs("div",{className:"rounded-lg border border-zinc-800/60 bg-zinc-900/30 px-4 py-3",children:[o.jsxs("div",{className:"flex items-center gap-3",children:[o.jsx("span",{className:"h-2 w-2 rounded-full bg-emerald-500"}),o.jsx("span",{className:"text-sm text-zinc-200",children:"Authorized for this project domain"}),o.jsx("span",{className:"text-xs text-zinc-500",children:t.domain})]}),o.jsx("p",{className:"mt-2 text-xs text-zinc-500",children:"The API key is connected, but no Bing site is selected yet. Pick the verified site that should receive inspections and indexing requests."})]}),o.jsxs("div",{className:"grid gap-3 lg:grid-cols-2",children:[o.jsxs("div",{className:"rounded-lg border border-zinc-800/60 bg-zinc-900/20 p-3",children:[o.jsx("p",{className:"text-xs uppercase tracking-wide text-zinc-500",children:"Registered domain"}),o.jsx("p",{className:"mt-1 text-sm text-zinc-200",children:t.domain})]}),o.jsxs("div",{className:"rounded-lg border border-zinc-800/60 bg-zinc-900/20 p-3",children:[o.jsx("p",{className:"text-xs uppercase tracking-wide text-zinc-500",children:"Last auth update"}),o.jsx("p",{className:"mt-1 text-sm text-zinc-200",children:t.updatedAt?ls(t.updatedAt):"—"})]})]}),o.jsxs("div",{className:"rounded-lg border border-zinc-800/60 bg-zinc-900/20 p-3",children:[o.jsx("p",{className:"text-xs uppercase tracking-wide text-zinc-500",children:"Select site"}),a.length>0?o.jsxs("div",{className:"mt-3 flex flex-col gap-2 lg:flex-row",children:[o.jsxs("select",{className:"flex-1 rounded border border-zinc-700 bg-zinc-900 px-2 py-1.5 text-sm text-zinc-200 focus:border-zinc-500 focus:outline-none",value:k,onChange:V=>A(V.target.value),children:[o.jsx("option",{value:"",children:"Select a site..."}),a.map(V=>o.jsxs("option",{value:V.url,children:[V.url,V.verified?" (verified)":""]},V.url))]}),o.jsx(oe,{size:"sm",disabled:!k,onClick:ze,children:"Set Site"})]}):o.jsx("div",{className:"mt-3",children:o.jsx(oe,{size:"sm",onClick:async()=>{const V=await A2(e);r(V.sites)},children:"Load Sites"})})]})]}),E&&o.jsx("p",{className:"mt-3 text-xs text-rose-400",children:E})]});const me=[{key:"coverage",label:"Coverage"},{key:"inspections",label:"Inspections"},{key:"performance",label:"Performance"}];return o.jsxs("div",{className:"space-y-3",children:[o.jsxs(Le,{className:"surface-card",children:[o.jsxs("div",{className:"section-head section-head-inline",children:[o.jsxs("div",{children:[o.jsx("p",{className:"eyebrow eyebrow-soft",children:"Connection"}),o.jsx("h3",{children:"Domain authorization"})]}),o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(lt,{tone:"positive",children:"Connected"}),o.jsx(oe,{size:"sm",variant:"ghost",onClick:ue,children:"Disconnect"})]})]}),E&&o.jsx("p",{className:"mb-3 text-xs text-rose-400",children:E}),o.jsxs("div",{className:"space-y-3",children:[o.jsxs("div",{className:"rounded-lg border border-zinc-800/60 bg-zinc-900/30 px-4 py-3",children:[o.jsxs("div",{className:"flex items-center gap-3",children:[o.jsx("span",{className:"h-2 w-2 rounded-full bg-emerald-500"}),o.jsx("span",{className:"text-sm text-zinc-200",children:"Authorized for this project domain"}),o.jsx("span",{className:"text-xs text-zinc-500",children:t.domain})]}),o.jsxs("p",{className:"mt-2 text-xs text-zinc-500",children:["Canonry stores Bing connections per canonical domain. This project is currently mapped to ",o.jsx("code",{children:t.siteUrl}),"."]})]}),o.jsxs("div",{className:"grid gap-3 lg:grid-cols-2",children:[o.jsxs("div",{className:"rounded-lg border border-zinc-800/60 bg-zinc-900/20 p-3",children:[o.jsx("p",{className:"text-xs uppercase tracking-wide text-zinc-500",children:"Selected site"}),o.jsx("p",{className:"mt-1 text-sm text-zinc-200",children:t.siteUrl})]}),o.jsxs("div",{className:"rounded-lg border border-zinc-800/60 bg-zinc-900/20 p-3",children:[o.jsx("p",{className:"text-xs uppercase tracking-wide text-zinc-500",children:"Last auth update"}),o.jsx("p",{className:"mt-1 text-sm text-zinc-200",children:t.updatedAt?ls(t.updatedAt):"—"})]})]})]})]}),o.jsxs(Le,{className:"surface-card",children:[o.jsxs("div",{className:"section-head section-head-inline",children:[o.jsxs("div",{children:[o.jsx("p",{className:"eyebrow eyebrow-soft",children:"Coverage"}),o.jsx("h3",{children:"Index monitoring"})]}),o.jsx("p",{className:"text-xs text-zinc-500",children:c?.lastInspectedAt?`Last inspected ${ls(c.lastInspectedAt)}`:"No inspection history yet"})]}),o.jsx("div",{className:"flex gap-1 border-b border-zinc-800",children:me.map(V=>o.jsx("button",{className:`px-3 py-1.5 text-xs font-medium border-b-2 transition-colors ${U===V.key?"border-zinc-200 text-zinc-200":"border-transparent text-zinc-500 hover:text-zinc-300"}`,onClick:()=>X(V.key),children:V.label},V.key))}),U==="coverage"&&c&&o.jsxs("div",{className:"mt-4 space-y-4",children:[o.jsxs("div",{className:"grid gap-3 sm:grid-cols-4",children:[o.jsx(ru,{label:"Indexed",value:c.summary.indexed,tone:"positive"}),o.jsx(ru,{label:"Not in index",value:c.summary.notIndexed+(c.summary.unknown??0),tone:"negative"}),o.jsx(ru,{label:"Status unknown",value:c.summary.unknown??0,tone:"neutral"}),o.jsx(ru,{label:"Coverage",value:`${c.summary.percentage}%`,tone:"neutral"})]}),c.notIndexed.length>0&&o.jsxs("div",{children:[o.jsxs("div",{className:"mb-2 flex items-center justify-between gap-3",children:[o.jsxs("h4",{className:"text-xs font-medium text-zinc-400",children:["Not Indexed (",c.notIndexed.length,")"]}),o.jsx(oe,{size:"sm",variant:"ghost",disabled:O,onClick:ae,children:O?"Submitting…":"Submit all to Bing"})]}),o.jsx("div",{className:"overflow-x-auto rounded-lg border border-zinc-800/60",children:o.jsxs("table",{className:"w-full text-xs",children:[o.jsx("thead",{children:o.jsxs("tr",{className:"border-b border-zinc-800",children:[o.jsx("th",{className:"text-left py-1.5 px-3 text-zinc-500 font-medium",children:"URL"}),o.jsx("th",{className:"text-left py-1.5 px-3 text-zinc-500 font-medium w-16",children:"HTTP"}),o.jsx("th",{className:"text-right py-1.5 px-3 text-zinc-500 font-medium w-20",children:"Action"})]})}),o.jsx("tbody",{children:c.notIndexed.map(V=>o.jsxs("tr",{className:"border-b border-zinc-800/50",children:[o.jsx("td",{className:"py-1.5 px-3 text-zinc-300 truncate max-w-[480px]",children:V.url}),o.jsx("td",{className:"py-1.5 px-3 text-zinc-400",children:V.httpCode??"—"}),o.jsx("td",{className:"py-1.5 px-3 text-right",children:o.jsx("button",{className:"text-[10px] text-zinc-400 hover:text-zinc-200 underline underline-offset-2",disabled:O,onClick:()=>K(V.url),children:"Submit"})})]},V.id))})]})})]}),(c.unknown??[]).length>0&&o.jsxs("div",{children:[o.jsxs("div",{className:"mb-2 flex items-center justify-between gap-3",children:[o.jsxs("h4",{className:"text-xs font-medium text-zinc-400",children:["Unknown — not yet confirmed (",(c.unknown??[]).length,")"]}),o.jsx(oe,{size:"sm",variant:"ghost",disabled:O,onClick:ae,children:O?"Submitting…":"Submit all to Bing"})]}),o.jsx("div",{className:"overflow-x-auto rounded-lg border border-zinc-800/60",children:o.jsxs("table",{className:"w-full text-xs",children:[o.jsx("thead",{children:o.jsxs("tr",{className:"border-b border-zinc-800",children:[o.jsx("th",{className:"text-left py-1.5 px-3 text-zinc-500 font-medium",children:"URL"}),o.jsx("th",{className:"text-left py-1.5 px-3 text-zinc-500 font-medium w-32",children:"Last Crawled"}),o.jsx("th",{className:"text-right py-1.5 px-3 text-zinc-500 font-medium w-20",children:"Action"})]})}),o.jsx("tbody",{children:(c.unknown??[]).map(V=>o.jsxs("tr",{className:"border-b border-zinc-800/50",children:[o.jsx("td",{className:"py-1.5 px-3 text-zinc-300 truncate max-w-[480px]",children:V.url}),o.jsx("td",{className:"py-1.5 px-3 text-zinc-400",children:V.lastCrawledDate?ls(V.lastCrawledDate):"—"}),o.jsx("td",{className:"py-1.5 px-3 text-right",children:o.jsx("button",{className:"text-[10px] text-zinc-400 hover:text-zinc-200 underline underline-offset-2",disabled:O,onClick:()=>K(V.url),children:"Submit"})})]},V.id))})]})})]}),c.indexed.length>0&&o.jsxs("div",{children:[o.jsxs("h4",{className:"mb-2 text-xs font-medium text-zinc-400",children:["Indexed (",c.indexed.length,")"]}),o.jsx("div",{className:"overflow-x-auto rounded-lg border border-zinc-800/60",children:o.jsxs("table",{className:"w-full text-xs",children:[o.jsx("thead",{children:o.jsxs("tr",{className:"border-b border-zinc-800",children:[o.jsx("th",{className:"text-left py-1.5 px-3 text-zinc-500 font-medium",children:"URL"}),o.jsx("th",{className:"text-left py-1.5 px-3 text-zinc-500 font-medium w-32",children:"Last Crawled"})]})}),o.jsx("tbody",{children:c.indexed.map(V=>o.jsxs("tr",{className:"border-b border-zinc-800/50",children:[o.jsx("td",{className:"py-1.5 px-3 text-zinc-300 truncate max-w-[480px]",children:V.url}),o.jsx("td",{className:"py-1.5 px-3 text-zinc-400",children:V.lastCrawledDate?ls(V.lastCrawledDate):"—"})]},V.id))})]})})]})]}),U==="coverage"&&!c&&o.jsx("p",{className:"mt-4 text-xs text-zinc-500",children:"No coverage data yet. Inspect URLs to build coverage data."}),U==="inspections"&&o.jsxs("div",{className:"mt-4 space-y-3",children:[o.jsxs("div",{className:"flex flex-col gap-2 lg:flex-row",children:[o.jsx("input",{type:"text",className:"flex-1 rounded border border-zinc-700 bg-transparent px-2 py-1.5 text-sm text-zinc-200 placeholder-zinc-600 focus:border-zinc-500 focus:outline-none",placeholder:"URL to inspect",value:b,onChange:V=>N(V.target.value),onKeyDown:V=>V.key==="Enter"&&je()}),o.jsx(oe,{size:"sm",disabled:!b.trim(),onClick:je,children:"Inspect"})]}),y&&o.jsxs("div",{className:"rounded border border-zinc-800 bg-zinc-900/40 p-3 text-xs space-y-1",children:[o.jsx("div",{className:"font-medium text-zinc-200",children:y.url}),o.jsxs("div",{className:"text-zinc-400",children:["In Index: ",o.jsx("span",{className:y.inIndex?"text-emerald-400":"text-rose-400",children:y.inIndex?"Yes":"No"})," · ","HTTP: ",y.httpCode??"—"," · ","Crawled: ",y.lastCrawledDate??"—"]})]}),f.length>0&&o.jsx("div",{className:"overflow-x-auto rounded-lg border border-zinc-800/60",children:o.jsxs("table",{className:"w-full text-xs",children:[o.jsx("thead",{children:o.jsxs("tr",{className:"border-b border-zinc-800",children:[o.jsx("th",{className:"text-left py-1.5 px-3 text-zinc-500 font-medium",children:"URL"}),o.jsx("th",{className:"text-left py-1.5 px-3 text-zinc-500 font-medium w-16",children:"Index"}),o.jsx("th",{className:"text-left py-1.5 px-3 text-zinc-500 font-medium w-14",children:"HTTP"}),o.jsx("th",{className:"text-left py-1.5 px-3 text-zinc-500 font-medium w-32",children:"Inspected"})]})}),o.jsx("tbody",{children:f.map(V=>o.jsxs("tr",{className:"border-b border-zinc-800/50",children:[o.jsx("td",{className:"py-1.5 px-3 text-zinc-300 truncate max-w-[480px]",children:V.url}),o.jsx("td",{className:"py-1.5 px-3",children:o.jsx(lt,{tone:V.inIndex?"positive":"negative",children:V.inIndex?"Yes":"No"})}),o.jsx("td",{className:"py-1.5 px-3 text-zinc-400",children:V.httpCode??"—"}),o.jsx("td",{className:"py-1.5 px-3 text-zinc-400",children:ls(V.inspectedAt)})]},V.id))})]})})]}),U==="performance"&&o.jsx("div",{className:"mt-4",children:p.length===0?o.jsx("p",{className:"text-xs text-zinc-500",children:"No Bing performance data available."}):o.jsx("div",{className:"overflow-x-auto rounded-lg border border-zinc-800/60",children:o.jsxs("table",{className:"w-full text-xs",children:[o.jsx("thead",{children:o.jsxs("tr",{className:"border-b border-zinc-800",children:[o.jsx("th",{className:"text-left py-1.5 px-3 text-zinc-500 font-medium",children:"Query"}),o.jsx("th",{className:"text-right py-1.5 px-3 text-zinc-500 font-medium w-16",children:"Clicks"}),o.jsx("th",{className:"text-right py-1.5 px-3 text-zinc-500 font-medium w-16",children:"Impr"}),o.jsx("th",{className:"text-right py-1.5 px-3 text-zinc-500 font-medium w-14",children:"CTR"}),o.jsx("th",{className:"text-right py-1.5 px-3 text-zinc-500 font-medium w-14",children:"Pos"})]})}),o.jsx("tbody",{children:p.map((V,H)=>o.jsxs("tr",{className:"border-b border-zinc-800/50",children:[o.jsx("td",{className:"py-1.5 px-3 text-zinc-300 truncate max-w-[480px]",children:V.query}),o.jsx("td",{className:"py-1.5 px-3 text-right text-zinc-200",children:V.clicks}),o.jsx("td",{className:"py-1.5 px-3 text-right text-zinc-400",children:V.impressions}),o.jsxs("td",{className:"py-1.5 px-3 text-right text-zinc-400",children:[(V.ctr*100).toFixed(1),"%"]}),o.jsx("td",{className:"py-1.5 px-3 text-right text-zinc-400",children:V.averagePosition.toFixed(1)})]},H))})]})})})]})]})}function b$({projectName:e}){const[t,s]=w.useState("google"),[a,r]=w.useState(!0),[c,u]=w.useState("idle"),[f,m]=w.useState(null),p=w.useRef(null),[v,y]=w.useState(!1),[x,b]=w.useState(null),[N,S]=w.useState(null),[C,k]=w.useState(!1),[A,R]=w.useState(null),[z,O]=w.useState(null);async function M(V=!1){V||r(!0),m(null);try{const[H,T,B]=await Promise.all([Sp().catch(()=>null),nj(e).catch(()=>[]),ij(e).catch(()=>null)]),se=T.find(fe=>fe.connectionType==="gsc")??null;y(!!H?.google?.configured),k(!!H?.bing?.configured),b(se),R(B);const[le,J]=await Promise.all([se?jp(e).catch(()=>null):Promise.resolve(null),B?.connected?wp(e).catch(()=>null):Promise.resolve(null)]);S(le),O(J)}catch(H){m(H instanceof Error?H.message:"Failed to load search console overview")}finally{r(!1)}}async function E(){if(c!=="idle")return;p.current?.abort();const V=new AbortController;p.current=V;const H=V.signal;u("syncing"),m(null);const T=[];try{async function B(){if(!x)return;const fe=await sj(e);if(!fe?.id)return;const ye=2e3,ge=Date.now()+12e4;for(;Date.now()<ge;){if(H.aborted||(await new Promise(et=>setTimeout(et,ye)),H.aborted))return;const Ze=await Pr(fe.id).catch(()=>null);if(!Ze)break;if(["completed","failed","cancelled"].includes(Ze.status)){Ze.status!=="completed"&&T.push(`Google sync ${Ze.status}`);break}}}const se=10;async function le(){if(!A?.connected)return;const fe=await aj(e).catch(()=>[]),ye=[...new Set(fe.map(_e=>_e.url))];if(ye.length!==0)for(let _e=0;_e<ye.length;_e+=se){if(H.aborted)return;const ge=ye.slice(_e,_e+se),et=(await Promise.allSettled(ge.map(de=>rj(e,de)))).filter(de=>de.status==="rejected").length;et>0&&T.push(`${et} Bing inspection(s) failed`)}}const J=await Promise.allSettled([B(),le()]);for(const fe of J)fe.status==="rejected"&&T.push(fe.reason instanceof Error?fe.reason.message:"Sync failed");if(H.aborted)return;u("reloading"),await M(!0),T.length>0&&m(`Partial refresh: ${T.join("; ")}`)}catch(B){H.aborted||m(B instanceof Error?B.message:"Refresh failed")}finally{H.aborted||u("idle")}}w.useEffect(()=>(M(),()=>{p.current?.abort()}),[e]);const L=x?"positive":v?"caution":"negative",U=x?"Connected":v?"Ready to connect":"Needs setup",X=N?`${N.summary.percentage}% indexed`:x?"Awaiting coverage":"No coverage data",Q=N?`${N.summary.notIndexed} not indexed${N.summary.deindexed>0?` · ${N.summary.deindexed} deindexed`:""}`:x?"Run sitemap inspection to populate coverage":v?"Connect Search Console for this domain":"Add Google OAuth credentials in Settings",ee=N?.lastInspectedAt??x?.updatedAt??null,ue=A?.connected?"positive":C?"caution":"negative",ze=A?.connected?"Connected":C?"Ready to connect":"Needs setup",je=z?`${z.summary.percentage}% indexed`:A?.connected?"Awaiting coverage":"No coverage data",K=z?z.summary.notIndexed+(z.summary.unknown??0):0,ae=z?`${K} not in index`:A?.connected?"Inspect URLs to populate coverage":C?"Connect Bing Webmaster Tools for this domain":"Add a Bing API key in Settings",me=z?.lastInspectedAt??A?.updatedAt??null;return o.jsxs("div",{className:"space-y-6",children:[o.jsxs(Le,{className:"surface-card",children:[o.jsxs("div",{className:"section-head section-head-inline",children:[o.jsxs("div",{children:[o.jsx("p",{className:"eyebrow eyebrow-soft",children:"Search console"}),o.jsx("h2",{children:"Search Engine Intelligence"}),o.jsx("p",{className:"mt-1 max-w-3xl text-sm leading-6 text-zinc-500",children:"Scan both engines at a glance, then open the Google or Bing workspace when you need to inspect coverage or take action."})]}),o.jsx(oe,{type:"button",variant:"outline",size:"sm",disabled:a||c!=="idle",onClick:()=>{E()},children:a?"Loading…":c==="syncing"?"Querying Google & Bing…":c==="reloading"?"Reloading…":"Refresh overview"})]}),f&&o.jsx("div",{className:"mb-3 rounded-lg border border-rose-800/40 bg-rose-950/20 px-3 py-2 text-sm text-rose-300",children:f}),o.jsxs("div",{className:"grid gap-3 lg:grid-cols-2",children:[o.jsx(fS,{eyebrow:"Google",title:"Google Search Console",status:a?"Loading…":U,tone:a?"neutral":L,targetLabel:"Selected property",targetValue:x?.propertyId??"No property selected",coverageValue:a?"Loading…":X,note:a?"Loading overview…":Q,updatedAt:ee,active:t==="google",onClick:()=>s("google")}),o.jsx(fS,{eyebrow:"Bing",title:"Bing Webmaster Tools",status:a?"Loading…":ze,tone:a?"neutral":ue,targetLabel:"Selected site",targetValue:A?.siteUrl??"No site selected",coverageValue:a?"Loading…":je,note:a?"Loading overview…":ae,updatedAt:me,active:t==="bing",onClick:()=>s("bing")})]})]}),o.jsx("div",{className:"flex flex-wrap gap-2",role:"tablist","aria-label":"Search engine workspaces",children:[["google","Google"],["bing","Bing"]].map(([V,H])=>o.jsx("button",{type:"button",role:"tab","aria-selected":t===V,className:`project-subnav-link ${t===V?"project-subnav-link-active":""}`,onClick:()=>s(V),children:H},V))}),t==="google"&&o.jsx(h$,{projectName:e}),t==="bing"&&o.jsxs("section",{className:"page-section-divider",children:[o.jsx("div",{className:"section-head section-head-inline",children:o.jsxs("div",{children:[o.jsx("p",{className:"eyebrow eyebrow-soft",children:"Search engine"}),o.jsx("h2",{children:"Bing Webmaster Tools"})]})}),o.jsx(x$,{projectName:e})]})]})}function S$({insights:e}){const{openEvidence:t}=Gr(),[s,a]=w.useState(null);return o.jsx("div",{className:"insight-list",children:e.map(r=>{const c=s===r.id,u=r.affectedPhrases.length>0;return o.jsxs("div",{children:[o.jsxs("div",{className:`insight-row insight-row-${r.tone} ${u?"cursor-pointer":""}`,onClick:u?()=>a(c?null:r.id):void 0,children:[o.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[u&&o.jsx(Fu,{size:12,className:`shrink-0 text-zinc-500 transition-transform duration-150 ${c?"rotate-90":""}`}),o.jsx(lt,{tone:r.tone,children:r.actionLabel}),o.jsx("span",{className:"text-sm font-medium text-zinc-100 truncate",children:r.title}),o.jsx("span",{className:"hidden sm:inline text-xs text-zinc-500 truncate",children:r.detail})]}),u&&o.jsxs("span",{className:"text-[11px] text-zinc-600 whitespace-nowrap",children:[r.affectedPhrases.length," phrase",r.affectedPhrases.length>1?"s":""]})]}),c&&o.jsx("div",{className:"divide-y divide-zinc-800/20",children:r.affectedPhrases.map(f=>o.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 py-2 pl-9 bg-zinc-900/40",children:[o.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[o.jsx(Bm,{state:f.citationState}),o.jsx("span",{className:"text-sm text-zinc-200 truncate",children:f.keyword}),o.jsx("div",{className:"hidden sm:flex gap-1",children:f.provider&&o.jsx(al,{provider:f.provider})})]}),o.jsx("button",{type:"button",className:"text-xs text-zinc-400 hover:text-zinc-200 whitespace-nowrap transition-colors",onClick:m=>{m.stopPropagation(),t(f.evidenceId)},children:"View →"})]},f.evidenceId))})]},r.id)})})}function vd({tab:e}){const{projectId:t}=Hu({from:"/projects/$projectId"}),s=Ii(),{dashboard:a,isLoading:r,refetch:c}=Oa();if(!a||r)return o.jsxs("div",{className:"page-skeleton",children:[o.jsxs("div",{className:"page-skeleton-header",children:[o.jsx("div",{className:"skeleton-text h-6 w-48"}),o.jsx("div",{className:"skeleton-text-sm w-32"})]}),o.jsx("div",{className:"grid grid-cols-3 gap-4",children:[1,2,3].map(re=>o.jsxs("div",{className:"page-skeleton-card flex flex-col items-center",children:[o.jsx("div",{className:"skeleton-circle size-20"}),o.jsx("div",{className:"skeleton-text w-16 mt-3"})]},re))}),o.jsxs("div",{className:"page-skeleton-card",children:[o.jsx("div",{className:"skeleton-text w-28"}),o.jsx("div",{className:"space-y-2 mt-2",children:[1,2,3,4].map(re=>o.jsx("div",{className:"skeleton-text-sm w-full"},re))})]})]});const u=$M(a,t),[f,m]=w.useState(!1),[p,v]=w.useState(!1),[y,x]=w.useState(!1),[b,N]=w.useState(""),[S,C]=w.useState(!1),[k,A]=w.useState(!1),[R,z]=w.useState(""),[O,M]=w.useState(!1),[E,L]=w.useState(!1),[U,X]=w.useState(""),[Q,ee]=w.useState(!1),[ue,ze]=w.useState(void 0),[je,K]=w.useState(!1),[ae,me]=w.useState(null),[V,H]=w.useState(!1),T=u?.visibilityEvidence??[],B=u?.project.name??"",se=u?.project.displayName||u?.project.name||B,le=qN(),J=w.useMemo(()=>new Set(T.map(re=>re.location??"")),[T]),fe=J.has(""),ye=w.useMemo(()=>[...J].filter(Boolean),[J]);w.useEffect(()=>{if(ue===void 0||ue===""||!B){me(null),H(!1);return}H(!0),ej(B,ue).then(re=>{me(re),H(!1)}).catch(()=>{me(null),H(!1)})},[ue,B]);const _e=w.useMemo(()=>{if(!ae)return null;const re=new Map;for(const Ge of ae){for(const[gt,Vt]of Object.entries(Ge.providerRuns??{}))re.set(`${Ge.keyword}::${gt}`,Vt.map(Qe=>({runId:Qe.runId,citationState:Qe.citationState,createdAt:Qe.createdAt})));(!Ge.providerRuns||Object.keys(Ge.providerRuns).length===0)&&re.set(`${Ge.keyword}::`,Ge.runs.map(gt=>({runId:gt.runId,citationState:gt.citationState,createdAt:gt.createdAt})))}return re},[ae]),ge=w.useMemo(()=>{const re=ue!==void 0?T.filter(Ge=>ue===""?!Ge.location:Ge.location===ue):T;return _e?re.map(Ge=>{const gt=_e.get(`${Ge.keyword}::${Ge.provider}`)??_e.get(`${Ge.keyword}::`);return gt?{...Ge,runHistory:gt}:Ge}):re},[T,ue,_e]);if(!u)return o.jsx("div",{className:"page-container",children:o.jsxs(Le,{className:"surface-card empty-card",children:[o.jsx("h1",{children:"Project not found"}),o.jsxs("p",{children:['Could not find a project with ID "',t,'".']}),o.jsx(oe,{asChild:!0,children:o.jsx(St,{to:"/",children:"Return to overview"})})]})});async function Ze(){try{await le.mutateAsync({projectName:B,projectLabel:se,sourceAction:"project-run"}),c()}catch{}}async function et(){v(!0);try{await W_(B),Ke({title:"Project deleted",detail:`${se} was removed.`,tone:"positive",dedupeKey:`project:delete:${B}`,dedupeMode:"drop"}),s({to:"/"}),c()}catch(re){console.error("Failed to delete project:",re)}finally{v(!1)}}async function de(){const re=await e2(B),Ge=typeof re=="string"?re:JSON.stringify(re,null,2),gt=new Blob([Ge],{type:"text/yaml"}),Vt=URL.createObjectURL(gt),Qe=document.createElement("a");Qe.href=Vt,Qe.download=`${B}.yaml`,Qe.click()}async function Ve(){const re=b.split(`
|
|
236
|
+
CTR: ${Je.impressions>0?(Je.clicks/Je.impressions*100).toFixed(1):0}%`}),o.jsx("rect",{x:ns-Ia-Cl/2,y:st.top+zn-Fi,width:Ia,height:Math.max(Fi,1),rx:2,fill:"#3b82f6",opacity:.85}),o.jsx("rect",{x:ns+Cl/2,y:st.top+zn-gs,width:Ia,height:Math.max(gs,1),rx:2,fill:"#10b981",opacity:.85})]},Me)}),(()=>{const Me=Math.min(he.length,7);return Array.from({length:Me},(Je,it)=>{const ns=he.length===1?0:Math.round(it/(Me-1)*(he.length-1)),Fi=st.left+ks*ns+ks/2;return o.jsx("text",{x:Fi,y:cn-8,textAnchor:"middle",fill:"#71717a",fontSize:"10",fontFamily:"inherit",children:he[ns][0].slice(5)},`xl-${ns}`)})})()]})})]})})(),o.jsxs("div",{className:"mt-3 grid gap-2 lg:grid-cols-5",children:[o.jsx("input",{className:"rounded border border-zinc-700 bg-transparent px-2 py-1.5 text-sm text-zinc-200 placeholder-zinc-600 focus:border-zinc-500 focus:outline-none",type:"date",value:E.startDate,onChange:I=>L(he=>({...he,startDate:I.target.value}))}),o.jsx("input",{className:"rounded border border-zinc-700 bg-transparent px-2 py-1.5 text-sm text-zinc-200 placeholder-zinc-600 focus:border-zinc-500 focus:outline-none",type:"date",value:E.endDate,onChange:I=>L(he=>({...he,endDate:I.target.value}))}),o.jsx("input",{className:"rounded border border-zinc-700 bg-transparent px-2 py-1.5 text-sm text-zinc-200 placeholder-zinc-600 focus:border-zinc-500 focus:outline-none",type:"text",placeholder:"Filter query",value:E.query,onChange:I=>L(he=>({...he,query:I.target.value}))}),o.jsx("input",{className:"rounded border border-zinc-700 bg-transparent px-2 py-1.5 text-sm text-zinc-200 placeholder-zinc-600 focus:border-zinc-500 focus:outline-none",type:"text",placeholder:"Filter page",value:E.page,onChange:I=>L(he=>({...he,page:I.target.value}))}),o.jsx("input",{className:"rounded border border-zinc-700 bg-transparent px-2 py-1.5 text-sm text-zinc-200 placeholder-zinc-600 focus:border-zinc-500 focus:outline-none",type:"number",min:"1",placeholder:"Limit",value:E.limit,onChange:I=>L(he=>({...he,limit:I.target.value}))})]}),f.length>0?o.jsx("div",{className:"mt-3 overflow-x-auto",children:o.jsxs("table",{className:"data-table w-full text-sm",children:[o.jsx("thead",{children:o.jsxs("tr",{children:[o.jsx("th",{className:"text-left",children:"Date"}),o.jsx("th",{className:"text-left",children:"Query"}),o.jsx("th",{className:"text-left",children:"Page"}),o.jsx("th",{className:"text-right",children:"Clicks"}),o.jsx("th",{className:"text-right",children:"Impressions"}),o.jsx("th",{className:"text-right",children:"CTR"}),o.jsx("th",{className:"text-right",children:"Position"})]})}),o.jsx("tbody",{children:f.map((I,he)=>o.jsxs("tr",{children:[o.jsx("td",{className:"text-zinc-400",children:I.date}),o.jsx("td",{className:"max-w-xs truncate text-zinc-200",children:I.query}),o.jsx("td",{className:"max-w-xs truncate text-zinc-400",children:I.page}),o.jsx("td",{className:"text-right tabular-nums text-zinc-300",children:I.clicks.toLocaleString()}),o.jsx("td",{className:"text-right tabular-nums text-zinc-400",children:I.impressions.toLocaleString()}),o.jsxs("td",{className:"text-right tabular-nums text-zinc-400",children:[(Number.isFinite(I.ctr)?I.ctr*100:0).toFixed(1),"%"]}),o.jsx("td",{className:"text-right tabular-nums text-zinc-400",children:I.position.toFixed(1)})]},`${I.date}:${I.query}:${I.page}:${he}`))})]})}):o.jsx("p",{className:"mt-3 text-sm text-zinc-500",children:"No performance rows match the current filters yet."})]}),o.jsxs(Le,{className:"surface-card",children:[o.jsx("div",{className:"section-head",children:o.jsxs("div",{children:[o.jsx("p",{className:"eyebrow eyebrow-soft",children:"Inspection"}),o.jsx("h3",{children:"Inspect a URL"})]})}),o.jsxs("div",{className:"mt-3 flex flex-col gap-2 lg:flex-row",children:[o.jsx("input",{className:"flex-1 rounded border border-zinc-700 bg-transparent px-2 py-1.5 text-sm text-zinc-200 placeholder-zinc-600 focus:border-zinc-500 focus:outline-none",type:"url",placeholder:"https://example.com/page",value:k,onChange:I=>A(I.target.value),onKeyDown:I=>I.key==="Enter"&&void Nl()}),o.jsx(oe,{type:"button",size:"sm",disabled:se||!nt?.propertyId||!k.trim(),onClick:Nl,children:se?"Inspecting…":"Inspect URL"})]}),b&&o.jsxs("div",{className:"mt-3 grid gap-3 md:grid-cols-2 xl:grid-cols-4",children:[o.jsxs("div",{className:"rounded-lg border border-zinc-800/60 bg-zinc-900/20 p-3",children:[o.jsx("p",{className:"text-xs uppercase tracking-wide text-zinc-500",children:"Indexing state"}),o.jsx("p",{className:"mt-1 text-sm text-zinc-200",children:b.indexingState??"Unknown"})]}),o.jsxs("div",{className:"rounded-lg border border-zinc-800/60 bg-zinc-900/20 p-3",children:[o.jsx("p",{className:"text-xs uppercase tracking-wide text-zinc-500",children:"Verdict"}),o.jsx("p",{className:"mt-1 text-sm text-zinc-200",children:b.verdict??"Unknown"})]}),o.jsxs("div",{className:"rounded-lg border border-zinc-800/60 bg-zinc-900/20 p-3",children:[o.jsx("p",{className:"text-xs uppercase tracking-wide text-zinc-500",children:"Mobile friendly"}),o.jsx("p",{className:"mt-1 text-sm text-zinc-200",children:Wx(b.isMobileFriendly)})]}),o.jsxs("div",{className:"rounded-lg border border-zinc-800/60 bg-zinc-900/20 p-3",children:[o.jsx("p",{className:"text-xs uppercase tracking-wide text-zinc-500",children:"Last crawl"}),o.jsx("p",{className:"mt-1 text-sm text-zinc-200",children:ls(b.crawlTime)})]})]})]}),o.jsxs(Le,{className:"surface-card",children:[o.jsxs("div",{className:"section-head section-head-inline",children:[o.jsxs("div",{children:[o.jsx("p",{className:"eyebrow eyebrow-soft",children:"History"}),o.jsx("h3",{children:"Inspection log"})]}),o.jsx(oe,{type:"button",variant:"outline",size:"sm",disabled:T,onClick:()=>{Ma()},children:T?"Loading…":"Refresh history"})]}),o.jsxs("div",{className:"mt-3 flex flex-col gap-2 lg:flex-row",children:[o.jsx("input",{className:"flex-1 rounded border border-zinc-700 bg-transparent px-2 py-1.5 text-sm text-zinc-200 placeholder-zinc-600 focus:border-zinc-500 focus:outline-none",type:"text",placeholder:"Filter exact URL",value:U,onChange:I=>X(I.target.value)}),o.jsx(oe,{type:"button",size:"sm",variant:"outline",disabled:T,onClick:()=>{Ma()},children:"Apply filter"})]}),p.length>0?o.jsx("div",{className:"mt-3 overflow-x-auto",children:o.jsxs("table",{className:"data-table w-full text-sm",children:[o.jsx("thead",{children:o.jsxs("tr",{children:[o.jsx("th",{className:"text-left",children:"URL"}),o.jsx("th",{className:"text-left",children:"Indexing"}),o.jsx("th",{className:"text-left",children:"Verdict"}),o.jsx("th",{className:"text-left",children:"Coverage"}),o.jsx("th",{className:"text-left",children:"Mobile"}),o.jsx("th",{className:"text-left",children:"Inspected"})]})}),o.jsx("tbody",{children:p.map(I=>o.jsxs("tr",{children:[o.jsx("td",{className:"max-w-sm truncate text-zinc-200",children:I.url}),o.jsx("td",{className:"text-zinc-300",children:I.indexingState??"Unknown"}),o.jsx("td",{className:"text-zinc-400",children:I.verdict??"Unknown"}),o.jsx("td",{className:"text-zinc-400",children:I.coverageState??"Unknown"}),o.jsx("td",{className:"text-zinc-400",children:Wx(I.isMobileFriendly)}),o.jsx("td",{className:"text-zinc-400",children:ls(I.inspectedAt)})]},I.id))})]})}):o.jsx("p",{className:"mt-3 text-sm text-zinc-500",children:"No inspection history yet."})]}),o.jsxs(Le,{className:"surface-card",children:[o.jsx("div",{className:"section-head",children:o.jsxs("div",{children:[o.jsx("p",{className:"eyebrow eyebrow-soft",children:"Deindexed"}),o.jsx("h3",{children:"Recent indexing losses"})]})}),y.length>0?o.jsx("div",{className:"mt-3 overflow-x-auto",children:o.jsxs("table",{className:"data-table w-full text-sm",children:[o.jsx("thead",{children:o.jsxs("tr",{children:[o.jsx("th",{className:"text-left",children:"URL"}),o.jsx("th",{className:"text-left",children:"Previous"}),o.jsx("th",{className:"text-left",children:"Current"}),o.jsx("th",{className:"text-left",children:"Changed at"})]})}),o.jsx("tbody",{children:y.map(I=>o.jsxs("tr",{children:[o.jsx("td",{className:"max-w-sm truncate text-zinc-200",children:I.url}),o.jsx("td",{className:"text-zinc-400",children:I.previousState??"Unknown"}),o.jsx("td",{className:"text-zinc-300",children:I.currentState??"Unknown"}),o.jsx("td",{className:"text-zinc-400",children:ls(I.transitionDate)})]},`${I.url}:${I.transitionDate}`))})]})}):o.jsx("p",{className:"mt-3 text-sm text-zinc-500",children:"No deindexed transitions recorded."})]})]}),nt&&o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"border-t border-zinc-800/60 pt-3",children:o.jsxs("button",{type:"button",className:"flex w-full items-center gap-2 text-left",onClick:()=>nn(I=>!I),children:[o.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",className:`h-4 w-4 text-zinc-500 transition-transform ${Dn?"rotate-90":""}`,"aria-hidden":"true",children:o.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"})}),o.jsx("span",{className:"text-xs uppercase tracking-wide text-zinc-500",children:"Setup & Configuration"})]})}),Dn&&o.jsxs("div",{className:"space-y-3",children:[o.jsxs("div",{className:"grid gap-3 xl:grid-cols-2",children:[o.jsxs(Le,{className:"surface-card",children:[o.jsx("div",{className:"section-head",children:o.jsxs("div",{children:[o.jsx("p",{className:"eyebrow eyebrow-soft",children:"Property"}),o.jsx("h3",{children:"Pick the Search Console property"})]})}),o.jsxs("div",{className:"mt-3 space-y-2",children:[o.jsx("label",{className:"text-xs text-zinc-500",htmlFor:`gsc-property-${e}`,children:"Property URL"}),o.jsx("select",{id:`gsc-property-${e}`,className:"w-full rounded border border-zinc-700 bg-transparent px-2 py-1.5 text-sm text-zinc-200 focus:border-zinc-500 focus:outline-none",value:S,disabled:je||c.length===0,onChange:I=>C(I.target.value),children:c.length===0?o.jsx("option",{value:"",children:je?"Loading properties…":"No properties available"}):c.map(I=>o.jsxs("option",{value:I.siteUrl,children:[I.siteUrl," · ",I.permissionLevel]},I.siteUrl))}),o.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[o.jsx(oe,{type:"button",size:"sm",variant:"outline",disabled:je,onClick:()=>{ce(nt)},children:je?"Refreshing…":"Refresh properties"}),o.jsx(oe,{type:"button",size:"sm",disabled:!S||ae,onClick:Jr,children:ae?"Saving…":"Save property"})]}),o.jsx("p",{className:"text-xs text-zinc-500",children:"The selected property is used for future syncs and URL inspections for this project."})]})]}),o.jsxs(Le,{className:"surface-card",children:[o.jsx("div",{className:"section-head",children:o.jsxs("div",{children:[o.jsx("p",{className:"eyebrow eyebrow-soft",children:"Sync"}),o.jsx("h3",{children:"Import GSC performance data"})]})}),o.jsxs("div",{className:"mt-3 space-y-3",children:[o.jsxs("div",{className:"grid gap-3 sm:grid-cols-[160px_1fr]",children:[o.jsxs("div",{children:[o.jsx("label",{className:"text-xs text-zinc-500",htmlFor:`gsc-sync-days-${e}`,children:"Days"}),o.jsx("input",{id:`gsc-sync-days-${e}`,type:"number",min:"1",className:"mt-0.5 w-full rounded border border-zinc-700 bg-transparent px-2 py-1.5 text-sm text-zinc-200 placeholder-zinc-600 focus:border-zinc-500 focus:outline-none",value:R,onChange:I=>z(I.target.value)})]}),o.jsxs("label",{className:"flex items-center gap-2 rounded border border-zinc-800/60 bg-zinc-900/20 px-3 py-2 text-sm text-zinc-300",children:[o.jsx("input",{type:"checkbox",checked:O,onChange:I=>M(I.target.checked)}),"Replace existing imported rows for the requested range"]})]}),o.jsx(oe,{type:"button",size:"sm",disabled:ts.isPending||!nt.propertyId,onClick:Gi,children:ts.isPending?"Queueing…":"Queue sync"}),!nt.propertyId&&o.jsx("p",{className:"text-xs text-amber-400",children:"Select a Search Console property before queueing a sync."})]})]})]}),o.jsxs(Le,{className:"surface-card",children:[o.jsx("div",{className:"section-head",children:o.jsxs("div",{children:[o.jsx("p",{className:"eyebrow eyebrow-soft",children:"Sitemap"}),o.jsx("h3",{children:"Sitemap configuration"})]})}),o.jsxs("div",{className:"mt-3 space-y-3",children:[nt.sitemapUrl&&o.jsxs("div",{className:"rounded-lg border border-zinc-800/60 bg-zinc-900/20 p-3",children:[o.jsx("p",{className:"text-xs uppercase tracking-wide text-zinc-500",children:"Current sitemap URL"}),o.jsx("p",{className:"mt-1 text-sm text-zinc-200 break-all",children:nt.sitemapUrl})]}),o.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[o.jsx(oe,{type:"button",size:"sm",variant:"outline",disabled:ge||!nt.propertyId,onClick:()=>{Pa()},children:ge?"Loading…":"Browse sitemaps from GSC"}),o.jsx(oe,{type:"button",size:"sm",variant:"outline",disabled:ht.isPending||!nt.propertyId,onClick:hs,children:ht.isPending?"Discovering…":"Auto-discover and queue inspection"})]}),o.jsx("p",{className:"text-xs text-zinc-500",children:"Browse lists available sitemaps without queueing a run. Auto-discover saves the primary sitemap and queues an inspection."}),et&&et.length>0&&o.jsxs("div",{className:"rounded-lg border border-zinc-800/60 bg-zinc-900/20 p-3 space-y-2",children:[o.jsxs("p",{className:"text-xs uppercase tracking-wide text-zinc-500",children:["Sitemaps (",et.length,")"]}),et.map(I=>{const he=I.contents?.[0];return o.jsxs("div",{className:"flex items-start justify-between gap-2 text-xs",children:[o.jsxs("div",{children:[o.jsx("p",{className:"text-zinc-200 break-all",children:I.path}),I.lastSubmitted&&o.jsxs("p",{className:"text-zinc-500",children:["Submitted: ",I.lastSubmitted.split("T")[0]]})]}),o.jsxs("div",{className:"flex items-center gap-3 shrink-0",children:[he&&o.jsxs("div",{className:"text-right",children:[o.jsxs("p",{className:"text-zinc-300",children:[he.indexed," / ",he.submitted]}),o.jsx("p",{className:"text-zinc-500",children:"indexed"})]}),o.jsx("button",{type:"button",className:"text-xs text-zinc-400 hover:text-zinc-200 transition-colors",onClick:()=>at(I.path),children:"Use"})]})]},I.path)})]}),o.jsxs("div",{className:"flex flex-col gap-2 lg:flex-row",children:[o.jsx("input",{className:"flex-1 rounded border border-zinc-700 bg-transparent px-2 py-1.5 text-sm text-zinc-200 placeholder-zinc-600 focus:border-zinc-500 focus:outline-none",type:"url",placeholder:nt.sitemapUrl?"Update sitemap URL…":"https://example.com/sitemap.xml",value:Ve,onChange:I=>at(I.target.value),onKeyDown:I=>I.key==="Enter"&&Ve.trim()&&void Cs()}),o.jsx(oe,{type:"button",size:"sm",disabled:Zt||!Ve.trim(),onClick:Cs,children:Zt?"Saving…":nt.sitemapUrl?"Update":"Save"})]}),o.jsxs("div",{className:"flex flex-col gap-2 lg:flex-row",children:[o.jsx("input",{className:"flex-1 rounded border border-zinc-700 bg-transparent px-2 py-1.5 text-sm text-zinc-200 placeholder-zinc-600 focus:border-zinc-500 focus:outline-none",type:"url",placeholder:"Sitemap URL for inspection (leave empty for saved default)",id:`gsc-sitemap-inspect-${e}`}),o.jsx(oe,{type:"button",size:"sm",variant:"outline",disabled:gn.isPending||!nt.propertyId,onClick:async()=>{const he=document.getElementById(`gsc-sitemap-inspect-${e}`)?.value?.trim()||nt.sitemapUrl||void 0;Be(null),pn(null);try{await gn.mutateAsync({projectName:e,projectLabel:e,opts:{sitemapUrl:he}})}catch{}},children:gn.isPending?"Queueing…":"Inspect sitemap"})]}),!nt.propertyId&&o.jsx("p",{className:"text-xs text-amber-400",children:"Select a Search Console property first."})]})]})]})]})]})]})}function m$({project:e,onUpdateProject:t,onRefresh:s}){const[a,r]=w.useState(!1),[c,u]=w.useState(!1),[f,m]=w.useState(null),[p,v]=w.useState(e.displayName),[y,x]=w.useState(e.canonicalDomain),[b,N]=w.useState(e.country),[S,C]=w.useState(e.language),[k,A]=w.useState(e.ownedDomains??[]),[R,z]=w.useState(""),[O,M]=w.useState(null),[E,L]=w.useState(!1),[U,X]=w.useState(!1),[Q,ee]=w.useState(""),[ue,ze]=w.useState(""),[je,K]=w.useState(""),[ae,me]=w.useState(""),[V,H]=w.useState("");w.useEffect(()=>{a||(v(e.displayName),x(e.canonicalDomain),N(e.country),C(e.language),A(e.ownedDomains??[]))},[e,a]);function T(){r(!1),m(null),v(e.displayName),x(e.canonicalDomain),N(e.country),C(e.language),A(e.ownedDomains??[]),z("")}function B(){const de=R.trim();de&&(k.includes(de)||A([...k,de]),z(""))}function se(de){A(k.filter(Ve=>Ve!==de))}async function le(){if(!(!p.trim()||!y.trim()||!b.trim()||!S.trim())){u(!0),m(null);try{await t(e.name,{displayName:p.trim(),canonicalDomain:y.trim(),ownedDomains:k,country:b.trim(),language:S.trim()}),r(!1),Ke({title:"Project settings saved",detail:`${p.trim()} was updated.`,tone:"positive",dedupeKey:`project:update:${e.name}`,dedupeMode:"replace"})}catch(de){m(de instanceof Error?de.message:"Failed to save")}finally{u(!1)}}}async function J(){const de=Q.trim(),Ve=ue.trim(),at=je.trim(),Zt=ae.trim();if(!(!de||!Ve||!at||!Zt)){L(!0),M(null);try{const $t={label:de,city:Ve,region:at,country:Zt};V.trim()&&($t.timezone=V.trim()),await Y_(e.name,$t),s(),ee(""),ze(""),K(""),me(""),H(""),X(!1),Ke({title:"Location added",detail:`${de} is now available for ${e.name}.`,tone:"positive",dedupeKey:`project:location:add:${e.name}:${de}`,dedupeMode:"drop"})}catch($t){M($t instanceof Error?$t.message:"Failed to add location")}finally{L(!1)}}}async function fe(de){L(!0),M(null);try{await J_(e.name,de),s(),Ke({title:"Location removed",detail:`${de} was removed from ${e.name}.`,tone:"positive",dedupeKey:`project:location:remove:${e.name}:${de}`,dedupeMode:"drop"})}catch(Ve){M(Ve instanceof Error?Ve.message:"Failed to remove location")}finally{L(!1)}}async function ye(de){L(!0),M(null);try{await X_(e.name,de),s(),Ke({title:"Default location updated",detail:`${de} is now the default for ${e.name}.`,tone:"positive",dedupeKey:`project:location:default:${e.name}`,dedupeMode:"replace"})}catch(Ve){M(Ve instanceof Error?Ve.message:"Failed to set default location")}finally{L(!1)}}const _e=p!==e.displayName||y!==e.canonicalDomain||b!==e.country||S!==e.language||JSON.stringify(k)!==JSON.stringify(e.ownedDomains??[]),ge="w-full rounded border border-zinc-700 bg-transparent px-2 py-1.5 text-sm text-zinc-200 placeholder-zinc-600 focus:border-zinc-500 focus:outline-none",Ze="block text-xs font-medium text-zinc-400 mb-1",et=Q.trim()&&ue.trim()&&je.trim()&&ae.trim();return o.jsxs("section",{className:"page-section-divider",children:[o.jsxs("div",{className:"section-head section-head-inline",children:[o.jsxs("div",{children:[o.jsx("p",{className:"eyebrow eyebrow-soft",children:"Configuration"}),o.jsx("h2",{children:"Project settings"})]}),!a&&o.jsx(oe,{type:"button",variant:"outline",size:"sm",onClick:()=>r(!0),children:"Edit settings"})]}),f&&o.jsxs("div",{className:"mb-3 rounded-lg border border-rose-800/40 bg-rose-950/20 px-3 py-2 text-sm text-rose-300",children:[f,o.jsx("button",{type:"button",className:"ml-2 text-rose-400 hover:text-rose-200",onClick:()=>m(null),children:"×"})]}),a?o.jsxs("div",{className:"rounded-lg border border-zinc-800 bg-zinc-900/40 p-4 space-y-4",children:[o.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[o.jsxs("div",{children:[o.jsx("label",{className:Ze,children:"Display name"}),o.jsx("input",{className:ge,type:"text",value:p,onChange:de=>v(de.target.value),placeholder:"My Project"})]}),o.jsxs("div",{children:[o.jsx("label",{className:Ze,children:"Canonical domain"}),o.jsx("input",{className:ge,type:"text",value:y,onChange:de=>x(de.target.value),placeholder:"example.com"})]}),o.jsxs("div",{children:[o.jsx("label",{className:Ze,children:"Country"}),o.jsx("input",{className:ge,type:"text",value:b,onChange:de=>N(de.target.value),placeholder:"US",maxLength:2})]}),o.jsxs("div",{children:[o.jsx("label",{className:Ze,children:"Language"}),o.jsx("input",{className:ge,type:"text",value:S,onChange:de=>C(de.target.value),placeholder:"en"})]})]}),o.jsxs("div",{children:[o.jsx("label",{className:Ze,children:"Owned domains"}),o.jsx("div",{className:"flex flex-wrap gap-1.5 mb-2",children:k.map(de=>o.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full border border-zinc-700/60 bg-zinc-800/40 px-2 py-0.5 text-xs text-zinc-300",children:[de,o.jsx("button",{type:"button",className:"ml-0.5 text-zinc-500 hover:text-zinc-200 transition-colors",onClick:()=>se(de),"aria-label":`Remove ${de}`,children:"×"})]},de))}),o.jsxs("div",{className:"flex gap-2",children:[o.jsx("input",{className:`${ge} flex-1`,type:"text",placeholder:"docs.example.com",value:R,onChange:de=>z(de.target.value),onKeyDown:de=>de.key==="Enter"&&(de.preventDefault(),B())}),o.jsx(oe,{type:"button",variant:"outline",size:"sm",disabled:!R.trim(),onClick:B,children:"Add"})]})]}),o.jsxs("div",{className:"flex items-center gap-2 pt-2 border-t border-zinc-800/60",children:[o.jsx(oe,{type:"button",disabled:c||!_e||!p.trim()||!y.trim(),onClick:le,children:c?"Saving...":"Save changes"}),o.jsx(oe,{type:"button",variant:"outline",disabled:c,onClick:T,children:"Cancel"})]})]}):o.jsx("div",{className:"rounded-lg border border-zinc-800/60 bg-zinc-900/30 overflow-hidden",children:o.jsx("table",{className:"w-full text-sm",children:o.jsxs("tbody",{children:[o.jsxs("tr",{className:"border-b border-zinc-800/40",children:[o.jsx("td",{className:"px-4 py-2.5 text-zinc-500 font-medium w-40",children:"Display name"}),o.jsx("td",{className:"px-4 py-2.5 text-zinc-200",children:e.displayName||"—"})]}),o.jsxs("tr",{className:"border-b border-zinc-800/40",children:[o.jsx("td",{className:"px-4 py-2.5 text-zinc-500 font-medium",children:"Canonical domain"}),o.jsx("td",{className:"px-4 py-2.5 text-zinc-200",children:e.canonicalDomain})]}),o.jsxs("tr",{className:"border-b border-zinc-800/40",children:[o.jsx("td",{className:"px-4 py-2.5 text-zinc-500 font-medium",children:"Owned domains"}),o.jsx("td",{className:"px-4 py-2.5",children:(e.ownedDomains??[]).length>0?o.jsx("div",{className:"flex flex-wrap gap-1.5",children:e.ownedDomains.map(de=>o.jsx("span",{className:"rounded-full border border-zinc-700/60 bg-zinc-800/40 px-2 py-0.5 text-xs text-zinc-300",children:de},de))}):o.jsx("span",{className:"text-zinc-500",children:"—"})})]}),o.jsxs("tr",{className:"border-b border-zinc-800/40",children:[o.jsx("td",{className:"px-4 py-2.5 text-zinc-500 font-medium",children:"Country"}),o.jsx("td",{className:"px-4 py-2.5 text-zinc-200",children:e.country})]}),o.jsxs("tr",{className:"border-b border-zinc-800/40",children:[o.jsx("td",{className:"px-4 py-2.5 text-zinc-500 font-medium",children:"Language"}),o.jsx("td",{className:"px-4 py-2.5 text-zinc-200",children:e.language})]}),o.jsxs("tr",{children:[o.jsx("td",{className:"px-4 py-2.5 text-zinc-500 font-medium align-top pt-3",children:"Locations"}),o.jsxs("td",{className:"px-4 py-2.5",children:[O&&o.jsxs("div",{className:"mb-2 rounded border border-rose-800/40 bg-rose-950/20 px-2 py-1 text-xs text-rose-300",children:[O,o.jsx("button",{type:"button",className:"ml-1 text-rose-400 hover:text-rose-200",onClick:()=>M(null),children:"×"})]}),(e.locations??[]).length>0?o.jsxs("table",{className:"w-full text-xs mb-2",children:[o.jsx("thead",{children:o.jsxs("tr",{className:"text-zinc-600",children:[o.jsx("th",{className:"text-left pb-1 font-medium pr-3",children:"Label"}),o.jsx("th",{className:"text-left pb-1 font-medium pr-3",children:"City"}),o.jsx("th",{className:"text-left pb-1 font-medium pr-3",children:"Region"}),o.jsx("th",{className:"text-left pb-1 font-medium pr-3",children:"Country"}),o.jsx("th",{className:"text-left pb-1 font-medium pr-3",children:"Timezone"}),o.jsx("th",{className:"pb-1"})]})}),o.jsx("tbody",{children:e.locations.map(de=>o.jsxs("tr",{className:"border-t border-zinc-800/30",children:[o.jsx("td",{className:"py-1.5 pr-3",children:o.jsxs("span",{className:`inline-flex items-center gap-1 rounded-full border px-1.5 py-0.5 text-[10px] font-medium ${de.label===e.defaultLocation?"border-emerald-700/60 bg-emerald-950/30 text-emerald-300":"border-zinc-700/60 bg-zinc-800/40 text-zinc-300"}`,children:[de.label,de.label===e.defaultLocation?" ★":""]})}),o.jsx("td",{className:"py-1.5 pr-3 text-zinc-300",children:de.city}),o.jsx("td",{className:"py-1.5 pr-3 text-zinc-300",children:de.region}),o.jsx("td",{className:"py-1.5 pr-3 text-zinc-300",children:de.country}),o.jsx("td",{className:"py-1.5 pr-3 text-zinc-500",children:de.timezone??"—"}),o.jsx("td",{className:"py-1.5",children:o.jsxs("div",{className:"flex items-center gap-1.5",children:[de.label!==e.defaultLocation&&o.jsx("button",{type:"button",disabled:E,onClick:()=>ye(de.label),className:"text-[10px] text-zinc-500 hover:text-emerald-400 transition-colors disabled:opacity-40","aria-label":`Set ${de.label} as default location`,children:"Set default"}),o.jsx("button",{type:"button",disabled:E,onClick:()=>fe(de.label),className:"text-[10px] text-zinc-500 hover:text-rose-400 transition-colors disabled:opacity-40","aria-label":`Remove location ${de.label}`,children:"Remove"})]})})]},de.label))})]}):o.jsx("p",{className:"text-zinc-500 text-xs mb-2",children:"No locations configured"}),U?o.jsxs("div",{className:"mt-2 rounded border border-zinc-800 bg-zinc-900/50 p-3 space-y-2",children:[o.jsx("p",{className:"text-[10px] font-medium uppercase tracking-wide text-zinc-500",children:"Add location"}),o.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[o.jsxs("div",{children:[o.jsx("label",{className:"block text-[10px] text-zinc-500 mb-0.5",children:"Label *"}),o.jsx("input",{className:ge,type:"text",value:Q,onChange:de=>ee(de.target.value),placeholder:"nyc"})]}),o.jsxs("div",{children:[o.jsx("label",{className:"block text-[10px] text-zinc-500 mb-0.5",children:"City *"}),o.jsx("input",{className:ge,type:"text",value:ue,onChange:de=>ze(de.target.value),placeholder:"New York"})]}),o.jsxs("div",{children:[o.jsx("label",{className:"block text-[10px] text-zinc-500 mb-0.5",children:"Region *"}),o.jsx("input",{className:ge,type:"text",value:je,onChange:de=>K(de.target.value),placeholder:"NY"})]}),o.jsxs("div",{children:[o.jsx("label",{className:"block text-[10px] text-zinc-500 mb-0.5",children:"Country *"}),o.jsx("input",{className:ge,type:"text",value:ae,onChange:de=>me(de.target.value),placeholder:"US",maxLength:2})]}),o.jsxs("div",{className:"col-span-2",children:[o.jsx("label",{className:"block text-[10px] text-zinc-500 mb-0.5",children:"Timezone (optional)"}),o.jsx("input",{className:ge,type:"text",value:V,onChange:de=>H(de.target.value),placeholder:"America/New_York"})]})]}),o.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[o.jsx(oe,{type:"button",size:"sm",disabled:E||!et,onClick:J,children:E?"Adding...":"Add location"}),o.jsx(oe,{type:"button",size:"sm",variant:"outline",disabled:E,onClick:()=>{X(!1),M(null)},children:"Cancel"})]})]}):o.jsx(oe,{type:"button",size:"sm",variant:"outline",onClick:()=>X(!0),children:"+ Add location"})]})]})]})})})]})}const p$=[{value:"daily",label:"Every day"},{value:"weekly@mon",label:"Every Monday"},{value:"weekly@wed",label:"Every Wednesday"},{value:"weekly@fri",label:"Every Friday"},{value:"twice-daily",label:"Twice a day (6am & 6pm)"},{value:"custom",label:"Custom cron expression"}],dS=["UTC","America/New_York","America/Chicago","America/Denver","America/Los_Angeles","America/Toronto","America/Vancouver","Europe/London","Europe/Paris","Europe/Berlin","Asia/Tokyo","Asia/Shanghai","Asia/Singapore","Australia/Sydney"];function g$({projectName:e}){const[t,s]=w.useState("loading"),[a,r]=w.useState(!1),[c,u]=w.useState("daily"),[f,m]=w.useState(6),[p,v]=w.useState(""),[y,x]=w.useState("UTC"),[b,N]=w.useState(!1),[S,C]=w.useState(""),[k,A]=w.useState(!1),[R,z]=w.useState(!1),[O,M]=w.useState(null);w.useEffect(()=>{r2(e).then(s).catch(()=>s(null))},[e]);const E=()=>{if(t&&t!=="loading"){const Q=AE(t.preset??null,t.cronExpr);u(Q.freq),m(Q.hour),v(Q.customCron);const ee=dS.includes(t.timezone);x(ee?t.timezone:"Other"),N(!ee),C(ee?"":t.timezone)}else u("daily"),m(6),v(""),x("UTC"),N(!1),C("");M(null),r(!0)},L=async()=>{A(!0),M(null);try{const ee={timezone:b?S.trim()||"UTC":y};c==="custom"?ee.cron=p.trim():ee.preset=RE(c,f);const ue=await qx(e,ee);s(ue),r(!1),Ke({title:"Schedule saved",detail:Gh(ue.preset??null,ue.cronExpr,ue.timezone),tone:"positive",dedupeKey:`schedule:${e}`,dedupeMode:"replace"})}catch(Q){M(Q instanceof Error?Q.message:"Failed to save schedule")}finally{A(!1)}},U=async()=>{if(!(!t||t==="loading")){A(!0),M(null);try{const Q={timezone:t.timezone,enabled:!t.enabled};t.preset?Q.preset=t.preset:Q.cron=t.cronExpr;const ee=await qx(e,Q);s(ee),Ke({title:ee.enabled?"Schedule resumed":"Schedule paused",detail:Gh(ee.preset??null,ee.cronExpr,ee.timezone),tone:"positive",dedupeKey:`schedule:toggle:${e}`,dedupeMode:"replace"})}catch(Q){M(Q instanceof Error?Q.message:"Failed to update schedule")}finally{A(!1)}}},X=async()=>{z(!0),M(null);try{await o2(e),s(null),r(!1),Ke({title:"Schedule removed",detail:`${e} will no longer run automatically.`,tone:"positive",dedupeKey:`schedule:remove:${e}`,dedupeMode:"drop"})}catch(Q){M(Q instanceof Error?Q.message:"Failed to remove schedule")}finally{z(!1)}};return o.jsxs("section",{className:"page-section-divider",children:[o.jsxs("div",{className:"section-head section-head-inline",children:[o.jsxs("div",{children:[o.jsx("p",{className:"eyebrow eyebrow-soft",children:"Automation"}),o.jsx("h2",{children:"Scheduled runs"})]}),t!=="loading"&&!a&&o.jsx(oe,{type:"button",variant:"outline",size:"sm",onClick:E,children:t?"Edit schedule":"+ Set schedule"})]}),t==="loading"&&o.jsx("p",{className:"supporting-copy",children:"Loading..."}),t!=="loading"&&!a&&t===null&&o.jsx(Le,{className:"surface-card compact-card",children:o.jsx("p",{className:"supporting-copy",children:"No schedule configured. Set one to automatically trigger visibility sweeps."})}),t!=="loading"&&!a&&t!==null&&o.jsxs(Le,{className:"surface-card compact-card",children:[o.jsxs("div",{className:"flex items-start justify-between gap-4",children:[o.jsxs("div",{className:"space-y-1",children:[o.jsx("p",{className:"text-sm font-medium text-zinc-200",children:Gh(t.preset??null,t.cronExpr,t.timezone)}),o.jsxs("p",{className:"text-xs text-zinc-500",children:["Cron: ",o.jsx("span",{className:"font-mono",children:t.cronExpr})]}),t.nextRunAt&&o.jsxs("p",{className:"text-xs text-zinc-500",children:["Next run: ",new Date(t.nextRunAt).toLocaleString()]}),t.lastRunAt&&o.jsxs("p",{className:"text-xs text-zinc-500",children:["Last run: ",new Date(t.lastRunAt).toLocaleString()]})]}),o.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[o.jsx(lt,{tone:t.enabled?"positive":"neutral",children:t.enabled?"Active":"Paused"}),o.jsx(oe,{type:"button",variant:"outline",size:"sm",disabled:k,onClick:U,children:t.enabled?"Pause":"Resume"}),o.jsx(oe,{type:"button",variant:"ghost",size:"sm",disabled:R,onClick:X,children:R?"Removing...":"Remove"})]})]}),O&&o.jsx("p",{className:"text-rose-400 text-sm mt-2",children:O})]}),a&&o.jsxs("div",{className:"rounded-lg border border-zinc-800 bg-zinc-900/40 p-4 space-y-3",children:[o.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[o.jsxs("div",{className:"space-y-1.5",children:[o.jsx("label",{className:"text-xs font-medium text-zinc-400",children:"Frequency"}),o.jsx("select",{className:"w-full rounded border border-zinc-700 bg-zinc-900 px-2 py-1.5 text-sm text-zinc-200 focus:border-zinc-500 focus:outline-none",value:c,onChange:Q=>u(Q.target.value),children:p$.map(Q=>o.jsx("option",{value:Q.value,children:Q.label},Q.value))})]}),o.jsxs("div",{className:"space-y-1.5",children:[o.jsx("label",{className:"text-xs font-medium text-zinc-400",children:"Time"}),o.jsx("select",{className:"w-full rounded border border-zinc-700 bg-zinc-900 px-2 py-1.5 text-sm text-zinc-200 focus:border-zinc-500 focus:outline-none disabled:opacity-40",value:f,disabled:c==="twice-daily"||c==="custom",onChange:Q=>m(parseInt(Q.target.value)),children:Array.from({length:24},(Q,ee)=>o.jsx("option",{value:ee,children:Am(ee)},ee))})]})]}),c==="custom"&&o.jsxs("div",{className:"space-y-1.5",children:[o.jsx("label",{className:"text-xs font-medium text-zinc-400",children:"Cron expression"}),o.jsx("input",{className:"w-full rounded border border-zinc-700 bg-transparent px-2 py-1.5 text-sm text-zinc-200 placeholder-zinc-600 font-mono focus:border-zinc-500 focus:outline-none",type:"text",placeholder:"0 9 * * 1-5",value:p,onChange:Q=>v(Q.target.value)})]}),o.jsxs("div",{className:"space-y-1.5",children:[o.jsx("label",{className:"text-xs font-medium text-zinc-400",children:"Timezone"}),o.jsxs("select",{className:"w-full rounded border border-zinc-700 bg-zinc-900 px-2 py-1.5 text-sm text-zinc-200 focus:border-zinc-500 focus:outline-none",value:b?"Other":y,onChange:Q=>{Q.target.value==="Other"?(N(!0),x("Other")):(N(!1),x(Q.target.value))},children:[dS.map(Q=>o.jsx("option",{value:Q,children:Q},Q)),o.jsx("option",{value:"Other",children:"Other (enter manually)\\u2026"})]}),b&&o.jsx("input",{className:"w-full rounded border border-zinc-700 bg-transparent px-2 py-1.5 text-sm text-zinc-200 placeholder-zinc-600 focus:border-zinc-500 focus:outline-none",type:"text",placeholder:"e.g. America/New_York",value:S,onChange:Q=>C(Q.target.value)})]}),O&&o.jsx("p",{className:"text-rose-400 text-sm",children:O}),o.jsxs("div",{className:"flex gap-2 justify-end",children:[o.jsx(oe,{type:"button",variant:"outline",size:"sm",onClick:()=>{r(!1),M(null)},children:"Cancel"}),o.jsx(oe,{type:"button",size:"sm",disabled:k||c==="custom"&&!p.trim(),onClick:L,children:k?"Saving...":"Save schedule"})]})]})]})}const y$=[{value:"citation.lost",label:"Citation lost"},{value:"citation.gained",label:"Citation gained"},{value:"run.completed",label:"Run completed"},{value:"run.failed",label:"Run failed"}];function v$({projectName:e}){const[t,s]=w.useState("loading"),[a,r]=w.useState(!1),[c,u]=w.useState(""),[f,m]=w.useState(["citation.lost","citation.gained"]),[p,v]=w.useState(!1),[y,x]=w.useState(null),[b,N]=w.useState({});w.useEffect(()=>{l2(e).then(s).catch(()=>s([]))},[e]);const S=R=>{m(z=>z.includes(R)?z.filter(O=>O!==R):[...z,R])},C=async()=>{if(!(!c.trim()||f.length===0)){v(!0),x(null);try{const R=await c2(e,{channel:"webhook",url:c.trim(),events:f});s(z=>z==="loading"?[R]:[...z,R]),u(""),m(["citation.lost","citation.gained"]),r(!1),Ke({title:"Webhook added",detail:`Notifications will be sent to ${R.url}.`,tone:"positive",dedupeKey:`notification:add:${e}`,dedupeMode:"drop"})}catch(R){x(R instanceof Error?R.message:"Failed to add webhook")}finally{v(!1)}}},k=async R=>{try{await u2(e,R),s(z=>z==="loading"?z:z.filter(O=>O.id!==R)),Ke({title:"Webhook removed",detail:`${e} no longer sends notifications to this endpoint.`,tone:"positive",dedupeKey:`notification:remove:${e}:${R}`,dedupeMode:"drop"})}catch(z){x(z instanceof Error?z.message:"Failed to remove webhook")}},A=async R=>{N(z=>({...z,[R]:{state:"testing"}}));try{const z=await d2(e,R);N(O=>({...O,[R]:{state:z.ok?"ok":"fail",status:z.status}})),z.ok&&Ke({title:"Test notification sent",detail:`Webhook returned status ${z.status}.`,tone:"positive",dedupeKey:`notification:test:${e}:${R}`,dedupeMode:"replace"})}catch{N(z=>({...z,[R]:{state:"fail"}}))}};return o.jsxs("section",{className:"page-section-divider",children:[o.jsxs("div",{className:"section-head section-head-inline",children:[o.jsxs("div",{children:[o.jsx("p",{className:"eyebrow eyebrow-soft",children:"Automation"}),o.jsx("h2",{children:"Notifications"})]}),t!=="loading"&&o.jsx(oe,{type:"button",variant:"outline",size:"sm",onClick:()=>{r(!a),x(null)},children:a?"Cancel":"+ Add webhook"})]}),a&&o.jsxs("div",{className:"mb-3 rounded-lg border border-zinc-800 bg-zinc-900/40 p-4 space-y-3",children:[o.jsxs("div",{className:"space-y-1.5",children:[o.jsx("label",{className:"text-xs font-medium text-zinc-400",children:"Webhook URL"}),o.jsx("input",{className:"w-full rounded border border-zinc-700 bg-transparent px-2 py-1.5 text-sm text-zinc-200 placeholder-zinc-600 focus:border-zinc-500 focus:outline-none",type:"url",placeholder:"https://hooks.example.com/canonry",value:c,onChange:R=>u(R.target.value)})]}),o.jsxs("div",{className:"space-y-1.5",children:[o.jsx("label",{className:"text-xs font-medium text-zinc-400",children:"Trigger on"}),o.jsx("div",{className:"flex flex-wrap gap-3",children:y$.map(R=>o.jsxs("label",{className:"flex items-center gap-1.5 cursor-pointer select-none",children:[o.jsx("input",{type:"checkbox",className:"rounded border-zinc-600 bg-zinc-800",checked:f.includes(R.value),onChange:()=>S(R.value)}),o.jsx("span",{className:"text-sm text-zinc-300",children:R.label})]},R.value))})]}),y&&o.jsx("p",{className:"text-rose-400 text-sm",children:y}),o.jsxs("div",{className:"flex gap-2 justify-end",children:[o.jsx(oe,{type:"button",variant:"outline",size:"sm",onClick:()=>{r(!1),x(null)},children:"Cancel"}),o.jsx(oe,{type:"button",size:"sm",disabled:p||!c.trim()||f.length===0,onClick:C,children:p?"Adding...":"Add webhook"})]})]}),t==="loading"&&o.jsx("p",{className:"supporting-copy",children:"Loading..."}),t!=="loading"&&t.length===0&&!a&&o.jsx(Le,{className:"surface-card compact-card",children:o.jsx("p",{className:"supporting-copy",children:"No webhooks configured. Add one to get alerted when citations change or runs complete."})}),t!=="loading"&&t.length>0&&o.jsxs("div",{className:"evidence-table-wrap",children:[o.jsxs("table",{className:"evidence-table",children:[o.jsx("thead",{children:o.jsxs("tr",{children:[o.jsx("th",{children:"Endpoint"}),o.jsx("th",{children:"Events"}),o.jsx("th",{children:"Status"}),o.jsx("th",{})]})}),o.jsx("tbody",{children:t.map(R=>o.jsxs("tr",{children:[o.jsx("td",{className:"evidence-keyword-cell",children:o.jsx("span",{className:"font-mono text-xs text-zinc-300 break-all",title:R.urlHost,children:R.urlDisplay??R.url})}),o.jsx("td",{children:o.jsx("div",{className:"flex flex-wrap gap-1",children:R.events.map(z=>o.jsx("span",{className:"inline-flex items-center rounded-full border border-zinc-700 bg-zinc-800/60 px-2 py-0.5 text-[10px] font-medium text-zinc-400 uppercase tracking-wide",children:z.replace("."," ")},z))})}),o.jsx("td",{children:o.jsx(lt,{tone:R.enabled?"positive":"neutral",children:R.enabled?"Active":"Paused"})}),o.jsx("td",{children:o.jsxs("div",{className:"flex items-center gap-1 justify-end",children:[b[R.id]&&(()=>{const z=b[R.id],O=z.state==="testing"?"Sending…":z.state==="ok"?`Delivered${z.status?` (${z.status})`:""}`:`Failed${z.status?` (${z.status})`:""}`;return o.jsx(lt,{tone:z.state==="ok"?"positive":z.state==="fail"?"negative":"neutral",children:O})})(),o.jsx(oe,{variant:"ghost",size:"sm",type:"button",disabled:b[R.id]?.state==="testing",onClick:()=>A(R.id),children:"Test"}),o.jsx(oe,{variant:"ghost",size:"sm",type:"button",onClick:()=>k(R.id),children:"Remove"})]})})]},R.id))})]}),y&&o.jsx("p",{className:"text-rose-400 text-sm mt-2",children:y})]})]})}function fS({eyebrow:e,title:t,status:s,tone:a,targetLabel:r,targetValue:c,coverageValue:u,note:f,updatedAt:m,active:p,onClick:v}){return o.jsxs("button",{type:"button",onClick:v,className:`surface-card w-full text-left transition-colors ${p?"border-zinc-200 bg-zinc-900/50":"hover:border-zinc-700 hover:bg-zinc-900/40"}`,children:[o.jsxs("div",{className:"section-head",children:[o.jsxs("div",{className:"min-w-0",children:[o.jsx("p",{className:"eyebrow eyebrow-soft",children:e}),o.jsx("h3",{children:t})]}),o.jsx(lt,{tone:a,children:s})]}),o.jsxs("div",{className:"mt-4 grid gap-3 sm:grid-cols-2",children:[o.jsxs("div",{className:"rounded-lg border border-zinc-800/60 bg-zinc-900/20 p-3",children:[o.jsx("p",{className:"text-xs uppercase tracking-wide text-zinc-500",children:r}),o.jsx("p",{className:"mt-1 truncate text-sm text-zinc-200",children:c})]}),o.jsxs("div",{className:"rounded-lg border border-zinc-800/60 bg-zinc-900/20 p-3",children:[o.jsx("p",{className:"text-xs uppercase tracking-wide text-zinc-500",children:"Coverage"}),o.jsx("p",{className:"mt-1 text-sm text-zinc-200",children:u})]})]}),o.jsxs("div",{className:"mt-3 flex flex-col gap-1 text-xs text-zinc-500 sm:flex-row sm:items-center sm:justify-between",children:[o.jsx("span",{children:f}),o.jsx("span",{children:m?`Updated ${ls(m)}`:"No recent sync yet"})]})]})}function ru({label:e,value:t,tone:s}){const a=s==="positive"?"text-emerald-400":s==="negative"?"text-rose-400":"text-zinc-200";return o.jsxs("div",{className:"rounded-lg border border-zinc-800/60 bg-zinc-900/20 p-3",children:[o.jsx("p",{className:"text-xs uppercase tracking-wide text-zinc-500",children:e}),o.jsx("p",{className:`mt-2 text-2xl font-semibold ${a}`,children:t})]})}function x$({projectName:e}){const[t,s]=w.useState(null),[a,r]=w.useState([]),[c,u]=w.useState(null),[f,m]=w.useState([]),[p,v]=w.useState([]),[y,x]=w.useState(null),[b,N]=w.useState(""),[S,C]=w.useState(""),[k,A]=w.useState(""),[R,z]=w.useState(!0),[O,M]=w.useState(!1),[E,L]=w.useState(null),[U,X]=w.useState("coverage");w.useEffect(()=>{Q()},[e]);async function Q(){z(!0),L(null);try{const V=await ij(e);if(s(V),V.connected){const[H,T,B]=await Promise.all([wp(e).catch(()=>null),aj(e).catch(()=>[]),O2(e).catch(()=>[])]);H&&u(H),m(T),v(B)}}catch(V){L(V instanceof Error?V.message:"Failed to load Bing data")}finally{z(!1)}}async function ee(){if(S.trim()){L(null);try{const V=await E2(e,S.trim());C(""),V.availableSites.length>0&&r(V.availableSites),await Q()}catch(V){L(V instanceof Error?V.message:"Failed to connect")}}}async function ue(){try{await R2(e),s(null),r([]),u(null),m([]),v([]),x(null),A(""),L(null)}catch(V){L(V instanceof Error?V.message:"Failed to disconnect")}}async function ze(){if(k)try{await T2(e,k),await Q()}catch(V){L(V instanceof Error?V.message:"Failed to set site")}}async function je(){if(b.trim())try{const V=await rj(e,b.trim());x(V),m(H=>[V,...H])}catch(V){L(V instanceof Error?V.message:"Inspection failed")}}async function K(V){M(!0),L(null);try{const H=await Gx(e,{urls:[V]}),{succeeded:T,failed:B,total:se}=H.summary;Ke({title:"Bing submission requested",detail:B===0?`${T} URL submitted to Bing.`:`${T}/${se} submitted successfully, ${B} failed.`,tone:B===0?"positive":"caution",dedupeKey:`bing:indexing:${e}:${V}`,dedupeMode:"replace"})}catch(H){const T=H instanceof Error?H.message:"Submission failed";L(T),Ke({title:"Bing submission failed",detail:T,tone:"negative",dedupeKey:`bing:indexing:${e}:${V}`,dedupeMode:"replace"})}finally{M(!1)}}async function ae(){M(!0),L(null),Ke({title:"Submitting URLs to Bing",detail:"Requesting indexing for all currently unindexed URLs.",tone:"neutral",dedupeKey:`bing:indexing-all:${e}`,dedupeMode:"replace"});try{const V=await Gx(e,{allUnindexed:!0}),{succeeded:H,failed:T,total:B}=V.summary;Ke({title:"Bing submissions requested",detail:T===0?`${H}/${B} URL${B!==1?"s":""} submitted to Bing.`:`${H}/${B} submitted successfully, ${T} failed.`,tone:T===0?"positive":"caution",dedupeKey:`bing:indexing-all:${e}`,dedupeMode:"replace"})}catch(V){const H=V instanceof Error?V.message:"Batch submission failed";L(H),Ke({title:"Bing submissions failed",detail:H,tone:"negative",dedupeKey:`bing:indexing-all:${e}`,dedupeMode:"replace"})}finally{M(!1)}}if(R)return o.jsx(Le,{className:"surface-card",children:o.jsx("div",{className:"text-sm text-zinc-400",children:"Loading Bing data..."})});if(!t?.connected)return o.jsxs(Le,{className:"surface-card",children:[o.jsxs("div",{className:"section-head section-head-inline",children:[o.jsxs("div",{children:[o.jsx("p",{className:"eyebrow eyebrow-soft",children:"Connection"}),o.jsx("h3",{children:"Domain authorization"})]}),o.jsx(lt,{tone:"caution",children:"Not connected"})]}),o.jsx("p",{className:"text-sm text-zinc-300",children:"Connect Bing Webmaster Tools to inspect URLs, monitor index coverage, and submit pages for indexing."}),o.jsxs("div",{className:"mt-3",children:[o.jsx("label",{className:"text-xs text-zinc-500",htmlFor:"bing-api-key",children:"API Key"}),o.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[o.jsx("input",{id:"bing-api-key",type:"password",className:"flex-1 rounded border border-zinc-700 bg-transparent px-2 py-1.5 text-sm text-zinc-200 placeholder-zinc-600 focus:border-zinc-500 focus:outline-none",placeholder:"Bing Webmaster Tools API key",value:S,onChange:V=>C(V.target.value),onKeyDown:V=>V.key==="Enter"&&ee()}),o.jsx(oe,{size:"sm",disabled:!S.trim(),onClick:ee,children:"Connect"})]}),o.jsxs("p",{className:"mt-1 text-[11px] text-zinc-500",children:["Get your API key from"," ",o.jsx("a",{href:"https://www.bing.com/webmasters/",target:"_blank",rel:"noopener noreferrer",className:"text-zinc-400 hover:text-zinc-300 underline underline-offset-2",children:"Bing Webmaster Tools"})]})]}),E&&o.jsx("p",{className:"mt-3 text-xs text-rose-400",children:E})]});if(!t.siteUrl)return o.jsxs(Le,{className:"surface-card",children:[o.jsxs("div",{className:"section-head section-head-inline",children:[o.jsxs("div",{children:[o.jsx("p",{className:"eyebrow eyebrow-soft",children:"Connection"}),o.jsx("h3",{children:"Domain authorization"})]}),o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(lt,{tone:"positive",children:"Connected"}),o.jsx(oe,{size:"sm",variant:"ghost",onClick:ue,children:"Disconnect"})]})]}),o.jsxs("div",{className:"space-y-3",children:[o.jsxs("div",{className:"rounded-lg border border-zinc-800/60 bg-zinc-900/30 px-4 py-3",children:[o.jsxs("div",{className:"flex items-center gap-3",children:[o.jsx("span",{className:"h-2 w-2 rounded-full bg-emerald-500"}),o.jsx("span",{className:"text-sm text-zinc-200",children:"Authorized for this project domain"}),o.jsx("span",{className:"text-xs text-zinc-500",children:t.domain})]}),o.jsx("p",{className:"mt-2 text-xs text-zinc-500",children:"The API key is connected, but no Bing site is selected yet. Pick the verified site that should receive inspections and indexing requests."})]}),o.jsxs("div",{className:"grid gap-3 lg:grid-cols-2",children:[o.jsxs("div",{className:"rounded-lg border border-zinc-800/60 bg-zinc-900/20 p-3",children:[o.jsx("p",{className:"text-xs uppercase tracking-wide text-zinc-500",children:"Registered domain"}),o.jsx("p",{className:"mt-1 text-sm text-zinc-200",children:t.domain})]}),o.jsxs("div",{className:"rounded-lg border border-zinc-800/60 bg-zinc-900/20 p-3",children:[o.jsx("p",{className:"text-xs uppercase tracking-wide text-zinc-500",children:"Last auth update"}),o.jsx("p",{className:"mt-1 text-sm text-zinc-200",children:t.updatedAt?ls(t.updatedAt):"—"})]})]}),o.jsxs("div",{className:"rounded-lg border border-zinc-800/60 bg-zinc-900/20 p-3",children:[o.jsx("p",{className:"text-xs uppercase tracking-wide text-zinc-500",children:"Select site"}),a.length>0?o.jsxs("div",{className:"mt-3 flex flex-col gap-2 lg:flex-row",children:[o.jsxs("select",{className:"flex-1 rounded border border-zinc-700 bg-zinc-900 px-2 py-1.5 text-sm text-zinc-200 focus:border-zinc-500 focus:outline-none",value:k,onChange:V=>A(V.target.value),children:[o.jsx("option",{value:"",children:"Select a site..."}),a.map(V=>o.jsxs("option",{value:V.url,children:[V.url,V.verified?" (verified)":""]},V.url))]}),o.jsx(oe,{size:"sm",disabled:!k,onClick:ze,children:"Set Site"})]}):o.jsx("div",{className:"mt-3",children:o.jsx(oe,{size:"sm",onClick:async()=>{const V=await A2(e);r(V.sites)},children:"Load Sites"})})]})]}),E&&o.jsx("p",{className:"mt-3 text-xs text-rose-400",children:E})]});const me=[{key:"coverage",label:"Coverage"},{key:"inspections",label:"Inspections"},{key:"performance",label:"Performance"}];return o.jsxs("div",{className:"space-y-3",children:[o.jsxs(Le,{className:"surface-card",children:[o.jsxs("div",{className:"section-head section-head-inline",children:[o.jsxs("div",{children:[o.jsx("p",{className:"eyebrow eyebrow-soft",children:"Connection"}),o.jsx("h3",{children:"Domain authorization"})]}),o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(lt,{tone:"positive",children:"Connected"}),o.jsx(oe,{size:"sm",variant:"ghost",onClick:ue,children:"Disconnect"})]})]}),E&&o.jsx("p",{className:"mb-3 text-xs text-rose-400",children:E}),o.jsxs("div",{className:"space-y-3",children:[o.jsxs("div",{className:"rounded-lg border border-zinc-800/60 bg-zinc-900/30 px-4 py-3",children:[o.jsxs("div",{className:"flex items-center gap-3",children:[o.jsx("span",{className:"h-2 w-2 rounded-full bg-emerald-500"}),o.jsx("span",{className:"text-sm text-zinc-200",children:"Authorized for this project domain"}),o.jsx("span",{className:"text-xs text-zinc-500",children:t.domain})]}),o.jsxs("p",{className:"mt-2 text-xs text-zinc-500",children:["Canonry stores Bing connections per canonical domain. This project is currently mapped to ",o.jsx("code",{children:t.siteUrl}),"."]})]}),o.jsxs("div",{className:"grid gap-3 lg:grid-cols-2",children:[o.jsxs("div",{className:"rounded-lg border border-zinc-800/60 bg-zinc-900/20 p-3",children:[o.jsx("p",{className:"text-xs uppercase tracking-wide text-zinc-500",children:"Selected site"}),o.jsx("p",{className:"mt-1 text-sm text-zinc-200",children:t.siteUrl})]}),o.jsxs("div",{className:"rounded-lg border border-zinc-800/60 bg-zinc-900/20 p-3",children:[o.jsx("p",{className:"text-xs uppercase tracking-wide text-zinc-500",children:"Last auth update"}),o.jsx("p",{className:"mt-1 text-sm text-zinc-200",children:t.updatedAt?ls(t.updatedAt):"—"})]})]})]})]}),o.jsxs(Le,{className:"surface-card",children:[o.jsxs("div",{className:"section-head section-head-inline",children:[o.jsxs("div",{children:[o.jsx("p",{className:"eyebrow eyebrow-soft",children:"Coverage"}),o.jsx("h3",{children:"Index monitoring"})]}),o.jsx("p",{className:"text-xs text-zinc-500",children:c?.lastInspectedAt?`Last inspected ${ls(c.lastInspectedAt)}`:"No inspection history yet"})]}),o.jsx("div",{className:"flex gap-1 border-b border-zinc-800",children:me.map(V=>o.jsx("button",{className:`px-3 py-1.5 text-xs font-medium border-b-2 transition-colors ${U===V.key?"border-zinc-200 text-zinc-200":"border-transparent text-zinc-500 hover:text-zinc-300"}`,onClick:()=>X(V.key),children:V.label},V.key))}),U==="coverage"&&c&&o.jsxs("div",{className:"mt-4 space-y-4",children:[o.jsxs("div",{className:"grid gap-3 sm:grid-cols-4",children:[o.jsx(ru,{label:"Indexed",value:c.summary.indexed,tone:"positive"}),o.jsx(ru,{label:"Not in index",value:c.summary.notIndexed+(c.summary.unknown??0),tone:"negative"}),o.jsx(ru,{label:"Status unknown",value:c.summary.unknown??0,tone:"neutral"}),o.jsx(ru,{label:"Coverage",value:`${c.summary.percentage}%`,tone:"neutral"})]}),c.notIndexed.length>0&&o.jsxs("div",{children:[o.jsxs("div",{className:"mb-2 flex items-center justify-between gap-3",children:[o.jsxs("h4",{className:"text-xs font-medium text-zinc-400",children:["Not Indexed (",c.notIndexed.length,")"]}),o.jsx(oe,{size:"sm",variant:"ghost",disabled:O,onClick:ae,children:O?"Submitting…":"Submit all to Bing"})]}),o.jsx("div",{className:"overflow-x-auto rounded-lg border border-zinc-800/60",children:o.jsxs("table",{className:"w-full text-xs",children:[o.jsx("thead",{children:o.jsxs("tr",{className:"border-b border-zinc-800",children:[o.jsx("th",{className:"text-left py-1.5 px-3 text-zinc-500 font-medium",children:"URL"}),o.jsx("th",{className:"text-left py-1.5 px-3 text-zinc-500 font-medium w-16",children:"HTTP"}),o.jsx("th",{className:"text-right py-1.5 px-3 text-zinc-500 font-medium w-20",children:"Action"})]})}),o.jsx("tbody",{children:c.notIndexed.map(V=>o.jsxs("tr",{className:"border-b border-zinc-800/50",children:[o.jsx("td",{className:"py-1.5 px-3 text-zinc-300 truncate max-w-[480px]",children:V.url}),o.jsx("td",{className:"py-1.5 px-3 text-zinc-400",children:V.httpCode??"—"}),o.jsx("td",{className:"py-1.5 px-3 text-right",children:o.jsx("button",{className:"text-[10px] text-zinc-400 hover:text-zinc-200 underline underline-offset-2",disabled:O,onClick:()=>K(V.url),children:"Submit"})})]},V.id))})]})})]}),(c.unknown??[]).length>0&&o.jsxs("div",{children:[o.jsxs("div",{className:"mb-2 flex items-center justify-between gap-3",children:[o.jsxs("h4",{className:"text-xs font-medium text-zinc-400",children:["Unknown — not yet confirmed (",(c.unknown??[]).length,")"]}),o.jsx(oe,{size:"sm",variant:"ghost",disabled:O,onClick:ae,children:O?"Submitting…":"Submit all to Bing"})]}),o.jsx("div",{className:"overflow-x-auto rounded-lg border border-zinc-800/60",children:o.jsxs("table",{className:"w-full text-xs",children:[o.jsx("thead",{children:o.jsxs("tr",{className:"border-b border-zinc-800",children:[o.jsx("th",{className:"text-left py-1.5 px-3 text-zinc-500 font-medium",children:"URL"}),o.jsx("th",{className:"text-left py-1.5 px-3 text-zinc-500 font-medium w-32",children:"Last Crawled"}),o.jsx("th",{className:"text-right py-1.5 px-3 text-zinc-500 font-medium w-20",children:"Action"})]})}),o.jsx("tbody",{children:(c.unknown??[]).map(V=>o.jsxs("tr",{className:"border-b border-zinc-800/50",children:[o.jsx("td",{className:"py-1.5 px-3 text-zinc-300 truncate max-w-[480px]",children:V.url}),o.jsx("td",{className:"py-1.5 px-3 text-zinc-400",children:V.lastCrawledDate?ls(V.lastCrawledDate):"—"}),o.jsx("td",{className:"py-1.5 px-3 text-right",children:o.jsx("button",{className:"text-[10px] text-zinc-400 hover:text-zinc-200 underline underline-offset-2",disabled:O,onClick:()=>K(V.url),children:"Submit"})})]},V.id))})]})})]}),c.indexed.length>0&&o.jsxs("div",{children:[o.jsxs("h4",{className:"mb-2 text-xs font-medium text-zinc-400",children:["Indexed (",c.indexed.length,")"]}),o.jsx("div",{className:"overflow-x-auto rounded-lg border border-zinc-800/60",children:o.jsxs("table",{className:"w-full text-xs",children:[o.jsx("thead",{children:o.jsxs("tr",{className:"border-b border-zinc-800",children:[o.jsx("th",{className:"text-left py-1.5 px-3 text-zinc-500 font-medium",children:"URL"}),o.jsx("th",{className:"text-left py-1.5 px-3 text-zinc-500 font-medium w-32",children:"Last Crawled"})]})}),o.jsx("tbody",{children:c.indexed.map(V=>o.jsxs("tr",{className:"border-b border-zinc-800/50",children:[o.jsx("td",{className:"py-1.5 px-3 text-zinc-300 truncate max-w-[480px]",children:V.url}),o.jsx("td",{className:"py-1.5 px-3 text-zinc-400",children:V.lastCrawledDate?ls(V.lastCrawledDate):"—"})]},V.id))})]})})]})]}),U==="coverage"&&!c&&o.jsx("p",{className:"mt-4 text-xs text-zinc-500",children:"No coverage data yet. Inspect URLs to build coverage data."}),U==="inspections"&&o.jsxs("div",{className:"mt-4 space-y-3",children:[o.jsxs("div",{className:"flex flex-col gap-2 lg:flex-row",children:[o.jsx("input",{type:"text",className:"flex-1 rounded border border-zinc-700 bg-transparent px-2 py-1.5 text-sm text-zinc-200 placeholder-zinc-600 focus:border-zinc-500 focus:outline-none",placeholder:"URL to inspect",value:b,onChange:V=>N(V.target.value),onKeyDown:V=>V.key==="Enter"&&je()}),o.jsx(oe,{size:"sm",disabled:!b.trim(),onClick:je,children:"Inspect"})]}),y&&o.jsxs("div",{className:"rounded border border-zinc-800 bg-zinc-900/40 p-3 text-xs space-y-1",children:[o.jsx("div",{className:"font-medium text-zinc-200",children:y.url}),o.jsxs("div",{className:"text-zinc-400",children:["In Index: ",o.jsx("span",{className:y.inIndex?"text-emerald-400":"text-rose-400",children:y.inIndex?"Yes":"No"})," · ","HTTP: ",y.httpCode??"—"," · ","Crawled: ",y.lastCrawledDate??"—"]})]}),f.length>0&&o.jsx("div",{className:"overflow-x-auto rounded-lg border border-zinc-800/60",children:o.jsxs("table",{className:"w-full text-xs",children:[o.jsx("thead",{children:o.jsxs("tr",{className:"border-b border-zinc-800",children:[o.jsx("th",{className:"text-left py-1.5 px-3 text-zinc-500 font-medium",children:"URL"}),o.jsx("th",{className:"text-left py-1.5 px-3 text-zinc-500 font-medium w-16",children:"Index"}),o.jsx("th",{className:"text-left py-1.5 px-3 text-zinc-500 font-medium w-14",children:"HTTP"}),o.jsx("th",{className:"text-left py-1.5 px-3 text-zinc-500 font-medium w-32",children:"Inspected"})]})}),o.jsx("tbody",{children:f.map(V=>o.jsxs("tr",{className:"border-b border-zinc-800/50",children:[o.jsx("td",{className:"py-1.5 px-3 text-zinc-300 truncate max-w-[480px]",children:V.url}),o.jsx("td",{className:"py-1.5 px-3",children:o.jsx(lt,{tone:V.inIndex?"positive":"negative",children:V.inIndex?"Yes":"No"})}),o.jsx("td",{className:"py-1.5 px-3 text-zinc-400",children:V.httpCode??"—"}),o.jsx("td",{className:"py-1.5 px-3 text-zinc-400",children:ls(V.inspectedAt)})]},V.id))})]})})]}),U==="performance"&&o.jsx("div",{className:"mt-4",children:p.length===0?o.jsx("p",{className:"text-xs text-zinc-500",children:"No Bing performance data available."}):o.jsx("div",{className:"overflow-x-auto rounded-lg border border-zinc-800/60",children:o.jsxs("table",{className:"w-full text-xs",children:[o.jsx("thead",{children:o.jsxs("tr",{className:"border-b border-zinc-800",children:[o.jsx("th",{className:"text-left py-1.5 px-3 text-zinc-500 font-medium",children:"Query"}),o.jsx("th",{className:"text-right py-1.5 px-3 text-zinc-500 font-medium w-16",children:"Clicks"}),o.jsx("th",{className:"text-right py-1.5 px-3 text-zinc-500 font-medium w-16",children:"Impr"}),o.jsx("th",{className:"text-right py-1.5 px-3 text-zinc-500 font-medium w-14",children:"CTR"}),o.jsx("th",{className:"text-right py-1.5 px-3 text-zinc-500 font-medium w-14",children:"Pos"})]})}),o.jsx("tbody",{children:p.map((V,H)=>o.jsxs("tr",{className:"border-b border-zinc-800/50",children:[o.jsx("td",{className:"py-1.5 px-3 text-zinc-300 truncate max-w-[480px]",children:V.query}),o.jsx("td",{className:"py-1.5 px-3 text-right text-zinc-200",children:V.clicks}),o.jsx("td",{className:"py-1.5 px-3 text-right text-zinc-400",children:V.impressions}),o.jsxs("td",{className:"py-1.5 px-3 text-right text-zinc-400",children:[(Number.isFinite(V.ctr)?V.ctr*100:0).toFixed(1),"%"]}),o.jsx("td",{className:"py-1.5 px-3 text-right text-zinc-400",children:V.averagePosition.toFixed(1)})]},H))})]})})})]})]})}function b$({projectName:e}){const[t,s]=w.useState("google"),[a,r]=w.useState(!0),[c,u]=w.useState("idle"),[f,m]=w.useState(null),p=w.useRef(null),[v,y]=w.useState(!1),[x,b]=w.useState(null),[N,S]=w.useState(null),[C,k]=w.useState(!1),[A,R]=w.useState(null),[z,O]=w.useState(null);async function M(V=!1){V||r(!0),m(null);try{const[H,T,B]=await Promise.all([Sp().catch(()=>null),nj(e).catch(()=>[]),ij(e).catch(()=>null)]),se=T.find(fe=>fe.connectionType==="gsc")??null;y(!!H?.google?.configured),k(!!H?.bing?.configured),b(se),R(B);const[le,J]=await Promise.all([se?jp(e).catch(()=>null):Promise.resolve(null),B?.connected?wp(e).catch(()=>null):Promise.resolve(null)]);S(le),O(J)}catch(H){m(H instanceof Error?H.message:"Failed to load search console overview")}finally{r(!1)}}async function E(){if(c!=="idle")return;p.current?.abort();const V=new AbortController;p.current=V;const H=V.signal;u("syncing"),m(null);const T=[];try{async function B(){if(!x)return;const fe=await sj(e);if(!fe?.id)return;const ye=2e3,ge=Date.now()+12e4;for(;Date.now()<ge;){if(H.aborted||(await new Promise(et=>setTimeout(et,ye)),H.aborted))return;const Ze=await Pr(fe.id).catch(()=>null);if(!Ze)break;if(["completed","failed","cancelled"].includes(Ze.status)){Ze.status!=="completed"&&T.push(`Google sync ${Ze.status}`);break}}}const se=10;async function le(){if(!A?.connected)return;const fe=await aj(e).catch(()=>[]),ye=[...new Set(fe.map(_e=>_e.url))];if(ye.length!==0)for(let _e=0;_e<ye.length;_e+=se){if(H.aborted)return;const ge=ye.slice(_e,_e+se),et=(await Promise.allSettled(ge.map(de=>rj(e,de)))).filter(de=>de.status==="rejected").length;et>0&&T.push(`${et} Bing inspection(s) failed`)}}const J=await Promise.allSettled([B(),le()]);for(const fe of J)fe.status==="rejected"&&T.push(fe.reason instanceof Error?fe.reason.message:"Sync failed");if(H.aborted)return;u("reloading"),await M(!0),T.length>0&&m(`Partial refresh: ${T.join("; ")}`)}catch(B){H.aborted||m(B instanceof Error?B.message:"Refresh failed")}finally{H.aborted||u("idle")}}w.useEffect(()=>(M(),()=>{p.current?.abort()}),[e]);const L=x?"positive":v?"caution":"negative",U=x?"Connected":v?"Ready to connect":"Needs setup",X=N?`${N.summary.percentage}% indexed`:x?"Awaiting coverage":"No coverage data",Q=N?`${N.summary.notIndexed} not indexed${N.summary.deindexed>0?` · ${N.summary.deindexed} deindexed`:""}`:x?"Run sitemap inspection to populate coverage":v?"Connect Search Console for this domain":"Add Google OAuth credentials in Settings",ee=N?.lastInspectedAt??x?.updatedAt??null,ue=A?.connected?"positive":C?"caution":"negative",ze=A?.connected?"Connected":C?"Ready to connect":"Needs setup",je=z?`${z.summary.percentage}% indexed`:A?.connected?"Awaiting coverage":"No coverage data",K=z?z.summary.notIndexed+(z.summary.unknown??0):0,ae=z?`${K} not in index`:A?.connected?"Inspect URLs to populate coverage":C?"Connect Bing Webmaster Tools for this domain":"Add a Bing API key in Settings",me=z?.lastInspectedAt??A?.updatedAt??null;return o.jsxs("div",{className:"space-y-6",children:[o.jsxs(Le,{className:"surface-card",children:[o.jsxs("div",{className:"section-head section-head-inline",children:[o.jsxs("div",{children:[o.jsx("p",{className:"eyebrow eyebrow-soft",children:"Search console"}),o.jsx("h2",{children:"Search Engine Intelligence"}),o.jsx("p",{className:"mt-1 max-w-3xl text-sm leading-6 text-zinc-500",children:"Scan both engines at a glance, then open the Google or Bing workspace when you need to inspect coverage or take action."})]}),o.jsx(oe,{type:"button",variant:"outline",size:"sm",disabled:a||c!=="idle",onClick:()=>{E()},children:a?"Loading…":c==="syncing"?"Querying Google & Bing…":c==="reloading"?"Reloading…":"Refresh overview"})]}),f&&o.jsx("div",{className:"mb-3 rounded-lg border border-rose-800/40 bg-rose-950/20 px-3 py-2 text-sm text-rose-300",children:f}),o.jsxs("div",{className:"grid gap-3 lg:grid-cols-2",children:[o.jsx(fS,{eyebrow:"Google",title:"Google Search Console",status:a?"Loading…":U,tone:a?"neutral":L,targetLabel:"Selected property",targetValue:x?.propertyId??"No property selected",coverageValue:a?"Loading…":X,note:a?"Loading overview…":Q,updatedAt:ee,active:t==="google",onClick:()=>s("google")}),o.jsx(fS,{eyebrow:"Bing",title:"Bing Webmaster Tools",status:a?"Loading…":ze,tone:a?"neutral":ue,targetLabel:"Selected site",targetValue:A?.siteUrl??"No site selected",coverageValue:a?"Loading…":je,note:a?"Loading overview…":ae,updatedAt:me,active:t==="bing",onClick:()=>s("bing")})]})]}),o.jsx("div",{className:"flex flex-wrap gap-2",role:"tablist","aria-label":"Search engine workspaces",children:[["google","Google"],["bing","Bing"]].map(([V,H])=>o.jsx("button",{type:"button",role:"tab","aria-selected":t===V,className:`project-subnav-link ${t===V?"project-subnav-link-active":""}`,onClick:()=>s(V),children:H},V))}),t==="google"&&o.jsx(h$,{projectName:e}),t==="bing"&&o.jsxs("section",{className:"page-section-divider",children:[o.jsx("div",{className:"section-head section-head-inline",children:o.jsxs("div",{children:[o.jsx("p",{className:"eyebrow eyebrow-soft",children:"Search engine"}),o.jsx("h2",{children:"Bing Webmaster Tools"})]})}),o.jsx(x$,{projectName:e})]})]})}function S$({insights:e}){const{openEvidence:t}=Gr(),[s,a]=w.useState(null);return o.jsx("div",{className:"insight-list",children:e.map(r=>{const c=s===r.id,u=r.affectedPhrases.length>0;return o.jsxs("div",{children:[o.jsxs("div",{className:`insight-row insight-row-${r.tone} ${u?"cursor-pointer":""}`,onClick:u?()=>a(c?null:r.id):void 0,children:[o.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[u&&o.jsx(Fu,{size:12,className:`shrink-0 text-zinc-500 transition-transform duration-150 ${c?"rotate-90":""}`}),o.jsx(lt,{tone:r.tone,children:r.actionLabel}),o.jsx("span",{className:"text-sm font-medium text-zinc-100 truncate",children:r.title}),o.jsx("span",{className:"hidden sm:inline text-xs text-zinc-500 truncate",children:r.detail})]}),u&&o.jsxs("span",{className:"text-[11px] text-zinc-600 whitespace-nowrap",children:[r.affectedPhrases.length," phrase",r.affectedPhrases.length>1?"s":""]})]}),c&&o.jsx("div",{className:"divide-y divide-zinc-800/20",children:r.affectedPhrases.map(f=>o.jsxs("div",{className:"flex items-center justify-between gap-3 px-4 py-2 pl-9 bg-zinc-900/40",children:[o.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[o.jsx(Bm,{state:f.citationState}),o.jsx("span",{className:"text-sm text-zinc-200 truncate",children:f.keyword}),o.jsx("div",{className:"hidden sm:flex gap-1",children:f.provider&&o.jsx(al,{provider:f.provider})})]}),o.jsx("button",{type:"button",className:"text-xs text-zinc-400 hover:text-zinc-200 whitespace-nowrap transition-colors",onClick:m=>{m.stopPropagation(),t(f.evidenceId)},children:"View →"})]},f.evidenceId))})]},r.id)})})}function vd({tab:e}){const{projectId:t}=Hu({from:"/projects/$projectId"}),s=Ii(),{dashboard:a,isLoading:r,refetch:c}=Oa();if(!a||r)return o.jsxs("div",{className:"page-skeleton",children:[o.jsxs("div",{className:"page-skeleton-header",children:[o.jsx("div",{className:"skeleton-text h-6 w-48"}),o.jsx("div",{className:"skeleton-text-sm w-32"})]}),o.jsx("div",{className:"grid grid-cols-3 gap-4",children:[1,2,3].map(re=>o.jsxs("div",{className:"page-skeleton-card flex flex-col items-center",children:[o.jsx("div",{className:"skeleton-circle size-20"}),o.jsx("div",{className:"skeleton-text w-16 mt-3"})]},re))}),o.jsxs("div",{className:"page-skeleton-card",children:[o.jsx("div",{className:"skeleton-text w-28"}),o.jsx("div",{className:"space-y-2 mt-2",children:[1,2,3,4].map(re=>o.jsx("div",{className:"skeleton-text-sm w-full"},re))})]})]});const u=$M(a,t),[f,m]=w.useState(!1),[p,v]=w.useState(!1),[y,x]=w.useState(!1),[b,N]=w.useState(""),[S,C]=w.useState(!1),[k,A]=w.useState(!1),[R,z]=w.useState(""),[O,M]=w.useState(!1),[E,L]=w.useState(!1),[U,X]=w.useState(""),[Q,ee]=w.useState(!1),[ue,ze]=w.useState(void 0),[je,K]=w.useState(!1),[ae,me]=w.useState(null),[V,H]=w.useState(!1),T=u?.visibilityEvidence??[],B=u?.project.name??"",se=u?.project.displayName||u?.project.name||B,le=qN(),J=w.useMemo(()=>new Set(T.map(re=>re.location??"")),[T]),fe=J.has(""),ye=w.useMemo(()=>[...J].filter(Boolean),[J]);w.useEffect(()=>{if(ue===void 0||ue===""||!B){me(null),H(!1);return}H(!0),ej(B,ue).then(re=>{me(re),H(!1)}).catch(()=>{me(null),H(!1)})},[ue,B]);const _e=w.useMemo(()=>{if(!ae)return null;const re=new Map;for(const Ge of ae){for(const[gt,Vt]of Object.entries(Ge.providerRuns??{}))re.set(`${Ge.keyword}::${gt}`,Vt.map(Qe=>({runId:Qe.runId,citationState:Qe.citationState,createdAt:Qe.createdAt})));(!Ge.providerRuns||Object.keys(Ge.providerRuns).length===0)&&re.set(`${Ge.keyword}::`,Ge.runs.map(gt=>({runId:gt.runId,citationState:gt.citationState,createdAt:gt.createdAt})))}return re},[ae]),ge=w.useMemo(()=>{const re=ue!==void 0?T.filter(Ge=>ue===""?!Ge.location:Ge.location===ue):T;return _e?re.map(Ge=>{const gt=_e.get(`${Ge.keyword}::${Ge.provider}`)??_e.get(`${Ge.keyword}::`);return gt?{...Ge,runHistory:gt}:Ge}):re},[T,ue,_e]);if(!u)return o.jsx("div",{className:"page-container",children:o.jsxs(Le,{className:"surface-card empty-card",children:[o.jsx("h1",{children:"Project not found"}),o.jsxs("p",{children:['Could not find a project with ID "',t,'".']}),o.jsx(oe,{asChild:!0,children:o.jsx(St,{to:"/",children:"Return to overview"})})]})});async function Ze(){try{await le.mutateAsync({projectName:B,projectLabel:se,sourceAction:"project-run"}),c()}catch{}}async function et(){v(!0);try{await W_(B),Ke({title:"Project deleted",detail:`${se} was removed.`,tone:"positive",dedupeKey:`project:delete:${B}`,dedupeMode:"drop"}),s({to:"/"}),c()}catch(re){console.error("Failed to delete project:",re)}finally{v(!1)}}async function de(){const re=await e2(B),Ge=typeof re=="string"?re:JSON.stringify(re,null,2),gt=new Blob([Ge],{type:"text/yaml"}),Vt=URL.createObjectURL(gt),Qe=document.createElement("a");Qe.href=Vt,Qe.download=`${B}.yaml`,Qe.click()}async function Ve(){const re=b.split(`
|
|
237
237
|
`).map(Ge=>Ge.trim()).filter(Boolean);if(re.length!==0){C(!0);try{await Z_(B,re),c(),N(""),x(!1)}finally{C(!1)}}}async function at(){const re=R.trim();if(re){M(!0);try{const gt=(await WS(B)).map(Qe=>Qe.domain),Vt=[...new Set([...gt,re])];await tj(B,Vt),c(),z(""),A(!1)}finally{M(!1)}}}async function Zt(){const re=U.trim();if(re){ee(!0);try{const Ge=u?.project.ownedDomains??[];await Bx(B,[...Ge,re]),c(),X(""),L(!1)}finally{ee(!1)}}}async function $t(re){ee(!0);try{const Ge=u?.project.ownedDomains??[];await Bx(B,Ge.filter(gt=>gt!==re)),c()}finally{ee(!1)}}async function Dn(re,Ge){await V_(re,Ge),c()}const nn=re=>!Number.isNaN(Number.parseInt(re,10)),_t=[{key:"overview",label:"Overview",href:`/projects/${u.project.id}`},{key:"search-console",label:"Search Engine Intelligence",href:`/projects/${u.project.id}/search-console`},{key:"traffic",label:"Traffic",href:`/projects/${u.project.id}/traffic`},{key:"analytics",label:"Visibility",href:`/projects/${u.project.id}/analytics`}];return o.jsxs("div",{className:"page-container",children:[f?o.jsxs(Le,{className:"surface-card p-6 mb-6 border-rose-800/60",children:[o.jsx("h3",{className:"text-base font-semibold text-rose-400 mb-2",children:"Delete project?"}),o.jsxs("p",{className:"text-sm text-zinc-400 mb-4",children:["This will permanently delete ",o.jsx("strong",{className:"text-zinc-200",children:u.project.displayName||u.project.name})," and all its key phrases, competitors, runs, and snapshots. This cannot be undone."]}),o.jsxs("div",{className:"flex items-center gap-3",children:[o.jsx(oe,{type:"button",variant:"destructive",disabled:p,onClick:et,children:p?"Deleting...":"Yes, delete project"}),o.jsx(oe,{type:"button",variant:"outline",disabled:p,onClick:()=>m(!1),children:"Cancel"})]})]}):null,o.jsxs("div",{className:"page-header",children:[o.jsxs("div",{className:"page-header-left",children:[o.jsx("h1",{className:"page-title",children:u.project.displayName||u.project.name}),o.jsxs("p",{className:"page-subtitle",children:[u.project.canonicalDomain,(u.project.ownedDomains??[]).length===0&&!E&&o.jsx("button",{type:"button",className:"ml-2 text-[10px] uppercase tracking-wide text-zinc-600 hover:text-zinc-400 transition-colors",onClick:()=>L(!0),children:"+ add domain"})," "," · ",u.contextLabel]}),o.jsxs("div",{className:"tag-row",children:[o.jsx("span",{className:"tag",children:u.project.country}),o.jsx("span",{className:"tag",children:u.project.language.toUpperCase()}),u.project.tags.map(re=>o.jsx("span",{className:"tag",children:re},re))]}),((u.project.ownedDomains??[]).length>0||E)&&o.jsxs("div",{className:"mt-1.5 flex flex-wrap items-center gap-1.5",children:[o.jsx("span",{className:"text-[10px] uppercase tracking-wide text-zinc-500 mr-1",children:"Also tracking"}),(u.project.ownedDomains??[]).map(re=>o.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full border border-zinc-700/60 bg-zinc-800/40 px-2 py-0.5 text-xs text-zinc-300",children:[re,o.jsx("button",{type:"button",className:"ml-0.5 text-zinc-500 hover:text-zinc-200 transition-colors",disabled:Q,onClick:()=>$t(re),"aria-label":`Remove ${re}`,children:"×"})]},re)),E?o.jsxs("span",{className:"inline-flex items-center gap-1",children:[o.jsx("input",{className:"rounded border border-zinc-700 bg-transparent px-1.5 py-0.5 text-xs text-zinc-200 placeholder-zinc-600 focus:border-zinc-500 focus:outline-none w-40",type:"text",placeholder:"docs.example.com",value:U,onChange:re=>X(re.target.value),onKeyDown:re=>re.key==="Enter"&&Zt(),autoFocus:!0}),o.jsx(oe,{type:"button",size:"sm",disabled:!U.trim()||Q,onClick:Zt,children:Q?"...":"Add"}),o.jsx("button",{type:"button",className:"text-xs text-zinc-500 hover:text-zinc-300",onClick:()=>{L(!1),X("")},children:"Cancel"})]}):o.jsx("button",{type:"button",className:"rounded-full border border-dashed border-zinc-700 px-2 py-0.5 text-[10px] uppercase tracking-wide text-zinc-500 hover:text-zinc-300 hover:border-zinc-500 transition-colors",onClick:()=>L(!0),children:"+ domain"})]})]}),o.jsxs("div",{className:"page-header-right",children:[o.jsx("p",{className:"text-sm text-zinc-500",children:u.dateRangeLabel}),o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx(oe,{type:"button",variant:"outline",size:"icon",onClick:de,"aria-label":"Export project as YAML",children:o.jsx(tE,{className:"h-4 w-4 text-zinc-400"})}),o.jsx(oe,{type:"button",variant:"outline",size:"icon",onClick:()=>m(!0),"aria-label":"Delete project",children:o.jsx(SE,{className:"h-4 w-4 text-zinc-400"})}),o.jsx(oe,{type:"button",disabled:le.isPending,onClick:Ze,children:le.isPending?"Starting...":"Run now"})]})]})]}),o.jsx("nav",{className:"project-subnav","aria-label":"Project sections",children:_t.map(re=>o.jsx(St,{to:re.href,className:`project-subnav-link ${re.key===e?"project-subnav-link-active":""}`,"aria-current":re.key===e?"page":void 0,children:re.label},re.key))}),e==="overview"?o.jsxs(o.Fragment,{children:[o.jsxs("section",{className:"gauge-row",children:[o.jsx(IN,{value:u.visibilitySummary.value,label:u.visibilitySummary.label,delta:u.visibilitySummary.delta,tone:u.visibilitySummary.tone,description:u.visibilitySummary.description,tooltip:u.visibilitySummary.tooltip,isNumeric:nn(u.visibilitySummary.value),progress:u.visibilitySummary.progress}),o.jsxs("div",{className:"metric-card",children:[o.jsxs("p",{className:"metric-card-eyebrow",children:["Gap Key Phrases",o.jsx(ws,{text:"Tracked key phrases where competitors are cited in the latest completed visibility run but your domain is not."})]}),o.jsxs("p",{className:"metric-card-big-value",children:[o.jsx("span",{className:"text-zinc-50",children:u.gapKeyPhrases.value}),o.jsxs("span",{className:"text-zinc-600",children:[" / ",u.keywordCounts.total]})]}),o.jsx("div",{className:"metric-card-bar",children:o.jsx("div",{className:`metric-card-bar-fill progress-fill-${u.gapKeyPhrases.tone}`,style:{width:u.gapKeyPhrases.progress!==void 0?`${u.gapKeyPhrases.progress*100}%`:"0%"}})}),o.jsx("p",{className:"metric-card-detail",children:u.gapKeyPhrases.delta}),o.jsx("p",{className:"metric-card-sub",children:u.gapKeyPhrases.description})]}),o.jsxs("div",{className:"metric-card",children:[o.jsxs("p",{className:"metric-card-eyebrow",children:["Index Coverage",o.jsx(ws,{text:"Percentage of inspected URLs that are currently indexed. Google Search Console is preferred when available, otherwise Bing Webmaster Tools is used."})]}),o.jsxs("p",{className:"metric-card-big-value",children:[o.jsx("span",{className:"text-zinc-50",children:u.indexCoverage.value}),o.jsx("span",{className:"text-zinc-600",children:"%"})]}),o.jsx("div",{className:"metric-card-bar",children:o.jsx("div",{className:`metric-card-bar-fill progress-fill-${u.indexCoverage.tone}`,style:{width:`${Number.parseInt(u.indexCoverage.value,10)||0}%`}})}),o.jsx("p",{className:"metric-card-detail",children:u.indexCoverage.delta}),o.jsx("p",{className:"metric-card-sub",children:u.indexCoverage.description})]}),o.jsxs("div",{className:"metric-card",children:[o.jsxs("p",{className:"metric-card-eyebrow",children:["Since Last Run",o.jsx(ws,{text:"Keyword-level citation changes compared to the previous completed run."})]}),u.movementSummary.hasPreviousRun?o.jsxs("div",{className:"metric-card-movement",children:[o.jsxs("span",{className:u.movementSummary.gained>0?"text-emerald-400":"text-zinc-500",children:["+",u.movementSummary.gained," gained"]}),o.jsx("span",{className:"text-zinc-600 mx-1.5",children:"·"}),o.jsxs("span",{className:u.movementSummary.lost>0?"text-rose-400":"text-zinc-500",children:["−",u.movementSummary.lost," lost"]})]}):o.jsx("p",{className:"metric-card-movement text-zinc-500",children:"First run — no comparison yet"}),o.jsx("p",{className:"metric-card-sub mt-auto",children:u.movementSummary.gained===0&&u.movementSummary.lost===0&&u.movementSummary.hasPreviousRun?"No changes since last run":u.movementSummary.gained>u.movementSummary.lost?"Visibility improving":u.movementSummary.lost>u.movementSummary.gained?"Visibility declining":""})]})]}),u.providerScores.length>1&&o.jsxs("section",{className:"page-section-divider",children:[o.jsx("div",{className:"section-head section-head-inline",children:o.jsxs("div",{children:[o.jsx("p",{className:"eyebrow eyebrow-soft",children:"Model breakdown"}),o.jsxs("h2",{children:["Visibility by model ",o.jsx(ws,{text:"Per-model citation rate. Shows how often each AI model cites your domain across all tracked key phrases. Switching models can significantly affect citation rates."})]})]})}),o.jsx("div",{className:"evidence-table-wrap",children:o.jsxs("table",{className:"evidence-table",children:[o.jsx("thead",{children:o.jsxs("tr",{children:[o.jsx("th",{children:"Model"}),o.jsx("th",{children:"Score"}),o.jsx("th",{children:"Cited key phrases"})]})}),o.jsx("tbody",{children:u.providerScores.map(re=>o.jsxs("tr",{children:[o.jsx("td",{children:o.jsxs("div",{className:"flex flex-col items-start gap-0.5",children:[o.jsx(al,{provider:re.provider}),re.model&&o.jsx("span",{className:"text-[11px] font-mono text-zinc-500",children:re.model})]})}),o.jsx("td",{children:o.jsxs("span",{className:`font-semibold ${re.score>=70?"text-emerald-400":re.score>=40?"text-amber-400":"text-rose-400"}`,children:[re.score,"%"]})}),o.jsxs("td",{className:"text-zinc-500",children:[re.cited," of ",re.total]})]},`${re.provider}::${re.model??"unknown"}`))})]})})]}),o.jsxs("section",{className:"page-section-divider",children:[o.jsx("div",{className:"section-head section-head-inline",children:o.jsxs("div",{children:[o.jsx("p",{className:"eyebrow eyebrow-soft",children:"What changed"}),o.jsx("h2",{children:"Citation signals"})]})}),o.jsx(S$,{insights:u.insights})]}),o.jsxs("section",{className:"page-section-divider",children:[o.jsxs("div",{className:"section-head section-head-inline",children:[o.jsxs("div",{children:[o.jsx("p",{className:"eyebrow eyebrow-soft",children:"Visibility evidence"}),o.jsx("h2",{children:"Key phrase citation tracking"})]}),o.jsxs("div",{className:"flex items-center gap-3",children:[o.jsxs("p",{className:"supporting-copy",children:[new Set(u.visibilityEvidence.map(re=>re.keyword)).size," key phrases tracked"]}),o.jsx(oe,{type:"button",variant:"outline",size:"sm",onClick:()=>x(!y),children:y?"Cancel":"+ Add key phrases"})]})]}),y&&o.jsxs("div",{className:"mb-3 rounded-lg border border-zinc-800 bg-zinc-900/40 p-3",children:[o.jsx("textarea",{className:"w-full resize-none rounded border border-zinc-700 bg-transparent px-2 py-1.5 text-sm text-zinc-200 placeholder-zinc-600 focus:border-zinc-500 focus:outline-none",rows:3,placeholder:"Enter key phrases, one per line",value:b,onChange:re=>N(re.target.value)}),o.jsxs("div",{className:"mt-2 flex items-center justify-between",children:[o.jsxs("p",{className:"text-xs text-zinc-500",children:[b.split(`
|
|
238
238
|
`).filter(re=>re.trim()).length," key phrases"]}),o.jsx(oe,{type:"button",size:"sm",disabled:!b.trim()||S,onClick:Ve,children:S?"Adding...":"Add key phrases"})]})]}),u.project.locations&&u.project.locations.length>0&&o.jsxs("div",{className:"filter-row mb-3",role:"toolbar","aria-label":"Location filters",children:[o.jsx("button",{className:`filter-chip ${ue===void 0?"filter-chip-active":""}`,type:"button","aria-pressed":ue===void 0,onClick:()=>{ze(void 0)},children:"All locations"}),u.project.locations.map(re=>J.has(re.label)&&o.jsx("button",{className:`filter-chip ${ue===re.label?"filter-chip-active":""}`,type:"button","aria-pressed":ue===re.label,onClick:()=>{ze(re.label),K(!1)},children:re.label},re.label)),fe&&o.jsx("button",{className:`filter-chip ${ue===""?"filter-chip-active":""}`,type:"button","aria-pressed":ue==="",onClick:()=>{ze(""),K(!1)},children:"No location"}),ye.length>1&&ue===void 0&&o.jsx("button",{className:`filter-chip filter-chip-compare ${je?"filter-chip-active":""}`,type:"button","aria-pressed":je,onClick:()=>K(re=>!re),title:"Side-by-side location comparison",children:"Compare"})]}),o.jsx(Z3,{evidence:ge})]}),o.jsxs("section",{className:"page-section-divider",children:[o.jsxs("div",{className:"section-head section-head-inline",children:[o.jsxs("div",{children:[o.jsx("p",{className:"eyebrow eyebrow-soft",children:"Competitors"}),o.jsx("h2",{children:"Competitive landscape"})]}),o.jsxs("div",{className:"flex items-center gap-3",children:[o.jsxs("p",{className:"supporting-copy",children:[u.competitors.length," tracked"]}),o.jsx(oe,{type:"button",variant:"outline",size:"sm",onClick:()=>A(!k),children:k?"Cancel":"+ Add competitor"})]})]}),k&&o.jsxs("div",{className:"mb-3 flex gap-2 rounded-lg border border-zinc-800 bg-zinc-900/40 p-3",children:[o.jsx("input",{className:"flex-1 rounded border border-zinc-700 bg-transparent px-2 py-1.5 text-sm text-zinc-200 placeholder-zinc-600 focus:border-zinc-500 focus:outline-none",type:"text",placeholder:"competitor.com",value:R,onChange:re=>z(re.target.value),onKeyDown:re=>re.key==="Enter"&&at()}),o.jsx(oe,{type:"button",size:"sm",disabled:!R.trim()||O,onClick:at,children:O?"Adding...":"Add"})]}),o.jsx(V3,{competitors:u.competitors})]}),o.jsxs("section",{className:"page-section-divider",children:[o.jsx("div",{className:"section-head section-head-inline",children:o.jsxs("div",{children:[o.jsx("p",{className:"eyebrow eyebrow-soft",children:"Run timeline"}),o.jsx("h2",{children:"Recent execution history"})]})}),o.jsx("div",{className:"run-list",children:u.recentRuns.map(re=>o.jsx(UN,{run:re},re.id))})]}),o.jsx(m$,{project:{...u.project,displayName:u.project.displayName??u.project.name,defaultLocation:u.project.defaultLocation??null},onUpdateProject:Dn,onRefresh:()=>{c()}}),o.jsx(g$,{projectName:u.project.name}),o.jsx(v$,{projectName:u.project.name})]}):e==="analytics"?o.jsx(J3,{projectName:u.project.name}):e==="traffic"?o.jsx(n$,{projectName:u.project.name}):o.jsx(b$,{projectName:u.project.name})]})}function j$(){const{dashboard:e,isLoading:t}=Oa(),s=c$();if(!e||t)return o.jsxs("div",{className:"page-skeleton",children:[o.jsxs("div",{className:"page-skeleton-header",children:[o.jsx("div",{className:"skeleton-text h-6 w-20"}),o.jsx("div",{className:"skeleton-text-sm w-72"})]}),o.jsx("div",{className:"space-y-2",children:[1,2,3,4].map(m=>o.jsxs("div",{className:"rounded-xl border border-zinc-800/60 bg-zinc-900/30 p-3 flex items-center gap-3",children:[o.jsxs("div",{className:"flex-1 space-y-1.5",children:[o.jsx("div",{className:"skeleton-text w-40"}),o.jsx("div",{className:"skeleton-text-sm w-56"})]}),o.jsx("div",{className:"skeleton h-5 w-16 rounded-full"})]},m))})]});const a=e.runs,[r,c]=w.useState("all"),u=r==="all"?a:a.filter(m=>m.status===r),f=async()=>{try{await s.mutateAsync(void 0)}catch{}};return o.jsxs("div",{className:"page-container",children:[o.jsxs("div",{className:"page-header",children:[o.jsxs("div",{className:"page-header-left",children:[o.jsx("h1",{className:"page-title",children:"Runs"}),o.jsx("p",{className:"page-subtitle",children:"Status, type, project, duration, and the shortest explanation that makes the outcome trustworthy."})]}),o.jsx(oe,{type:"button",variant:"outline",size:"sm",disabled:s.isPending,onClick:()=>{f()},children:s.isPending?"Queueing…":"Run all projects"})]}),o.jsxs("section",{children:[o.jsx("div",{className:"filter-row",role:"toolbar","aria-label":"Run filters",children:["all","queued","running","completed","partial","failed","cancelled"].map(m=>o.jsx("button",{className:`filter-chip ${r===m?"filter-chip-active":""}`,type:"button","aria-pressed":r===m,onClick:()=>c(m),children:m==="all"?"All runs":Vu(m)},m))}),o.jsx("div",{className:"run-list",children:u.length>0?u.map(m=>o.jsx(UN,{run:m},m.id)):o.jsxs(Le,{className:"surface-card empty-card",children:[o.jsx("h2",{children:"No runs match this filter"}),o.jsx("p",{children:"Try another status filter or queue a new run from a project command center."})]})})]})]})}function w$({providerName:e,keyUrl:t,modelHint:s,onSaved:a}){const r=e.toLowerCase()==="local",[c,u]=w.useState(""),[f,m]=w.useState(""),[p,v]=w.useState(""),[y,x]=w.useState(""),[b,N]=w.useState(""),[S,C]=w.useState(""),[k,A]=w.useState(!1),[R,z]=w.useState(null),[O,M]=w.useState(!1),E=r?f.trim().length>0:c.trim().length>0;async function L(){if(E){A(!0),z(null),M(!1);try{const X=je=>{const K=parseInt(je.trim(),10);return Number.isFinite(K)&&K>0?K:void 0},Q={},ee=X(y);ee!==void 0&&(Q.maxConcurrency=ee);const ue=X(b);ue!==void 0&&(Q.maxRequestsPerMinute=ue);const ze=X(S);ze!==void 0&&(Q.maxRequestsPerDay=ze),await i2(e.toLowerCase(),{...c.trim()?{apiKey:c.trim()}:{},...f.trim()?{baseUrl:f.trim()}:{},...p.trim()?{model:p.trim()}:{},...Object.keys(Q).length>0?{quota:Q}:{}}),u(""),m(""),v(""),x(""),N(""),C(""),M(!0),Ke({title:"Provider updated",detail:`${e} configuration saved.`,tone:"positive",dedupeKey:`settings:provider:${e}`,dedupeMode:"replace"}),a()}catch(X){z(X instanceof Error?X.message:"Failed to update provider")}finally{A(!1)}}}const U=s??"Use default model";return o.jsxs("div",{className:"mt-3 rounded-lg border border-zinc-800 bg-zinc-900/40 p-3 space-y-2",children:[r&&o.jsxs("div",{children:[o.jsx("label",{className:"text-xs text-zinc-500",htmlFor:`base-url-${e}`,children:"Base URL"}),o.jsx("input",{id:`base-url-${e}`,type:"text",className:"mt-0.5 w-full rounded border border-zinc-700 bg-transparent px-2 py-1.5 text-sm text-zinc-200 placeholder-zinc-600 focus:border-zinc-500 focus:outline-none",placeholder:"http://localhost:11434/v1",value:f,onChange:X=>m(X.target.value)}),o.jsx("p",{className:"mt-0.5 text-[10px] text-zinc-600",children:"Any OpenAI-compatible endpoint — Ollama, LM Studio, llama.cpp, vLLM"})]}),o.jsxs("div",{children:[o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsxs("label",{className:"text-xs text-zinc-500",htmlFor:`api-key-${e}`,children:["API Key",r?" (optional)":""]}),t&&o.jsxs("a",{href:t,target:"_blank",rel:"noopener noreferrer",className:"text-[10px] text-zinc-500 hover:text-zinc-300 underline underline-offset-2",children:["Get API key ","↗"]})]}),o.jsx("input",{id:`api-key-${e}`,type:"password",className:"mt-0.5 w-full rounded border border-zinc-700 bg-transparent px-2 py-1.5 text-sm text-zinc-200 placeholder-zinc-600 focus:border-zinc-500 focus:outline-none",placeholder:r?"Optional — most local servers don't need one":`Enter ${e} API key`,value:c,onChange:X=>u(X.target.value)})]}),o.jsxs("div",{children:[o.jsx("label",{className:"text-xs text-zinc-500",htmlFor:`model-${e}`,children:"Model (optional)"}),o.jsx("input",{id:`model-${e}`,type:"text",className:"mt-0.5 w-full rounded border border-zinc-700 bg-transparent px-2 py-1.5 text-sm text-zinc-200 placeholder-zinc-600 focus:border-zinc-500 focus:outline-none",placeholder:U,value:p,onChange:X=>v(X.target.value)})]}),o.jsxs("div",{children:[o.jsx("label",{className:"text-xs text-zinc-500",children:"Quota (optional)"}),o.jsxs("div",{className:"mt-0.5 grid grid-cols-3 gap-1.5",children:[o.jsxs("div",{children:[o.jsx("input",{type:"number",min:"1",className:"w-full rounded border border-zinc-700 bg-transparent px-2 py-1.5 text-sm text-zinc-200 placeholder-zinc-600 focus:border-zinc-500 focus:outline-none",placeholder:"Concurrent",value:y,onChange:X=>x(X.target.value)}),o.jsx("p",{className:"mt-0.5 text-[10px] text-zinc-600",children:"Max concurrent"})]}),o.jsxs("div",{children:[o.jsx("input",{type:"number",min:"1",className:"w-full rounded border border-zinc-700 bg-transparent px-2 py-1.5 text-sm text-zinc-200 placeholder-zinc-600 focus:border-zinc-500 focus:outline-none",placeholder:"/min",value:b,onChange:X=>N(X.target.value)}),o.jsx("p",{className:"mt-0.5 text-[10px] text-zinc-600",children:"Per minute"})]}),o.jsxs("div",{children:[o.jsx("input",{type:"number",min:"1",className:"w-full rounded border border-zinc-700 bg-transparent px-2 py-1.5 text-sm text-zinc-200 placeholder-zinc-600 focus:border-zinc-500 focus:outline-none",placeholder:"/day",value:S,onChange:X=>C(X.target.value)}),o.jsx("p",{className:"mt-0.5 text-[10px] text-zinc-600",children:"Per day"})]})]})]}),R&&o.jsx("p",{className:"text-xs text-rose-400",children:R}),O&&o.jsx("p",{className:"text-xs text-emerald-400",children:"Provider updated."}),o.jsx(oe,{type:"button",size:"sm",disabled:!E||k,onClick:L,children:k?"Saving...":"Save"})]})}function N$({onSaved:e}){const[t,s]=w.useState(""),[a,r]=w.useState(""),[c,u]=w.useState(!1),[f,m]=w.useState(null),[p,v]=w.useState(!1),y=t.trim().length>0&&a.trim().length>0;async function x(){if(y){u(!0),m(null),v(!1);try{await a2({clientId:t.trim(),clientSecret:a.trim()}),s(""),r(""),v(!0),Ke({title:"Google OAuth app updated",detail:"Dashboard Google credentials were saved.",tone:"positive",dedupeKey:"settings:google-oauth",dedupeMode:"replace"}),e()}catch(b){m(b instanceof Error?b.message:"Failed to update Google OAuth credentials")}finally{u(!1)}}}return o.jsxs("div",{className:"mt-3 rounded-lg border border-zinc-800 bg-zinc-900/40 p-3 space-y-2",children:[o.jsxs("div",{children:[o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx("label",{className:"text-xs text-zinc-500",htmlFor:"google-client-id",children:"Client ID"}),o.jsx("a",{href:"https://console.cloud.google.com/apis/credentials",target:"_blank",rel:"noopener noreferrer",className:"text-[10px] text-zinc-500 hover:text-zinc-300 underline underline-offset-2",children:"Google Cloud \\u2197"})]}),o.jsx("input",{id:"google-client-id",type:"text",className:"mt-0.5 w-full rounded border border-zinc-700 bg-transparent px-2 py-1.5 text-sm text-zinc-200 placeholder-zinc-600 focus:border-zinc-500 focus:outline-none",placeholder:"Google OAuth client ID",value:t,onChange:b=>s(b.target.value)})]}),o.jsxs("div",{children:[o.jsx("label",{className:"text-xs text-zinc-500",htmlFor:"google-client-secret",children:"Client secret"}),o.jsx("input",{id:"google-client-secret",type:"password",className:"mt-0.5 w-full rounded border border-zinc-700 bg-transparent px-2 py-1.5 text-sm text-zinc-200 placeholder-zinc-600 focus:border-zinc-500 focus:outline-none",placeholder:"Google OAuth client secret",value:a,onChange:b=>r(b.target.value)})]}),o.jsxs("p",{className:"text-[11px] text-zinc-500",children:["These credentials are stored in ",o.jsx("code",{children:"~/.canonry/config.yaml"}),". Project-level Search Console connections are created separately per canonical domain."]}),f&&o.jsx("p",{className:"text-xs text-rose-400",children:f}),p&&o.jsx("p",{className:"text-xs text-emerald-400",children:"Google OAuth credentials updated."}),o.jsx(oe,{type:"button",size:"sm",disabled:!y||c,onClick:x,children:c?"Saving...":"Save Google OAuth app"})]})}function C$(){const[e,t]=w.useState(null),[s,a]=w.useState(null),[r,c]=w.useState(!1),[u,f]=w.useState("localhost"),[m,p]=w.useState("9222"),[v,y]=w.useState(!1);return w.useEffect(()=>{Hx().then(t).catch(x=>{const b=x instanceof Error?x.message:String(x);b.includes("501")||a(b)})},[]),o.jsxs(Le,{className:"surface-card",children:[o.jsxs("div",{className:"section-head",children:[o.jsxs("div",{children:[o.jsx("p",{className:"eyebrow eyebrow-soft",children:"Browser provider"}),o.jsx("h2",{children:"ChatGPT (CDP)"})]}),o.jsx(lt,{tone:e?.connected?"positive":"caution",children:e?.connected?"Connected":"Not connected"})]}),o.jsxs("dl",{className:"definition-list mt-3",children:[e?.endpoint&&o.jsxs("div",{children:[o.jsx("dt",{children:"Endpoint"}),o.jsx("dd",{className:"font-mono text-xs",children:e.endpoint})]}),e?.browserVersion&&o.jsxs("div",{children:[o.jsx("dt",{children:"Browser"}),o.jsx("dd",{className:"text-xs",children:e.browserVersion})]}),e?.targets&&e.targets.length>0&&o.jsxs("div",{children:[o.jsx("dt",{children:"Tabs"}),o.jsx("dd",{children:e.targets.map(x=>o.jsxs("span",{className:"mr-2",children:[x.name,": ",x.alive?"● alive":"○ idle"]},x.name))})]})]}),o.jsx("p",{className:"mt-2 text-sm text-zinc-500",children:e?.connected?"Connected to Chrome via CDP. Launch Chrome with --remote-debugging-port to use this provider.":s||"Not configured. Set an endpoint below or run: canonry cdp connect --host localhost --port 9222"}),o.jsx("div",{className:"mt-2",children:o.jsx(oe,{type:"button",variant:"outline",size:"sm",onClick:()=>c(!r),children:r?"Cancel":e?.connected?"Update endpoint":"Configure"})}),r&&o.jsxs("form",{className:"mt-3 flex flex-col gap-2",onSubmit:async x=>{x.preventDefault(),y(!0);try{await _2(u,parseInt(m,10)||9222);const b=await Hx().catch(()=>null);b&&t(b),c(!1),Ke({title:"CDP endpoint saved",detail:`${u}:${parseInt(m,10)||9222} is now configured.`,tone:"positive",dedupeKey:"settings:cdp",dedupeMode:"replace"})}catch(b){a(b instanceof Error?b.message:String(b))}finally{y(!1)}},children:[o.jsxs("div",{className:"flex gap-2",children:[o.jsx("input",{className:"flex-1 rounded border border-zinc-700 bg-zinc-900 px-2 py-1 text-sm text-zinc-100 placeholder-zinc-500 focus:outline-none focus:ring-1 focus:ring-zinc-500",placeholder:"localhost",value:u,onChange:x=>f(x.target.value),"aria-label":"CDP host"}),o.jsx("input",{className:"w-24 rounded border border-zinc-700 bg-zinc-900 px-2 py-1 text-sm text-zinc-100 placeholder-zinc-500 focus:outline-none focus:ring-1 focus:ring-zinc-500",placeholder:"9222",value:m,onChange:x=>p(x.target.value),"aria-label":"CDP port"})]}),o.jsx("div",{children:o.jsx(oe,{type:"submit",size:"sm",disabled:v,children:v?"Saving…":"Save endpoint"})})]})]})}const k$={apiStatus:{state:"checking",detail:"Checking service health"},workerStatus:{state:"checking",detail:"Checking service health"}};function z$(){const e=pl(),{dashboard:t}=Oa(),s=t?.settings??e?.dashboard?.settings,c=ad(!e,e?.health).data??e?.health??k$,[u,f]=w.useState(null),[m,p]=w.useState(!1),[v,y]=w.useState(!1),[x,b]=w.useState(""),[N,S]=w.useState(!1),[C,k]=w.useState(null),[A,R]=w.useState(!1);return s?o.jsxs("div",{className:"page-container",children:[o.jsx("div",{className:"page-header",children:o.jsxs("div",{className:"page-header-left",children:[o.jsx("h1",{className:"page-title",children:"Settings"}),o.jsx("p",{className:"page-subtitle",children:"Provider state, Google OAuth, Bing WMT setup, and service health."})]})}),o.jsxs("section",{className:"settings-grid",children:[s.providerStatuses.map(z=>o.jsxs(Le,{className:"surface-card",children:[o.jsxs("div",{className:"section-head",children:[o.jsxs("div",{children:[o.jsx("p",{className:"eyebrow eyebrow-soft",children:"Provider"}),o.jsx("h2",{children:z.displayName??z.name})]}),o.jsx(lt,{tone:z.state==="ready"?"positive":"caution",children:z.state==="ready"?"Ready":"Needs config"})]}),o.jsxs("dl",{className:"definition-list mt-3",children:[o.jsxs("div",{children:[o.jsx("dt",{children:"Model"}),o.jsx("dd",{className:"font-mono text-xs",children:z.model})]}),z.quota&&o.jsxs(o.Fragment,{children:[o.jsxs("div",{children:[o.jsx("dt",{children:"Concurrency"}),o.jsx("dd",{children:z.quota.maxConcurrency})]}),o.jsxs("div",{children:[o.jsx("dt",{children:"Rate limit"}),o.jsxs("dd",{children:[z.quota.maxRequestsPerMinute,"/min · ",z.quota.maxRequestsPerDay,"/day"]})]})]})]}),o.jsx("p",{className:"mt-2 text-sm text-zinc-500",children:z.detail}),o.jsx("div",{className:"mt-2",children:o.jsx(oe,{type:"button",variant:"outline",size:"sm",onClick:()=>f(u===z.name?null:z.name),children:u===z.name?"Cancel":z.state==="ready"?z.name.toLowerCase()==="local"?"Update config":"Update key":"Configure"})}),u===z.name&&o.jsx(w$,{providerName:z.name,keyUrl:z.keyUrl,modelHint:z.modelHint,onSaved:()=>{f(null)}})]},z.name)),o.jsxs(Le,{className:"surface-card",children:[o.jsxs("div",{className:"section-head",children:[o.jsxs("div",{children:[o.jsx("p",{className:"eyebrow eyebrow-soft",children:"Google"}),o.jsx("h2",{children:"Search Console OAuth"})]}),o.jsx(lt,{tone:s.google.state==="ready"?"positive":"caution",children:s.google.state==="ready"?"Ready":"Needs config"})]}),o.jsxs("dl",{className:"definition-list mt-3",children:[o.jsxs("div",{children:[o.jsx("dt",{children:"Auth model"}),o.jsx("dd",{children:"One app credential set, then one OAuth connection per project domain"})]}),o.jsxs("div",{children:[o.jsx("dt",{children:"Storage"}),o.jsx("dd",{className:"font-mono text-xs",children:"~/.canonry/config.yaml"})]})]}),o.jsx("p",{className:"mt-2 text-sm text-zinc-500",children:s.google.detail}),o.jsx("div",{className:"mt-2",children:o.jsx(oe,{type:"button",variant:"outline",size:"sm",onClick:()=>p(!m),children:m?"Cancel":s.google.state==="ready"?"Update OAuth app":"Configure Google OAuth"})}),m&&o.jsx(N$,{onSaved:()=>{p(!1)}})]}),o.jsxs(Le,{className:"surface-card",children:[o.jsxs("div",{className:"section-head",children:[o.jsxs("div",{children:[o.jsx("p",{className:"eyebrow eyebrow-soft",children:"Bing"}),o.jsx("h2",{children:"Webmaster Tools"})]}),o.jsx(lt,{tone:s.bing.state==="ready"?"positive":"caution",children:s.bing.state==="ready"?"Ready":"Needs config"})]}),o.jsxs("dl",{className:"definition-list mt-3",children:[o.jsxs("div",{children:[o.jsx("dt",{children:"Auth model"}),o.jsx("dd",{children:"API key authentication — no OAuth needed"})]}),o.jsxs("div",{children:[o.jsx("dt",{children:"Storage"}),o.jsx("dd",{className:"font-mono text-xs",children:"~/.canonry/config.yaml"})]})]}),o.jsx("p",{className:"mt-2 text-sm text-zinc-500",children:s.bing.detail}),o.jsx("div",{className:"mt-2",children:o.jsx(oe,{type:"button",variant:"outline",size:"sm",onClick:()=>y(!v),children:v?"Cancel":s.bing.state==="ready"?"Update API key":"Configure Bing"})}),v&&o.jsxs("div",{className:"mt-3 rounded-lg border border-zinc-800 bg-zinc-900/40 p-3 space-y-2",children:[o.jsxs("div",{children:[o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsx("label",{className:"text-xs text-zinc-500",htmlFor:"bing-api-key",children:"API Key"}),o.jsx("a",{href:"https://www.bing.com/webmasters/",target:"_blank",rel:"noopener noreferrer",className:"text-[10px] text-zinc-500 hover:text-zinc-300 underline underline-offset-2",children:"Bing Webmaster Tools"})]}),o.jsx("input",{id:"bing-api-key",type:"password",className:"mt-0.5 w-full rounded border border-zinc-700 bg-transparent px-2 py-1.5 text-sm text-zinc-200 placeholder-zinc-600 focus:border-zinc-500 focus:outline-none",placeholder:"Bing Webmaster Tools API key",value:x,onChange:z=>b(z.target.value)})]}),o.jsxs("p",{className:"text-[11px] text-zinc-500",children:["This key is stored in ",o.jsx("code",{children:"~/.canonry/config.yaml"}),". Project-level Bing connections are created separately per canonical domain."]}),C&&o.jsx("p",{className:"text-xs text-rose-400",children:C}),A&&o.jsx("p",{className:"text-xs text-emerald-400",children:"Bing API key updated."}),o.jsx(oe,{type:"button",size:"sm",disabled:!x.trim()||N,onClick:async()=>{if(x.trim()){S(!0),k(null),R(!1);try{await L2(x.trim()),b(""),R(!0),y(!1),Ke({title:"Bing API key updated",detail:"Dashboard Bing credentials were saved.",tone:"positive",dedupeKey:"settings:bing",dedupeMode:"replace"})}catch(z){k(z instanceof Error?z.message:"Failed to update Bing API key")}finally{S(!1)}}},children:N?"Saving...":"Save Bing API key"})]})]}),o.jsx(C$,{}),o.jsxs(Le,{className:"surface-card",children:[o.jsx("div",{className:"section-head",children:o.jsxs("div",{children:[o.jsx("p",{className:"eyebrow eyebrow-soft",children:"Service health"}),o.jsx("h2",{children:"API and worker"})]})}),o.jsxs("div",{className:"compact-stack",children:[o.jsxs("div",{className:"health-row",children:[o.jsxs("div",{children:[o.jsx("p",{className:"run-row-title",children:"API"}),o.jsx("p",{className:"supporting-copy",children:c.apiStatus.detail})]}),o.jsx(lt,{tone:Ru(c.apiStatus),children:c.apiStatus.state==="ok"?"Healthy":"Attention"})]}),o.jsxs("div",{className:"health-row",children:[o.jsxs("div",{children:[o.jsx("p",{className:"run-row-title",children:"Worker"}),o.jsx("p",{className:"supporting-copy",children:c.workerStatus.detail})]}),o.jsx(lt,{tone:Ru(c.workerStatus),children:c.workerStatus.state==="ok"?"Healthy":"Attention"})]})]})]})]}),o.jsx("section",{className:"page-section",children:o.jsxs(Le,{className:"surface-card",children:[o.jsx("div",{className:"section-head",children:o.jsxs("div",{children:[o.jsx("p",{className:"eyebrow eyebrow-soft",children:"Self-host notes"}),o.jsx("h2",{children:"Operational guidance"})]})}),o.jsx("ul",{className:"detail-list",children:s.selfHostNotes.map(z=>o.jsx("li",{children:z},z))}),o.jsx("p",{className:"supporting-copy",children:s.bootstrapNote})]})})]}):null}const _$=[{label:"System check",description:"Verify your instance is ready"},{label:"Create project",description:"Name, domain, and locale"},{label:"Key phrases",description:"Add key phrases to track"},{label:"Competitors",description:"Add competitor domains"},{label:"Launch",description:"Start your first visibility sweep"}];function E$({current:e,labels:t}){return o.jsx("div",{className:"setup-steps",role:"list","aria-label":"Setup progress",children:t.map((s,a)=>{const r=a<e,c=a===e;return o.jsxs("div",{className:`setup-step ${r?"setup-step-done":""} ${c?"setup-step-active":""}`,role:"listitem","aria-current":c?"step":void 0,children:[o.jsx("span",{className:"setup-step-number",children:r?"✓":a+1}),o.jsx("span",{className:"setup-step-label",children:s.label})]},s.label)})})}function R$(){const e=pl(),{dashboard:t,isLoading:s,refetch:a}=Oa(),r=t??e?.dashboard;if(!r||s)return o.jsxs("div",{className:"page-skeleton",children:[o.jsxs("div",{className:"page-skeleton-header",children:[o.jsx("div",{className:"skeleton-text h-6 w-24"}),o.jsx("div",{className:"skeleton-text-sm w-80"})]}),o.jsxs("div",{className:"page-skeleton-card",children:[o.jsx("div",{className:"skeleton-text w-32"}),o.jsx("div",{className:"space-y-3 mt-3",children:[1,2,3].map(ce=>o.jsxs("div",{className:"flex items-center justify-between",children:[o.jsxs("div",{className:"space-y-1 flex-1",children:[o.jsx("div",{className:"skeleton-text w-24"}),o.jsx("div",{className:"skeleton-text-sm w-48"})]}),o.jsx("div",{className:"skeleton h-6 w-16 rounded-full"})]},ce))})]})]});const c=r.settings,m=ad(!e,e?.health).data??e?.health??{apiStatus:{label:"API",state:"checking",detail:"Checking service health"},workerStatus:{label:"Worker",state:"checking",detail:"Checking service health"}},p=A4(r.setup,m,c),v=Ii(),[y,x]=w.useState(0),[b,N]=w.useState(""),[S,C]=w.useState(""),[k,A]=w.useState(""),[R,z]=w.useState("US"),[O,M]=w.useState("en"),[E,L]=w.useState(null),[U,X]=w.useState(null),[Q,ee]=w.useState(null),[ue,ze]=w.useState(!1),[je,K]=w.useState(""),[ae,me]=w.useState(!1),[V,H]=w.useState(null),[T,B]=w.useState(!1),se=c.providerStatuses.filter(ce=>ce.state==="ready"),[le,J]=w.useState(se[0]?.name??""),[fe,ye]=w.useState(5),[_e,ge]=w.useState(!1),[Ze,et]=w.useState(null),[de,Ve]=w.useState(""),[at,Zt]=w.useState(!1),[$t,Dn]=w.useState(null),[nn,_t]=w.useState(!1),[re,Ge]=w.useState(!1),[gt,Vt]=w.useState(!1),Qe=qN(),De=b.toLowerCase().replace(/[^a-z0-9-]/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,""),Ye=je.split(`
|
|
239
239
|
`).map(ce=>ce.trim()).filter(Boolean),Nt=de.split(`
|
package/assets/index.html
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
<link rel="icon" type="image/png" sizes="32x32" href="./favicon-32.png" />
|
|
13
13
|
<link rel="apple-touch-icon" href="./apple-touch-icon.png" />
|
|
14
14
|
<title>Canonry</title>
|
|
15
|
-
<script type="module" crossorigin src="./assets/index-
|
|
15
|
+
<script type="module" crossorigin src="./assets/index-CIHb8Gk8.js"></script>
|
|
16
16
|
<link rel="stylesheet" crossorigin href="./assets/index-DwPC0zVy.css">
|
|
17
17
|
</head>
|
|
18
18
|
<body>
|
|
@@ -7345,7 +7345,7 @@ async function bingRoutes(app, opts) {
|
|
|
7345
7345
|
query: s.Query,
|
|
7346
7346
|
impressions: s.Impressions,
|
|
7347
7347
|
clicks: s.Clicks,
|
|
7348
|
-
ctr: s.Ctr,
|
|
7348
|
+
ctr: Number.isFinite(s.Ctr) ? s.Ctr : 0,
|
|
7349
7349
|
averagePosition: s.AverageClickPosition ?? s.AverageImpressionPosition ?? 0
|
|
7350
7350
|
}));
|
|
7351
7351
|
});
|
package/dist/cli.js
CHANGED
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ainyc/canonry",
|
|
3
|
-
"version": "1.28.
|
|
3
|
+
"version": "1.28.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "The ultimate open-source AEO monitoring tool - track how answer engines cite your domain",
|
|
6
6
|
"license": "FSL-1.1-ALv2",
|
|
@@ -52,19 +52,19 @@
|
|
|
52
52
|
"@types/node-cron": "^3.0.11",
|
|
53
53
|
"tsup": "^8.5.1",
|
|
54
54
|
"tsx": "^4.19.0",
|
|
55
|
-
"@ainyc/canonry-config": "0.0.0",
|
|
56
55
|
"@ainyc/canonry-api-routes": "0.0.0",
|
|
56
|
+
"@ainyc/canonry-config": "0.0.0",
|
|
57
57
|
"@ainyc/canonry-db": "0.0.0",
|
|
58
|
-
"@ainyc/canonry-provider-claude": "0.0.0",
|
|
59
58
|
"@ainyc/canonry-provider-gemini": "0.0.0",
|
|
60
|
-
"@ainyc/canonry-
|
|
59
|
+
"@ainyc/canonry-provider-claude": "0.0.0",
|
|
61
60
|
"@ainyc/canonry-provider-cdp": "0.0.0",
|
|
62
|
-
"@ainyc/canonry-
|
|
61
|
+
"@ainyc/canonry-contracts": "0.0.0",
|
|
63
62
|
"@ainyc/canonry-integration-bing": "0.0.0",
|
|
64
|
-
"@ainyc/canonry-
|
|
63
|
+
"@ainyc/canonry-provider-local": "0.0.0",
|
|
65
64
|
"@ainyc/canonry-integration-wordpress": "0.0.0",
|
|
66
|
-
"@ainyc/canonry-provider-
|
|
67
|
-
"@ainyc/canonry-
|
|
65
|
+
"@ainyc/canonry-provider-openai": "0.0.0",
|
|
66
|
+
"@ainyc/canonry-integration-google": "0.0.0",
|
|
67
|
+
"@ainyc/canonry-provider-perplexity": "0.0.0"
|
|
68
68
|
},
|
|
69
69
|
"scripts": {
|
|
70
70
|
"build": "tsup && tsx build-web.ts",
|