@burdenoff/microfe-healthybowl 2026.714.2 → 2026.714.4
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.
- package/dist/healthybowl/HealthyBowlRoutes.js +149 -109
- package/dist/healthybowl/HealthyBowlRoutes.js.map +1 -1
- package/dist/healthybowl/hooks/useHealthyBowlContacts.js +149 -0
- package/dist/healthybowl/hooks/useHealthyBowlContacts.js.map +1 -0
- package/dist/healthybowl/hooks/useHealthyBowlLivestockDepth.js +200 -0
- package/dist/healthybowl/hooks/useHealthyBowlLivestockDepth.js.map +1 -0
- package/dist/healthybowl/hooks/useHealthyBowlStorage.js +162 -0
- package/dist/healthybowl/hooks/useHealthyBowlStorage.js.map +1 -0
- package/dist/healthybowl/pages/contacts/ContactDetailPage.js +224 -0
- package/dist/healthybowl/pages/contacts/ContactDetailPage.js.map +1 -0
- package/dist/healthybowl/pages/contacts/ContactFormModal.js +147 -0
- package/dist/healthybowl/pages/contacts/ContactFormModal.js.map +1 -0
- package/dist/healthybowl/pages/contacts/ContactsPage.js +241 -0
- package/dist/healthybowl/pages/contacts/ContactsPage.js.map +1 -0
- package/dist/healthybowl/pages/contacts/CsvImportModal.js +155 -0
- package/dist/healthybowl/pages/contacts/CsvImportModal.js.map +1 -0
- package/dist/healthybowl/pages/contacts/RecordOrderModal.js +131 -0
- package/dist/healthybowl/pages/contacts/RecordOrderModal.js.map +1 -0
- package/dist/healthybowl/pages/contacts/labels.js +46 -0
- package/dist/healthybowl/pages/contacts/labels.js.map +1 -0
- package/dist/healthybowl/pages/livestock/AnimalDepthFormModal.js +152 -0
- package/dist/healthybowl/pages/livestock/AnimalDepthFormModal.js.map +1 -0
- package/dist/healthybowl/pages/livestock/AnimalDepthPage.js +245 -0
- package/dist/healthybowl/pages/livestock/AnimalDepthPage.js.map +1 -0
- package/dist/healthybowl/pages/livestock/AnimalGroupModal.js +210 -0
- package/dist/healthybowl/pages/livestock/AnimalGroupModal.js.map +1 -0
- package/dist/healthybowl/pages/livestock/HerdDepthPage.js +189 -0
- package/dist/healthybowl/pages/livestock/HerdDepthPage.js.map +1 -0
- package/dist/healthybowl/pages/livestock/RecordWeightModal.js +100 -0
- package/dist/healthybowl/pages/livestock/RecordWeightModal.js.map +1 -0
- package/dist/healthybowl/pages/livestock/depthLabels.js +31 -0
- package/dist/healthybowl/pages/livestock/depthLabels.js.map +1 -0
- package/dist/healthybowl/pages/satellite/CropHealthAlertsPage.js +188 -0
- package/dist/healthybowl/pages/satellite/CropHealthAlertsPage.js.map +1 -0
- package/dist/healthybowl/pages/satellite/NdviComparePanel.js +196 -0
- package/dist/healthybowl/pages/satellite/NdviComparePanel.js.map +1 -0
- package/dist/healthybowl/pages/satellite/NdviGridThumbnail.js +44 -0
- package/dist/healthybowl/pages/satellite/NdviGridThumbnail.js.map +1 -0
- package/dist/healthybowl/pages/satellite/NdviHeatmapMap.js +144 -0
- package/dist/healthybowl/pages/satellite/NdviHeatmapMap.js.map +1 -0
- package/dist/healthybowl/pages/satellite/SatelliteCropHealthPage.js +278 -0
- package/dist/healthybowl/pages/satellite/SatelliteCropHealthPage.js.map +1 -0
- package/dist/healthybowl/pages/satellite/SatelliteFieldDetailPage.js +447 -0
- package/dist/healthybowl/pages/satellite/SatelliteFieldDetailPage.js.map +1 -0
- package/dist/healthybowl/pages/satellite/SatelliteSettingsPage.js +252 -0
- package/dist/healthybowl/pages/satellite/SatelliteSettingsPage.js.map +1 -0
- package/dist/healthybowl/pages/satellite/YieldReportPanel.js +236 -0
- package/dist/healthybowl/pages/satellite/YieldReportPanel.js.map +1 -0
- package/dist/healthybowl/pages/satellite/YieldSimulationPanel.js +363 -0
- package/dist/healthybowl/pages/satellite/YieldSimulationPanel.js.map +1 -0
- package/dist/healthybowl/pages/satellite/ndviColors.js +116 -0
- package/dist/healthybowl/pages/satellite/ndviColors.js.map +1 -0
- package/dist/healthybowl/pages/satellite/satelliteApi.js +191 -0
- package/dist/healthybowl/pages/satellite/satelliteApi.js.map +1 -0
- package/dist/healthybowl/pages/satellite/useSatelliteApi.js +15 -0
- package/dist/healthybowl/pages/satellite/useSatelliteApi.js.map +1 -0
- package/dist/healthybowl/pages/storage/PlaceLotModal.js +150 -0
- package/dist/healthybowl/pages/storage/PlaceLotModal.js.map +1 -0
- package/dist/healthybowl/pages/storage/RecordMovementModal.js +140 -0
- package/dist/healthybowl/pages/storage/RecordMovementModal.js.map +1 -0
- package/dist/healthybowl/pages/storage/StorageLocationFormModal.js +139 -0
- package/dist/healthybowl/pages/storage/StorageLocationFormModal.js.map +1 -0
- package/dist/healthybowl/pages/storage/StorageLotDetailPage.js +150 -0
- package/dist/healthybowl/pages/storage/StorageLotDetailPage.js.map +1 -0
- package/dist/healthybowl/pages/storage/StoragePage.js +251 -0
- package/dist/healthybowl/pages/storage/StoragePage.js.map +1 -0
- package/dist/healthybowl/pages/storage/labels.js +67 -0
- package/dist/healthybowl/pages/storage/labels.js.map +1 -0
- package/dist/node_modules/recharts/es6/cartesian/Scatter.js +368 -0
- package/dist/node_modules/recharts/es6/cartesian/Scatter.js.map +1 -0
- package/dist/node_modules/recharts/es6/cartesian/ZAxis.js +103 -0
- package/dist/node_modules/recharts/es6/cartesian/ZAxis.js.map +1 -0
- package/dist/node_modules/recharts/es6/chart/ComposedChart.js +38 -0
- package/dist/node_modules/recharts/es6/chart/ComposedChart.js.map +1 -0
- package/dist/node_modules/recharts/es6/util/DataUtils.js +12 -2
- package/dist/node_modules/recharts/es6/util/DataUtils.js.map +1 -1
- package/dist/node_modules/recharts/es6/util/ScatterUtils.js +48 -0
- package/dist/node_modules/recharts/es6/util/ScatterUtils.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import { useBasePath as e } from "../../hooks/useBasePath.js";
|
|
2
|
+
import { PageLayout as t } from "../../components/PageLayout.js";
|
|
3
|
+
import { StatCard as n } from "../../components/StatCard.js";
|
|
4
|
+
import { DataTable as r } from "../../components/DataTable.js";
|
|
5
|
+
import { StatusBadge as i } from "../../components/StatusBadge.js";
|
|
6
|
+
import { EmptyState as a } from "../../components/EmptyState.js";
|
|
7
|
+
import { ErrorState as o } from "../../components/ErrorState.js";
|
|
8
|
+
import { PageLoader as s } from "../../components/PageLoader.js";
|
|
9
|
+
import { useToast as c } from "../../hooks/useToast.js";
|
|
10
|
+
import "../../components/index.js";
|
|
11
|
+
import { useSatelliteApi as l } from "./useSatelliteApi.js";
|
|
12
|
+
import { NDVI_LEGEND_GRADIENT as u, formatDate as d, formatNdvi as f, formatTonnes as p, severityVariant as m, trendArrow as h } from "./ndviColors.js";
|
|
13
|
+
import { useCallback as g, useEffect as _, useMemo as v, useState as y } from "react";
|
|
14
|
+
import { AlertTriangle as b, Bell as x, RefreshCw as S, Satellite as C, Settings as w } from "lucide-react";
|
|
15
|
+
import { useNavigate as T } from "react-router-dom";
|
|
16
|
+
import { jsx as E, jsxs as D } from "react/jsx-runtime";
|
|
17
|
+
import { Button as O, Input as k } from "@burdenoff/fe-libs/ui";
|
|
18
|
+
//#region src/healthybowl/pages/satellite/SatelliteCropHealthPage.tsx
|
|
19
|
+
var A = () => {
|
|
20
|
+
let { api: A } = l(), M = T(), { buildPath: N } = e(), { toast: P } = c(), [F, I] = y(null), [L, R] = y(!0), [z, B] = y(null), [V, H] = y(!1), [U, W] = y(""), [G, K] = y("all"), q = g(async () => {
|
|
21
|
+
B(null);
|
|
22
|
+
try {
|
|
23
|
+
I(await A.getOverview());
|
|
24
|
+
} catch (e) {
|
|
25
|
+
B(e instanceof Error ? e.message : "Failed to load crop health.");
|
|
26
|
+
} finally {
|
|
27
|
+
R(!1);
|
|
28
|
+
}
|
|
29
|
+
}, [A]);
|
|
30
|
+
_(() => {
|
|
31
|
+
q();
|
|
32
|
+
}, [q]);
|
|
33
|
+
let J = g(async () => {
|
|
34
|
+
if (F) {
|
|
35
|
+
H(!0);
|
|
36
|
+
try {
|
|
37
|
+
let e = F.fields.some((e) => e.meanNdvi !== null), t = await A.refreshNdvi(void 0, e ? 0 : 5);
|
|
38
|
+
P({
|
|
39
|
+
title: "Satellite imagery refreshed",
|
|
40
|
+
description: `${t.fieldsRefreshed} field(s) updated · ${t.readingsCreated} reading(s) · ${t.stressedZonesDetected} stressed zone(s)${t.fieldsSkippedNoBoundary ? ` · ${t.fieldsSkippedNoBoundary} skipped (no boundary)` : ""}`,
|
|
41
|
+
variant: "success"
|
|
42
|
+
}), await q();
|
|
43
|
+
} catch (e) {
|
|
44
|
+
P({
|
|
45
|
+
title: "Refresh failed",
|
|
46
|
+
description: e instanceof Error ? e.message : "Unknown error",
|
|
47
|
+
variant: "error"
|
|
48
|
+
});
|
|
49
|
+
} finally {
|
|
50
|
+
H(!1);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}, [
|
|
54
|
+
A,
|
|
55
|
+
F,
|
|
56
|
+
P,
|
|
57
|
+
q
|
|
58
|
+
]), Y = v(() => {
|
|
59
|
+
if (!F) return [];
|
|
60
|
+
let e = U.trim().toLowerCase();
|
|
61
|
+
return F.fields.filter((t) => e && !t.fieldName.toLowerCase().includes(e) && !(t.cropName ?? "").toLowerCase().includes(e) ? !1 : G === "stressed" ? t.stressedZoneCount > 0 : G === "healthy" ? t.healthBand === "HEALTHY" || t.healthBand === "EXCELLENT" : !0);
|
|
62
|
+
}, [
|
|
63
|
+
F,
|
|
64
|
+
U,
|
|
65
|
+
G
|
|
66
|
+
]);
|
|
67
|
+
return L ? /* @__PURE__ */ E(s, {}) : z ? /* @__PURE__ */ E(o, {
|
|
68
|
+
title: "Couldn't load crop health",
|
|
69
|
+
description: z,
|
|
70
|
+
onRetry: () => void q()
|
|
71
|
+
}) : F ? /* @__PURE__ */ D(t, {
|
|
72
|
+
title: "Satellite Crop Health",
|
|
73
|
+
titleAccent: "Crop Health",
|
|
74
|
+
description: `${F.farmName ?? "Your farm"} · ${F.monitoredFieldCount} field(s) monitored · ${F.fieldsWithBoundaryCount} with a saved boundary`,
|
|
75
|
+
helpPrompt: "Explain the NDVI satellite crop health page and how the yield forecast is calculated.",
|
|
76
|
+
purpose: "A health map from space for every field. HealthyBowl pulls satellite vegetation-index (NDVI) imagery, turns it into a red→green heatmap, auto-flags stressed patches, and gives a transparent, rule-based harvest-tonnage estimate — so you can spot a problem in one corner without walking every acre.",
|
|
77
|
+
purposeIcon: /* @__PURE__ */ E(C, { className: "h-5 w-5" }),
|
|
78
|
+
actions: /* @__PURE__ */ D("div", {
|
|
79
|
+
className: "flex flex-wrap items-center gap-2",
|
|
80
|
+
children: [
|
|
81
|
+
/* @__PURE__ */ D(O, {
|
|
82
|
+
variant: "outline",
|
|
83
|
+
size: "sm",
|
|
84
|
+
onClick: () => M(N("satellite/alerts")),
|
|
85
|
+
children: [
|
|
86
|
+
/* @__PURE__ */ E(x, { className: "mr-1.5 h-4 w-4" }),
|
|
87
|
+
" Alerts",
|
|
88
|
+
F.openStressedZoneCount > 0 && /* @__PURE__ */ E("span", {
|
|
89
|
+
className: "ml-1.5 rounded-full bg-destructive px-1.5 text-xs text-white",
|
|
90
|
+
children: F.openStressedZoneCount
|
|
91
|
+
})
|
|
92
|
+
]
|
|
93
|
+
}),
|
|
94
|
+
/* @__PURE__ */ D(O, {
|
|
95
|
+
variant: "outline",
|
|
96
|
+
size: "sm",
|
|
97
|
+
onClick: () => M(N("satellite/settings")),
|
|
98
|
+
children: [/* @__PURE__ */ E(w, { className: "mr-1.5 h-4 w-4" }), " Settings"]
|
|
99
|
+
}),
|
|
100
|
+
/* @__PURE__ */ D(O, {
|
|
101
|
+
size: "sm",
|
|
102
|
+
onClick: () => void J(),
|
|
103
|
+
disabled: V,
|
|
104
|
+
children: [/* @__PURE__ */ E(S, { className: `mr-1.5 h-4 w-4 ${V ? "animate-spin" : ""}` }), " Refresh NDVI"]
|
|
105
|
+
})
|
|
106
|
+
]
|
|
107
|
+
}),
|
|
108
|
+
children: [
|
|
109
|
+
/* @__PURE__ */ D("div", {
|
|
110
|
+
className: "grid grid-cols-2 gap-3 sm:grid-cols-4",
|
|
111
|
+
children: [
|
|
112
|
+
/* @__PURE__ */ E(n, {
|
|
113
|
+
label: "Monitored fields",
|
|
114
|
+
value: F.monitoredFieldCount,
|
|
115
|
+
icon: /* @__PURE__ */ E(C, { className: "h-4 w-4" })
|
|
116
|
+
}),
|
|
117
|
+
/* @__PURE__ */ E(n, {
|
|
118
|
+
label: "With boundary",
|
|
119
|
+
value: F.fieldsWithBoundaryCount
|
|
120
|
+
}),
|
|
121
|
+
/* @__PURE__ */ E(n, {
|
|
122
|
+
label: "Stressed fields",
|
|
123
|
+
value: F.stressedFieldCount,
|
|
124
|
+
trend: F.stressedFieldCount > 0 ? "down" : "stable"
|
|
125
|
+
}),
|
|
126
|
+
/* @__PURE__ */ E(n, {
|
|
127
|
+
label: "Open alerts",
|
|
128
|
+
value: F.openStressedZoneCount,
|
|
129
|
+
icon: /* @__PURE__ */ E(b, { className: "h-4 w-4" })
|
|
130
|
+
})
|
|
131
|
+
]
|
|
132
|
+
}),
|
|
133
|
+
/* @__PURE__ */ D("div", {
|
|
134
|
+
className: "mt-5 flex flex-wrap items-center gap-2",
|
|
135
|
+
children: [/* @__PURE__ */ E(k, {
|
|
136
|
+
value: U,
|
|
137
|
+
onChange: (e) => W(e.target.value),
|
|
138
|
+
placeholder: "Search fields or crops…",
|
|
139
|
+
className: "max-w-xs"
|
|
140
|
+
}), [
|
|
141
|
+
"all",
|
|
142
|
+
"stressed",
|
|
143
|
+
"healthy"
|
|
144
|
+
].map((e) => /* @__PURE__ */ E(O, {
|
|
145
|
+
variant: G === e ? "default" : "outline",
|
|
146
|
+
size: "sm",
|
|
147
|
+
onClick: () => K(e),
|
|
148
|
+
children: e === "all" ? "All fields" : e === "stressed" ? "Stressed" : "Healthy"
|
|
149
|
+
}, e))]
|
|
150
|
+
}),
|
|
151
|
+
/* @__PURE__ */ E("div", {
|
|
152
|
+
className: "mt-4",
|
|
153
|
+
children: Y.length === 0 ? F.monitoredFieldCount === 0 ? /* @__PURE__ */ E(a, {
|
|
154
|
+
title: "No fields yet",
|
|
155
|
+
description: "Add a farm field with a drawn boundary on the Field Map, then refresh NDVI to see its crop-health heatmap.",
|
|
156
|
+
action: /* @__PURE__ */ E(O, {
|
|
157
|
+
onClick: () => M(N("field-map")),
|
|
158
|
+
children: "Open Field Map"
|
|
159
|
+
})
|
|
160
|
+
}) : F.fields.every((e) => e.meanNdvi === null) ? /* @__PURE__ */ E(a, {
|
|
161
|
+
title: "No satellite readings yet",
|
|
162
|
+
description: "Pull the first satellite imagery for every field that has a saved boundary.",
|
|
163
|
+
action: /* @__PURE__ */ D(O, {
|
|
164
|
+
onClick: () => void J(),
|
|
165
|
+
disabled: V,
|
|
166
|
+
children: [/* @__PURE__ */ E(S, { className: `mr-1.5 h-4 w-4 ${V ? "animate-spin" : ""}` }), " Pull satellite imagery"]
|
|
167
|
+
})
|
|
168
|
+
}) : /* @__PURE__ */ E(a, {
|
|
169
|
+
title: "No matching fields",
|
|
170
|
+
description: "Adjust your search or filter."
|
|
171
|
+
}) : /* @__PURE__ */ E(r, {
|
|
172
|
+
columns: [
|
|
173
|
+
{
|
|
174
|
+
key: "fieldName",
|
|
175
|
+
header: "Field name",
|
|
176
|
+
render: (e) => /* @__PURE__ */ D("div", {
|
|
177
|
+
className: "flex items-center gap-2",
|
|
178
|
+
children: [e.stressedZoneCount > 0 && /* @__PURE__ */ E("span", {
|
|
179
|
+
className: `h-2 w-2 rounded-full ${e.maxZoneSeverity === "HIGH" ? "bg-destructive" : "bg-warning"}`,
|
|
180
|
+
"aria-hidden": !0
|
|
181
|
+
}), /* @__PURE__ */ E("span", {
|
|
182
|
+
className: "font-medium text-text-primary",
|
|
183
|
+
children: e.fieldName
|
|
184
|
+
})]
|
|
185
|
+
})
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
key: "cropName",
|
|
189
|
+
header: "Crop",
|
|
190
|
+
render: (e) => e.cropName ?? "—"
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
key: "areaAcres",
|
|
194
|
+
header: "Area (ac)",
|
|
195
|
+
render: (e) => e.areaAcres.toFixed(2)
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
key: "meanNdvi",
|
|
199
|
+
header: "NDVI health score",
|
|
200
|
+
render: (e) => e.meanNdvi === null ? /* @__PURE__ */ E(i, {
|
|
201
|
+
label: "No data",
|
|
202
|
+
variant: "muted"
|
|
203
|
+
}) : /* @__PURE__ */ D("div", {
|
|
204
|
+
className: "min-w-[120px]",
|
|
205
|
+
children: [/* @__PURE__ */ E("div", {
|
|
206
|
+
className: `text-base font-semibold ${j(e.healthBand)}`,
|
|
207
|
+
children: f(e.meanNdvi)
|
|
208
|
+
}), /* @__PURE__ */ E("div", {
|
|
209
|
+
style: { background: u },
|
|
210
|
+
className: "mt-1 h-1.5 w-24 rounded-full ring-1 ring-border-subtle",
|
|
211
|
+
children: /* @__PURE__ */ E("span", {
|
|
212
|
+
className: "relative block h-1.5",
|
|
213
|
+
style: { marginLeft: `${Math.max(0, Math.min(100, (e.meanNdvi - .2) / .6 * 100))}%` },
|
|
214
|
+
children: /* @__PURE__ */ E("span", { className: "absolute -top-0.5 -ml-1 h-2.5 w-2.5 rounded-full border-2 border-white bg-text-primary" })
|
|
215
|
+
})
|
|
216
|
+
})]
|
|
217
|
+
})
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
key: "trendPct",
|
|
221
|
+
header: "Trend",
|
|
222
|
+
render: (e) => e.meanNdvi === null ? "—" : /* @__PURE__ */ D("span", {
|
|
223
|
+
className: e.trendDirection === "DOWN" ? "text-destructive" : "text-success",
|
|
224
|
+
children: [
|
|
225
|
+
h(e.trendDirection),
|
|
226
|
+
" ",
|
|
227
|
+
Math.abs(e.trendPct).toFixed(1),
|
|
228
|
+
"%"
|
|
229
|
+
]
|
|
230
|
+
})
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
key: "stressedZoneCount",
|
|
234
|
+
header: "Stressed zones",
|
|
235
|
+
render: (e) => /* @__PURE__ */ D("div", {
|
|
236
|
+
className: "flex items-center gap-1.5",
|
|
237
|
+
children: [/* @__PURE__ */ E("span", {
|
|
238
|
+
className: "tabular-nums text-text-primary",
|
|
239
|
+
children: e.stressedZoneCount
|
|
240
|
+
}), e.maxZoneSeverity && /* @__PURE__ */ E(i, {
|
|
241
|
+
label: e.maxZoneSeverity,
|
|
242
|
+
variant: m(e.maxZoneSeverity),
|
|
243
|
+
dot: !0
|
|
244
|
+
})]
|
|
245
|
+
})
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
key: "estimatedTonnes",
|
|
249
|
+
header: "Est. yield (t)",
|
|
250
|
+
render: (e) => e.estimatedTonnes === null ? "—" : `${p(e.estimatedTonnes)} ±${p(e.confidenceBand)}`
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
key: "lastReadingDate",
|
|
254
|
+
header: "Last reading",
|
|
255
|
+
render: (e) => d(e.lastReadingDate)
|
|
256
|
+
}
|
|
257
|
+
],
|
|
258
|
+
data: Y,
|
|
259
|
+
keyField: "fieldId",
|
|
260
|
+
onRowClick: (e) => M(N(`satellite/${e.fieldId}`))
|
|
261
|
+
})
|
|
262
|
+
})
|
|
263
|
+
]
|
|
264
|
+
}) : null;
|
|
265
|
+
};
|
|
266
|
+
function j(e) {
|
|
267
|
+
switch (e) {
|
|
268
|
+
case "EXCELLENT":
|
|
269
|
+
case "HEALTHY": return "text-success";
|
|
270
|
+
case "BELOW_AVERAGE": return "text-warning";
|
|
271
|
+
case "STRESSED": return "text-destructive";
|
|
272
|
+
default: return "text-text-secondary";
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
//#endregion
|
|
276
|
+
export { A as SatelliteCropHealthPage };
|
|
277
|
+
|
|
278
|
+
//# sourceMappingURL=SatelliteCropHealthPage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SatelliteCropHealthPage.js","names":[],"sources":["../../../../src/healthybowl/pages/satellite/SatelliteCropHealthPage.tsx"],"sourcesContent":["/**\n * Satellite Crop Health — All Fields (BOFF-2886, landing page).\n *\n * The fields-list table: every field with its NDVI health score, trend, stressed-\n * zone count and yield estimate, plus a \"Refresh NDVI\" action that pulls the latest\n * satellite reading for every field with a saved boundary. Rows drill into the\n * per-field Satellite Crop Health detail. No mocks — live gateway data.\n */\nimport { type FC, useCallback, useEffect, useMemo, useState } from 'react';\nimport { useNavigate } from 'react-router-dom';\nimport { Button, Input } from '@burdenoff/fe-libs/ui';\nimport { RefreshCw, Satellite, Bell, Settings, AlertTriangle } from 'lucide-react';\nimport { PageLayout, StatCard, DataTable, StatusBadge, EmptyState, ErrorState, PageLoader } from '../../components';\nimport type { Column } from '../../components';\nimport { useToast } from '../../hooks/useToast';\nimport { useBasePath } from '../../hooks/useBasePath';\nimport { useSatelliteApi } from './useSatelliteApi';\nimport type { CropHealthOverview, CropHealthFieldSummary } from './satelliteApi';\nimport { NDVI_LEGEND_GRADIENT, formatDate, formatNdvi, formatTonnes, severityVariant, trendArrow } from './ndviColors';\n\ntype FilterKey = 'all' | 'stressed' | 'healthy';\n\nexport const SatelliteCropHealthPage: FC = () => {\n const { api } = useSatelliteApi();\n const navigate = useNavigate();\n const { buildPath } = useBasePath();\n const { toast } = useToast();\n\n const [overview, setOverview] = useState<CropHealthOverview | null>(null);\n const [loading, setLoading] = useState(true);\n const [error, setError] = useState<string | null>(null);\n const [refreshing, setRefreshing] = useState(false);\n const [search, setSearch] = useState('');\n const [filter, setFilter] = useState<FilterKey>('all');\n\n const load = useCallback(async () => {\n setError(null);\n try {\n const data = await api.getOverview();\n setOverview(data);\n } catch (e) {\n setError(e instanceof Error ? e.message : 'Failed to load crop health.');\n } finally {\n setLoading(false);\n }\n }, [api]);\n\n useEffect(() => {\n void load();\n }, [load]);\n\n const handleRefresh = useCallback(async () => {\n if (!overview) return;\n setRefreshing(true);\n try {\n const hasData = overview.fields.some((f) => f.meanNdvi !== null);\n const res = await api.refreshNdvi(undefined, hasData ? 0 : 5);\n toast({\n title: 'Satellite imagery refreshed',\n description: `${res.fieldsRefreshed} field(s) updated · ${res.readingsCreated} reading(s) · ${res.stressedZonesDetected} stressed zone(s)${\n res.fieldsSkippedNoBoundary ? ` · ${res.fieldsSkippedNoBoundary} skipped (no boundary)` : ''\n }`,\n variant: 'success',\n });\n await load();\n } catch (e) {\n toast({\n title: 'Refresh failed',\n description: e instanceof Error ? e.message : 'Unknown error',\n variant: 'error',\n });\n } finally {\n setRefreshing(false);\n }\n }, [api, overview, toast, load]);\n\n const rows = useMemo(() => {\n if (!overview) return [];\n const q = search.trim().toLowerCase();\n return overview.fields.filter((f) => {\n if (q && !f.fieldName.toLowerCase().includes(q) && !(f.cropName ?? '').toLowerCase().includes(q)) return false;\n if (filter === 'stressed') return f.stressedZoneCount > 0;\n if (filter === 'healthy') return f.healthBand === 'HEALTHY' || f.healthBand === 'EXCELLENT';\n return true;\n });\n }, [overview, search, filter]);\n\n if (loading) return <PageLoader />;\n if (error) return <ErrorState title=\"Couldn't load crop health\" description={error} onRetry={() => void load()} />;\n if (!overview) return null;\n\n const columns: Column<CropHealthFieldSummary>[] = [\n {\n key: 'fieldName',\n header: 'Field name',\n render: (f) => (\n <div className=\"flex items-center gap-2\">\n {f.stressedZoneCount > 0 && (\n <span\n className={`h-2 w-2 rounded-full ${f.maxZoneSeverity === 'HIGH' ? 'bg-destructive' : 'bg-warning'}`}\n aria-hidden\n />\n )}\n <span className=\"font-medium text-text-primary\">{f.fieldName}</span>\n </div>\n ),\n },\n { key: 'cropName', header: 'Crop', render: (f) => f.cropName ?? '—' },\n { key: 'areaAcres', header: 'Area (ac)', render: (f) => f.areaAcres.toFixed(2) },\n {\n key: 'meanNdvi',\n header: 'NDVI health score',\n render: (f) =>\n f.meanNdvi === null ? (\n <StatusBadge label=\"No data\" variant=\"muted\" />\n ) : (\n <div className=\"min-w-[120px]\">\n <div className={`text-base font-semibold ${scoreColor(f.healthBand)}`}>{formatNdvi(f.meanNdvi)}</div>\n <div\n style={{ background: NDVI_LEGEND_GRADIENT }}\n className=\"mt-1 h-1.5 w-24 rounded-full ring-1 ring-border-subtle\"\n >\n <span\n className=\"relative block h-1.5\"\n style={{ marginLeft: `${Math.max(0, Math.min(100, ((f.meanNdvi - 0.2) / 0.6) * 100))}%` }}\n >\n <span className=\"absolute -top-0.5 -ml-1 h-2.5 w-2.5 rounded-full border-2 border-white bg-text-primary\" />\n </span>\n </div>\n </div>\n ),\n },\n {\n key: 'trendPct',\n header: 'Trend',\n render: (f) =>\n f.meanNdvi === null ? (\n '—'\n ) : (\n <span className={f.trendDirection === 'DOWN' ? 'text-destructive' : 'text-success'}>\n {trendArrow(f.trendDirection)} {Math.abs(f.trendPct).toFixed(1)}%\n </span>\n ),\n },\n {\n key: 'stressedZoneCount',\n header: 'Stressed zones',\n render: (f) => (\n <div className=\"flex items-center gap-1.5\">\n <span className=\"tabular-nums text-text-primary\">{f.stressedZoneCount}</span>\n {f.maxZoneSeverity && (\n <StatusBadge label={f.maxZoneSeverity} variant={severityVariant(f.maxZoneSeverity)} dot />\n )}\n </div>\n ),\n },\n {\n key: 'estimatedTonnes',\n header: 'Est. yield (t)',\n render: (f) =>\n f.estimatedTonnes === null ? '—' : `${formatTonnes(f.estimatedTonnes)} ±${formatTonnes(f.confidenceBand)}`,\n },\n { key: 'lastReadingDate', header: 'Last reading', render: (f) => formatDate(f.lastReadingDate) },\n ];\n\n return (\n <PageLayout\n title=\"Satellite Crop Health\"\n titleAccent=\"Crop Health\"\n description={`${overview.farmName ?? 'Your farm'} · ${overview.monitoredFieldCount} field(s) monitored · ${overview.fieldsWithBoundaryCount} with a saved boundary`}\n helpPrompt=\"Explain the NDVI satellite crop health page and how the yield forecast is calculated.\"\n purpose=\"A health map from space for every field. HealthyBowl pulls satellite vegetation-index (NDVI) imagery, turns it into a red→green heatmap, auto-flags stressed patches, and gives a transparent, rule-based harvest-tonnage estimate — so you can spot a problem in one corner without walking every acre.\"\n purposeIcon={<Satellite className=\"h-5 w-5\" />}\n actions={\n <div className=\"flex flex-wrap items-center gap-2\">\n <Button variant=\"outline\" size=\"sm\" onClick={() => navigate(buildPath('satellite/alerts'))}>\n <Bell className=\"mr-1.5 h-4 w-4\" /> Alerts\n {overview.openStressedZoneCount > 0 && (\n <span className=\"ml-1.5 rounded-full bg-destructive px-1.5 text-xs text-white\">\n {overview.openStressedZoneCount}\n </span>\n )}\n </Button>\n <Button variant=\"outline\" size=\"sm\" onClick={() => navigate(buildPath('satellite/settings'))}>\n <Settings className=\"mr-1.5 h-4 w-4\" /> Settings\n </Button>\n <Button size=\"sm\" onClick={() => void handleRefresh()} disabled={refreshing}>\n <RefreshCw className={`mr-1.5 h-4 w-4 ${refreshing ? 'animate-spin' : ''}`} /> Refresh NDVI\n </Button>\n </div>\n }\n >\n <div className=\"grid grid-cols-2 gap-3 sm:grid-cols-4\">\n <StatCard\n label=\"Monitored fields\"\n value={overview.monitoredFieldCount}\n icon={<Satellite className=\"h-4 w-4\" />}\n />\n <StatCard label=\"With boundary\" value={overview.fieldsWithBoundaryCount} />\n <StatCard\n label=\"Stressed fields\"\n value={overview.stressedFieldCount}\n trend={overview.stressedFieldCount > 0 ? 'down' : 'stable'}\n />\n <StatCard\n label=\"Open alerts\"\n value={overview.openStressedZoneCount}\n icon={<AlertTriangle className=\"h-4 w-4\" />}\n />\n </div>\n\n <div className=\"mt-5 flex flex-wrap items-center gap-2\">\n <Input\n value={search}\n onChange={(e) => setSearch(e.target.value)}\n placeholder=\"Search fields or crops…\"\n className=\"max-w-xs\"\n />\n {(['all', 'stressed', 'healthy'] as FilterKey[]).map((k) => (\n <Button key={k} variant={filter === k ? 'default' : 'outline'} size=\"sm\" onClick={() => setFilter(k)}>\n {k === 'all' ? 'All fields' : k === 'stressed' ? 'Stressed' : 'Healthy'}\n </Button>\n ))}\n </div>\n\n <div className=\"mt-4\">\n {rows.length === 0 ? (\n overview.monitoredFieldCount === 0 ? (\n <EmptyState\n title=\"No fields yet\"\n description=\"Add a farm field with a drawn boundary on the Field Map, then refresh NDVI to see its crop-health heatmap.\"\n action={<Button onClick={() => navigate(buildPath('field-map'))}>Open Field Map</Button>}\n />\n ) : overview.fields.every((f) => f.meanNdvi === null) ? (\n <EmptyState\n title=\"No satellite readings yet\"\n description=\"Pull the first satellite imagery for every field that has a saved boundary.\"\n action={\n <Button onClick={() => void handleRefresh()} disabled={refreshing}>\n <RefreshCw className={`mr-1.5 h-4 w-4 ${refreshing ? 'animate-spin' : ''}`} /> Pull satellite imagery\n </Button>\n }\n />\n ) : (\n <EmptyState title=\"No matching fields\" description=\"Adjust your search or filter.\" />\n )\n ) : (\n <DataTable\n columns={columns}\n data={rows}\n keyField=\"fieldId\"\n onRowClick={(f) => navigate(buildPath(`satellite/${f.fieldId}`))}\n />\n )}\n </div>\n </PageLayout>\n );\n};\n\nfunction scoreColor(band: string): string {\n switch (band) {\n case 'EXCELLENT':\n case 'HEALTHY':\n return 'text-success';\n case 'BELOW_AVERAGE':\n return 'text-warning';\n case 'STRESSED':\n return 'text-destructive';\n default:\n return 'text-text-secondary';\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAsBA,IAAa,UAAoC;CAC/C,IAAM,EAAE,WAAQ,GAAiB,EAC3B,IAAW,GAAa,EACxB,EAAE,iBAAc,GAAa,EAC7B,EAAE,aAAU,GAAU,EAEtB,CAAC,GAAU,KAAe,EAAoC,KAAK,EACnE,CAAC,GAAS,KAAc,EAAS,GAAK,EACtC,CAAC,GAAO,KAAY,EAAwB,KAAK,EACjD,CAAC,GAAY,KAAiB,EAAS,GAAM,EAC7C,CAAC,GAAQ,KAAa,EAAS,GAAG,EAClC,CAAC,GAAQ,KAAa,EAAoB,MAAM,EAEhD,IAAO,EAAY,YAAY;AACnC,IAAS,KAAK;AACd,MAAI;AAEF,KADa,MAAM,EAAI,aAAa,CACnB;WACV,GAAG;AACV,KAAS,aAAa,QAAQ,EAAE,UAAU,8BAA8B;YAChE;AACR,KAAW,GAAM;;IAElB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