@burdenoff/microfe-healthybowl 2026.812.1 → 2026.812.3

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.
@@ -0,0 +1,83 @@
1
+ import { useHealthyBowl as e } from "../context/HealthyBowlContext.js";
2
+ import { useMemo as t } from "react";
3
+ import { gql as n } from "@apollo/client";
4
+ import { useQuery as r } from "@apollo/client/react";
5
+ //#region src/healthybowl/hooks/useHealthyBowlFertility.ts
6
+ var i = n`
7
+ query HealthyBowlLivestockFertility(
8
+ $context: ContextInput!
9
+ $groupId: ID
10
+ $from: String
11
+ $to: String
12
+ $granularity: HealthyBowlGrowthGranularity
13
+ ) {
14
+ healthyBowlLivestockFertility(
15
+ context: $context
16
+ groupId: $groupId
17
+ from: $from
18
+ to: $to
19
+ granularity: $granularity
20
+ ) {
21
+ truncated
22
+ periodLabel
23
+ granularity
24
+ services
25
+ conceived
26
+ conceptionRatePct
27
+ servicesPerConception
28
+ pregnancyLossPct
29
+ pregnancyLossUnavailableReason
30
+ meanCalvingIntervalDays
31
+ medianCalvingIntervalDays
32
+ damsWithInterval
33
+ calvingIntervalUnavailableReason
34
+ deliveries
35
+ deliveriesWithCounts
36
+ meanOffspringBorn
37
+ meanOffspringLive
38
+ perinatalMortalityPct
39
+ damsWithFirstCalving
40
+ meanAgeAtFirstCalvingDays
41
+ medianAgeAtFirstCalvingDays
42
+ dueSoon {
43
+ animalId
44
+ expectedDeliveryDate
45
+ daysUntilDue
46
+ }
47
+ trend {
48
+ bucket
49
+ services
50
+ conceived
51
+ conceptionRatePct
52
+ deliveries
53
+ }
54
+ }
55
+ }
56
+ `;
57
+ function a(n = {}) {
58
+ let { workspaceId: a } = e(), o = !!a, { data: s, loading: c, error: l, refetch: u } = r(i, {
59
+ variables: {
60
+ context: t(() => ({ workspaceId: a || "" }), [a]),
61
+ groupId: n.groupId ?? null,
62
+ from: n.from ?? null,
63
+ to: n.to ?? null,
64
+ granularity: n.granularity ?? "MONTH"
65
+ },
66
+ fetchPolicy: "cache-and-network",
67
+ skip: n.enabled === !1 || !o
68
+ }), d = s?.healthyBowlLivestockFertility ?? null;
69
+ return {
70
+ fertility: d,
71
+ truncated: d?.truncated ?? !1,
72
+ dueSoon: d?.dueSoon ?? [],
73
+ trend: d?.trend ?? [],
74
+ workspaceReady: o,
75
+ loading: c,
76
+ error: l,
77
+ refetch: u
78
+ };
79
+ }
80
+ //#endregion
81
+ export { a as useHealthyBowlFertility };
82
+
83
+ //# sourceMappingURL=useHealthyBowlFertility.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useHealthyBowlFertility.js","names":[],"sources":["../../../src/healthybowl/hooks/useHealthyBowlFertility.ts"],"sourcesContent":["/**\n * Fertility analytics — data hook (BOFF-6008).\n *\n * The fourth livestock analytics slice. Growth says how fast animals gain, feed says what that gain\n * cost, herd statistics says what the herd is made of — and this says whether it is actually\n * breeding. It shares the window and granularity contract with all three, so every livestock chart\n * describes the same period.\n *\n * The backend shipped on 2026-08-11 and had no UI at all until this hook, so nothing in the product\n * could reach it: a farmer could not see a single fertility number.\n *\n * The document is declared inline with `gql` for the same reason as its three siblings — codegen\n * validates against the committed `graphql/wspace.graphql` snapshot, which does not carry this\n * query. Types mirror `wspace-healthybowl-svc/src/modules/healthybowl/schema/livestock-depth.gql`.\n *\n * ⚠️ Two payload contracts the UI must not flatten:\n * - `calvingIntervalUnavailableReason` non-null means the interval is WRONG, not merely missing.\n * An undated delivery merges two births into one gap and overstates it. Render the reason, never\n * a number — `calvingIntervalDisplay` in `utils/fertility` enforces it.\n * - A null rate means unmeasured; `0` means measured and zero. Four services and nothing in calf\n * is `0`, and it is the most urgent thing this card can say. Never collapse the two.\n *\n * ★ Unlike its three siblings this hook does NOT fall back to a placeholder workspace id. Querying\n * a workspace that is not the user's returns an empty result, which this card would render as\n * \"No breeding records yet\" — a confident false statement about someone's farm. The query is\n * skipped until the workspace is known and `workspaceReady` says so, matching the fix made to\n * `useSharedMarket` for the same reason.\n */\n\nimport { useMemo } from 'react';\nimport { gql } from '@apollo/client';\nimport { useQuery } from '@apollo/client/react';\nimport { useHealthyBowl } from '../context/HealthyBowlContext';\nimport type { GrowthGranularity } from './useHealthyBowlLivestockGrowth';\nimport type { DueSoonRow, FertilityBucket } from '../utils/fertility';\n\nexport type { DueSoonRow, FertilityBucket };\n\nexport interface LivestockFertility {\n /** True when the backend hit its row cap — every figure below covers only part of the herd. */\n truncated: boolean;\n periodLabel: string;\n granularity: GrowthGranularity;\n\n services: number;\n conceived: number;\n /** Null = nothing was served. `0` = served and nothing conceived. Never conflate them. */\n conceptionRatePct: number | null;\n servicesPerConception: number | null;\n /** Share of CONFIRMED pregnancies that later failed — not of all services. */\n pregnancyLossPct: number | null;\n /** Non-null means loss could not be computed honestly, and says why. Always set today. */\n pregnancyLossUnavailableReason: string | null;\n\n meanCalvingIntervalDays: number | null;\n medianCalvingIntervalDays: number | null;\n damsWithInterval: number;\n /** Non-null means the interval could not be computed honestly, and says why. */\n calvingIntervalUnavailableReason: string | null;\n\n deliveries: number;\n deliveriesWithCounts: number;\n meanOffspringBorn: number | null;\n meanOffspringLive: number | null;\n /** Null where live counts were never recorded — an unrecorded count is not a total loss. */\n perinatalMortalityPct: number | null;\n\n damsWithFirstCalving: number;\n meanAgeAtFirstCalvingDays: number | null;\n medianAgeAtFirstCalvingDays: number | null;\n\n dueSoon: DueSoonRow[];\n trend: FertilityBucket[];\n}\n\ninterface HbContext {\n workspaceId: string;\n}\n\nconst GET_FERTILITY = gql`\n query HealthyBowlLivestockFertility(\n $context: ContextInput!\n $groupId: ID\n $from: String\n $to: String\n $granularity: HealthyBowlGrowthGranularity\n ) {\n healthyBowlLivestockFertility(\n context: $context\n groupId: $groupId\n from: $from\n to: $to\n granularity: $granularity\n ) {\n truncated\n periodLabel\n granularity\n services\n conceived\n conceptionRatePct\n servicesPerConception\n pregnancyLossPct\n pregnancyLossUnavailableReason\n meanCalvingIntervalDays\n medianCalvingIntervalDays\n damsWithInterval\n calvingIntervalUnavailableReason\n deliveries\n deliveriesWithCounts\n meanOffspringBorn\n meanOffspringLive\n perinatalMortalityPct\n damsWithFirstCalving\n meanAgeAtFirstCalvingDays\n medianAgeAtFirstCalvingDays\n dueSoon {\n animalId\n expectedDeliveryDate\n daysUntilDue\n }\n trend {\n bucket\n services\n conceived\n conceptionRatePct\n deliveries\n }\n }\n }\n`;\n\nexport interface UseFertilityOptions {\n enabled?: boolean;\n groupId?: string | null;\n from?: string | null;\n to?: string | null;\n granularity?: GrowthGranularity;\n}\n\nexport function useHealthyBowlFertility(options: UseFertilityOptions = {}) {\n const { workspaceId } = useHealthyBowl();\n // No placeholder id — see the module docstring. An empty result from someone else's workspace\n // would be rendered as a statement about this farm.\n const workspaceReady = Boolean(workspaceId);\n const ctx = useMemo<HbContext>(() => ({ workspaceId: workspaceId || '' }), [workspaceId]);\n\n const { data, loading, error, refetch } = useQuery<\n { healthyBowlLivestockFertility: LivestockFertility },\n {\n context: HbContext;\n groupId: string | null;\n from: string | null;\n to: string | null;\n granularity: GrowthGranularity;\n }\n >(GET_FERTILITY, {\n variables: {\n context: ctx,\n groupId: options.groupId ?? null,\n from: options.from ?? null,\n to: options.to ?? null,\n granularity: options.granularity ?? 'MONTH',\n },\n fetchPolicy: 'cache-and-network',\n skip: options.enabled === false || !workspaceReady,\n });\n\n const fertility = data?.healthyBowlLivestockFertility ?? null;\n\n return {\n fertility,\n truncated: fertility?.truncated ?? false,\n dueSoon: fertility?.dueSoon ?? [],\n trend: fertility?.trend ?? [],\n /** False until the workspace is known — the caller must not claim \"no records\" before then. */\n workspaceReady,\n loading,\n error,\n refetch,\n };\n}\n"],"mappings":";;;;;AA+EA,IAAM,IAAgB,CAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4DzB,SAAgB,EAAwB,IAA+B,EAAE,EAAE;CACzE,IAAM,EAAE,mBAAgB,GAAgB,EAGlC,IAAiB,EAAQ,GAGzB,EAAE,SAAM,YAAS,UAAO,eAAY,EASxC,GAAe;EACf,WAAW;GACT,SAbQ,SAA0B,EAAE,aAAa,KAAe,IAAI,GAAG,CAAC,EAAY,CAAC;GAcrF,SAAS,EAAQ,WAAW;GAC5B,MAAM,EAAQ,QAAQ;GACtB,IAAI,EAAQ,MAAM;GAClB,aAAa,EAAQ,eAAe;GACrC;EACD,aAAa;EACb,MAAM,EAAQ,YAAY,MAAS,CAAC;EACrC,CAAC,EAEI,IAAY,GAAM,iCAAiC;AAEzD,QAAO;EACL;EACA,WAAW,GAAW,aAAa;EACnC,SAAS,GAAW,WAAW,EAAE;EACjC,OAAO,GAAW,SAAS,EAAE;EAE7B;EACA;EACA;EACA;EACD"}
@@ -0,0 +1,399 @@
1
+ import { formatNumber as e } from "../../utils/helpers.js";
2
+ import { ChartCard as t } from "../../components/ChartCard.js";
3
+ import { AnalyticsControls as n } from "../../components/AnalyticsControls.js";
4
+ import { Legend as r } from "../../../node_modules/recharts/es6/component/Legend.js";
5
+ import { Tooltip as i } from "../../../node_modules/recharts/es6/component/Tooltip.js";
6
+ import { ResponsiveContainer as a } from "../../../node_modules/recharts/es6/component/ResponsiveContainer.js";
7
+ import { Bar as o } from "../../../node_modules/recharts/es6/cartesian/Bar.js";
8
+ import { CartesianGrid as s } from "../../../node_modules/recharts/es6/cartesian/CartesianGrid.js";
9
+ import { Line as c } from "../../../node_modules/recharts/es6/cartesian/Line.js";
10
+ import { XAxis as l } from "../../../node_modules/recharts/es6/cartesian/XAxis.js";
11
+ import { YAxis as u } from "../../../node_modules/recharts/es6/cartesian/YAxis.js";
12
+ import { ComposedChart as d } from "../../../node_modules/recharts/es6/chart/ComposedChart.js";
13
+ import { downloadCsv as f } from "../../utils/download.js";
14
+ import { optionalMetric as p } from "../../utils/optionalMetric.js";
15
+ import { FERTILITY_CSV_HEADERS as m, calvingIntervalDisplay as h, dueSoonUrgency as g, dueSoonUrgencyText as _, fertilityCsvRows as v, hasFertilityData as y, orderedDueSoon as b, orderedFertilityBuckets as x, pregnancyLossDisplay as S } from "../../utils/fertility.js";
16
+ import { useHealthyBowlFertility as C } from "../../hooks/useHealthyBowlFertility.js";
17
+ import { useMemo as w, useState as T } from "react";
18
+ import { useI18n as E } from "@burdenoff/fe-libs/shared/providers/shell/I18nProvider";
19
+ import { Fragment as D, jsx as O, jsxs as k } from "react/jsx-runtime";
20
+ //#region src/healthybowl/pages/livestock/FertilityCard.tsx
21
+ var A = [
22
+ "DAY",
23
+ "WEEK",
24
+ "MONTH"
25
+ ], j = {
26
+ OVERDUE: "text-status-error-text",
27
+ IMMINENT: "text-status-warning-text",
28
+ SOON: "text-text-primary",
29
+ LATER: "text-text-secondary"
30
+ }, M = ({ groupId: M = null, className: N }) => {
31
+ let { t: P } = E(), [F, I] = T("MONTH"), [L, R] = T(""), [z, B] = T(""), { fertility: V, dueSoon: H, trend: U, truncated: W, workspaceReady: G, loading: K, error: q } = C({
32
+ groupId: M,
33
+ granularity: F,
34
+ from: L || null,
35
+ to: z || null
36
+ }), J = w(() => x(U), [U]), Y = w(() => b(H), [H]), X = y({
37
+ services: V?.services,
38
+ deliveries: V?.deliveries,
39
+ damsWithInterval: V?.damsWithInterval,
40
+ dueSoonCount: Y.length,
41
+ trendCount: J.length
42
+ }), Z = V ? h(V) : null, Q = V ? S(V) : null, $ = () => {
43
+ V && f(`livestock-fertility-${(/* @__PURE__ */ new Date()).toISOString().slice(0, 10)}.csv`, [...m], v({
44
+ services: V.services,
45
+ conceived: V.conceived,
46
+ conceptionRatePct: V.conceptionRatePct,
47
+ deliveries: V.deliveries,
48
+ trend: J
49
+ }));
50
+ }, ee = /* @__PURE__ */ O("div", {
51
+ className: "flex items-center gap-1",
52
+ children: A.map((e) => /* @__PURE__ */ O("button", {
53
+ type: "button",
54
+ onClick: () => I(e),
55
+ "aria-pressed": F === e,
56
+ className: `min-h-[32px] rounded-md px-2 py-1 text-xs transition-colors ${F === e ? "bg-action-primary-bg text-action-primary-text" : "text-text-secondary hover:bg-bg-sunken/50"}`,
57
+ children: P(`healthybowl.livestock.fertility.granularity.${e.toLowerCase()}`, e.charAt(0) + e.slice(1).toLowerCase())
58
+ }, e))
59
+ });
60
+ return /* @__PURE__ */ O(t, {
61
+ title: P("healthybowl.livestock.fertility.title", "Fertility"),
62
+ description: P("healthybowl.livestock.fertility.description", "Whether the herd is actually breeding — conception, calving interval, litter size and who is due."),
63
+ actions: /* @__PURE__ */ O(n, {
64
+ from: L,
65
+ to: z,
66
+ onFromChange: R,
67
+ onToChange: B,
68
+ onExportCsv: $,
69
+ exportDisabled: !V || !X,
70
+ children: ee
71
+ }),
72
+ className: N,
73
+ children: q ? /* @__PURE__ */ k("div", {
74
+ className: "py-8 text-center",
75
+ children: [/* @__PURE__ */ O("p", {
76
+ className: "text-sm text-text-primary",
77
+ children: P("healthybowl.livestock.fertility.error.title", "Could not load fertility analytics")
78
+ }), /* @__PURE__ */ O("p", {
79
+ className: "mt-1 text-xs text-text-secondary",
80
+ children: q.message
81
+ })]
82
+ }) : !G || K && !X ? /* @__PURE__ */ O("p", {
83
+ className: "py-8 text-center text-xs text-text-secondary",
84
+ children: P("healthybowl.livestock.fertility.loading", "Loading fertility analytics…")
85
+ }) : X ? /* @__PURE__ */ k(D, { children: [
86
+ W && /* @__PURE__ */ O("p", {
87
+ className: "mb-3 rounded-md bg-bg-sunken/60 px-3 py-2 text-xs text-text-secondary",
88
+ children: P("healthybowl.livestock.fertility.truncated", "This herd has more breeding records than one view can load, so every figure below covers only part of it. Narrow the date range or filter by group for an exact figure.")
89
+ }),
90
+ /* @__PURE__ */ k("dl", {
91
+ className: "mb-4 grid grid-cols-2 gap-3 sm:grid-cols-4",
92
+ children: [
93
+ /* @__PURE__ */ k("div", { children: [
94
+ /* @__PURE__ */ O("dt", {
95
+ className: "text-xs text-text-secondary",
96
+ children: P("healthybowl.livestock.fertility.summary.conceptionRate", "Conception rate")
97
+ }),
98
+ /* @__PURE__ */ O("dd", {
99
+ className: "text-sm font-medium tabular-nums text-text-primary",
100
+ children: p(V?.conceptionRatePct, {
101
+ decimals: 1,
102
+ unit: "%"
103
+ })
104
+ }),
105
+ /* @__PURE__ */ O("dd", {
106
+ className: "text-xs text-text-secondary",
107
+ children: P("healthybowl.livestock.fertility.summary.ofServices", "{{c}} of {{s}} services", {
108
+ c: String(V?.conceived ?? 0),
109
+ s: String(V?.services ?? 0)
110
+ })
111
+ })
112
+ ] }),
113
+ /* @__PURE__ */ k("div", { children: [/* @__PURE__ */ O("dt", {
114
+ className: "text-xs text-text-secondary",
115
+ children: P("healthybowl.livestock.fertility.summary.servicesPerConception", "Services per conception")
116
+ }), /* @__PURE__ */ O("dd", {
117
+ className: "text-sm font-medium tabular-nums text-text-primary",
118
+ children: p(V?.servicesPerConception, { decimals: 1 })
119
+ })] }),
120
+ /* @__PURE__ */ k("div", { children: [
121
+ /* @__PURE__ */ O("dt", {
122
+ className: "text-xs text-text-secondary",
123
+ children: P("healthybowl.livestock.fertility.summary.calvingInterval", "Mean calving interval")
124
+ }),
125
+ /* @__PURE__ */ O("dd", {
126
+ className: "text-sm font-medium tabular-nums text-text-primary",
127
+ children: Z?.available ? P("healthybowl.livestock.fertility.summary.days", "{{n}} days", { n: e(Z.meanDays) }) : "—"
128
+ }),
129
+ Z?.available && Z.medianDays !== null && /* @__PURE__ */ O("dd", {
130
+ className: "text-xs text-text-secondary",
131
+ children: P("healthybowl.livestock.fertility.summary.median", "median {{n}}", { n: p(Z.medianDays, { decimals: 0 }) })
132
+ })
133
+ ] }),
134
+ /* @__PURE__ */ k("div", { children: [
135
+ /* @__PURE__ */ O("dt", {
136
+ className: "text-xs text-text-secondary",
137
+ children: P("healthybowl.livestock.fertility.summary.pregnancyLoss", "Pregnancy loss")
138
+ }),
139
+ /* @__PURE__ */ O("dd", {
140
+ className: "text-sm font-medium tabular-nums text-text-primary",
141
+ children: Q?.available ? p(Q.ratePct, {
142
+ decimals: 1,
143
+ unit: "%"
144
+ }) : "—"
145
+ }),
146
+ /* @__PURE__ */ O("dd", {
147
+ className: "text-xs text-text-secondary",
148
+ children: P("healthybowl.livestock.fertility.summary.ofConfirmed", "of confirmed pregnancies")
149
+ })
150
+ ] })
151
+ ]
152
+ }),
153
+ Z && !Z.available && Z.reason && /* @__PURE__ */ O("p", {
154
+ className: "mb-4 rounded-md bg-bg-sunken/60 px-3 py-2 text-xs text-text-secondary",
155
+ children: Z.reason
156
+ }),
157
+ Q && !Q.available && Q.reason && /* @__PURE__ */ O("p", {
158
+ className: "mb-4 rounded-md bg-bg-sunken/60 px-3 py-2 text-xs text-text-secondary",
159
+ children: Q.reason
160
+ }),
161
+ /* @__PURE__ */ k("div", {
162
+ className: "border-t border-border-subtle pt-4",
163
+ children: [/* @__PURE__ */ O("h4", {
164
+ className: "mb-2 text-xs font-medium uppercase tracking-wide text-text-secondary",
165
+ children: P("healthybowl.livestock.fertility.trend.title", "Services and conceptions")
166
+ }), J.length === 0 ? /* @__PURE__ */ O("p", {
167
+ className: "py-4 text-center text-xs text-text-secondary",
168
+ children: P("healthybowl.livestock.fertility.trend.empty", "No service in this period carries a mating date, so there is nothing to plot over time.")
169
+ }) : /* @__PURE__ */ O(a, {
170
+ width: "100%",
171
+ height: 220,
172
+ children: /* @__PURE__ */ k(d, {
173
+ data: J,
174
+ margin: {
175
+ top: 5,
176
+ right: 20,
177
+ left: 0,
178
+ bottom: 5
179
+ },
180
+ children: [
181
+ /* @__PURE__ */ O(s, {
182
+ strokeDasharray: "3 3",
183
+ stroke: "var(--color-border)"
184
+ }),
185
+ /* @__PURE__ */ O(l, {
186
+ dataKey: "bucket",
187
+ tick: { fontSize: 11 },
188
+ stroke: "var(--color-muted-foreground)"
189
+ }),
190
+ /* @__PURE__ */ O(u, {
191
+ yAxisId: "count",
192
+ allowDecimals: !1,
193
+ tick: { fontSize: 11 },
194
+ stroke: "var(--color-muted-foreground)"
195
+ }),
196
+ /* @__PURE__ */ O(u, {
197
+ yAxisId: "rate",
198
+ orientation: "right",
199
+ domain: [0, 100],
200
+ unit: "%",
201
+ tick: { fontSize: 11 },
202
+ stroke: "var(--color-muted-foreground)"
203
+ }),
204
+ /* @__PURE__ */ O(i, {
205
+ cursor: {
206
+ fill: "var(--color-muted)",
207
+ opacity: .2
208
+ },
209
+ contentStyle: {
210
+ backgroundColor: "var(--color-card)",
211
+ border: "1px solid var(--color-border)",
212
+ borderRadius: 8,
213
+ fontSize: 12
214
+ },
215
+ labelStyle: { color: "var(--color-foreground)" },
216
+ formatter: (t, n) => [typeof t == "number" ? e(t) : String(t ?? "—"), n]
217
+ }),
218
+ /* @__PURE__ */ O(r, { wrapperStyle: { fontSize: 11 } }),
219
+ /* @__PURE__ */ O(o, {
220
+ yAxisId: "count",
221
+ dataKey: "services",
222
+ name: P("healthybowl.livestock.fertility.trend.services", "Services"),
223
+ fill: "var(--color-chart-1)",
224
+ radius: [
225
+ 4,
226
+ 4,
227
+ 0,
228
+ 0
229
+ ]
230
+ }),
231
+ /* @__PURE__ */ O(o, {
232
+ yAxisId: "count",
233
+ dataKey: "conceived",
234
+ name: P("healthybowl.livestock.fertility.trend.conceived", "Conceived"),
235
+ fill: "var(--color-chart-2)",
236
+ radius: [
237
+ 4,
238
+ 4,
239
+ 0,
240
+ 0
241
+ ]
242
+ }),
243
+ /* @__PURE__ */ O(c, {
244
+ yAxisId: "rate",
245
+ type: "monotone",
246
+ dataKey: "conceptionRatePct",
247
+ name: P("healthybowl.livestock.fertility.trend.rate", "Conception rate %"),
248
+ stroke: "var(--color-chart-3)",
249
+ strokeWidth: 2,
250
+ dot: !1,
251
+ connectNulls: !1
252
+ })
253
+ ]
254
+ })
255
+ })]
256
+ }),
257
+ /* @__PURE__ */ k("div", {
258
+ className: "mt-4 grid grid-cols-1 gap-4 border-t border-border-subtle pt-4 sm:grid-cols-2",
259
+ children: [/* @__PURE__ */ k("div", { children: [
260
+ /* @__PURE__ */ O("h4", {
261
+ className: "mb-2 text-xs font-medium uppercase tracking-wide text-text-secondary",
262
+ children: P("healthybowl.livestock.fertility.litter.title", "Litter size")
263
+ }),
264
+ /* @__PURE__ */ k("dl", {
265
+ className: "grid grid-cols-2 gap-3",
266
+ children: [
267
+ /* @__PURE__ */ k("div", { children: [/* @__PURE__ */ O("dt", {
268
+ className: "text-xs text-text-secondary",
269
+ children: P("healthybowl.livestock.fertility.litter.born", "Mean born")
270
+ }), /* @__PURE__ */ O("dd", {
271
+ className: "text-sm font-medium tabular-nums text-text-primary",
272
+ children: p(V?.meanOffspringBorn, { decimals: 1 })
273
+ })] }),
274
+ /* @__PURE__ */ k("div", { children: [/* @__PURE__ */ O("dt", {
275
+ className: "text-xs text-text-secondary",
276
+ children: P("healthybowl.livestock.fertility.litter.live", "Mean born alive")
277
+ }), /* @__PURE__ */ O("dd", {
278
+ className: "text-sm font-medium tabular-nums text-text-primary",
279
+ children: p(V?.meanOffspringLive, { decimals: 1 })
280
+ })] }),
281
+ /* @__PURE__ */ k("div", { children: [/* @__PURE__ */ O("dt", {
282
+ className: "text-xs text-text-secondary",
283
+ children: P("healthybowl.livestock.fertility.litter.perinatal", "Perinatal mortality")
284
+ }), /* @__PURE__ */ O("dd", {
285
+ className: "text-sm font-medium tabular-nums text-text-primary",
286
+ children: p(V?.perinatalMortalityPct, {
287
+ decimals: 1,
288
+ unit: "%"
289
+ })
290
+ })] }),
291
+ /* @__PURE__ */ k("div", { children: [/* @__PURE__ */ O("dt", {
292
+ className: "text-xs text-text-secondary",
293
+ children: P("healthybowl.livestock.fertility.litter.deliveries", "Deliveries")
294
+ }), /* @__PURE__ */ O("dd", {
295
+ className: "text-sm font-medium tabular-nums text-text-primary",
296
+ children: e(V?.deliveries ?? 0)
297
+ })] })
298
+ ]
299
+ }),
300
+ /* @__PURE__ */ O("p", {
301
+ className: "mt-2 text-xs text-text-secondary",
302
+ children: P("healthybowl.livestock.fertility.litter.coverage", "{{counted}} of {{total}} deliveries recorded how many were born — the averages are of those.", {
303
+ counted: String(V?.deliveriesWithCounts ?? 0),
304
+ total: String(V?.deliveries ?? 0)
305
+ })
306
+ })
307
+ ] }), /* @__PURE__ */ k("div", { children: [
308
+ /* @__PURE__ */ O("h4", {
309
+ className: "mb-2 text-xs font-medium uppercase tracking-wide text-text-secondary",
310
+ children: P("healthybowl.livestock.fertility.firstCalving.title", "Age at first calving")
311
+ }),
312
+ /* @__PURE__ */ k("dl", {
313
+ className: "grid grid-cols-2 gap-3",
314
+ children: [
315
+ /* @__PURE__ */ k("div", { children: [/* @__PURE__ */ O("dt", {
316
+ className: "text-xs text-text-secondary",
317
+ children: P("healthybowl.livestock.fertility.firstCalving.mean", "Mean")
318
+ }), /* @__PURE__ */ O("dd", {
319
+ className: "text-sm font-medium tabular-nums text-text-primary",
320
+ children: V?.meanAgeAtFirstCalvingDays !== null && V?.meanAgeAtFirstCalvingDays !== void 0 ? P("healthybowl.livestock.fertility.summary.days", "{{n}} days", { n: e(V.meanAgeAtFirstCalvingDays) }) : "—"
321
+ })] }),
322
+ /* @__PURE__ */ k("div", { children: [/* @__PURE__ */ O("dt", {
323
+ className: "text-xs text-text-secondary",
324
+ children: P("healthybowl.livestock.fertility.firstCalving.median", "Median")
325
+ }), /* @__PURE__ */ O("dd", {
326
+ className: "text-sm font-medium tabular-nums text-text-primary",
327
+ children: p(V?.medianAgeAtFirstCalvingDays, { decimals: 0 })
328
+ })] }),
329
+ /* @__PURE__ */ k("div", {
330
+ className: "col-span-2",
331
+ children: [/* @__PURE__ */ O("dt", {
332
+ className: "text-xs text-text-secondary",
333
+ children: P("healthybowl.livestock.fertility.firstCalving.dams", "Dams with a first calving")
334
+ }), /* @__PURE__ */ k("dd", {
335
+ className: "text-sm font-medium tabular-nums text-text-primary",
336
+ children: [e(V?.damsWithFirstCalving ?? 0), /* @__PURE__ */ O("span", {
337
+ className: "ms-2 text-xs font-normal text-text-secondary",
338
+ children: P("healthybowl.livestock.fertility.firstCalving.intervalDams", "· {{n}} with an interval", { n: String(V?.damsWithInterval ?? 0) })
339
+ })]
340
+ })]
341
+ })
342
+ ]
343
+ }),
344
+ /* @__PURE__ */ O("p", {
345
+ className: "mt-2 text-xs text-text-secondary",
346
+ children: P("healthybowl.livestock.fertility.firstCalving.coverage", "Only dams whose own date of birth is recorded can contribute — an unknown birth date makes the age unknowable.")
347
+ })
348
+ ] })]
349
+ }),
350
+ /* @__PURE__ */ k("div", {
351
+ className: "mt-4 border-t border-border-subtle pt-4",
352
+ children: [/* @__PURE__ */ O("h4", {
353
+ className: "mb-2 text-xs font-medium uppercase tracking-wide text-text-secondary",
354
+ children: P("healthybowl.livestock.fertility.due.title", "Due in the next 30 days")
355
+ }), Y.length === 0 ? /* @__PURE__ */ O("p", {
356
+ className: "text-xs text-text-secondary",
357
+ children: P("healthybowl.livestock.fertility.due.empty", "No confirmed or mated pregnancy is due in the next 30 days.")
358
+ }) : /* @__PURE__ */ O("ul", {
359
+ className: "flex flex-col gap-1.5",
360
+ children: Y.map((e) => {
361
+ let t = g(e.daysUntilDue), n = _(t);
362
+ return /* @__PURE__ */ k("li", {
363
+ className: "flex flex-wrap items-baseline justify-between gap-2 text-xs",
364
+ children: [/* @__PURE__ */ O("span", {
365
+ className: "font-medium text-text-primary",
366
+ children: e.animalId
367
+ }), /* @__PURE__ */ k("span", {
368
+ className: "flex items-baseline gap-2",
369
+ children: [/* @__PURE__ */ O("span", {
370
+ className: "tabular-nums text-text-secondary",
371
+ children: e.expectedDeliveryDate
372
+ }), /* @__PURE__ */ k("span", {
373
+ className: `tabular-nums ${j[t]}`,
374
+ children: [P(n.key, n.defaultValue), t !== "OVERDUE" && /* @__PURE__ */ k("span", {
375
+ className: "text-text-secondary",
376
+ children: [" ", P("healthybowl.livestock.fertility.due.inDays", "({{n}}d)", { n: String(e.daysUntilDue) })]
377
+ })]
378
+ })]
379
+ })]
380
+ }, `${e.animalId}:${e.expectedDeliveryDate}`);
381
+ })
382
+ })]
383
+ })
384
+ ] }) : /* @__PURE__ */ k("div", {
385
+ className: "py-8 text-center",
386
+ children: [/* @__PURE__ */ O("p", {
387
+ className: "text-sm text-text-primary",
388
+ children: P("healthybowl.livestock.fertility.empty.title", "No breeding records yet")
389
+ }), /* @__PURE__ */ O("p", {
390
+ className: "mt-1 text-xs text-text-secondary",
391
+ children: P("healthybowl.livestock.fertility.empty.hint", "Record a mating on the Breeding page, then set its outcome — delivery date and offspring — to see conception, calving interval and litter size here.")
392
+ })]
393
+ })
394
+ });
395
+ };
396
+ //#endregion
397
+ export { M as FertilityCard };
398
+
399
+ //# sourceMappingURL=FertilityCard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FertilityCard.js","names":[],"sources":["../../../../src/healthybowl/pages/livestock/FertilityCard.tsx"],"sourcesContent":["/**\n * Fertility card (BOFF-6008).\n *\n * The fourth card beside growth, feed and herd statistics. Growth says how fast animals gain, feed\n * says what that gain cost, herd statistics says what the herd is made of — this says whether it is\n * actually breeding, which is the number a farmer culls on.\n *\n * The backend for this shipped without any UI, so until now no user of HealthyBowl could see a\n * single fertility figure.\n *\n * Deliberate choices:\n * - **The calving interval prints its reason, never a number, whenever the backend supplies one.**\n * A DELIVERED record with no delivery date merges two births into one gap and OVERSTATES the\n * interval — the direction that hides a fertility problem behind a figure reading as merely\n * mediocre. `calvingIntervalDisplay` owns that predicate and is unit-tested; the card cannot\n * reach the number when a reason exists. Same treatment as herd statistics gives mortality.\n * - **An unmeasured rate renders as an em dash; a measured zero renders as `0%`.** Four services\n * and nothing in calf is the most urgent thing this card can say, and it must not be flattened\n * into the same appearance as \"we have no breeding data\".\n * - **The empty state is decided by breeding ACTIVITY, not by a falsy rate** (`hasFertilityData`).\n * Deciding it on `conceptionRatePct` would print \"No breeding records yet\" over a barren herd.\n * - **Two y-axes on the trend, unlike the herd-turnover chart's one.** There, entries and exits\n * were both counts of animals and shared a scale honestly. Here counts and a percentage have no\n * common scale, so the rate rides its own right-hand axis, fixed to 0–100 so a good month and a\n * bad month are comparable across reloads rather than rescaled to whatever happened.\n * - **Due-soon is a worklist, not a chart.** It answers \"who do I check on this week\", so it is\n * ordered soonest-first and banded by urgency, with a passed due date called out rather than\n * folded into \"later\".\n * - A query error is surfaced as an error, never as the empty state — \"no breeding records\" is a\n * statement about the farm and must not be shown when the truth is \"we could not load\".\n */\n\nimport { useMemo, useState, type FC } from 'react';\nimport { Bar, CartesianGrid, ComposedChart, Legend, Line, ResponsiveContainer, Tooltip, XAxis, YAxis } from 'recharts';\nimport { useI18n } from '@burdenoff/fe-libs/shared/providers/shell/I18nProvider';\nimport { ChartCard } from '../../components/ChartCard';\nimport { AnalyticsControls } from '../../components/AnalyticsControls';\nimport { formatNumber } from '../../utils/helpers';\nimport { downloadCsv } from '../../utils/download';\nimport { NOT_MEASURED, optionalMetric } from '../../utils/optionalMetric';\nimport {\n calvingIntervalDisplay,\n dueSoonUrgency,\n dueSoonUrgencyText,\n fertilityCsvRows,\n FERTILITY_CSV_HEADERS,\n hasFertilityData,\n orderedDueSoon,\n orderedFertilityBuckets,\n pregnancyLossDisplay,\n type DueSoonUrgency,\n} from '../../utils/fertility';\nimport { useHealthyBowlFertility } from '../../hooks/useHealthyBowlFertility';\nimport type { GrowthGranularity } from '../../hooks/useHealthyBowlLivestockGrowth';\n\nconst GRANULARITIES: GrowthGranularity[] = ['DAY', 'WEEK', 'MONTH'];\n\n/**\n * Urgency → text colour. Only OVERDUE and IMMINENT earn a status colour; the rest stay neutral.\n *\n * Keyed on the union rather than `string` so adding a band to `DueSoonUrgency` fails the build here\n * instead of silently rendering an unstyled row.\n */\nconst URGENCY_CLASS: Record<DueSoonUrgency, string> = {\n OVERDUE: 'text-status-error-text',\n IMMINENT: 'text-status-warning-text',\n SOON: 'text-text-primary',\n LATER: 'text-text-secondary',\n};\n\ninterface FertilityCardProps {\n groupId?: string | null;\n className?: string;\n}\n\nexport const FertilityCard: FC<FertilityCardProps> = ({ groupId = null, className }) => {\n const { t } = useI18n();\n const [granularity, setGranularity] = useState<GrowthGranularity>('MONTH');\n const [from, setFrom] = useState('');\n const [to, setTo] = useState('');\n const { fertility, dueSoon, trend, truncated, workspaceReady, loading, error } = useHealthyBowlFertility({\n groupId,\n granularity,\n from: from || null,\n to: to || null,\n });\n\n const trendData = useMemo(() => orderedFertilityBuckets(trend), [trend]);\n const dueSoonRows = useMemo(() => orderedDueSoon(dueSoon), [dueSoon]);\n\n const hasData = hasFertilityData({\n services: fertility?.services,\n deliveries: fertility?.deliveries,\n damsWithInterval: fertility?.damsWithInterval,\n dueSoonCount: dueSoonRows.length,\n trendCount: trendData.length,\n });\n\n const interval = fertility ? calvingIntervalDisplay(fertility) : null;\n const loss = fertility ? pregnancyLossDisplay(fertility) : null;\n\n const handleExportCsv = () => {\n if (!fertility) return;\n downloadCsv(\n `livestock-fertility-${new Date().toISOString().slice(0, 10)}.csv`,\n [...FERTILITY_CSV_HEADERS],\n fertilityCsvRows({\n services: fertility.services,\n conceived: fertility.conceived,\n conceptionRatePct: fertility.conceptionRatePct,\n deliveries: fertility.deliveries,\n trend: trendData,\n })\n );\n };\n\n const granularityToggle = (\n <div className=\"flex items-center gap-1\">\n {GRANULARITIES.map((g) => (\n <button\n key={g}\n type=\"button\"\n onClick={() => setGranularity(g)}\n aria-pressed={granularity === g}\n className={`min-h-[32px] rounded-md px-2 py-1 text-xs transition-colors ${\n granularity === g\n ? 'bg-action-primary-bg text-action-primary-text'\n : 'text-text-secondary hover:bg-bg-sunken/50'\n }`}\n >\n {t(`healthybowl.livestock.fertility.granularity.${g.toLowerCase()}`, g.charAt(0) + g.slice(1).toLowerCase())}\n </button>\n ))}\n </div>\n );\n\n return (\n <ChartCard\n title={t('healthybowl.livestock.fertility.title', 'Fertility')}\n description={t(\n 'healthybowl.livestock.fertility.description',\n 'Whether the herd is actually breeding — conception, calving interval, litter size and who is due.'\n )}\n actions={\n <AnalyticsControls\n from={from}\n to={to}\n onFromChange={setFrom}\n onToChange={setTo}\n onExportCsv={handleExportCsv}\n exportDisabled={!fertility || !hasData}\n >\n {granularityToggle}\n </AnalyticsControls>\n }\n className={className}\n >\n {error ? (\n <div className=\"py-8 text-center\">\n <p className=\"text-sm text-text-primary\">\n {t('healthybowl.livestock.fertility.error.title', 'Could not load fertility analytics')}\n </p>\n <p className=\"mt-1 text-xs text-text-secondary\">{error.message}</p>\n </div>\n ) : !workspaceReady || (loading && !hasData) ? (\n <p className=\"py-8 text-center text-xs text-text-secondary\">\n {t('healthybowl.livestock.fertility.loading', 'Loading fertility analytics…')}\n </p>\n ) : !hasData ? (\n <div className=\"py-8 text-center\">\n <p className=\"text-sm text-text-primary\">\n {t('healthybowl.livestock.fertility.empty.title', 'No breeding records yet')}\n </p>\n <p className=\"mt-1 text-xs text-text-secondary\">\n {t(\n 'healthybowl.livestock.fertility.empty.hint',\n 'Record a mating on the Breeding page, then set its outcome — delivery date and offspring — to see conception, calving interval and litter size here.'\n )}\n </p>\n </div>\n ) : (\n <>\n {truncated && (\n <p className=\"mb-3 rounded-md bg-bg-sunken/60 px-3 py-2 text-xs text-text-secondary\">\n {t(\n 'healthybowl.livestock.fertility.truncated',\n 'This herd has more breeding records than one view can load, so every figure below covers only part of it. Narrow the date range or filter by group for an exact figure.'\n )}\n </p>\n )}\n\n {/* Headline — conception is what a farmer checks first. */}\n <dl className=\"mb-4 grid grid-cols-2 gap-3 sm:grid-cols-4\">\n <div>\n <dt className=\"text-xs text-text-secondary\">\n {t('healthybowl.livestock.fertility.summary.conceptionRate', 'Conception rate')}\n </dt>\n <dd className=\"text-sm font-medium tabular-nums text-text-primary\">\n {optionalMetric(fertility?.conceptionRatePct, { decimals: 1, unit: '%' })}\n </dd>\n <dd className=\"text-xs text-text-secondary\">\n {t('healthybowl.livestock.fertility.summary.ofServices', '{{c}} of {{s}} services', {\n c: String(fertility?.conceived ?? 0),\n s: String(fertility?.services ?? 0),\n })}\n </dd>\n </div>\n <div>\n <dt className=\"text-xs text-text-secondary\">\n {t('healthybowl.livestock.fertility.summary.servicesPerConception', 'Services per conception')}\n </dt>\n <dd className=\"text-sm font-medium tabular-nums text-text-primary\">\n {optionalMetric(fertility?.servicesPerConception, { decimals: 1 })}\n </dd>\n </div>\n <div>\n <dt className=\"text-xs text-text-secondary\">\n {t('healthybowl.livestock.fertility.summary.calvingInterval', 'Mean calving interval')}\n </dt>\n <dd className=\"text-sm font-medium tabular-nums text-text-primary\">\n {/* Never reachable when a reason exists — see calvingIntervalDisplay. */}\n {interval?.available\n ? t('healthybowl.livestock.fertility.summary.days', '{{n}} days', {\n n: formatNumber(interval.meanDays),\n })\n : NOT_MEASURED}\n </dd>\n {interval?.available && interval.medianDays !== null && (\n <dd className=\"text-xs text-text-secondary\">\n {t('healthybowl.livestock.fertility.summary.median', 'median {{n}}', {\n n: optionalMetric(interval.medianDays, { decimals: 0 }),\n })}\n </dd>\n )}\n </div>\n <div>\n <dt className=\"text-xs text-text-secondary\">\n {t('healthybowl.livestock.fertility.summary.pregnancyLoss', 'Pregnancy loss')}\n </dt>\n <dd className=\"text-sm font-medium tabular-nums text-text-primary\">\n {/* Unreachable while a reason exists — the raw figure is a structural 0, not a\n measurement, and printing it would read as a herd that lost nothing. */}\n {loss?.available ? optionalMetric(loss.ratePct, { decimals: 1, unit: '%' }) : NOT_MEASURED}\n </dd>\n <dd className=\"text-xs text-text-secondary\">\n {t('healthybowl.livestock.fertility.summary.ofConfirmed', 'of confirmed pregnancies')}\n </dd>\n </div>\n </dl>\n\n {/* The reason IS the value in both of these — never a blank, and never a number. */}\n {interval && !interval.available && interval.reason && (\n <p className=\"mb-4 rounded-md bg-bg-sunken/60 px-3 py-2 text-xs text-text-secondary\">{interval.reason}</p>\n )}\n {loss && !loss.available && loss.reason && (\n <p className=\"mb-4 rounded-md bg-bg-sunken/60 px-3 py-2 text-xs text-text-secondary\">{loss.reason}</p>\n )}\n\n {/* Trend — counts as bars, rate as its own axis. */}\n <div className=\"border-t border-border-subtle pt-4\">\n <h4 className=\"mb-2 text-xs font-medium uppercase tracking-wide text-text-secondary\">\n {t('healthybowl.livestock.fertility.trend.title', 'Services and conceptions')}\n </h4>\n {trendData.length === 0 ? (\n <p className=\"py-4 text-center text-xs text-text-secondary\">\n {t(\n 'healthybowl.livestock.fertility.trend.empty',\n 'No service in this period carries a mating date, so there is nothing to plot over time.'\n )}\n </p>\n ) : (\n <ResponsiveContainer width=\"100%\" height={220}>\n <ComposedChart data={trendData} margin={{ top: 5, right: 20, left: 0, bottom: 5 }}>\n <CartesianGrid strokeDasharray=\"3 3\" stroke=\"var(--color-border)\" />\n <XAxis dataKey=\"bucket\" tick={{ fontSize: 11 }} stroke=\"var(--color-muted-foreground)\" />\n <YAxis\n yAxisId=\"count\"\n allowDecimals={false}\n tick={{ fontSize: 11 }}\n stroke=\"var(--color-muted-foreground)\"\n />\n {/* Fixed 0–100 so two periods are comparable, not rescaled to whatever happened. */}\n <YAxis\n yAxisId=\"rate\"\n orientation=\"right\"\n domain={[0, 100]}\n unit=\"%\"\n tick={{ fontSize: 11 }}\n stroke=\"var(--color-muted-foreground)\"\n />\n <Tooltip\n cursor={{ fill: 'var(--color-muted)', opacity: 0.2 }}\n contentStyle={{\n backgroundColor: 'var(--color-card)',\n border: '1px solid var(--color-border)',\n borderRadius: 8,\n fontSize: 12,\n }}\n labelStyle={{ color: 'var(--color-foreground)' }}\n formatter={(value: number | string, name: string) => [\n typeof value === 'number' ? formatNumber(value) : String(value ?? NOT_MEASURED),\n name,\n ]}\n />\n <Legend wrapperStyle={{ fontSize: 11 }} />\n <Bar\n yAxisId=\"count\"\n dataKey=\"services\"\n name={t('healthybowl.livestock.fertility.trend.services', 'Services')}\n fill=\"var(--color-chart-1)\"\n radius={[4, 4, 0, 0]}\n />\n <Bar\n yAxisId=\"count\"\n dataKey=\"conceived\"\n name={t('healthybowl.livestock.fertility.trend.conceived', 'Conceived')}\n fill=\"var(--color-chart-2)\"\n radius={[4, 4, 0, 0]}\n />\n <Line\n yAxisId=\"rate\"\n type=\"monotone\"\n dataKey=\"conceptionRatePct\"\n name={t('healthybowl.livestock.fertility.trend.rate', 'Conception rate %')}\n stroke=\"var(--color-chart-3)\"\n strokeWidth={2}\n dot={false}\n connectNulls={false}\n />\n </ComposedChart>\n </ResponsiveContainer>\n )}\n </div>\n\n {/* Litter and first calving. */}\n <div className=\"mt-4 grid grid-cols-1 gap-4 border-t border-border-subtle pt-4 sm:grid-cols-2\">\n <div>\n <h4 className=\"mb-2 text-xs font-medium uppercase tracking-wide text-text-secondary\">\n {t('healthybowl.livestock.fertility.litter.title', 'Litter size')}\n </h4>\n <dl className=\"grid grid-cols-2 gap-3\">\n <div>\n <dt className=\"text-xs text-text-secondary\">\n {t('healthybowl.livestock.fertility.litter.born', 'Mean born')}\n </dt>\n <dd className=\"text-sm font-medium tabular-nums text-text-primary\">\n {optionalMetric(fertility?.meanOffspringBorn, { decimals: 1 })}\n </dd>\n </div>\n <div>\n <dt className=\"text-xs text-text-secondary\">\n {t('healthybowl.livestock.fertility.litter.live', 'Mean born alive')}\n </dt>\n <dd className=\"text-sm font-medium tabular-nums text-text-primary\">\n {optionalMetric(fertility?.meanOffspringLive, { decimals: 1 })}\n </dd>\n </div>\n <div>\n <dt className=\"text-xs text-text-secondary\">\n {t('healthybowl.livestock.fertility.litter.perinatal', 'Perinatal mortality')}\n </dt>\n <dd className=\"text-sm font-medium tabular-nums text-text-primary\">\n {optionalMetric(fertility?.perinatalMortalityPct, { decimals: 1, unit: '%' })}\n </dd>\n </div>\n <div>\n <dt className=\"text-xs text-text-secondary\">\n {t('healthybowl.livestock.fertility.litter.deliveries', 'Deliveries')}\n </dt>\n <dd className=\"text-sm font-medium tabular-nums text-text-primary\">\n {formatNumber(fertility?.deliveries ?? 0)}\n </dd>\n </div>\n </dl>\n {/* The denominator caveat, as animalsWithoutAge is for the age chart. */}\n <p className=\"mt-2 text-xs text-text-secondary\">\n {t(\n 'healthybowl.livestock.fertility.litter.coverage',\n '{{counted}} of {{total}} deliveries recorded how many were born — the averages are of those.',\n {\n counted: String(fertility?.deliveriesWithCounts ?? 0),\n total: String(fertility?.deliveries ?? 0),\n }\n )}\n </p>\n </div>\n\n <div>\n <h4 className=\"mb-2 text-xs font-medium uppercase tracking-wide text-text-secondary\">\n {t('healthybowl.livestock.fertility.firstCalving.title', 'Age at first calving')}\n </h4>\n <dl className=\"grid grid-cols-2 gap-3\">\n <div>\n <dt className=\"text-xs text-text-secondary\">\n {t('healthybowl.livestock.fertility.firstCalving.mean', 'Mean')}\n </dt>\n <dd className=\"text-sm font-medium tabular-nums text-text-primary\">\n {fertility?.meanAgeAtFirstCalvingDays !== null && fertility?.meanAgeAtFirstCalvingDays !== undefined\n ? t('healthybowl.livestock.fertility.summary.days', '{{n}} days', {\n n: formatNumber(fertility.meanAgeAtFirstCalvingDays),\n })\n : NOT_MEASURED}\n </dd>\n </div>\n <div>\n <dt className=\"text-xs text-text-secondary\">\n {t('healthybowl.livestock.fertility.firstCalving.median', 'Median')}\n </dt>\n <dd className=\"text-sm font-medium tabular-nums text-text-primary\">\n {optionalMetric(fertility?.medianAgeAtFirstCalvingDays, { decimals: 0 })}\n </dd>\n </div>\n <div className=\"col-span-2\">\n <dt className=\"text-xs text-text-secondary\">\n {t('healthybowl.livestock.fertility.firstCalving.dams', 'Dams with a first calving')}\n </dt>\n <dd className=\"text-sm font-medium tabular-nums text-text-primary\">\n {formatNumber(fertility?.damsWithFirstCalving ?? 0)}\n <span className=\"ms-2 text-xs font-normal text-text-secondary\">\n {t('healthybowl.livestock.fertility.firstCalving.intervalDams', '· {{n}} with an interval', {\n n: String(fertility?.damsWithInterval ?? 0),\n })}\n </span>\n </dd>\n </div>\n </dl>\n <p className=\"mt-2 text-xs text-text-secondary\">\n {t(\n 'healthybowl.livestock.fertility.firstCalving.coverage',\n 'Only dams whose own date of birth is recorded can contribute — an unknown birth date makes the age unknowable.'\n )}\n </p>\n </div>\n </div>\n\n {/* Due soon — a worklist, soonest first. */}\n <div className=\"mt-4 border-t border-border-subtle pt-4\">\n <h4 className=\"mb-2 text-xs font-medium uppercase tracking-wide text-text-secondary\">\n {t('healthybowl.livestock.fertility.due.title', 'Due in the next 30 days')}\n </h4>\n {dueSoonRows.length === 0 ? (\n <p className=\"text-xs text-text-secondary\">\n {t(\n 'healthybowl.livestock.fertility.due.empty',\n 'No confirmed or mated pregnancy is due in the next 30 days.'\n )}\n </p>\n ) : (\n <ul className=\"flex flex-col gap-1.5\">\n {dueSoonRows.map((row) => {\n const urgency = dueSoonUrgency(row.daysUntilDue);\n const label = dueSoonUrgencyText(urgency);\n return (\n <li\n key={`${row.animalId}:${row.expectedDeliveryDate}`}\n className=\"flex flex-wrap items-baseline justify-between gap-2 text-xs\"\n >\n <span className=\"font-medium text-text-primary\">{row.animalId}</span>\n <span className=\"flex items-baseline gap-2\">\n <span className=\"tabular-nums text-text-secondary\">{row.expectedDeliveryDate}</span>\n <span className={`tabular-nums ${URGENCY_CLASS[urgency]}`}>\n {t(label.key, label.defaultValue)}\n {urgency !== 'OVERDUE' && (\n <span className=\"text-text-secondary\">\n {' '}\n {t('healthybowl.livestock.fertility.due.inDays', '({{n}}d)', {\n n: String(row.daysUntilDue),\n })}\n </span>\n )}\n </span>\n </span>\n </li>\n );\n })}\n </ul>\n )}\n </div>\n </>\n )}\n </ChartCard>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAuDA,IAAM,IAAqC;CAAC;CAAO;CAAQ;CAAQ,EAQ7D,IAAgD;CACpD,SAAS;CACT,UAAU;CACV,MAAM;CACN,OAAO;CACR,EAOY,KAAyC,EAAE,aAAU,MAAM,mBAAgB;CACtF,IAAM,EAAE,SAAM,GAAS,EACjB,CAAC,GAAa,KAAkB,EAA4B,QAAQ,EACpE,CAAC,GAAM,KAAW,EAAS,GAAG,EAC9B,CAAC,GAAI,KAAS,EAAS,GAAG,EAC1B,EAAE,cAAW,YAAS,UAAO,cAAW,mBAAgB,YAAS,aAAU,EAAwB;EACvG;EACA;EACA,MAAM,KAAQ;EACd,IAAI,KAAM;EACX,CAAC,EAEI,IAAY,QAAc,EAAwB,EAAM,EAAE,CAAC,EAAM,CAAC,EAClE,IAAc,QAAc,EAAe,EAAQ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lBE,GAAG,EAAI,SAAS,GAAG,EAAI,uBAkBzB;OAEP;KACC,CAAA,CAEH;;GACL,EAAA,CAAA,GArTH,kBAAC,OAAD;GAAK,WAAU;aAAf,CACE,kBAAC,KAAD;IAAG,WAAU;cACV,EAAE,+CAA+C,0BAA0B;IAC1E,CAAA,EACJ,kBAAC,KAAD;IAAG,WAAU;cACV,EACC,8CACA,uJACD;IACC,CAAA,CACA;;EA6SE,CAAA"}
@@ -4,31 +4,33 @@ import "../../components/index.js";
4
4
  import { LivestockGrowthCard as n } from "./LivestockGrowthCard.js";
