@burdenoff/microfe-govcitizenhub 2026.720.6 → 2026.730.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (171) hide show
  1. package/dist/govcitizenhub/GovCitizenHubRoot.d.ts.map +1 -1
  2. package/dist/govcitizenhub/GovCitizenHubRoot.js +44 -36
  3. package/dist/govcitizenhub/GovCitizenHubRoot.js.map +1 -1
  4. package/dist/govcitizenhub/GovCitizenHubRoutes.d.ts.map +1 -1
  5. package/dist/govcitizenhub/GovCitizenHubRoutes.js +134 -6
  6. package/dist/govcitizenhub/GovCitizenHubRoutes.js.map +1 -1
  7. package/dist/govcitizenhub/components/DocumentUploadField.d.ts +17 -11
  8. package/dist/govcitizenhub/components/DocumentUploadField.d.ts.map +1 -1
  9. package/dist/govcitizenhub/components/DocumentUploadField.js +45 -42
  10. package/dist/govcitizenhub/components/DocumentUploadField.js.map +1 -1
  11. package/dist/govcitizenhub/components/GovCharts.js +127 -51
  12. package/dist/govcitizenhub/components/GovCharts.js.map +1 -1
  13. package/dist/govcitizenhub/hooks/index.d.ts +2 -0
  14. package/dist/govcitizenhub/hooks/index.d.ts.map +1 -1
  15. package/dist/govcitizenhub/hooks/index.js +2 -0
  16. package/dist/govcitizenhub/hooks/useGovApi.d.ts +23 -0
  17. package/dist/govcitizenhub/hooks/useGovApi.d.ts.map +1 -1
  18. package/dist/govcitizenhub/hooks/useGovApi.js +18 -7
  19. package/dist/govcitizenhub/hooks/useGovApi.js.map +1 -1
  20. package/dist/govcitizenhub/hooks/useGovCitizenHubAnalytics.d.ts +24 -0
  21. package/dist/govcitizenhub/hooks/useGovCitizenHubAnalytics.d.ts.map +1 -0
  22. package/dist/govcitizenhub/hooks/useGovCitizenHubAnalytics.js +40 -0
  23. package/dist/govcitizenhub/hooks/useGovCitizenHubAnalytics.js.map +1 -0
  24. package/dist/govcitizenhub/hooks/useIntelligenceApi.d.ts +214 -0
  25. package/dist/govcitizenhub/hooks/useIntelligenceApi.d.ts.map +1 -0
  26. package/dist/govcitizenhub/hooks/useIntelligenceApi.js +1140 -0
  27. package/dist/govcitizenhub/hooks/useIntelligenceApi.js.map +1 -0
  28. package/dist/govcitizenhub/index.d.ts +1 -0
  29. package/dist/govcitizenhub/index.d.ts.map +1 -1
  30. package/dist/govcitizenhub/index.js +18 -0
  31. package/dist/govcitizenhub/pages/agencies/AgenciesPage.js +7 -7
  32. package/dist/govcitizenhub/pages/agencies/AgencyFormDialog.js +6 -6
  33. package/dist/govcitizenhub/pages/applications/ApplicationDetailPage.d.ts.map +1 -1
  34. package/dist/govcitizenhub/pages/applications/ApplicationDetailPage.js +178 -172
  35. package/dist/govcitizenhub/pages/applications/ApplicationDetailPage.js.map +1 -1
  36. package/dist/govcitizenhub/pages/applications/ApplicationsPage.js +35 -35
  37. package/dist/govcitizenhub/pages/applications/ApplicationsPage.js.map +1 -1
  38. package/dist/govcitizenhub/pages/applications/NewApplicationPage.d.ts.map +1 -1
  39. package/dist/govcitizenhub/pages/applications/NewApplicationPage.js +151 -147
  40. package/dist/govcitizenhub/pages/applications/NewApplicationPage.js.map +1 -1
  41. package/dist/govcitizenhub/pages/documents/DocumentsPage.js +5 -5
  42. package/dist/govcitizenhub/pages/grievances/GrievanceDetailPage.js +30 -30
  43. package/dist/govcitizenhub/pages/grievances/GrievanceDetailPage.js.map +1 -1
  44. package/dist/govcitizenhub/pages/grievances/GrievancesPage.d.ts.map +1 -1
  45. package/dist/govcitizenhub/pages/grievances/GrievancesPage.js +176 -172
  46. package/dist/govcitizenhub/pages/grievances/GrievancesPage.js.map +1 -1
  47. package/dist/govcitizenhub/pages/intelligence/AdminLevelsPage.d.ts +4 -0
  48. package/dist/govcitizenhub/pages/intelligence/AdminLevelsPage.d.ts.map +1 -0
  49. package/dist/govcitizenhub/pages/intelligence/AdminLevelsPage.js +634 -0
  50. package/dist/govcitizenhub/pages/intelligence/AdminLevelsPage.js.map +1 -0
  51. package/dist/govcitizenhub/pages/intelligence/AssetFormDialog.d.ts +20 -0
  52. package/dist/govcitizenhub/pages/intelligence/AssetFormDialog.d.ts.map +1 -0
  53. package/dist/govcitizenhub/pages/intelligence/AssetFormDialog.js +537 -0
  54. package/dist/govcitizenhub/pages/intelligence/AssetFormDialog.js.map +1 -0
  55. package/dist/govcitizenhub/pages/intelligence/AssetImage.d.ts +11 -0
  56. package/dist/govcitizenhub/pages/intelligence/AssetImage.d.ts.map +1 -0
  57. package/dist/govcitizenhub/pages/intelligence/AssetImage.js +25 -0
  58. package/dist/govcitizenhub/pages/intelligence/AssetImage.js.map +1 -0
  59. package/dist/govcitizenhub/pages/intelligence/AssetMapPanel.d.ts +15 -0
  60. package/dist/govcitizenhub/pages/intelligence/AssetMapPanel.d.ts.map +1 -0
  61. package/dist/govcitizenhub/pages/intelligence/AssetMapPanel.js +203 -0
  62. package/dist/govcitizenhub/pages/intelligence/AssetMapPanel.js.map +1 -0
  63. package/dist/govcitizenhub/pages/intelligence/BenchmarkPage.d.ts +4 -0
  64. package/dist/govcitizenhub/pages/intelligence/BenchmarkPage.d.ts.map +1 -0
  65. package/dist/govcitizenhub/pages/intelligence/BenchmarkPage.js +497 -0
  66. package/dist/govcitizenhub/pages/intelligence/BenchmarkPage.js.map +1 -0
  67. package/dist/govcitizenhub/pages/intelligence/BudgetPage.d.ts +4 -0
  68. package/dist/govcitizenhub/pages/intelligence/BudgetPage.d.ts.map +1 -0
  69. package/dist/govcitizenhub/pages/intelligence/BudgetPage.js +1084 -0
  70. package/dist/govcitizenhub/pages/intelligence/BudgetPage.js.map +1 -0
  71. package/dist/govcitizenhub/pages/intelligence/ConsultationFormDialog.d.ts +13 -0
  72. package/dist/govcitizenhub/pages/intelligence/ConsultationFormDialog.d.ts.map +1 -0
  73. package/dist/govcitizenhub/pages/intelligence/ConsultationFormDialog.js +581 -0
  74. package/dist/govcitizenhub/pages/intelligence/ConsultationFormDialog.js.map +1 -0
  75. package/dist/govcitizenhub/pages/intelligence/ConsultationParticipateDialog.d.ts +11 -0
  76. package/dist/govcitizenhub/pages/intelligence/ConsultationParticipateDialog.d.ts.map +1 -0
  77. package/dist/govcitizenhub/pages/intelligence/ConsultationParticipateDialog.js +429 -0
  78. package/dist/govcitizenhub/pages/intelligence/ConsultationParticipateDialog.js.map +1 -0
  79. package/dist/govcitizenhub/pages/intelligence/ConsultationResultsPanel.d.ts +8 -0
  80. package/dist/govcitizenhub/pages/intelligence/ConsultationResultsPanel.d.ts.map +1 -0
  81. package/dist/govcitizenhub/pages/intelligence/ConsultationResultsPanel.js +235 -0
  82. package/dist/govcitizenhub/pages/intelligence/ConsultationResultsPanel.js.map +1 -0
  83. package/dist/govcitizenhub/pages/intelligence/ConsultationsPage.d.ts +4 -0
  84. package/dist/govcitizenhub/pages/intelligence/ConsultationsPage.d.ts.map +1 -0
  85. package/dist/govcitizenhub/pages/intelligence/ConsultationsPage.js +534 -0
  86. package/dist/govcitizenhub/pages/intelligence/ConsultationsPage.js.map +1 -0
  87. package/dist/govcitizenhub/pages/intelligence/CorrectionsPage.d.ts +4 -0
  88. package/dist/govcitizenhub/pages/intelligence/CorrectionsPage.d.ts.map +1 -0
  89. package/dist/govcitizenhub/pages/intelligence/CorrectionsPage.js +723 -0
  90. package/dist/govcitizenhub/pages/intelligence/CorrectionsPage.js.map +1 -0
  91. package/dist/govcitizenhub/pages/intelligence/ElectionsPage.d.ts +5 -0
  92. package/dist/govcitizenhub/pages/intelligence/ElectionsPage.d.ts.map +1 -0
  93. package/dist/govcitizenhub/pages/intelligence/ElectionsPage.js +1029 -0
  94. package/dist/govcitizenhub/pages/intelligence/ElectionsPage.js.map +1 -0
  95. package/dist/govcitizenhub/pages/intelligence/GovernancePage.d.ts +5 -0
  96. package/dist/govcitizenhub/pages/intelligence/GovernancePage.d.ts.map +1 -0
  97. package/dist/govcitizenhub/pages/intelligence/GovernancePage.js +1545 -0
  98. package/dist/govcitizenhub/pages/intelligence/GovernancePage.js.map +1 -0
  99. package/dist/govcitizenhub/pages/intelligence/IndicatorCatalogPage.d.ts +4 -0
  100. package/dist/govcitizenhub/pages/intelligence/IndicatorCatalogPage.d.ts.map +1 -0
  101. package/dist/govcitizenhub/pages/intelligence/IndicatorCatalogPage.js +960 -0
  102. package/dist/govcitizenhub/pages/intelligence/IndicatorCatalogPage.js.map +1 -0
  103. package/dist/govcitizenhub/pages/intelligence/IndicatorsPage.d.ts +13 -0
  104. package/dist/govcitizenhub/pages/intelligence/IndicatorsPage.d.ts.map +1 -0
  105. package/dist/govcitizenhub/pages/intelligence/IndicatorsPage.js +927 -0
  106. package/dist/govcitizenhub/pages/intelligence/IndicatorsPage.js.map +1 -0
  107. package/dist/govcitizenhub/pages/intelligence/JurisdictionDirectoryPage.d.ts +4 -0
  108. package/dist/govcitizenhub/pages/intelligence/JurisdictionDirectoryPage.d.ts.map +1 -0
  109. package/dist/govcitizenhub/pages/intelligence/JurisdictionDirectoryPage.js +620 -0
  110. package/dist/govcitizenhub/pages/intelligence/JurisdictionDirectoryPage.js.map +1 -0
  111. package/dist/govcitizenhub/pages/intelligence/JurisdictionLayout.d.ts +20 -0
  112. package/dist/govcitizenhub/pages/intelligence/JurisdictionLayout.d.ts.map +1 -0
  113. package/dist/govcitizenhub/pages/intelligence/JurisdictionLayout.js +183 -0
  114. package/dist/govcitizenhub/pages/intelligence/JurisdictionLayout.js.map +1 -0
  115. package/dist/govcitizenhub/pages/intelligence/JurisdictionProfilePage.d.ts +4 -0
  116. package/dist/govcitizenhub/pages/intelligence/JurisdictionProfilePage.d.ts.map +1 -0
  117. package/dist/govcitizenhub/pages/intelligence/JurisdictionProfilePage.js +629 -0
  118. package/dist/govcitizenhub/pages/intelligence/JurisdictionProfilePage.js.map +1 -0
  119. package/dist/govcitizenhub/pages/intelligence/OpenDataPage.d.ts +4 -0
  120. package/dist/govcitizenhub/pages/intelligence/OpenDataPage.d.ts.map +1 -0
  121. package/dist/govcitizenhub/pages/intelligence/OpenDataPage.js +1124 -0
  122. package/dist/govcitizenhub/pages/intelligence/OpenDataPage.js.map +1 -0
  123. package/dist/govcitizenhub/pages/intelligence/ProjectsPage.d.ts +4 -0
  124. package/dist/govcitizenhub/pages/intelligence/ProjectsPage.d.ts.map +1 -0
  125. package/dist/govcitizenhub/pages/intelligence/ProjectsPage.js +1518 -0
  126. package/dist/govcitizenhub/pages/intelligence/ProjectsPage.js.map +1 -0
  127. package/dist/govcitizenhub/pages/intelligence/PublicAssetsPage.d.ts +4 -0
  128. package/dist/govcitizenhub/pages/intelligence/PublicAssetsPage.d.ts.map +1 -0
  129. package/dist/govcitizenhub/pages/intelligence/PublicAssetsPage.js +577 -0
  130. package/dist/govcitizenhub/pages/intelligence/PublicAssetsPage.js.map +1 -0
  131. package/dist/govcitizenhub/pages/intelligence/ServicePerformancePage.d.ts +4 -0
  132. package/dist/govcitizenhub/pages/intelligence/ServicePerformancePage.d.ts.map +1 -0
  133. package/dist/govcitizenhub/pages/intelligence/ServicePerformancePage.js +534 -0
  134. package/dist/govcitizenhub/pages/intelligence/ServicePerformancePage.js.map +1 -0
  135. package/dist/govcitizenhub/pages/intelligence/TimelinePage.d.ts +5 -0
  136. package/dist/govcitizenhub/pages/intelligence/TimelinePage.d.ts.map +1 -0
  137. package/dist/govcitizenhub/pages/intelligence/TimelinePage.js +538 -0
  138. package/dist/govcitizenhub/pages/intelligence/TimelinePage.js.map +1 -0
  139. package/dist/govcitizenhub/pages/intelligence/consultationQuestions.d.ts +53 -0
  140. package/dist/govcitizenhub/pages/intelligence/consultationQuestions.d.ts.map +1 -0
  141. package/dist/govcitizenhub/pages/intelligence/consultationQuestions.js +138 -0
  142. package/dist/govcitizenhub/pages/intelligence/consultationQuestions.js.map +1 -0
  143. package/dist/govcitizenhub/pages/intelligence/index.d.ts +27 -0
  144. package/dist/govcitizenhub/pages/intelligence/index.d.ts.map +1 -0
  145. package/dist/govcitizenhub/pages/intelligence/index.js +17 -0
  146. package/dist/govcitizenhub/pages/payments/PaymentsPage.d.ts.map +1 -1
  147. package/dist/govcitizenhub/pages/payments/PaymentsPage.js +53 -49
  148. package/dist/govcitizenhub/pages/payments/PaymentsPage.js.map +1 -1
  149. package/dist/govcitizenhub/pages/permits/IssuePermitDialog.d.ts.map +1 -1
  150. package/dist/govcitizenhub/pages/permits/IssuePermitDialog.js +82 -76
  151. package/dist/govcitizenhub/pages/permits/IssuePermitDialog.js.map +1 -1
  152. package/dist/govcitizenhub/pages/permits/PermitsPage.d.ts.map +1 -1
  153. package/dist/govcitizenhub/pages/permits/PermitsPage.js +174 -120
  154. package/dist/govcitizenhub/pages/permits/PermitsPage.js.map +1 -1
  155. package/dist/govcitizenhub/pages/services/ServiceDetailPage.js +8 -8
  156. package/dist/govcitizenhub/pages/services/ServiceFormDialog.js +98 -98
  157. package/dist/govcitizenhub/pages/services/ServiceFormDialog.js.map +1 -1
  158. package/dist/govcitizenhub/types/index.d.ts +1 -0
  159. package/dist/govcitizenhub/types/index.d.ts.map +1 -1
  160. package/dist/govcitizenhub/types/intelligence.d.ts +1559 -0
  161. package/dist/govcitizenhub/types/intelligence.d.ts.map +1 -0
  162. package/dist/govcitizenhub/types/intelligence.js +125 -0
  163. package/dist/govcitizenhub/types/intelligence.js.map +1 -0
  164. package/dist/index.js +19 -2
  165. package/dist/node_modules/recharts/es6/chart/BarChart.js +24 -0
  166. package/dist/node_modules/recharts/es6/chart/BarChart.js.map +1 -0
  167. package/dist/utils/pageContext.d.ts +1 -0
  168. package/dist/utils/pageContext.d.ts.map +1 -1
  169. package/dist/utils/pageContext.js +44 -17
  170. package/dist/utils/pageContext.js.map +1 -1
  171. package/package.json +1 -1
