1import{t as G,h as E,f as N,r as g,i as K,j as e,af as s,B as S,c as q,V as I,ah as U,L as z}from"./index-BBoqvoq_.js";import{t as m}from"./index-DQig6sn5.js";import{T as J}from"./sonner-Davet4ay.js";import{d as X,s as Y,a as Z,r as ee,b as se,c as te,e as H,f as ae,h as le,i as re,j as oe,l as ne,p as ie,k as ce,m as de,n as me,o as xe}from"./political-monitoring.functions-DU3LVJnG.js";import{S as ue}from"./shield-alert-DxPZGw6x.js";import{C as pe}from"./circle-check-BDKlHp6R.js";import{T as he}from"./triangle-alert-Bc-MM6DZ.js";import{P as ye}from"./pause-ByQmxbZA.js";import{P as ge}from"./play-D8qLbwLO.js";import{r as fe}from"./election-review.functions-DQ96zwTV.js";import{C as be,P as je}from"./PoliticalTopicDepthPanel-I5nxuqTj.js";import{A as Ne}from"./arrow-left-RMPIXC-k.js";import"./demo-write-middleware-Dn-Ho4yG.js";const ve=[["path",{d:"M4.9 16.1C1 12.2 1 5.8 4.9 1.9",key:"s0qx1y"}],["path",{d:"M7.8 4.7a6.14 6.14 0 0 0-.8 7.5",key:"1idnkw"}],["circle",{cx:"12",cy:"9",r:"2",key:"1092wv"}],["path",{d:"M16.2 4.8c2 2 2.26 5.11.8 7.47",key:"ojru2q"}],["path",{d:"M19.1 1.9a9.96 9.96 0 0 1 0 14.1",key:"rhi7fg"}],["path",{d:"M9.5 18h5",key:"mfy3pd"}],["path",{d:"m8 22 4-11 4 11",key:"25yftu"}]],we=G("radio-tower",ve);const Ce=[["path",{d:"m10.586 5.414-5.172 5.172",key:"4mc350"}],["path",{d:"m18.586 13.414-5.172 5.172",key:"8c96vv"}],["path",{d:"M6 12h12",key:"8npq4p"}],["circle",{cx:"12",cy:"20",r:"2",key:"144qzu"}],["circle",{cx:"12",cy:"4",r:"2",key:"muu5ef"}],["circle",{cx:"20",cy:"12",r:"2",key:"1xzzfp"}],["circle",{cx:"4",cy:"12",r:"2",key:"1hvhnz"}]],Se=G("waypoints",Ce),ke=["hashtag","phrase","issue","party_acronym"];function Pe(o,w){const b=new Map(w.map(d=>[`${d.kind}:${d.normalized}`,d])),h=new Map;for(const d of o){const x=b.get(`${d.kind}:${d.normalized}`),u=x?.termClass??(d.kind==="hashtag"?"hashtag_phrase":d.kind==="party_acronym"?"party_acronym":"election_context"),f=h.get(u)??[];f.push({...d,matchingPolicy:x?.matchingPolicy??"context_signal_review_required",queryable:x?.queryable??!1}),h.set(u,f)}return["election_context","candidate","party","party_acronym","hashtag_phrase"].filter(d=>h.has(d)).map(d=>({termClass:d,terms:h.get(d)}))}const Te={backgroundColor:s.cardBg,borderColor:s.border},Me={election_context:"Election context",candidate:"Candidates",party:"Parties",party_acronym:"Party acronyms (context signal only)",hashtag_phrase:"Hashtags & phrases"};function qe({profileId:o,profileStatus:w,terms:b}){const h=E(),j=N(X),d=N(Y),x=N(Z),u=N(ee),f=N(se),[c,l]=g.useState(null),[C,_]=g.useState(null),[r,t]=g.useState(null),[i,k]=g.useState(null),v=K({queryKey:["political-term-set",o],queryFn:()=>j({data:{profileId:o}}),retry:!1}),T=v.data?.proposals??[],M=g.useMemo(()=>Pe(b,T),[b,T]),n=g.useCallback(()=>{h.invalidateQueries({queryKey:["political-monitoring-profiles"]}),h.invalidateQueries({queryKey:["political-term-set",o]}),h.invalidateQueries({queryKey:["political-corpus-readiness"]}),h.invalidateQueries({queryKey:["political-monitoring-audit"]})},[h,o]),B=g.useCallback(async(p,y,O)=>{l(p);try{const A=await y();return A.refusal?m.error(A.refusal):m.success(O),n(),A}catch(A){return m.error(A instanceof Error?A.message:"Action failed"),null}finally{l(null)}},[n]);return e.jsxs("section",{className:"rounded-2xl border p-6",style:Te,children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-widest",style:{color:s.gold},children:"Gate 4.10C â political-term-set-v1.0.0"}),e.jsx("h2",{className:"mt-1 text-sm font-semibold",style:{color:s.textPrimary},children:"Governed term set & shared ingestion binding"}),e.jsx("p",{className:"mt-1 max-w-2xl text-xs leading-relaxed",style:{color:s.textSecondary},children:"Terms are derived only from the governed contest key and published roster. Candidate and party queries are always bound to the governed geographic context; acronyms and surnames are discovery signals that require human review and are never queried on their own. Collection uses the shared news/web connectors, canonical dedupe and the existing sentiment pipeline. Nothing here admits evidence."})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(S,{size:"sm",disabled:c!==null,onClick:()=>B("seed",()=>d({data:{profileId:o}}),"Governed term set seeded"),children:[c==="seed"?e.jsx(q,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(I,{className:"mr-2 h-4 w-4"}),"Seed term set"]}),e.jsxs(S,{size:"sm",variant:"outline",disabled:c!==null,onClick:async()=>{const p=await B("sync",()=>x({data:{profileId:o}}
1),"Bound to shared ingestion");p&&_(p)},children:[c==="sync"?e.jsx(q,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(Se,{className:"mr-2 h-4 w-4"}),"Bind to shared ingestion"]}),e.jsxs(S,{size:"sm",variant:"outline",disabled:c!==null||w!=="active",onClick:async()=>{const p=await B("collect",()=>u({data:{profileId:o}}),"Collection run complete");p&&t(p)},children:[c==="collect"?e.jsx(q,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(we,{className:"mr-2 h-4 w-4"}),"Run collection now"]}),e.jsxs(S,{size:"sm",variant:"outline",disabled:c!==null,onClick:async()=>{const p=await B("enrich",()=>f({data:{profileId:o}}),"Article evidence enrichment complete");p&&k(p)},children:[c==="enrich"?e.jsx(q,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(U,{className:"mr-2 h-4 w-4"}),"Enrich article evidence"]})]})]}),w!=="active"?e.jsxs("p",{className:"mt-3 text-[11px]",style:{color:s.gold},children:["Profile is ",w," â query generation is paused. Terms and history are retained."]}):null,v.isLoading?e.jsxs("p",{className:"mt-4 flex items-center gap-2 text-xs",style:{color:s.textSecondary},children:[e.jsx(q,{className:"h-3.5 w-3.5 animate-spin"})," Deriving governed termsâ¦"]}):v.data?.refusal?e.jsx("p",{className:"mt-4 text-xs",style:{color:s.gold},children:v.data.refusal}):e.jsxs("div",{className:"mt-5 grid gap-4 lg:grid-cols-2",children:[M.map(p=>e.jsxs("div",{className:"rounded-xl border p-3",style:{borderColor:s.border},children:[e.jsxs("p",{className:"text-[10px] uppercase tracking-widest",style:{color:s.textMuted},children:[Me[p.termClass]," · ",p.terms.length]}),e.jsx("ul",{className:"mt-2 space-y-1",children:p.terms.map(y=>e.jsxs("li",{className:"flex items-center justify-between gap-2 text-xs",style:{color:s.textSecondary},children:[e.jsx("span",{className:"font-data",children:y.kind==="hashtag"?`#${y.value}`:y.value}),e.jsxs("span",{className:"text-[10px]",style:{color:y.enabled?s.gold:s.textMuted},children:[y.enabled?"enabled":"disabled"," · ",y.queryable?"queried":"context only"," · ",y.provenance.source]})]},y.termId))})]},p.termClass)),M.length===0?e.jsxs("p",{className:"text-xs",style:{color:s.textSecondary},children:["No term is stored on this profile yet. Seed the governed term set to propose"," ",(v.data?.proposals??[]).length," reviewed terms."]}):null]}),i?e.jsxs("div",{className:"mt-3 rounded-xl border p-3 text-[11px]",style:{borderColor:s.border},children:[e.jsxs("p",{className:"font-data",style:{color:s.textPrimary},children:["Enrichment · attempted ",i.attempted," · enriched ",i.enriched," · inaccessible"," ",i.inaccessible," · extraction failed ",i.extractionFailed," · unchanged ",i.unchanged]}),e.jsxs("p",{className:"mt-1",style:{color:s.textSecondary},children:["Bounded publisher excerpts only â full article bodies are never stored or shown to clients."," ",Object.entries(i.reasons).map(([p,y])=>`${p}: ${y}`).join(" · ")]})]}):null,C?e.jsxs("div",{className:"mt-5 rounded-xl border p-3 text-[11px]",style:{borderColor:s.border},children:[e.jsxs("p",{className:"font-data",style:{color:s.textPrimary},children:["Bound to ",C.brandName??"â"," · ",C.queries.length," queries · ",C.rulesActive," active keyword rules · schedule ",C.scheduleActive?"active":"paused"]}),C.withheld.length?e.jsxs("p",{className:"mt-1",style:{color:s.textSecondary},children:["Withheld from queries: ",C.withheld.map(p=>p.value).join(", ")]}):null]}):null,r?e.jsxs("div",{className:"mt-3 rounded-xl border p-3 text-[11px] font-data",style:{borderColor:s.border,color:s.textSecondary},children:[e.jsxs("div",{children:["Queries run ",r.queriesRun," · fetched ",r.fetched," · inserted ",r.inserted," · duplicates"," ",r.duplicates," · stale ",r.stale," · blocked ",r.blocked," · unattributed"," ",r.unattributed,r.errors.length?` · errors ${r.errors.length}`:""]}),Object.keys(r.rejections??{}).length?e.jsxs("div",{className:"mt-2",children:["Rejections by canonical gate:"," ",Object.entries(r.rejections).sort((p,y)=>y[1]-p[1]).map(([p,y])=>`${p} ${y}`).join(" · ")]}):null,e.jsxs("div",{className:"mt-2",children:["Sources: news/web connector `","gdelt","` only. Digital Street social listening â not connected / not yet measured."]})]}):null]})}const Ae={backgroundColor:s.cardBg,borderColor:s.border};function Re({contestKey:o}){const w=N(te),b=K({queryKey:["political-corpus-readiness",o],queryFn:()=>w({data:{contestKey:o}}),retry:!1}),h=b.data??null,j=h?.readiness??null,d=h?.handoff??null,x=h?.reviewProgress??null,u=x?.remaining??d?.reviewReady.length??0;return e.jsxs("section",{className:"rounded-2xl border p-6",style:Ae,children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("h2",{className:"text-sm font-semibold",style:{color:s.textPrimary},children:["Corpus readiness â ",o]}),e.jsx("p",{className:"mt-1 text-xs",style:{color:s.textSecondary},children:"Operational proof for the political pilot. Read-only: nothing on this panel admits evidence."})]}),j?e.jsx("span",{className:"rounded-full px-3 py-1 text-[11px] font-d
1ata uppercase tracking-wide",style:{color:j.operational?s.gold:s.textSecondary,border:`1px solid ${j.operational?s.gold:s.border}`},children:j.operational?"Operational":j.stopCondition??"Blocked"}):null]}),b.isLoading?e.jsxs("div",{className:"mt-4 flex items-center gap-2 text-xs",style:{color:s.textSecondary},children:[e.jsx(q,{className:"h-3.5 w-3.5 animate-spin"})," Resolving tenant and scanning the governed corpusâ¦"]}):b.isError?e.jsxs("p",{className:"mt-4 flex items-center gap-2 text-xs",style:{color:s.textSecondary},children:[e.jsx(ue,{className:"h-3.5 w-3.5"}),"Readiness is available to platform administrators only."]}):e.jsxs(e.Fragment,{children:[e.jsx("ul",{className:"mt-4 space-y-2",children:(j?.gates??[]).map(f=>e.jsxs("li",{className:"rounded-xl border p-3",style:{borderColor:s.border},children:[e.jsxs("div",{className:"flex items-center gap-2",children:[f.state==="ready"?e.jsx(pe,{className:"h-4 w-4",style:{color:s.gold}}):e.jsx(he,{className:"h-4 w-4",style:{color:s.textSecondary}}),e.jsx("span",{className:"text-xs font-semibold",style:{color:s.textPrimary},children:f.label}),e.jsx("span",{className:"ml-auto font-data text-[11px] uppercase",style:{color:s.textSecondary},children:f.state})]}),e.jsx("p",{className:"mt-1 text-[11px]",style:{color:s.textSecondary},children:f.detail}),f.nextHumanAction?e.jsxs("p",{className:"mt-1 text-[11px]",style:{color:s.gold},children:["Next: ",f.nextHumanAction]}):null]},f.id))}),x?e.jsxs("div",{className:"mt-4 rounded-xl border p-3",style:{borderColor:s.border},children:[e.jsx("p",{className:"text-xs font-semibold",style:{color:s.textPrimary},children:"Review progress"}),e.jsxs("div",{className:"mt-2 grid grid-cols-2 gap-2 font-data text-[11px] sm:grid-cols-3",style:{color:s.textSecondary},children:[e.jsxs("span",{children:["Review-ready total: ",e.jsx("strong",{style:{color:s.textPrimary},children:x.reviewReadyTotal})]}),e.jsxs("span",{children:["Adjudicated: ",e.jsx("strong",{style:{color:s.textPrimary},children:x.adjudicated})]}),e.jsxs("span",{children:["Admitted: ",e.jsx("strong",{style:{color:s.textPrimary},children:x.admitted})]}),e.jsxs("span",{children:["Remaining: ",e.jsx("strong",{style:{color:s.textPrimary},children:x.remaining})]}),e.jsxs("span",{children:["Ambiguous withheld: ",x.ambiguousWithheld]}),e.jsxs("span",{children:["Out of scope: ",x.outOfScope]})]}),x.divergenceNote?e.jsx("p",{className:"mt-2 text-[11px]",style:{color:s.textSecondary},children:x.divergenceNote}):null]}):null,d?e.jsxs("div",{className:"mt-4 rounded-xl border p-3",style:{borderColor:s.border},children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-4 font-data text-[11px]",style:{color:s.textSecondary},children:[e.jsxs("span",{children:["Term matches:"," ",e.jsx("strong",{style:{color:s.textPrimary},children:d.reviewReady.length})]}),e.jsxs("span",{children:["Ambiguous withheld: ",d.ambiguousWithheld]}),e.jsxs("span",{children:["Out of scope: ",d.outOfScope]})]}),e.jsx("p",{className:"mt-2 text-[11px]",style:{color:s.textSecondary},children:d.disclosures[0]}),e.jsx(z,{to:"/admin/election-review",className:u>0?"mt-3 inline-block rounded-lg border px-3 py-1.5 text-[11px] font-semibold":"mt-2 inline-block text-[11px] underline",style:u>0?{borderColor:s.gold,color:s.gold}:{color:s.gold},children:u>0?`Review ${u} pending mention${u===1?"":"s"}`:"Open the election observation review lane"})]}):h?.refusal?e.jsx("p",{className:"mt-4 text-[11px]",style:{color:s.gold},children:h.refusal}):null]})]})}const R={backgroundColor:s.cardBg,borderColor:s.border},_e={ok:"#3FBF7F",attention:s.gold,blocked:"#E2574C",not_activated:s.textMuted};function Q({status:o}){return e.jsx("span",{className:"inline-block h-2 w-2 rounded-full",style:{backgroundColor:_e[o]??s.textMuted},"aria-hidden":!0})}function Be({profileId:o}){const w=E(),b=N(H),h=N(ae),j=N(le),d=N(re),[x,u]=g.useState(null),f=K({queryKey:["political-operations",o],enabled:!!o,queryFn:()=>b({data:{profileId:o}})}),c=g.useCallback(()=>{w.invalidateQueries({queryKey:["political-operations",o]})},[w,o]);if(!o)return null;if(f.isLoading)return e.jsx("section",{className:"rounded-2xl border p-6",style:R,children:e.jsx(q,{className:"h-4 w-4 animate-spin",style:{color:s.gold}})});const l=f.data;if(!l)return null;const C=async t=>{u("schedule");try{const i=await h({data:{profileId:o,action:t}});i.ok?m.success(t==="pause"?"Collection paused. History retained.":"Collection resumed."):m.error(i.refusal??"Refused."),c()}catch(i){console.error("[political.ops.ui] schedule toggle failed",i),m.error("Schedule change failed.")}finally{u(null)}},_=async(t,i,k,v)=>{u(t);try{const T=await j({data:{profileId:o,alertId:t,enabled:i,thresholdPct:k,minItems:v}});T.ok?m.success(i?"Alert enabled (in-product only).":"Alert disabled."):m.error(T.refusal??"Refused."),c()}catch(T){console.error("[political.ops.ui] alert control failed",T),m.error("Alert control failed.")}finally{u(null)}},r=async(t,i,k)=>{u(t);try{const v=await d({data:{profileId:o,termKey:t,decision:i,label:k}});
1v.ok?m.success(i==="approve"?"Topic approved.":"Topic updated."):m.error(v.refusal??"Refused."),c()}catch(v){console.error("[political.ops.ui] topic decision failed",v),m.error("Topic decision failed.")}finally{u(null)}};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("section",{className:"rounded-2xl border p-6",style:R,children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-widest",style:{color:s.gold},children:"Gate 4.12 · continuous operations"}),e.jsxs("h2",{className:"mt-1 text-sm font-semibold",style:{color:s.textPrimary},children:["Operations & readiness â ",l.brandName??"unbound brand"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Q,{status:l.health.overall}),e.jsx("span",{className:"text-xs font-data uppercase",style:{color:s.textSecondary},children:l.health.overall})]})]}),e.jsx("div",{className:"mt-4 grid gap-3 sm:grid-cols-2 lg:grid-cols-3",children:l.health.sections.map(t=>e.jsxs("div",{className:"rounded-xl border p-4",style:{backgroundColor:s.canvasBg,borderColor:s.border},children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Q,{status:t.status}),e.jsx("span",{className:"text-xs font-semibold",style:{color:s.textPrimary},children:t.label})]}),e.jsx("p",{className:"mt-2 text-xs leading-relaxed",style:{color:s.textSecondary},children:t.headline}),t.measures.length>0&&e.jsx("ul",{className:"mt-2 space-y-0.5 text-[11px] font-data",style:{color:s.textMuted},children:t.measures.map(i=>e.jsxs("li",{children:[i.label,": ",i.value]},i.label))})]},t.id))})]}),e.jsxs("section",{className:"rounded-2xl border p-6",style:R,children:[e.jsx("h2",{className:"text-sm font-semibold",style:{color:s.textPrimary},children:"Scheduled collection"}),e.jsx("p",{className:"mt-2 text-xs",style:{color:s.textSecondary},children:l.schedule.statement}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[e.jsxs(S,{size:"sm",variant:"outline",disabled:x==="schedule",onClick:()=>C(l.schedule.status==="active"?"pause":"resume"),style:{borderColor:s.border,color:s.textPrimary},children:[l.schedule.status==="active"?e.jsx(ye,{className:"mr-2 h-3 w-3"}):e.jsx(ge,{className:"mr-2 h-3 w-3"}),l.schedule.status==="active"?"Pause collection":"Resume collection"]}),e.jsxs("span",{className:"text-[11px] font-data",style:{color:s.textMuted},children:["last ",l.schedule.lastRunAt?.slice(0,16).replace("T"," ")??"â"," · next"," ",l.schedule.nextRunAt?.slice(0,16).replace("T"," ")??"â"]})]}),l.lastRuns.length>0&&e.jsx("ul",{className:"mt-3 space-y-1 text-[11px] font-data",style:{color:s.textSecondary},children:l.lastRuns.slice(0,5).map(t=>e.jsxs("li",{children:[t.at.slice(0,16).replace("T"," ")," · fetched ",t.fetched," · inserted ",t.inserted," · deduped ",t.deduped," · rejected"," ",t.rejected]},t.at))}),l.sourceHealth.length>0&&e.jsxs("div",{className:"mt-3",children:[e.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-widest",style:{color:s.textMuted},children:"Source health"}),e.jsx("ul",{className:"mt-1 grid gap-x-6 text-[11px] font-data sm:grid-cols-2",style:{color:s.textSecondary},children:l.sourceHealth.slice(0,10).map(t=>e.jsxs("li",{children:[t.domain,": ",t.items," · ",t.state]},t.domain))})]})]}),e.jsxs("section",{className:"rounded-2xl border p-6",style:R,children:[e.jsx("h2",{className:"text-sm font-semibold",style:{color:s.textPrimary},children:"Alert controls"}),e.jsx("p",{className:"mt-1 text-xs",style:{color:s.textSecondary},children:"Off by default. In-product delivery only â no email, SMS or WhatsApp dispatch is configured for political alerts."}),e.jsx("ul",{className:"mt-3 space-y-2",children:l.alertControls.map(t=>e.jsxs("li",{className:"flex flex-wrap items-center justify-between gap-3 rounded-xl border p-3",style:{backgroundColor:s.canvasBg,borderColor:s.border},children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-xs font-semibold",style:{color:s.textPrimary},children:t.label}
1),e.jsxs("p",{className:"text-[11px] font-data",style:{color:s.textMuted},children:[t.source==="gate_4_11_watch_rule"?"watch rule":"Gate 4.8 definition"," · threshold"," ",t.thresholdPct??"â","% · min items ",t.minItems??"â"," · ",t.cadence," · ",t.channel]})]}),e.jsx(S,{size:"sm",variant:"outline",disabled:x===t.alertId,onClick:()=>_(t.alertId,!t.enabled,t.thresholdPct,t.minItems),style:{borderColor:t.enabled?s.gold:s.border,color:t.enabled?s.gold:s.textSecondary},children:t.enabled?"Disable":"Enable"})]},t.alertId))}),e.jsxs("div",{className:"mt-4",children:[e.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-widest",style:{color:s.textMuted},children:"In-product inbox"}),l.alertInbox.instances.length===0?e.jsx("p",{className:"mt-1 text-xs",style:{color:s.textSecondary},children:"No measured trigger in the disclosed period."}):e.jsx("ul",{className:"mt-2 space-y-2",children:l.alertInbox.instances.map(t=>e.jsxs("li",{className:"rounded-xl border p-3",style:{backgroundColor:s.canvasBg,borderColor:s.border},children:[e.jsx("p",{className:"text-xs font-semibold",style:{color:s.textPrimary},children:t.title}),e.jsxs("p",{className:"text-[11px] font-data",style:{color:s.textMuted},children:[t.period," · denominator ",t.denominator," ·"," ",t.measuredTrigger.map(i=>`${i.label} ${i.value}`).join(" · ")]}),e.jsx("p",{className:"mt-1 text-[11px]",style:{color:s.textSecondary},children:t.limitations}),e.jsx("p",{className:"mt-1 text-[10px]",style:{color:s.textMuted},children:t.doctrine})]},t.alertId))})]})]}),e.jsxs("section",{className:"rounded-2xl border p-6",style:R,children:[e.jsx("h2",{className:"text-sm font-semibold",style:{color:s.textPrimary},children:"Narratives & issues â corpus diagnostics"}),e.jsx("p",{className:"mt-1 text-xs",style:{color:s.textSecondary},children:"Deterministic term frequency across admitted evidence. Nothing here populates a client surface until it is approved."}),e.jsxs("ul",{className:"mt-3 space-y-2",children:[l.suggestions.map(t=>{const i=l.approvedTopics.find(k=>k.sourceTermKey===t.termKey);return e.jsxs("li",{className:"flex flex-wrap items-center justify-between gap-3 rounded-xl border p-3",style:{backgroundColor:s.canvasBg,borderColor:s.border},children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-xs font-semibold",style:{color:s.textPrimary},children:t.label}),e.jsxs("p",{className:"text-[11px] font-data",style:{color:s.textMuted},children:[i?i.enabled?"approved":"disabled":t.stateLabel," · ",t.items," items · ",t.sharePct??"â","%"]}),e.jsx("p",{className:"text-[11px]",style:{color:s.textSecondary},children:t.examples.map(k=>k.title).filter(Boolean).slice(0,2).join(" · ")})]}),e.jsxs("div",{className:"flex gap-2",children:[!i&&e.jsx(S,{size:"sm",variant:"outline",disabled:x===t.termKey,onClick:()=>r(t.termKey,"approve",t.label),style:{borderColor:s.gold,color:s.gold},children:"Approve"}),i&&e.jsx(S,{size:"sm",variant:"outline",disabled:x===t.termKey,onClick:()=>r(t.termKey,i.enabled?"disable":"enable"),style:{borderColor:s.border,color:s.textSecondary},children:i.enabled?"Disable":"Enable"})]})]},t.termKey)}),l.suggestions.length===0&&e.jsx("li",{className:"text-xs",style:{color:s.textSecondary},children:"No candidate terms reach the minimum evidence threshold yet."})]}),l.matchedTopics.length>0&&e.jsx("ul",{className:"mt-3 space-y-1 text-[11px] font-data",style:{color:s.textSecondary},children:l.matchedTopics.map(t=>e.jsxs("li",{children:[t.label,": ",t.items," admitted items (",t.sharePct??"â","%)"]},t.topicId))})]}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-2",children:[e.jsxs("section",{className:"rounded-2xl border p-6",style:R,children:[e.jsx("h2",{className:"text-sm font-semibold",style:{color:s.textPrimary},children:"Media Impact Framework readiness"}),e.jsx("p",{className:"mt-1 text-xs",style:{color:s.textSecondary},children:l.mif.statement}),e.jsx("ul",{className:"mt-3 space-y-1 text-[11px] font-data",style:{color:s.textMuted},children:l.mif.dimensions.map(t=>e.jsxs("li",{children:[t.label,": ",t.status]},t.id))}),e.jsx("p",{className:"mt-3 text-[10px] font-semibold uppercase tracking-widest",style:{color:s.textMuted},children:"Blockers"}),e.jsx("ul",{className:"mt-1 space-y-1 text-[11px]",style:{color:s.textSecondary},children:l.mif.blockers.map(t=>e.jsxs("li",{children:["⢠",t]},t))}),e.jsx("p",{className:"mt-3 text-[10px]",style:{color:s.gold},children:"Provider activation requires explicit approval. Nothing has been activated."})]}),e.jsxs("section",{className:"rounded-2xl border p-6",style:R,children:[e.jsx("h2",{className:"text-sm font-semibold",style:{color:s.textPrimary},children:"Digital Street source audit"}),e.jsx("p",{className:"mt-1 text-xs",style:{color:s.textSecondary},children:l.social.doctrine}),e.jsxs("p",{className:"mt-3 text-xs",style:{color:s.textPrimary},children:["Recommended first surface: ",e.jsx("span",{style:{color:s.gold},children:l.social.recommendedFirstSurface})]}),e.jsx("ul",{className:"mt-2 space-y-1 text-[11px]",style:{color:s.textSecondary},children:l.social.rationale.map(t=>e.jsxs("li",{children:["⢠",t]},t))}
1),e.jsx("ul",{className:"mt-3 space-y-1 text-[11px] font-data",style:{color:s.textMuted},children:l.social.matrix.map(t=>e.jsxs("li",{children:[t.platform,": ",t.accessRoute," · feasibility ",t.feasibility]},t.platform))})]})]}),e.jsxs("section",{className:"rounded-2xl border p-6",style:R,children:[e.jsxs("h2",{className:"text-sm font-semibold",style:{color:s.textPrimary},children:["Monthly political brief â ",l.monthly.period.label]}),e.jsxs("p",{className:"mt-1 text-[11px] font-data",style:{color:s.textMuted},children:[l.monthly.contract," · ",l.monthly.generation??"no generation"," · window"," ",l.monthly.period.startIso.slice(0,10)," â ",l.monthly.period.endIso.slice(0,10)," · evidence cutoff"," ",l.monthly.period.evidenceCutoffIso.slice(0,10)," · ",l.monthly.period.basis]}),e.jsx("ul",{className:"mt-3 space-y-1 text-[11px]",style:{color:s.textSecondary},children:l.monthly.sections.map(t=>e.jsxs("li",{children:[e.jsx("span",{style:{color:t.measurement==="measured"?s.textPrimary:s.textMuted},children:t.label}),":"," ",t.measurement," â ",t.reason]},t.sectionId))}),l.monthly.blockers.length>0&&e.jsx("ul",{className:"mt-3 space-y-1 text-[11px]",style:{color:s.gold},children:l.monthly.blockers.map(t=>e.jsxs("li",{children:["⢠",t]},t))}),e.jsx("p",{className:"mt-3 text-[10px]",style:{color:s.textMuted},children:"Internal preview only. No automatic external send is configured."})]})]})}const Ke=[{id:"off",label:"Off",hint:"Classification is not applied to the review lane."},{id:"dry_run",label:"Dry run",hint:"Classify and record counts only. Nothing is admitted."},{id:"high_confidence",label:"High-confidence only",hint:"Admit only deterministic exact-match evidence through the canonical writer."}];function Fe({profileId:o,contestKey:w}){const b=E(),h=N(H),j=N(oe),d=N(fe),[x,u]=g.useState(!1),f=K({queryKey:["political-operations",o],queryFn:()=>h({data:{profileId:o}}),retry:!1,staleTime:6e4}),c=f.data?.automation,l=g.useCallback(async r=>{u(!0);try{const t=await j({data:{profileId:o,mode:r}});t.refusal?m.error(t.refusal):m.success(`Automation mode set to ${r.replace("_"," ")}`),await b.invalidateQueries({queryKey:["political-operations",o]})}catch(t){console.error("[admin/political-automation] mode change failed",t),m.error(t instanceof Error?t.message:"Mode change failed")}finally{u(!1)}},[j,o,b]),C=g.useCallback(async()=>{u(!0);try{const r=await j({data:{profileId:o,autoSuppress:!(c?.autoSuppress??!1)}});r.refusal?m.error(r.refusal):m.success("Auto-suppression setting saved"),await b.invalidateQueries({queryKey:["political-operations",o]})}catch(r){m.error(r instanceof Error?r.message:"Setting change failed")}finally{u(!1)}},[j,o,c,b]),_=g.useCallback(async()=>{if(!w){m.error("This profile is not bound to a governed contest");return}u(!0);try{const r=await d({data:{contestKey:w,mode:c?.mode??"dry_run",autoSuppress:c?.autoSuppress??!1}}),t=r.run.counts;r.safety.safe?m.success(`${r.executed?"Executed":"Dry run"} â ${t.auto_admit_high_confidence} high-confidence, ${t.human_review_required} exceptions, ${r.admitted.length} admitted`):m.error(`Fail-closed: ${r.safety.reason}`),await b.invalidateQueries({queryKey:["political-operations",o]})}catch(r){console.error("[admin/political-automation] run failed",r),m.error(r instanceof Error?r.message:"Automation run failed")}finally{u(!1)}},[d,w,c,b,o]);return e.jsxs("section",{className:"space-y-4 rounded-xl border border-border bg-card p-5",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-sm font-medium text-foreground",children:"Review automation (Gate 4.13A)"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Rule version ",e.jsx("span",{className:"font-data",children:c?.ruleVersion??"â"})," · last run"," ",e.jsx("span",{className:"font-data",children:c?.lastRunAt?c.lastRunAt.slice(0,16).replace("T"," "):"not run"})]})]}),e.jsxs(S,{size:"sm",variant:"outline",disabled:x||f.isPending,onClick:_,children:[x?e.jsx(q,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(be,{className:"mr-2 h-4 w-4"}),"Run automation"]})]}),e.jsx("div",{className:"grid gap-2 md:grid-cols-3",children:Ke.map(r=>{const t=(c?.mode??"dry_run")===r.id;return e.jsxs("button",{type:"button",disabled:x,onClick:()=>l(r.id),className:`rounded-lg border p-3 text-left text-xs transition ${t?"border-primary text-foreground":"border-border text-muted-foreground"}`,children:[e.jsxs("span",{className:"flex items-center gap-2 text-sm text-foreground",children:[t?e.jsx(I,{className:"h-4 w-4"}):null,r.label]}),e.jsx("span",{className:"mt-1 block leading-relaxed",children:r.hint})]},r.id)})}),e.jsxs("label",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx("input",{type:"checkbox",checked:c?.autoSuppress??!1,disabled:x,onChange:C}),"Persist automatic suppression of routine out-of-scope items (separate from auto-admit; always reversible)"]}),c?.lastRunCounts?e.jsx("dl",{className:"grid grid-cols-2 gap-2 text-xs md:grid-cols-5",children:Object.entries(c.lastRunCounts).map(([r,t])=>e.jsxs("div",{className:"rounded-lg border border-border/60 p-2",children:[e.jsx("dt",{className:"text-muted-foreground",children:r.replace(/_/g," ")}),e.jsx("dd",{className:"font-data tabular-nums text-foreground",children:t})]},r))}):null,e.jsx("p",{className:"text-xs leading-relaxed text-muted-foreground",children:f.data?.automationDisclosure}),e.jsx("p",{className:"text-xs leading-relaxed text-muted-foreground",children:f.data?.aiIdentityStage.statement})]})}const $={backgroundColor:s.cardBg,borderColor:s.border};function Je(){const o=E(),w=N(ne),b=N(ie),h=N(ce),j=N(de),d=N(me),x=N(xe),[u,f]=g.useState(null),[c,l]=g.useState(!1),[C,_]=g.useState("hashtag"),[r,t]=g.useState(""),[i,k]=g.useState(""),[v,T]=g.useState({orgId:"",contestKey:"ng:osun:gov:2026:governor",profileKey:"osun-2026-pilot",label:"Osun 2026 reference pilot",jurisdiction:"NG/Osun"}),M=K({queryKey:["political-monitoring-profiles"],queryFn:()=>w({}),retry:!1}),n=g.useMemo(()=>(M.data??[]).find(a=>a.id===u)??(M.data??[])[0]??null,[M.data,u]),B=K({queryKey:["political-monitoring-events",n?.id],queryFn:()=>x({data:{profileId:n.id}}),enabled:!!n?.id,retry:!1}),p=K({queryKey:["political-monitoring-audit",n?.id],queryFn:()=>d({data:{profileId:n.id}}),enabled:!!n?.id,retry:!1}),y=g.useCallback(()=>{o.invalidateQueries({queryKey:["political-monitoring-profiles"]}),o.invalidateQueries({queryKey:["political-monitoring-events"]}),o.invalidateQueries({queryKey:["political-monitoring-audit"]})}
1,[o]),O=g.useCallback(async()=>{l(!0);try{const a=await b({data:v});a.created?(m.success("Draft profile created from governed roster facts"),f(a.profile?.id??null),y()):m.error(a.refusal??"Prefill refused")}catch(a){m.error(a instanceof Error?a.message:"Prefill failed")}finally{l(!1)}},[v,b,y]),A=g.useCallback(async()=>{if(!(!n||r.trim().length<2)){l(!0);try{const a=await h({data:{profileId:n.id,kind:C,value:r.trim(),enabled:!0,note:i||null}});a.ok?(m.success("Term recorded with provenance"),t(""),k(""),y()):m.error(a.refusal??"Term refused")}finally{l(!1)}}},[n,h,C,r,i,y]),W=g.useCallback(async(a,F,D)=>{if(n){l(!0);try{const L=await h({data:{profileId:n.id,kind:a,value:F,enabled:D,note:null}});L.ok?y():m.error(L.refusal??"Change refused")}finally{l(!1)}}},[n,h,y]),V=g.useCallback(async a=>{if(n){l(!0);try{const F=await j({data:{profileId:n.id,status:a}});F.ok?(m.success(`Profile ${a}`),y()):m.error(F.refusal??"Status change refused")}finally{l(!1)}}},[n,j,y]),P=p.data?.audit??null;return e.jsxs("div",{className:"min-h-screen px-4 py-8 sm:px-8",style:{backgroundColor:s.appBg},children:[e.jsx(J,{}),e.jsxs("div",{className:"mx-auto max-w-6xl space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(z,{to:"/admin",className:"inline-flex items-center gap-2 text-sm",style:{color:s.textSecondary},children:[e.jsx(Ne,{className:"h-4 w-4"})," Platform admin"]}),e.jsx(z,{to:"/portal/election",className:"text-sm",style:{color:s.gold},children:"Political & Election Intelligence â"})]}),e.jsxs("header",{className:"rounded-2xl border p-6",style:$,children:[e.jsx("p",{className:"text-[10px] font-semibold uppercase tracking-widest",style:{color:s.gold},children:"Gate 4.9 â political-monitoring-profile-v1.0.0"}),e.jsx("h1",{className:"mt-2 text-2xl font-semibold",style:{color:s.textPrimary},children:"Political Monitoring Configuration"}),e.jsx("p",{className:"mt-2 max-w-3xl text-sm leading-relaxed",style:{color:s.textSecondary},children:"Configuration decides what the existing AGENTPR monitoring corpus is watched FOR. It creates no ingestion path, copies no candidate or party into brands, and admits nothing: exact governed identity matches become review-ready, and surname, acronym, hashtag or phrase matches stay withheld for human review."})]}),e.jsxs("section",{className:"rounded-2xl border p-6",style:$,children:[e.jsx("h2",{className:"text-sm font-semibold",style:{color:s.textPrimary},children:"Create a draft from governed reference facts"}),e.jsx("div",{className:"mt-4 grid gap-3 sm:grid-cols-2 lg:grid-cols-5",children:["orgId","contestKey","profileKey","label","jurisdiction"].map(a=>e.jsxs("label",{className:"text-xs",style:{color:s.textSecondary},children:[a,e.jsx("input",{value:v[a],onChange:F=>T(D=>({...D,[a]:F.target.value})),className:"mt-1 w-full rounded-lg border px-3 py-2 text-sm font-data outline-none",style:{backgroundColor:s.canvasBg,borderColor:s.border,color:s.textPrimary}})]},a))}),e.jsxs(S,{className:"mt-4",disabled:c||!v.orgId,onClick:O,children:[c?e.jsx(q,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(I,{className:"mr-2 h-4 w-4"}),"Prefill draft profile"]})]}),e.jsxs("section",{className:"rounded-2xl border p-6",style:$,children:[e.jsx("h2",{className:"text-sm font-semibold",style:{color:s.textPrimary},children:"Monitoring profiles"}),M.isLoading?e.jsx("p",{className:"mt-3 text-sm",style:{color:s.textSecondary},children:"Loadingâ¦"}):(M.data??[]).length===0?e.jsx("p",{className:"mt-3 text-sm",style:{color:s.textSecondary},children:"No profile is configured yet. Nothing political is being watched."}):e.jsx("ul",{className:"mt-3 flex flex-wrap gap-2",children:(M.data??[]).map(a=>e.jsx("li",{children:e.jsxs("button",{onClick:()=>f(a.id),className:"rounded-full border px-3 py-1.5 text-xs font-semibold",style:n?.id===a.id?{borderColor:s.goldBorder,backgroundColor:s.goldBg,color:s.gold}:{borderColor:s.border,color:s.textSecondary},children:[a.label," · ",a.status]})},a.id))}),n&&e.jsxs("div",{className:"mt-5 space-y-5",children:[e.jsx("div",{className:"flex flex-wrap gap-2",children:["draft","active","disabled"].map(a=>e.jsx(S,{variant:n.status===a?"default":"outline",size:"sm",disabled:c,onClick:()=>V(a),children:a},a))}),e.jsxs("div",{children:[e.jsxs("h3",{className:"text-xs font-semibold uppercase tracking-widest",style:{color:s.textMuted},children:["Governed subjects (",n.subjects.length,")"]}),e.jsx("ul",{className:"mt-2 grid gap-1 sm:grid-cols-2",children:n.subjects.map(a=>e.jsxs("li",{className:"text-sm",style:{color:s.textSecondary},children:[a.displayName,a.partyName?` â ${a.partyName}`:""]},a.subjectId))})]}),e.jsxs("div",{children:[e.jsxs("h3",{className:"text-xs font-semibold uppercase tracking-widest",style:{color:s.textMuted},children:["Tracked terms (",n.terms.length,")"]}),e.jsx("ul",{className:"mt-2 space-y-1",children:n.terms.map(a=>e.jsxs("li",{className:"flex items-center justify-between gap-3 text-sm",style:{color:s.textSecondary},children:[e.jsxs("span",{children:[e.jsx("span",{className:"font-data",children:a.kind==="hashtag"?`#${a.value.replace(/^#+/,"")}`:a.value}),e.jsxs("span",{className:"ml-2 text-xs",style:{color:s.textMuted},children:[a.kind," · ",a.provenance.source," · ",a.provenance.recordedAt.slice(0,10)]})]}),e.jsx(S,{size:"sm",variant:"outline",disabled:c,onClick:()=>W(a.kind,a.value,!a.enabled),children:a.enabled?"Disable":"Enable"})]},a.termId))}),e.jsxs("div",{className:"mt-4 flex flex-wrap items-end gap-3",children:[e.jsxs("label",{className:"text-xs",style:{color:s.textSecondary},children:["Kind",e.jsx("select",{value:C,onChange:a=>_(a.target.value),className:"mt-1 block rounded-lg border px-3 py-2 text-sm",style:{backgroundColor:s.canvasBg,borderColor:s.border,color:s.textPrimary},children:ke.map(a=>e.jsx("option",{value:a,children:a},a))})]}),e.jsxs("label",{className:"text-xs",style:{color:s.textSecondary},children:["Value",e.jsx("input",{value:r,onChange:a=>t(a.target.value),placeholder:"#OsunDecides",className:"mt-1 block rounded-lg border px-3 py-2 text-sm",style:{backgroundColor:s.canvasBg,borderColor:s.border,color:s.textPrimary}})]}),e.jsxs("label",{className:"text-xs",style:{color:s.textSecondary},children:["Provenance note",e.jsx("input",{value:i,onChange:a=>k(a.target.value),placeholder:"Where this term was reviewed from",className:"mt-1 block w-64 roun
1ded-lg border px-3 py-2 text-sm",style:{backgroundColor:s.canvasBg,borderColor:s.border,color:s.textPrimary}})]}),e.jsx(S,{disabled:c||r.trim().length<2,onClick:A,children:"Add term"})]})]})]})]}),n?e.jsx(qe,{profileId:n.id,profileStatus:n.status,terms:n.terms}):null,n?.contestKey?e.jsx(Re,{contestKey:n.contestKey}):null,n&&e.jsxs("section",{className:"rounded-2xl border p-6",style:$,children:[e.jsx("h2",{className:"text-sm font-semibold",style:{color:s.textPrimary},children:"Pilot corpus audit â existing mentions only"}),p.isLoading?e.jsx("p",{className:"mt-3 text-sm",style:{color:s.textSecondary},children:"Scanning existing corpusâ¦"}):P?e.jsxs("div",{className:"mt-4 space-y-4",children:[e.jsx("div",{className:"grid gap-3 sm:grid-cols-4",children:[{label:"Scanned",value:P.scanned},{label:"Review-ready",value:P.reviewReady},{label:"Ambiguous (withheld)",value:P.ambiguous},{label:"Out of scope",value:P.outOfScope}].map(a=>e.jsxs("div",{className:"rounded-xl border p-3",style:{borderColor:s.border,backgroundColor:s.canvasBg},children:[e.jsx("p",{className:"text-[10px] uppercase tracking-widest",style:{color:s.textMuted},children:a.label}),e.jsx("p",{className:"font-data text-xl tabular-nums",style:{color:s.textPrimary},children:a.value})]},a.label))}),e.jsxs("p",{className:"text-xs",style:{color:s.textSecondary},children:["Date range ",P.dateRange.earliest?.slice(0,10)??"â"," â ",P.dateRange.latest?.slice(0,10)??"â"," ·"," ",P.dateRange.undated," undated · hashtags present on ",P.hashtagAvailability.itemsWithHashtags," items (",P.hashtagAvailability.distinctHashtags," distinct)"]}),e.jsx("ul",{className:"text-xs",style:{color:s.textMuted},children:P.byChannel.map(a=>e.jsxs("li",{className:"font-data",children:[a.channel,": ",a.scanned," scanned · ",a.reviewReady," ready · ",a.ambiguous," ambiguous"]},a.channel))}),e.jsx("ul",{className:"space-y-1 text-xs",style:{color:s.textSecondary},children:P.disclosures.map(a=>e.jsxs("li",{children:["⢠",a]},a))})]}):e.jsx("p",{className:"mt-3 text-sm",style:{color:s.textSecondary},children:p.data?.refusal??"No audit available."})]}),n&&e.jsx(Fe,{profileId:n.id,contestKey:n.contestKey??null}),n&&e.jsx(Be,{profileId:n.id}),n&&e.jsx(je,{profileId:n.id}),n&&e.jsxs("section",{className:"rounded-2xl border p-6",style:$,children:[e.jsx("h2",{className:"text-sm font-semibold",style:{color:s.textPrimary},children:"Configuration provenance"}),e.jsxs("ul",{className:"mt-3 space-y-1 text-xs font-data",style:{color:s.textSecondary},children:[(B.data??[]).map(a=>e.jsxs("li",{children:[a.createdAt.slice(0,19).replace("T"," ")," · ",a.eventType," · ",a.actorId?.slice(0,8)??"system"]},a.id)),(B.data??[]).length===0&&e.jsx("li",{children:"No configuration change recorded yet."})]})]})]})]})}export{Je as component};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.