5
5
  import { LivestockFeedCard as r } from "./LivestockFeedCard.js";
6
6
  import { HerdStatsCard as i } from "./HerdStatsCard.js";
7
- import { useI18n as a } from "@burdenoff/fe-libs/shared/providers/shell/I18nProvider";
8
- import { ArrowLeft as o } from "lucide-react";
9
- import { useNavigate as s } from "react-router";
10
- import { jsx as c, jsxs as l } from "react/jsx-runtime";
11
- import { Button as u } from "@burdenoff/fe-libs/ui";
7
+ import { FertilityCard as a } from "./FertilityCard.js";
8
+ import { useI18n as o } from "@burdenoff/fe-libs/shared/providers/shell/I18nProvider";
9
+ import { ArrowLeft as s } from "lucide-react";
10
+ import { useNavigate as c } from "react-router";
11
+ import { jsx as l, jsxs as u } from "react/jsx-runtime";
12
+ import { Button as d } from "@burdenoff/fe-libs/ui";
12
13
  //#region src/healthybowl/pages/livestock/LivestockAnalyticsPage.tsx
13
- var d = () => {
14
- let { t: d } = a(), f = s(), { buildPath: p } = e();
15
- return /* @__PURE__ */ l(t, {
16
- title: d("healthybowl.livestock.analytics.title", "Livestock Analytics"),
17
- description: d("healthybowl.livestock.analytics.description", "Growth, feed and herd trends in one place — each chart filters by date range and exports to CSV."),
18
- purpose: "A dedicated home for the three herd analytics — growth, feed spend and herd composition. The same charts also appear on the livestock dashboard; this page gives them full width and a shareable URL.",
19
- actions: /* @__PURE__ */ l(u, {
14
+ var f = () => {
15
+ let { t: f } = o(), p = c(), { buildPath: m } = e();
16
+ return /* @__PURE__ */ u(t, {
17
+ title: f("healthybowl.livestock.analytics.title", "Livestock Analytics"),
18
+ description: f("healthybowl.livestock.analytics.description", "Growth, feed, herd and fertility trends in one place — each chart filters by date range and exports to CSV."),
19
+ purpose: "A dedicated home for the four herd analytics — growth, feed spend, herd composition and fertility. The same charts also appear on the livestock dashboard; this page gives them full width and a shareable URL.",
20
+ actions: /* @__PURE__ */ u(d, {
20
21
  variant: "outline",
21
- onClick: () => f(p("livestock")),
22
- children: [/* @__PURE__ */ c(o, { className: "h-4 w-4" }), d("healthybowl.livestock.analytics.backToDashboard", "Back to Livestock")]
22
+ onClick: () => p(m("livestock")),
23
+ children: [/* @__PURE__ */ l(s, { className: "h-4 w-4" }), f("healthybowl.livestock.analytics.backToDashboard", "Back to Livestock")]
23
24
  }),
24
25
  children: [
25
- /* @__PURE__ */ c(n, {}),
26
- /* @__PURE__ */ c(r, {}),
27
- /* @__PURE__ */ c(i, {})
26
+ /* @__PURE__ */ l(n, {}),
27
+ /* @__PURE__ */ l(r, {}),
28
+ /* @__PURE__ */ l(i, {}),
29
+ /* @__PURE__ */ l(a, {})
28
30
  ]
29
31
  });
30
32
  };
31
33
  //#endregion
32
- export { d as LivestockAnalyticsPage };
34
+ export { f as LivestockAnalyticsPage };
33
35
 
34
36
  //# sourceMappingURL=LivestockAnalyticsPage.js.map