@@ -0,0 +1,1029 @@
1
+ import { cn as e } from "../../utils/cn.js";
2
+ import { GovAreaChart as t } from "../../components/GovCharts.js";
3
+ import { formatDate as n, formatNumber as r } from "../../utils/formatters.js";
4
+ import { EmptyState as i } from "../../components/EmptyState.js";
5
+ import { useGovCreateElection as a, useGovDeleteElection as o, useGovElection as s, useGovElections as c, useGovRecordElectionResults as l, useGovUpdateElection as u } from "../../hooks/useIntelligenceApi.js";
6
+ import { useCursorPager as d } from "../../hooks/useCursorPager.js";
7
+ import "../../hooks/index.js";
8
+ import { ErrorView as f, LoadingView as p } from "../../components/StateViews.js";
9
+ import { FilterTabs as m } from "../../components/FilterTabs.js";
10
+ import { SectionCard as h } from "../../components/SectionCard.js";
11
+ import { Pagination as g } from "../../components/Pagination.js";
12
+ import { describeError as _, notify as v } from "../../lib/toast.js";
13
+ import { GOV_VERIFICATION_LABELS as ee } from "../../types/intelligence.js";
14
+ import { JurisdictionLayout as y, VerificationChip as b } from "./JurisdictionLayout.js";
15
+ import { ConfirmDialog as te } from "../../components/ConfirmDialog.js";
16
+ import { SummaryStrip as ne } from "../../components/SummaryStrip.js";
17
+ import { useMemo as x, useState as S } from "react";
18
+ import { CalendarDays as C, CheckCircle2 as w, ExternalLink as T, ListChecks as E, Pencil as re, Percent as D, Plus as O, Trash2 as k, TrendingUp as A, Trophy as j, Users as ie, Vote as M } from "lucide-react";
19
+ import { useParams as ae } from "react-router-dom";
20
+ import { Fragment as N, jsx as P, jsxs as F } from "react/jsx-runtime";
21
+ import { Button as I, GlassCard as oe, Input as L, Label as R, ResponsiveDialog as z, ResponsiveDialogContent as B, ResponsiveDialogDescription as V, ResponsiveDialogFooter as H, ResponsiveDialogHeader as U, ResponsiveDialogTitle as W, Select as G, SelectContent as K, SelectItem as q, SelectTrigger as J, SelectValue as Y, Switch as se } from "@burdenoff/fe-libs/ui";
22
+ //#region src/govcitizenhub/pages/intelligence/ElectionsPage.tsx
23
+ var ce = 25, le = [
24
+ "GENERAL",
25
+ "LOCAL",
26
+ "BY_ELECTION",
27
+ "REFERENDUM",
28
+ "PRIMARY",
29
+ "OTHER"
30
+ ], ue = {
31
+ GENERAL: "General",
32
+ LOCAL: "Local",
33
+ BY_ELECTION: "By-election",
34
+ REFERENDUM: "Referendum",
35
+ PRIMARY: "Primary",
36
+ OTHER: "Other"
37
+ }, de = [
38
+ "SCHEDULED",
39
+ "IN_PROGRESS",
40
+ "COUNTING",
41
+ "DECLARED",
42
+ "CANCELLED"
43
+ ], X = {
44
+ SCHEDULED: "Scheduled",
45
+ IN_PROGRESS: "In progress",
46
+ COUNTING: "Counting",
47
+ DECLARED: "Declared",
48
+ CANCELLED: "Cancelled"
49
+ }, fe = {
50
+ SCHEDULED: "bg-[var(--color-accent-soft)] text-action-primary-text",
51
+ IN_PROGRESS: "bg-status-warning-bg-subtle text-status-warning-text",
52
+ COUNTING: "bg-status-warning-bg-subtle text-status-warning-text",
53
+ DECLARED: "bg-status-success-bg-subtle text-status-success-text",
54
+ CANCELLED: "bg-status-error-bg-subtle text-status-error-text"
55
+ }, pe = [{
56
+ value: "ALL",
57
+ label: "All"
58
+ }, ...de.map((e) => ({
59
+ value: e,
60
+ label: X[e]
61
+ }))], me = [
62
+ "UNVERIFIED",
63
+ "OFFICIAL",
64
+ "COMMUNITY_VERIFIED",
65
+ "DISPUTED"
66
+ ];
67
+ function he(e) {
68
+ return e ? /^https?:\/\//i.test(e.trim()) : !1;
69
+ }
70
+ function ge(e) {
71
+ if (!e) return "";
72
+ let t = new Date(e);
73
+ return Number.isNaN(t.getTime()) ? "" : t.toISOString().slice(0, 10);
74
+ }
75
+ function _e(e) {
76
+ if (!e) return null;
77
+ let t = new Date(e);
78
+ return Number.isNaN(t.getTime()) ? null : t.toISOString();
79
+ }
80
+ function Z(e) {
81
+ let t = e.trim();
82
+ return t === "" ? null : t;
83
+ }
84
+ function Q(e) {
85
+ if (e.trim() === "") return null;
86
+ let t = Number(e);
87
+ return Number.isFinite(t) ? t : null;
88
+ }
89
+ function $(e) {
90
+ return e == null ? "—" : `${r(e, { maximumFractionDigits: 1 })}%`;
91
+ }
92
+ function ve(e) {
93
+ let t = new Date(e);
94
+ return Number.isNaN(t.getTime()) ? "—" : String(t.getFullYear());
95
+ }
96
+ var ye = ({ status: t }) => /* @__PURE__ */ P("span", {
97
+ className: e("inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-medium", fe[t]),
98
+ children: X[t]
99
+ }), be = ({ type: e }) => /* @__PURE__ */ P("span", {
100
+ className: "inline-flex items-center rounded-full bg-bg-sunken px-2.5 py-0.5 text-xs font-medium text-text-secondary",
101
+ children: ue[e]
102
+ }), xe = ({ election: t, selected: r, onSelect: i }) => /* @__PURE__ */ P("li", { children: /* @__PURE__ */ F("button", {
103
+ type: "button",
104
+ onClick: i,
105
+ "aria-pressed": r,
106
+ className: e("w-full rounded-lg border px-3 py-3 text-left outline-none transition-colors focus-visible:ring-1 focus-visible:ring-border-focus", r ? "border-border-strong bg-bg-sunken" : "border-border-seam bg-bg-surface hover:bg-bg-sunken"),
107
+ children: [
108
+ /* @__PURE__ */ F("div", {
109
+ className: "flex items-start justify-between gap-2",
110
+ children: [/* @__PURE__ */ P("span", {
111
+ className: "min-w-0 truncate text-sm font-medium text-text-primary",
112
+ children: t.name
113
+ }), /* @__PURE__ */ P("span", {
114
+ className: "shrink-0 text-xs text-text-muted tabular-nums",
115
+ children: n(t.electionDate)
116
+ })]
117
+ }),
118
+ t.officeTitle && /* @__PURE__ */ P("p", {
119
+ className: "mt-0.5 truncate text-xs text-text-muted",
120
+ children: t.officeTitle
121
+ }),
122
+ /* @__PURE__ */ F("div", {
123
+ className: "mt-2 flex flex-wrap items-center gap-1.5",
124
+ children: [
125
+ /* @__PURE__ */ P(be, { type: t.electionType }),
126
+ /* @__PURE__ */ P(ye, { status: t.status }),
127
+ t.turnoutPercent != null && /* @__PURE__ */ F("span", {
128
+ className: "inline-flex items-center gap-1 rounded-full bg-bg-sunken px-2.5 py-0.5 text-xs font-medium text-text-secondary tabular-nums",
129
+ children: [
130
+ /* @__PURE__ */ P(D, {
131
+ className: "size-3",
132
+ "aria-hidden": "true"
133
+ }),
134
+ $(t.turnoutPercent),
135
+ " turnout"
136
+ ]
137
+ })
138
+ ]
139
+ })
140
+ ]
141
+ }) }), Se = ({ results: e }) => {
142
+ let t = x(() => [...e].sort((e, t) => e.position != null && t.position != null ? e.position - t.position : e.position == null ? t.position == null ? t.votes - e.votes : 1 : -1), [e]);
143
+ return /* @__PURE__ */ P("div", {
144
+ className: "overflow-x-auto",
145
+ children: /* @__PURE__ */ F("table", {
146
+ className: "w-full min-w-[36rem] border-collapse text-left",
147
+ children: [/* @__PURE__ */ P("thead", { children: /* @__PURE__ */ F("tr", {
148
+ className: "border-b border-border-seam text-xs font-medium uppercase tracking-wide text-text-muted",
149
+ children: [
150
+ /* @__PURE__ */ P("th", {
151
+ scope: "col",
152
+ className: "py-2.5 pr-3 font-medium",
153
+ children: "Candidate"
154
+ }),
155
+ /* @__PURE__ */ P("th", {
156
+ scope: "col",
157
+ className: "px-3 py-2.5 font-medium",
158
+ children: "Party"
159
+ }),
160
+ /* @__PURE__ */ P("th", {
161
+ scope: "col",
162
+ className: "px-3 py-2.5 text-right font-medium",
163
+ children: "Votes"
164
+ }),
165
+ /* @__PURE__ */ P("th", {
166
+ scope: "col",
167
+ className: "px-3 py-2.5 text-right font-medium",
168
+ children: "Share"
169
+ }),
170
+ /* @__PURE__ */ P("th", {
171
+ scope: "col",
172
+ className: "px-3 py-2.5 text-right font-medium",
173
+ children: "Position"
174
+ })
175
+ ]
176
+ }) }), /* @__PURE__ */ P("tbody", { children: t.map((e) => /* @__PURE__ */ F("tr", {
177
+ className: "border-b border-border-subtle last:border-0 align-middle",
178
+ children: [
179
+ /* @__PURE__ */ P("td", {
180
+ className: "py-3 pr-3",
181
+ children: /* @__PURE__ */ F("span", {
182
+ className: "flex items-center gap-2",
183
+ children: [e.isWinner && /* @__PURE__ */ P(j, {
184
+ className: "size-4 shrink-0 text-status-success-text",
185
+ "aria-label": "Winner"
186
+ }), /* @__PURE__ */ P("span", {
187
+ className: "truncate text-sm font-medium text-text-primary",
188
+ children: e.candidateName
189
+ })]
190
+ })
191
+ }),
192
+ /* @__PURE__ */ P("td", {
193
+ className: "px-3 py-3 text-sm text-text-secondary",
194
+ children: e.isIndependent ? "Independent" : e.party ?? "—"
195
+ }),
196
+ /* @__PURE__ */ P("td", {
197
+ className: "px-3 py-3 text-right text-sm font-medium tabular-nums text-text-primary",
198
+ children: r(e.votes)
199
+ }),
200
+ /* @__PURE__ */ P("td", {
201
+ className: "px-3 py-3 text-right text-sm tabular-nums text-text-secondary",
202
+ children: $(e.votePercent)
203
+ }),
204
+ /* @__PURE__ */ P("td", {
205
+ className: "px-3 py-3 text-right text-sm tabular-nums text-text-secondary",
206
+ children: e.position == null ? "—" : r(e.position)
207
+ })
208
+ ]
209
+ }, e.id)) })]
210
+ })
211
+ });
212
+ }, Ce = ({ electionId: e, onEdit: t, onDelete: a, onRecordResults: o }) => {
213
+ let { data: c, isLoading: l, isError: u, refetch: d } = s(e);
214
+ if (l) return /* @__PURE__ */ P(h, {
215
+ title: "Election",
216
+ icon: /* @__PURE__ */ P(M, {}),
217
+ className: "border-border-seam",
218
+ children: /* @__PURE__ */ P(p, {
219
+ label: "Loading election…",
220
+ className: "min-h-[16rem]"
221
+ })
222
+ });
223
+ if (u || !c) return /* @__PURE__ */ P(h, {
224
+ title: "Election",
225
+ icon: /* @__PURE__ */ P(M, {}),
226
+ className: "border-border-seam",
227
+ children: /* @__PURE__ */ P(f, {
228
+ className: "min-h-[16rem]",
229
+ message: "We couldn't load this election.",
230
+ onRetry: () => {
231
+ d();
232
+ }
233
+ })
234
+ });
235
+ let m = c.results ?? [], g = [
236
+ {
237
+ label: "Registered voters",
238
+ value: r(c.registeredVoters),
239
+ icon: /* @__PURE__ */ P(ie, {})
240
+ },
241
+ {
242
+ label: "Votes cast",
243
+ value: r(c.votesCast),
244
+ icon: /* @__PURE__ */ P(M, {})
245
+ },
246
+ {
247
+ label: "Turnout",
248
+ value: $(c.turnoutPercent),
249
+ icon: /* @__PURE__ */ P(D, {}),
250
+ tone: "accent"
251
+ },
252
+ {
253
+ label: "Valid votes",
254
+ value: r(c.validVotes),
255
+ icon: /* @__PURE__ */ P(w, {}),
256
+ tone: "success"
257
+ },
258
+ {
259
+ label: "Invalid votes",
260
+ value: r(c.invalidVotes),
261
+ icon: /* @__PURE__ */ P(E, {}),
262
+ tone: "warning"
263
+ }
264
+ ];
265
+ return /* @__PURE__ */ F("div", {
266
+ className: "space-y-4",
267
+ children: [/* @__PURE__ */ F(h, {
268
+ title: c.name,
269
+ icon: /* @__PURE__ */ P(M, {}),
270
+ className: "border-border-seam",
271
+ actions: /* @__PURE__ */ F("div", {
272
+ className: "flex items-center gap-1",
273
+ children: [
274
+ /* @__PURE__ */ F(I, {
275
+ size: "sm",
276
+ variant: "outline",
277
+ onClick: () => o(c),
278
+ children: [/* @__PURE__ */ P(E, { className: "mr-1.5 h-4 w-4" }), " Record results"]
279
+ }),
280
+ /* @__PURE__ */ P(I, {
281
+ size: "sm",
282
+ variant: "ghost",
283
+ onClick: () => t(c),
284
+ "aria-label": `Edit ${c.name}`,
285
+ children: /* @__PURE__ */ P(re, { className: "h-4 w-4" })
286
+ }),
287
+ /* @__PURE__ */ P(I, {
288
+ size: "sm",
289
+ variant: "ghost",
290
+ onClick: () => a(c),
291
+ "aria-label": `Delete ${c.name}`,
292
+ children: /* @__PURE__ */ P(k, { className: "h-4 w-4" })
293
+ })
294
+ ]
295
+ }),
296
+ children: [
297
+ /* @__PURE__ */ F("div", {
298
+ className: "flex flex-wrap items-center gap-2",
299
+ children: [
300
+ /* @__PURE__ */ P(be, { type: c.electionType }),
301
+ /* @__PURE__ */ P(ye, { status: c.status }),
302
+ /* @__PURE__ */ P(b, { status: c.verification }),
303
+ /* @__PURE__ */ F("span", {
304
+ className: "inline-flex items-center gap-1.5 text-sm text-text-secondary",
305
+ children: [/* @__PURE__ */ P(C, {
306
+ className: "size-4 text-text-muted",
307
+ "aria-hidden": "true"
308
+ }), n(c.electionDate)]
309
+ }),
310
+ c.resultDeclaredOn && /* @__PURE__ */ F("span", {
311
+ className: "text-sm text-text-muted",
312
+ children: ["Declared ", n(c.resultDeclaredOn)]
313
+ })
314
+ ]
315
+ }),
316
+ c.officeTitle && /* @__PURE__ */ F("p", {
317
+ className: "mt-2 text-sm text-text-secondary",
318
+ children: ["Office: ", c.officeTitle]
319
+ }),
320
+ /* @__PURE__ */ P("div", {
321
+ className: "mt-4",
322
+ children: /* @__PURE__ */ P(ne, { stats: g })
323
+ }),
324
+ (c.sourceName || he(c.sourceUrl)) && /* @__PURE__ */ F("div", {
325
+ className: "mt-3 flex flex-wrap items-center gap-3 text-xs text-text-muted",
326
+ children: [c.sourceName && /* @__PURE__ */ F("span", { children: ["Source: ", c.sourceName] }), he(c.sourceUrl) && /* @__PURE__ */ F("a", {
327
+ href: c.sourceUrl ?? void 0,
328
+ target: "_blank",
329
+ rel: "noreferrer noopener",
330
+ className: "inline-flex items-center gap-1 font-medium text-action-primary-text underline-offset-2 hover:underline",
331
+ children: ["Open source ", /* @__PURE__ */ P(T, {
332
+ className: "size-3.5",
333
+ "aria-hidden": "true"
334
+ })]
335
+ })]
336
+ })
337
+ ]
338
+ }), /* @__PURE__ */ P(h, {
339
+ title: "Declared results",
340
+ icon: /* @__PURE__ */ P(j, {}),
341
+ className: "border-border-seam",
342
+ flush: m.length > 0,
343
+ bodyClassName: m.length > 0 ? "px-5 pb-5" : void 0,
344
+ children: m.length === 0 ? /* @__PURE__ */ P(i, {
345
+ illustration: "empty-data",
346
+ title: "No results declared yet",
347
+ description: "Once counting is complete, record each candidate's vote count here and the shares are computed for you.",
348
+ action: /* @__PURE__ */ F(I, {
349
+ onClick: () => o(c),
350
+ children: [/* @__PURE__ */ P(E, { className: "mr-1.5 h-4 w-4" }), " Record results"]
351
+ })
352
+ }) : /* @__PURE__ */ F(N, { children: [/* @__PURE__ */ P(Se, { results: m }), (c.winningMarginVotes != null || c.winningMarginPercent != null) && /* @__PURE__ */ F("p", {
353
+ className: "mt-3 text-sm text-text-secondary",
354
+ children: [
355
+ /* @__PURE__ */ P("span", {
356
+ className: "font-medium text-text-primary",
357
+ children: "Winning margin: "
358
+ }),
359
+ c.winningMarginVotes == null ? "not published" : `${r(c.winningMarginVotes)} votes`,
360
+ c.winningMarginPercent != null && ` (${$(c.winningMarginPercent)} of valid votes)`
361
+ ]
362
+ })] })
363
+ })]
364
+ });
365
+ }, we = ({ election: e, busy: t, onCancel: n, onSubmit: r }) => {
366
+ let [i, a] = S(e?.name ?? ""), [o, s] = S(e?.electionType ?? "LOCAL"), [c, l] = S(e?.officeTitle ?? ""), [u, d] = S(ge(e?.electionDate)), [f, p] = S(e?.status ?? "SCHEDULED"), [m, h] = S(e?.registeredVoters == null ? "" : String(e.registeredVoters)), [g, v] = S(e?.votesCast == null ? "" : String(e.votesCast)), [y, b] = S(e?.validVotes == null ? "" : String(e.validVotes)), [te, ne] = S(e?.invalidVotes == null ? "" : String(e.invalidVotes)), [x, C] = S(ge(e?.resultDeclaredOn)), [w, T] = S(e?.sourceName ?? ""), [E, re] = S(e?.sourceUrl ?? ""), [D, O] = S(e?.verification ?? "UNVERIFIED"), [k, A] = S(null), j = async () => {
367
+ if (!i.trim()) {
368
+ A("An election name is required.");
369
+ return;
370
+ }
371
+ let e = _e(u);
372
+ if (!e) {
373
+ A("A valid election date is required.");
374
+ return;
375
+ }
376
+ let t = {
377
+ registeredVoters: Q(m),
378
+ votesCast: Q(g),
379
+ validVotes: Q(y),
380
+ invalidVotes: Q(te)
381
+ };
382
+ if (Object.values(t).some((e) => e != null && e < 0)) {
383
+ A("Vote counts cannot be negative.");
384
+ return;
385
+ }
386
+ let n = {
387
+ name: i.trim(),
388
+ electionType: o,
389
+ officeTitle: Z(c),
390
+ status: f,
391
+ registeredVoters: t.registeredVoters,
392
+ votesCast: t.votesCast,
393
+ validVotes: t.validVotes,
394
+ invalidVotes: t.invalidVotes,
395
+ resultDeclaredOn: _e(x),
396
+ sourceName: Z(w),
397
+ sourceUrl: Z(E),
398
+ verification: D
399
+ };
400
+ try {
401
+ await r({
402
+ create: {
403
+ jurisdictionId: "",
404
+ electionDate: e,
405
+ ...n
406
+ },
407
+ update: {
408
+ electionDate: e,
409
+ ...n
410
+ }
411
+ });
412
+ } catch (e) {
413
+ A(_(e));
414
+ }
415
+ };
416
+ return /* @__PURE__ */ F(N, { children: [
417
+ /* @__PURE__ */ F(U, { children: [/* @__PURE__ */ P(W, { children: e ? "Edit election" : "Add an election" }), /* @__PURE__ */ P(V, { children: "Publish an electoral event for this jurisdiction. Turnout is computed from the counts you record — leave a figure blank until it is officially published." })] }),
418
+ /* @__PURE__ */ F("div", {
419
+ className: "flex flex-col gap-4 py-2",
420
+ children: [
421
+ /* @__PURE__ */ F("div", {
422
+ className: "grid gap-1.5",
423
+ children: [/* @__PURE__ */ P(R, {
424
+ htmlFor: "election-name",
425
+ children: "Name"
426
+ }), /* @__PURE__ */ P(L, {
427
+ id: "election-name",
428
+ value: i,
429
+ onChange: (e) => a(e.target.value)
430
+ })]
431
+ }),
432
+ /* @__PURE__ */ F("div", {
433
+ className: "grid gap-4 sm:grid-cols-2",
434
+ children: [/* @__PURE__ */ F("div", {
435
+ className: "grid gap-1.5",
436
+ children: [/* @__PURE__ */ P(R, { children: "Election type" }), /* @__PURE__ */ F(G, {
437
+ value: o,
438
+ onValueChange: (e) => s(e),
439
+ children: [/* @__PURE__ */ P(J, {
440
+ "aria-label": "Election type",
441
+ children: /* @__PURE__ */ P(Y, {})
442
+ }), /* @__PURE__ */ P(K, { children: le.map((e) => /* @__PURE__ */ P(q, {
443
+ value: e,
444
+ children: ue[e]
445
+ }, e)) })]
446
+ })]
447
+ }), /* @__PURE__ */ F("div", {
448
+ className: "grid gap-1.5",
449
+ children: [/* @__PURE__ */ P(R, { children: "Status" }), /* @__PURE__ */ F(G, {
450
+ value: f,
451
+ onValueChange: (e) => p(e),
452
+ children: [/* @__PURE__ */ P(J, {
453
+ "aria-label": "Status",
454
+ children: /* @__PURE__ */ P(Y, {})
455
+ }), /* @__PURE__ */ P(K, { children: de.map((e) => /* @__PURE__ */ P(q, {
456
+ value: e,
457
+ children: X[e]
458
+ }, e)) })]
459
+ })]
460
+ })]
461
+ }),
462
+ /* @__PURE__ */ F("div", {
463
+ className: "grid gap-4 sm:grid-cols-2",
464
+ children: [/* @__PURE__ */ F("div", {
465
+ className: "grid gap-1.5",
466
+ children: [/* @__PURE__ */ P(R, {
467
+ htmlFor: "election-date",
468
+ children: "Election date"
469
+ }), /* @__PURE__ */ P(L, {
470
+ id: "election-date",
471
+ type: "date",
472
+ value: u,
473
+ onChange: (e) => d(e.target.value)
474
+ })]
475
+ }), /* @__PURE__ */ F("div", {
476
+ className: "grid gap-1.5",
477
+ children: [/* @__PURE__ */ P(R, {
478
+ htmlFor: "election-office",
479
+ children: "Office contested (optional)"
480
+ }), /* @__PURE__ */ P(L, {
481
+ id: "election-office",
482
+ value: c,
483
+ onChange: (e) => l(e.target.value)
484
+ })]
485
+ })]
486
+ }),
487
+ /* @__PURE__ */ F("div", {
488
+ className: "grid gap-4 sm:grid-cols-2",
489
+ children: [
490
+ /* @__PURE__ */ F("div", {
491
+ className: "grid gap-1.5",
492
+ children: [/* @__PURE__ */ P(R, {
493
+ htmlFor: "election-registered",
494
+ children: "Registered voters (optional)"
495
+ }), /* @__PURE__ */ P(L, {
496
+ id: "election-registered",
497
+ type: "number",
498
+ min: "0",
499
+ value: m,
500
+ onChange: (e) => h(e.target.value)
501
+ })]
502
+ }),
503
+ /* @__PURE__ */ F("div", {
504
+ className: "grid gap-1.5",
505
+ children: [/* @__PURE__ */ P(R, {
506
+ htmlFor: "election-cast",
507
+ children: "Votes cast (optional)"
508
+ }), /* @__PURE__ */ P(L, {
509
+ id: "election-cast",
510
+ type: "number",
511
+ min: "0",
512
+ value: g,
513
+ onChange: (e) => v(e.target.value)
514
+ })]
515
+ }),
516
+ /* @__PURE__ */ F("div", {
517
+ className: "grid gap-1.5",
518
+ children: [/* @__PURE__ */ P(R, {
519
+ htmlFor: "election-valid",
520
+ children: "Valid votes (optional)"
521
+ }), /* @__PURE__ */ P(L, {
522
+ id: "election-valid",
523
+ type: "number",
524
+ min: "0",
525
+ value: y,
526
+ onChange: (e) => b(e.target.value)
527
+ })]
528
+ }),
529
+ /* @__PURE__ */ F("div", {
530
+ className: "grid gap-1.5",
531
+ children: [/* @__PURE__ */ P(R, {
532
+ htmlFor: "election-invalid",
533
+ children: "Invalid votes (optional)"
534
+ }), /* @__PURE__ */ P(L, {
535
+ id: "election-invalid",
536
+ type: "number",
537
+ min: "0",
538
+ value: te,
539
+ onChange: (e) => ne(e.target.value)
540
+ })]
541
+ })
542
+ ]
543
+ }),
544
+ /* @__PURE__ */ F("div", {
545
+ className: "grid gap-4 sm:grid-cols-2",
546
+ children: [/* @__PURE__ */ F("div", {
547
+ className: "grid gap-1.5",
548
+ children: [/* @__PURE__ */ P(R, {
549
+ htmlFor: "election-declared",
550
+ children: "Result declared on (optional)"
551
+ }), /* @__PURE__ */ P(L, {
552
+ id: "election-declared",
553
+ type: "date",
554
+ value: x,
555
+ onChange: (e) => C(e.target.value)
556
+ })]
557
+ }), /* @__PURE__ */ F("div", {
558
+ className: "grid gap-1.5",
559
+ children: [/* @__PURE__ */ P(R, { children: "Provenance" }), /* @__PURE__ */ F(G, {
560
+ value: D,
561
+ onValueChange: (e) => O(e),
562
+ children: [/* @__PURE__ */ P(J, {
563
+ "aria-label": "Provenance",
564
+ children: /* @__PURE__ */ P(Y, {})
565
+ }), /* @__PURE__ */ P(K, { children: me.map((e) => /* @__PURE__ */ P(q, {
566
+ value: e,
567
+ children: ee[e]
568
+ }, e)) })]
569
+ })]
570
+ })]
571
+ }),
572
+ /* @__PURE__ */ F("div", {
573
+ className: "grid gap-4 sm:grid-cols-2",
574
+ children: [/* @__PURE__ */ F("div", {
575
+ className: "grid gap-1.5",
576
+ children: [/* @__PURE__ */ P(R, {
577
+ htmlFor: "election-source-name",
578
+ children: "Source name (optional)"
579
+ }), /* @__PURE__ */ P(L, {
580
+ id: "election-source-name",
581
+ value: w,
582
+ onChange: (e) => T(e.target.value)
583
+ })]
584
+ }), /* @__PURE__ */ F("div", {
585
+ className: "grid gap-1.5",
586
+ children: [/* @__PURE__ */ P(R, {
587
+ htmlFor: "election-source-url",
588
+ children: "Source URL (optional)"
589
+ }), /* @__PURE__ */ P(L, {
590
+ id: "election-source-url",
591
+ value: E,
592
+ placeholder: "https://",
593
+ onChange: (e) => re(e.target.value)
594
+ })]
595
+ })]
596
+ }),
597
+ k && /* @__PURE__ */ P("p", {
598
+ className: "text-sm text-status-error-text",
599
+ children: k
600
+ })
601
+ ]
602
+ }),
603
+ /* @__PURE__ */ F(H, { children: [/* @__PURE__ */ P(I, {
604
+ variant: "outline",
605
+ onClick: n,
606
+ disabled: t,
607
+ children: "Cancel"
608
+ }), /* @__PURE__ */ P(I, {
609
+ onClick: () => {
610
+ j();
611
+ },
612
+ disabled: t,
613
+ children: e ? "Save changes" : "Add election"
614
+ })] })
615
+ ] });
616
+ }, Te = ({ open: e, onOpenChange: t, jurisdictionId: n, election: r, onSaved: i }) => {
617
+ let o = a(), s = u(), c = o.isPending || s.isPending;
618
+ return /* @__PURE__ */ P(z, {
619
+ open: e,
620
+ onOpenChange: (e) => c ? void 0 : t(e),
621
+ children: /* @__PURE__ */ P(B, {
622
+ className: "max-h-[90vh] overflow-y-auto sm:max-w-2xl",
623
+ children: e && /* @__PURE__ */ P(we, {
624
+ election: r,
625
+ busy: c,
626
+ onCancel: () => t(!1),
627
+ onSubmit: async ({ create: e, update: a }) => {
628
+ if (r) {
629
+ let e = await s.mutateAsync({
630
+ id: r.id,
631
+ input: a
632
+ });
633
+ v.success("Election updated", e.name), i(e);
634
+ } else {
635
+ let t = await o.mutateAsync({
636
+ ...e,
637
+ jurisdictionId: n
638
+ });
639
+ v.success("Election added", t.name), i(t);
640
+ }
641
+ t(!1);
642
+ }
643
+ })
644
+ })
645
+ });
646
+ }, Ee = () => ({
647
+ candidateName: "",
648
+ party: "",
649
+ isIndependent: !1,
650
+ votes: "",
651
+ position: "",
652
+ isWinner: !1
653
+ });
654
+ function De(e) {
655
+ return e.length === 0 ? [Ee()] : [...e].sort((e, t) => e.position != null && t.position != null ? e.position - t.position : t.votes - e.votes).map((e) => ({
656
+ candidateName: e.candidateName,
657
+ party: e.party ?? "",
658
+ isIndependent: e.isIndependent,
659
+ votes: String(e.votes),
660
+ position: e.position == null ? "" : String(e.position),
661
+ isWinner: e.isWinner
662
+ }));
663
+ }
664
+ var Oe = ({ election: e, busy: t, onCancel: n, onSubmit: r }) => {
665
+ let [i, a] = S(() => De(e.results ?? [])), [o, s] = S(null), c = (e, t) => {
666
+ a((n) => n.map((n, r) => r === e ? {
667
+ ...n,
668
+ ...t
669
+ } : n));
670
+ }, l = async () => {
671
+ let e = i.filter((e) => e.candidateName.trim() !== "");
672
+ if (e.length === 0) {
673
+ s("Add at least one candidate.");
674
+ return;
675
+ }
676
+ let t = [];
677
+ for (let n of e) {
678
+ let e = Q(n.votes);
679
+ if (e == null || e < 0 || !Number.isInteger(e)) {
680
+ s(`Enter a whole, non-negative vote count for ${n.candidateName.trim()}.`);
681
+ return;
682
+ }
683
+ let r = Q(n.position);
684
+ if (r != null && (r < 1 || !Number.isInteger(r))) {
685
+ s(`Position for ${n.candidateName.trim()} must be a whole number from 1 upwards.`);
686
+ return;
687
+ }
688
+ t.push({
689
+ candidateName: n.candidateName.trim(),
690
+ party: n.isIndependent ? null : Z(n.party),
691
+ isIndependent: n.isIndependent,
692
+ votes: e,
693
+ position: r,
694
+ isWinner: n.isWinner
695
+ });
696
+ }
697
+ try {
698
+ await r(t);
699
+ } catch (e) {
700
+ s(_(e));
701
+ }
702
+ };
703
+ return /* @__PURE__ */ F(N, { children: [
704
+ /* @__PURE__ */ F(U, { children: [/* @__PURE__ */ P(W, { children: "Record results" }), /* @__PURE__ */ F(V, { children: [
705
+ "These rows replace every declared result for ",
706
+ e.name,
707
+ ". Vote shares are recomputed from the counts you enter."
708
+ ] })] }),
709
+ /* @__PURE__ */ F("div", {
710
+ className: "flex flex-col gap-3 py-2",
711
+ children: [
712
+ i.map((e, t) => /* @__PURE__ */ F("div", {
713
+ className: "rounded-lg border border-border-seam bg-bg-surface p-3 sm:p-4",
714
+ children: [
715
+ /* @__PURE__ */ F("div", {
716
+ className: "flex items-center justify-between gap-2",
717
+ children: [/* @__PURE__ */ F("span", {
718
+ className: "text-xs font-semibold uppercase tracking-wide text-text-muted",
719
+ children: ["Candidate ", t + 1]
720
+ }), /* @__PURE__ */ P(I, {
721
+ type: "button",
722
+ size: "sm",
723
+ variant: "ghost",
724
+ "aria-label": `Remove candidate ${t + 1}`,
725
+ disabled: i.length === 1,
726
+ onClick: () => a((e) => e.filter((e, n) => n !== t)),
727
+ children: /* @__PURE__ */ P(k, { className: "h-4 w-4" })
728
+ })]
729
+ }),
730
+ /* @__PURE__ */ F("div", {
731
+ className: "mt-2 grid gap-3 sm:grid-cols-2",
732
+ children: [
733
+ /* @__PURE__ */ F("div", {
734
+ className: "grid gap-1.5",
735
+ children: [/* @__PURE__ */ P(R, {
736
+ htmlFor: `result-name-${t}`,
737
+ children: "Candidate name"
738
+ }), /* @__PURE__ */ P(L, {
739
+ id: `result-name-${t}`,
740
+ value: e.candidateName,
741
+ onChange: (e) => c(t, { candidateName: e.target.value })
742
+ })]
743
+ }),
744
+ /* @__PURE__ */ F("div", {
745
+ className: "grid gap-1.5",
746
+ children: [/* @__PURE__ */ P(R, {
747
+ htmlFor: `result-party-${t}`,
748
+ children: "Party"
749
+ }), /* @__PURE__ */ P(L, {
750
+ id: `result-party-${t}`,
751
+ value: e.party,
752
+ disabled: e.isIndependent,
753
+ placeholder: e.isIndependent ? "Independent" : void 0,
754
+ onChange: (e) => c(t, { party: e.target.value })
755
+ })]
756
+ }),
757
+ /* @__PURE__ */ F("div", {
758
+ className: "grid gap-1.5",
759
+ children: [/* @__PURE__ */ P(R, {
760
+ htmlFor: `result-votes-${t}`,
761
+ children: "Votes"
762
+ }), /* @__PURE__ */ P(L, {
763
+ id: `result-votes-${t}`,
764
+ type: "number",
765
+ min: "0",
766
+ step: "1",
767
+ value: e.votes,
768
+ onChange: (e) => c(t, { votes: e.target.value })
769
+ })]
770
+ }),
771
+ /* @__PURE__ */ F("div", {
772
+ className: "grid gap-1.5",
773
+ children: [/* @__PURE__ */ P(R, {
774
+ htmlFor: `result-position-${t}`,
775
+ children: "Position (optional)"
776
+ }), /* @__PURE__ */ P(L, {
777
+ id: `result-position-${t}`,
778
+ type: "number",
779
+ min: "1",
780
+ step: "1",
781
+ value: e.position,
782
+ onChange: (e) => c(t, { position: e.target.value })
783
+ })]
784
+ })
785
+ ]
786
+ }),
787
+ /* @__PURE__ */ F("div", {
788
+ className: "mt-3 flex flex-wrap items-center gap-6",
789
+ children: [/* @__PURE__ */ F("div", {
790
+ className: "flex items-center gap-2",
791
+ children: [/* @__PURE__ */ P(se, {
792
+ id: `result-independent-${t}`,
793
+ checked: e.isIndependent,
794
+ onCheckedChange: (e) => c(t, { isIndependent: e })
795
+ }), /* @__PURE__ */ P(R, {
796
+ htmlFor: `result-independent-${t}`,
797
+ children: "Independent"
798
+ })]
799
+ }), /* @__PURE__ */ F("div", {
800
+ className: "flex items-center gap-2",
801
+ children: [/* @__PURE__ */ P(se, {
802
+ id: `result-winner-${t}`,
803
+ checked: e.isWinner,
804
+ onCheckedChange: (e) => c(t, { isWinner: e })
805
+ }), /* @__PURE__ */ P(R, {
806
+ htmlFor: `result-winner-${t}`,
807
+ children: "Winner"
808
+ })]
809
+ })]
810
+ })
811
+ ]
812
+ }, t)),
813
+ /* @__PURE__ */ F(I, {
814
+ type: "button",
815
+ size: "sm",
816
+ variant: "outline",
817
+ className: "self-start",
818
+ onClick: () => a((e) => [...e, Ee()]),
819
+ children: [/* @__PURE__ */ P(O, { className: "mr-1.5 h-4 w-4" }), " Add candidate"]
820
+ }),
821
+ o && /* @__PURE__ */ P("p", {
822
+ className: "text-sm text-status-error-text",
823
+ children: o
824
+ })
825
+ ]
826
+ }),
827
+ /* @__PURE__ */ F(H, { children: [/* @__PURE__ */ P(I, {
828
+ variant: "outline",
829
+ onClick: n,
830
+ disabled: t,
831
+ children: "Cancel"
832
+ }), /* @__PURE__ */ P(I, {
833
+ onClick: () => {
834
+ l();
835
+ },
836
+ disabled: t,
837
+ children: "Save results"
838
+ })] })
839
+ ] });
840
+ }, ke = ({ open: e, onOpenChange: t, election: n }) => {
841
+ let r = l();
842
+ return /* @__PURE__ */ P(z, {
843
+ open: e,
844
+ onOpenChange: (e) => r.isPending ? void 0 : t(e),
845
+ children: /* @__PURE__ */ P(B, {
846
+ className: "max-h-[90vh] overflow-y-auto sm:max-w-2xl",
847
+ children: e && n && /* @__PURE__ */ P(Oe, {
848
+ election: n,
849
+ busy: r.isPending,
850
+ onCancel: () => t(!1),
851
+ onSubmit: async (e) => {
852
+ let i = await r.mutateAsync({
853
+ electionId: n.id,
854
+ results: e
855
+ });
856
+ v.success("Results recorded", i.name), t(!1);
857
+ }
858
+ })
859
+ })
860
+ });
861
+ };
862
+ function Ae() {
863
+ let { jurisdictionId: n } = ae(), r = d(), [a, s] = S("ALL"), [l, u] = S(null), [ee, b] = S(!1), [ne, w] = S(null), [T, E] = S(!1), [re, D] = S(null), [k, j] = S(null), ie = o(), { data: N, isLoading: L, isError: R, refetch: z } = c({
864
+ jurisdictionId: n,
865
+ status: a === "ALL" ? void 0 : a
866
+ }, {
867
+ limit: ce,
868
+ cursor: r.cursor
869
+ }), B = x(() => N?.items ?? [], [N]), V = x(() => [...B].sort((e, t) => new Date(t.electionDate).getTime() - new Date(e.electionDate).getTime()), [B]), H = x(() => {
870
+ let e = [...B].sort((e, t) => new Date(e.electionDate).getTime() - new Date(t.electionDate).getTime()), t = [];
871
+ for (let n of e) {
872
+ let e = n.turnoutPercent;
873
+ e != null && t.push({
874
+ label: ve(n.electionDate),
875
+ value: e
876
+ });
877
+ }
878
+ return t;
879
+ }, [B]), U = l ?? V[0]?.id ?? null, W = () => {
880
+ w(null), b(!0);
881
+ };
882
+ return /* @__PURE__ */ F(y, {
883
+ description: "Electoral history, turnout and declared results for this jurisdiction.",
884
+ actions: /* @__PURE__ */ F(I, {
885
+ onClick: W,
886
+ children: [/* @__PURE__ */ P(O, { className: "mr-1.5 h-4 w-4" }), " Add election"]
887
+ }),
888
+ children: [
889
+ /* @__PURE__ */ F(oe, {
890
+ treatment: "plain",
891
+ className: "mb-5 border-border-seam p-5",
892
+ children: [/* @__PURE__ */ F("div", {
893
+ className: "flex items-start justify-between gap-4",
894
+ children: [/* @__PURE__ */ F("div", { children: [/* @__PURE__ */ P("h2", {
895
+ className: "text-lg font-semibold text-text-primary",
896
+ children: "Voter turnout over time"
897
+ }), /* @__PURE__ */ P("p", {
898
+ className: "mt-0.5 text-xs text-text-muted",
899
+ children: "Turnout as a percentage of registered voters. Only elections that publish a turnout figure are plotted."
900
+ })] }), /* @__PURE__ */ F("span", {
901
+ className: "shrink-0 rounded-full border border-border-seam bg-bg-surface px-3 py-1 text-xs font-medium text-text-secondary",
902
+ children: [
903
+ /* @__PURE__ */ P(A, {
904
+ className: "mr-1 inline size-3.5",
905
+ "aria-hidden": "true"
906
+ }),
907
+ H.length,
908
+ " ",
909
+ H.length === 1 ? "election plotted" : "elections plotted"
910
+ ]
911
+ })]
912
+ }), /* @__PURE__ */ P("div", {
913
+ className: "mt-4",
914
+ children: /* @__PURE__ */ P(t, {
915
+ data: H,
916
+ emptyLabel: "No turnout figures published yet."
917
+ })
918
+ })]
919
+ }),
920
+ /* @__PURE__ */ P("div", {
921
+ className: "mb-5",
922
+ children: /* @__PURE__ */ P(m, {
923
+ options: pe,
924
+ value: a,
925
+ onChange: (e) => {
926
+ s(e), r.reset(), u(null);
927
+ }
928
+ })
929
+ }),
930
+ L ? /* @__PURE__ */ P(p, { label: "Loading elections…" }) : R ? /* @__PURE__ */ P(f, {
931
+ message: "We couldn't load the elections for this jurisdiction.",
932
+ onRetry: () => {
933
+ z();
934
+ }
935
+ }) : V.length === 0 ? /* @__PURE__ */ P(i, {
936
+ illustration: "empty-data",
937
+ title: "No elections published yet",
938
+ description: a === "ALL" ? "Add the first electoral event for this jurisdiction to start publishing turnout and results." : `No election in this jurisdiction is currently ${X[a].toLowerCase()}.`,
939
+ action: a === "ALL" ? /* @__PURE__ */ F(I, {
940
+ onClick: W,
941
+ children: [/* @__PURE__ */ P(O, { className: "mr-1.5 h-4 w-4" }), " Add election"]
942
+ }) : /* @__PURE__ */ P(I, {
943
+ variant: "outline",
944
+ onClick: () => s("ALL"),
945
+ children: "Show all elections"
946
+ })
947
+ }) : /* @__PURE__ */ F("div", {
948
+ className: "grid gap-4 lg:grid-cols-3",
949
+ children: [/* @__PURE__ */ P("div", {
950
+ className: "lg:col-span-1",
951
+ children: /* @__PURE__ */ F(h, {
952
+ title: "Elections",
953
+ icon: /* @__PURE__ */ P(C, {}),
954
+ className: "border-border-seam",
955
+ children: [/* @__PURE__ */ P("ul", {
956
+ className: "space-y-2",
957
+ children: V.map((e) => /* @__PURE__ */ P(xe, {
958
+ election: e,
959
+ selected: e.id === U,
960
+ onSelect: () => u(e.id)
961
+ }, e.id))
962
+ }), /* @__PURE__ */ P(g, {
963
+ page: r.page,
964
+ pageSize: ce,
965
+ itemCount: V.length,
966
+ hasMore: N?.pageInfo.hasMore ?? !1,
967
+ onPageChange: (e) => {
968
+ r.onPageChange(e, N?.pageInfo.cursor), u(null);
969
+ }
970
+ })]
971
+ })
972
+ }), /* @__PURE__ */ P("div", {
973
+ className: e("lg:col-span-2", l ? "order-first lg:order-none" : void 0),
974
+ children: U ? /* @__PURE__ */ P(Ce, {
975
+ electionId: U,
976
+ onEdit: (e) => {
977
+ w(e), b(!0);
978
+ },
979
+ onDelete: j,
980
+ onRecordResults: (e) => {
981
+ D(e), E(!0);
982
+ }
983
+ }) : /* @__PURE__ */ P(h, {
984
+ title: "Election",
985
+ icon: /* @__PURE__ */ P(M, {}),
986
+ className: "border-border-seam",
987
+ children: /* @__PURE__ */ P("p", {
988
+ className: "text-sm text-text-secondary",
989
+ children: "Select an election to see its turnout and declared results."
990
+ })
991
+ })
992
+ })]
993
+ }),
994
+ n && /* @__PURE__ */ P(Te, {
995
+ open: ee,
996
+ onOpenChange: b,
997
+ jurisdictionId: n,
998
+ election: ne,
999
+ onSaved: (e) => u(e.id)
1000
+ }),
1001
+ /* @__PURE__ */ P(ke, {
1002
+ open: T,
1003
+ onOpenChange: E,
1004
+ election: re
1005
+ }),
1006
+ k && /* @__PURE__ */ P(te, {
1007
+ open: !!k,
1008
+ onOpenChange: (e) => e ? void 0 : j(null),
1009
+ title: `Delete ${k.name}?`,
1010
+ description: "This removes the election and every result declared against it.",
1011
+ confirmLabel: "Delete election",
1012
+ destructive: !0,
1013
+ onConfirm: async () => {
1014
+ try {
1015
+ await ie.mutateAsync(k.id), v.success("Election deleted", k.name), l === k.id && u(null);
1016
+ } catch (e) {
1017
+ v.error("Could not delete the election", _(e));
1018
+ } finally {
1019
+ j(null);
1020
+ }
1021
+ }
1022
+ })
1023
+ ]
1024
+ });
1025
+ }
1026
+ //#endregion
1027
+ export { Ae as ElectionsPage };
1028
+
1029
+ //# sourceMappingURL=ElectionsPage.js.map