@burdenoff/microfe-healthybowl 2026.904.21 → 2026.904.22
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/components/assistant/AssistantChatArea.js +7 -9
- package/dist/components/assistant/AssistantChatArea.js.map +1 -1
- package/dist/healthybowl/HealthyBowlRoot.js +56 -57
- package/dist/healthybowl/HealthyBowlRoot.js.map +1 -1
- package/dist/healthybowl/HealthyBowlRoutes.js +36 -48
- package/dist/healthybowl/HealthyBowlRoutes.js.map +1 -1
- package/dist/healthybowl/components/CreateFarmTaskButton.js.map +1 -1
- package/dist/healthybowl/components/PageLayout.js +10 -11
- package/dist/healthybowl/components/PageLayout.js.map +1 -1
- package/dist/healthybowl/context/HealthyBowlContext.js +7 -7
- package/dist/healthybowl/context/HealthyBowlContext.js.map +1 -1
- package/dist/healthybowl/hooks/useHealthyBowlCompliance.js +141 -157
- package/dist/healthybowl/hooks/useHealthyBowlCompliance.js.map +1 -1
- package/dist/healthybowl/hooks/useHealthyBowlData.js +0 -18
- package/dist/healthybowl/hooks/useHealthyBowlData.js.map +1 -1
- package/dist/healthybowl/hooks/useHealthyBowlDistribution.js +37 -52
- package/dist/healthybowl/hooks/useHealthyBowlDistribution.js.map +1 -1
- package/dist/healthybowl/hooks/useHealthyBowlLivestockDepth.js +78 -135
- package/dist/healthybowl/hooks/useHealthyBowlLivestockDepth.js.map +1 -1
- package/dist/healthybowl/hooks/useIrrigationAutomation.js +1 -1
- package/dist/healthybowl/hooks/useIrrigationAutomation.js.map +1 -1
- package/dist/healthybowl/hooks/useSuccessionPlanning.js +1 -1
- package/dist/healthybowl/hooks/useSuccessionPlanning.js.map +1 -1
- package/dist/healthybowl/hooks/useWeatherIntelligence.js +1 -1
- package/dist/healthybowl/hooks/useWeatherIntelligence.js.map +1 -1
- package/dist/healthybowl/offline/OfflineStatusPill.js +21 -40
- package/dist/healthybowl/offline/OfflineStatusPill.js.map +1 -1
- package/dist/healthybowl/offline/OfflineSyncProvider.js +130 -153
- package/dist/healthybowl/offline/OfflineSyncProvider.js.map +1 -1
- package/dist/healthybowl/offline/graphql.js.map +1 -1
- package/dist/healthybowl/offline/store.js +1 -1
- package/dist/healthybowl/offline/syncEngine.js +1 -2
- package/dist/healthybowl/offline/syncEngine.js.map +1 -1
- package/dist/healthybowl/offline/types.js.map +1 -1
- package/dist/healthybowl/pages/GettingStartedPage.js +0 -1
- package/dist/healthybowl/pages/GettingStartedPage.js.map +1 -1
- package/dist/healthybowl/pages/analytics/InsightsPage.js +2 -2
- package/dist/healthybowl/pages/analytics/InsightsPage.js.map +1 -1
- package/dist/healthybowl/pages/analytics/ReportsPage.js +99 -136
- package/dist/healthybowl/pages/analytics/ReportsPage.js.map +1 -1
- package/dist/healthybowl/pages/compliance/ComplianceOverviewPage.js +162 -204
- package/dist/healthybowl/pages/compliance/ComplianceOverviewPage.js.map +1 -1
- package/dist/healthybowl/pages/compliance/IcsGroupDetailPage.js +178 -196
- package/dist/healthybowl/pages/compliance/IcsGroupDetailPage.js.map +1 -1
- package/dist/healthybowl/pages/compliance/IcsGrowerDetailPage.js +141 -142
- package/dist/healthybowl/pages/compliance/IcsGrowerDetailPage.js.map +1 -1
- package/dist/healthybowl/pages/crops/CropFieldsPage.js +0 -2
- package/dist/healthybowl/pages/crops/CropFieldsPage.js.map +1 -1
- package/dist/healthybowl/pages/crops/CropHarvestPage.js +272 -316
- package/dist/healthybowl/pages/crops/CropHarvestPage.js.map +1 -1
- package/dist/healthybowl/pages/crops/CropPlanningPage.js +0 -6
- package/dist/healthybowl/pages/crops/CropPlanningPage.js.map +1 -1
- package/dist/healthybowl/pages/crops/FieldDetailsPage.js +846 -871
- package/dist/healthybowl/pages/crops/FieldDetailsPage.js.map +1 -1
- package/dist/healthybowl/pages/crops/HarvestDetailsPage.js +334 -376
- package/dist/healthybowl/pages/crops/HarvestDetailsPage.js.map +1 -1
- package/dist/healthybowl/pages/distribution/CsaPlanDetailPage.js +188 -415
- package/dist/healthybowl/pages/distribution/CsaPlanDetailPage.js.map +1 -1
- package/dist/healthybowl/pages/distribution/labels.js +2 -10
- package/dist/healthybowl/pages/distribution/labels.js.map +1 -1
- package/dist/healthybowl/pages/farm/FarmProfilePage.js +0 -1
- package/dist/healthybowl/pages/farm/FarmProfilePage.js.map +1 -1
- package/dist/healthybowl/pages/field-capture/CaptureObservationForm.js +8 -8
- package/dist/healthybowl/pages/fields/FieldMapPage.js +0 -2
- package/dist/healthybowl/pages/fields/FieldMapPage.js.map +1 -1
- package/dist/healthybowl/pages/financial/FinancialReportsPage.js +107 -92
- package/dist/healthybowl/pages/financial/FinancialReportsPage.js.map +1 -1
- package/dist/healthybowl/pages/government-schemes/ApplicationTrackingPage.js +188 -228
- package/dist/healthybowl/pages/government-schemes/ApplicationTrackingPage.js.map +1 -1
- package/dist/healthybowl/pages/government-schemes/SchemeDetailsPage.js +191 -261
- package/dist/healthybowl/pages/government-schemes/SchemeDetailsPage.js.map +1 -1
- package/dist/healthybowl/pages/inputs-insurance/InputsInsuranceOverviewPage.js +14 -14
- package/dist/healthybowl/pages/inputs-insurance/InputsInsuranceOverviewPage.js.map +1 -1
- package/dist/healthybowl/pages/irrigation/IrrigationPage.js +307 -338
- package/dist/healthybowl/pages/irrigation/IrrigationPage.js.map +1 -1
- package/dist/healthybowl/pages/livestock/AnimalDepthFormModal.js +102 -126
- package/dist/healthybowl/pages/livestock/AnimalDepthFormModal.js.map +1 -1
- package/dist/healthybowl/pages/livestock/AnimalDepthPage.js +215 -257
- package/dist/healthybowl/pages/livestock/AnimalDepthPage.js.map +1 -1
- package/dist/healthybowl/pages/livestock/GrazingPage.js +0 -1
- package/dist/healthybowl/pages/livestock/GrazingPage.js.map +1 -1
- package/dist/healthybowl/pages/livestock/HerdDepthPage.js +0 -4
- package/dist/healthybowl/pages/livestock/HerdDepthPage.js.map +1 -1
- package/dist/healthybowl/pages/livestock/grazing/RecordGrazingMoveModal.js +9 -8
- package/dist/healthybowl/pages/livestock/grazing/RecordGrazingMoveModal.js.map +1 -1
- package/dist/healthybowl/pages/network/ExpertsPage.js +419 -520
- package/dist/healthybowl/pages/network/ExpertsPage.js.map +1 -1
- package/dist/healthybowl/pages/weather/WeatherAlertHistoryPage.js +130 -129
- package/dist/healthybowl/pages/weather/WeatherAlertHistoryPage.js.map +1 -1
- package/dist/healthybowl/pages/weather/WeatherSettingsPage.js +237 -285
- package/dist/healthybowl/pages/weather/WeatherSettingsPage.js.map +1 -1
- package/dist/healthybowl/utils/plantingCapacity.js +10 -10
- package/dist/healthybowl/utils/plantingCapacity.js.map +1 -1
- package/dist/node_modules/fast-equals/dist/es/index.js +86 -74
- package/dist/node_modules/fast-equals/dist/es/index.js.map +1 -1
- package/dist/services/assistantApi.js +30 -59
- package/dist/services/assistantApi.js.map +1 -1
- package/dist/utils/pageContext.js +1 -15
- package/dist/utils/pageContext.js.map +1 -1
- package/package.json +1 -1
- package/dist/healthybowl/hooks/useAgronomyDecisions.js +0 -79
- package/dist/healthybowl/hooks/useAgronomyDecisions.js.map +0 -1
- package/dist/healthybowl/hooks/useAnalyticsReports.js +0 -173
- package/dist/healthybowl/hooks/useAnalyticsReports.js.map +0 -1
- package/dist/healthybowl/hooks/useComplianceExports.js +0 -74
- package/dist/healthybowl/hooks/useComplianceExports.js.map +0 -1
- package/dist/healthybowl/hooks/useConsultationPayments.js +0 -59
- package/dist/healthybowl/hooks/useConsultationPayments.js.map +0 -1
- package/dist/healthybowl/hooks/usePlantingEstimate.js +0 -88
- package/dist/healthybowl/hooks/usePlantingEstimate.js.map +0 -1
- package/dist/healthybowl/offline/HeaderOfflinePill.js +0 -28
- package/dist/healthybowl/offline/HeaderOfflinePill.js.map +0 -1
- package/dist/healthybowl/offline/captureCache.js +0 -30
- package/dist/healthybowl/offline/captureCache.js.map +0 -1
- package/dist/healthybowl/offline/headerSlot.js +0 -24
- package/dist/healthybowl/offline/headerSlot.js.map +0 -1
- package/dist/healthybowl/pages/ai/AiDecisionsPage.js +0 -287
- package/dist/healthybowl/pages/ai/AiDecisionsPage.js.map +0 -1
- package/dist/healthybowl/pages/compliance/ResidueTestsPage.js +0 -291
- package/dist/healthybowl/pages/compliance/ResidueTestsPage.js.map +0 -1
- package/dist/healthybowl/pages/compliance/SubstanceRulesPage.js +0 -300
- package/dist/healthybowl/pages/compliance/SubstanceRulesPage.js.map +0 -1
- package/dist/healthybowl/pages/compliance/substanceRuleForm.js +0 -135
- package/dist/healthybowl/pages/compliance/substanceRuleForm.js.map +0 -1
- package/dist/healthybowl/pages/government-schemes/schemeApplicationTransitions.js +0 -49
- package/dist/healthybowl/pages/government-schemes/schemeApplicationTransitions.js.map +0 -1
- package/dist/healthybowl/pages/government-schemes/schemeDocumentSlots.js +0 -48
- package/dist/healthybowl/pages/government-schemes/schemeDocumentSlots.js.map +0 -1
- package/dist/healthybowl/pages/government-schemes/useSchemeApplicationTransition.js +0 -54
- package/dist/healthybowl/pages/government-schemes/useSchemeApplicationTransition.js.map +0 -1
- package/dist/healthybowl/pages/livestock/PedigreeTree.js +0 -154
- package/dist/healthybowl/pages/livestock/PedigreeTree.js.map +0 -1
- package/dist/healthybowl/pages/livestock/eidTagInput.js +0 -39
- package/dist/healthybowl/pages/livestock/eidTagInput.js.map +0 -1
- package/dist/healthybowl/pages/livestock/pedigreeLayout.js +0 -68
- package/dist/healthybowl/pages/livestock/pedigreeLayout.js.map +0 -1
- package/dist/healthybowl/pages/weather/alertDelivery.js +0 -105
- package/dist/healthybowl/pages/weather/alertDelivery.js.map +0 -1
- package/dist/healthybowl/utils/icsInspection.js +0 -18
- package/dist/healthybowl/utils/icsInspection.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AnimalDepthPage.js","names":[],"sources":["../../../../src/healthybowl/pages/livestock/AnimalDepthPage.tsx"],"sourcesContent":["/**\n * Single-animal deep record (BOFF-2890 · L-1).\n * EID/RFID, body-condition score, group, grazing/rotation, dam/sire genealogy, ADG, latest\n * weight and weight history, plus the medication-withdrawal compliance badge (reused from\n * BOFF-2885). Edit the record or log a new weight in place. No fabricated data.\n */\nimport { useMemo, useState } from 'react';\nimport { useNavigate, useParams } from 'react-router';\nimport { AlertTriangle, ArrowLeft, GitBranch, Pencil, Scale, TrendingUp } from 'lucide-react';\nimport { Button } from '@burdenoff/fe-libs/ui';\nimport { useI18n } from '@burdenoff/fe-libs/shared/providers/shell/I18nProvider';\nimport { PageLayout, StatusBadge, ErrorState, PageLoader, Breadcrumbs, useConfirm } from '../../components';\nimport { useToast } from '../../hooks/useToast';\nimport { useBasePath } from '../../hooks/useBasePath';\nimport { useHealthyBowlLivestockDepth } from '../../hooks/useHealthyBowlLivestockDepth';\nimport { useHealthyBowlGrazingEvents } from '../../hooks/useHealthyBowlGrazing';\nimport { AnimalDepthFormModal, type AnimalOption } from './AnimalDepthFormModal';\nimport { RecordWeightModal } from './RecordWeightModal';\nimport { PedigreeTree } from './PedigreeTree';\nimport { formatAdg, formatBcs, formatShortDate, formatWeight, withdrawalBadgeVariant } from './depthLabels';\n\nconst DetailRow = ({ label, value }: { label: string; value: React.ReactNode }) => (\n <div className=\"flex items-center justify-between gap-4 border-b border-border-subtle py-3 last:border-0\">\n <span className=\"text-sm text-text-secondary\">{label}</span>\n <span className=\"text-end text-sm font-medium text-text-primary\">{value}</span>\n </div>\n);\n\n/**\n * One parent on the genealogy row (BOFF-6195).\n *\n * Deliberately NOT a link. `healthyBowlAnimalDepth` filters `deletedAt: null`, so navigating to an\n * archived parent dead-ends on NOT_FOUND — a link that reliably breaks is worse than plain text.\n *\n * The \"(archived)\" marker is driven by the API's `damArchived`/`sireArchived`, never inferred from\n * whether the tag happens to be missing from the live herd list: that read is capped, so an absence\n * there is not evidence the animal left the herd.\n */\nconst ParentTag = ({ role, tag, archived }: { role: string; tag: string | null; archived: boolean }) => {\n const { t } = useI18n();\n if (!tag) return <span>{`${role} —`}</span>;\n return (\n <span>\n {`${role} ${tag}`}\n {archived ? (\n <span className=\"ms-1 font-normal text-text-secondary\">\n {t('healthybowl.livestock.depth.detail.archivedSuffix', '(archived)')}\n </span>\n ) : null}\n </span>\n );\n};\n\nexport const AnimalDepthPage = () => {\n const { t } = useI18n();\n const navigate = useNavigate();\n const { buildPath } = useBasePath();\n const { toast } = useToast();\n const confirm = useConfirm();\n const { animalId } = useParams<{ animalId: string }>();\n\n const {\n animalDepth,\n herd,\n groups,\n pedigree,\n loading,\n errors,\n refetchAnimal,\n updateAnimalDepth,\n recordWeight,\n deleteWeight,\n } = useHealthyBowlLivestockDepth({\n animalId: animalId ?? null,\n herd: true,\n // The Dam/Sire picker must be able to offer a culled or sold parent — the backend has\n // accepted that link since BOFF-6011, and this page is the only place it can be recorded\n // (BOFF-6195). Archived rows are additive to `rows` only; the compliance summary and the\n // group counts stay live-only server-side.\n herdIncludeArchived: true,\n groups: true,\n // The one-hop Dam/Sire row answers \"who are the parents\"; the pedigree answers \"where does\n // this animal come from, and what has it produced\" (BOFF-6097).\n pedigree: true,\n });\n\n /**\n * Where this animal actually is (BOFF-5970).\n *\n * `recordHealthyBowlGrazingMove` writes a grazing EVENT and never touches the animal's legacy\n * `grazingPaddock` / `rotationDate` columns, so after any move recorded on the Grazing page those\n * two are a frozen snapshot of a previous model — and rendering them as a plain current fact made\n * this page and the Grazing page give two different answers to the same question. The event is\n * the live answer whenever one exists; the legacy pair is annotated in the VALUE, not only in its\n * label, because the label is not what a farmer reads off the row.\n */\n const {\n latest: latestGrazing,\n loading: grazingLoading,\n error: grazingError,\n } = useHealthyBowlGrazingEvents({ animalId: animalId ?? null, limit: 5 });\n\n const [editOpen, setEditOpen] = useState(false);\n const [weightOpen, setWeightOpen] = useState(false);\n\n const animalOptions = useMemo<AnimalOption[]>(\n () =>\n (herd?.rows ?? []).map((r) => ({\n animalId: r.animalId,\n tagNumber: r.tagNumber,\n name: r.name,\n // `archived` is only selected by the archived-aware herd document, which this page opts\n // into above. Defaulting to false keeps the option type honest for any future caller that\n // does not.\n archived: r.archived ?? false,\n })),\n [herd]\n );\n\n if (loading.animal && !animalDepth) {\n return <PageLoader />;\n }\n if ((errors.animal && !animalDepth) || !animalDepth) {\n return (\n <PageLayout title={t('healthybowl.livestock.depth.detail.title', 'Animal Record')}>\n <ErrorState\n description={errors.animal?.message ?? t('healthybowl.livestock.depth.detail.notFound', 'Animal not found.')}\n onRetry={() => void refetchAnimal()}\n />\n </PageLayout>\n );\n }\n\n const a = animalDepth;\n const initials = a.name.slice(0, 2).toUpperCase();\n\n const handleEdit = async (input: Record<string, unknown>) => {\n await updateAnimalDepth(input);\n toast({\n title: t('healthybowl.livestock.depth.toast.updated', 'Record updated'),\n description: a.name,\n variant: 'success',\n });\n };\n\n const handleWeight = async (input: Record<string, unknown>) => {\n await recordWeight({ ...input, animalId: a.animalId });\n toast({\n title: t('healthybowl.livestock.depth.toast.weightSaved', 'Weight recorded'),\n description: `${String(input.weightKg)} kg`,\n variant: 'success',\n });\n };\n\n const handleDeleteWeight = async (id: string) => {\n if (\n !(await confirm({\n title: t('healthybowl.livestock.depth.confirm.delWeightTitle', 'Delete weight?'),\n message: t('healthybowl.livestock.depth.confirm.delWeight', 'Remove this weight measurement?'),\n }))\n ) {\n return;\n }\n try {\n await deleteWeight(id);\n toast({ title: t('healthybowl.livestock.depth.toast.weightDeleted', 'Weight removed'), variant: 'success' });\n } catch (err) {\n toast({\n title: t('healthybowl.livestock.depth.toast.error', 'Something went wrong'),\n description: err instanceof Error ? err.message : String(err),\n variant: 'error',\n });\n }\n };\n\n return (\n <PageLayout\n title={a.name}\n description={`${a.type} · ${a.tagNumber}`}\n actions={\n <div className=\"flex items-center gap-2\">\n <Button variant=\"outline\" onClick={() => setWeightOpen(true)}>\n <Scale className=\"h-4 w-4\" />\n {t('healthybowl.livestock.depth.detail.logWeight', 'Record weight')}\n </Button>\n <Button onClick={() => setEditOpen(true)}>\n <Pencil className=\"h-4 w-4\" />\n {t('healthybowl.livestock.depth.detail.edit', 'Edit')}\n </Button>\n </div>\n }\n >\n <Breadcrumbs\n items={[\n { label: t('healthybowl.livestock.depth.title', 'Livestock Records'), href: buildPath('livestock/records') },\n { label: a.name },\n ]}\n />\n\n <div className=\"mt-2\">\n <Button variant=\"ghost\" size=\"sm\" onClick={() => navigate(buildPath('livestock/records'))}>\n <ArrowLeft className=\"h-4 w-4\" />\n {t('common.back', 'Back')}\n </Button>\n </div>\n\n {a.withdrawal.blocked ? (\n <div\n role=\"alert\"\n className=\"mt-3 flex items-center gap-3 rounded-lg border border-status-error-border bg-status-error-bg px-4 py-3 text-status-error-text\"\n >\n <AlertTriangle className=\"h-5 w-5 shrink-0\" />\n <span className=\"text-sm font-semibold\">\n {t(\n 'healthybowl.livestock.depth.detail.withdrawalBanner',\n 'In medication withdrawal — Withdrawal ends {{date}} · do not sell milk or meat',\n {\n date: formatShortDate(a.withdrawal.endDate),\n }\n )}\n </span>\n </div>\n ) : null}\n\n <div className=\"mt-4 grid grid-cols-1 gap-4 lg:grid-cols-3\">\n <div className=\"rounded-xl border border-border-subtle bg-bg-surface p-5 lg:col-span-2\">\n <div className=\"mb-2 flex items-center gap-3\">\n <div className=\"flex h-14 w-14 items-center justify-center rounded-full bg-accent-teal/10 text-lg font-semibold text-accent-teal\">\n {initials}\n </div>\n <div>\n <div className=\"text-lg font-semibold text-text-primary\">{a.name}</div>\n <div className=\"text-sm text-text-secondary\">\n {a.type} #{a.tagNumber}\n </div>\n </div>\n <div className=\"ms-auto\">\n <StatusBadge\n variant={withdrawalBadgeVariant(a.withdrawal.status)}\n label={\n a.withdrawal.blocked\n ? t('healthybowl.livestock.depth.detail.inWithdrawal', 'In withdrawal')\n : t('healthybowl.livestock.depth.detail.clear', 'Clear to sell')\n }\n dot\n />\n </div>\n </div>\n\n <DetailRow label={t('healthybowl.livestock.depth.detail.eid', 'EID / RFID Tag')} value={a.eidTag ?? '—'} />\n <DetailRow\n label={t('healthybowl.livestock.depth.detail.bcs', 'Body Condition Score')}\n value={formatBcs(a.bodyConditionScore)}\n />\n <DetailRow label={t('healthybowl.livestock.depth.detail.group', 'Group')} value={a.groupName ?? '—'} />\n {/* The live answer, from the grazing event model (BOFF-5970). Error before empty: \"no\n move recorded\" is a claim about this animal and must not stand in for a failed read. */}\n <DetailRow\n label={t('healthybowl.livestock.depth.detail.grazingNow', 'Grazing — where this animal is')}\n value={\n <span className=\"inline-flex flex-col items-end gap-0.5\">\n {grazingError ? (\n <span className=\"text-status-error-text\">\n {t(\n 'healthybowl.livestock.depth.detail.grazingFailed',\n 'The grazing log could not be read — {{message}}',\n { message: grazingError.message }\n )}\n </span>\n ) : grazingLoading && !latestGrazing ? (\n <span className=\"font-normal text-text-secondary\">\n {t('healthybowl.livestock.depth.detail.grazingLoading', 'Reading the grazing log…')}\n </span>\n ) : latestGrazing ? (\n <>\n <span>{latestGrazing.paddockName}</span>\n <span className=\"text-xs font-normal text-text-secondary\">\n {latestGrazing.active\n ? t('healthybowl.livestock.depth.detail.grazingIn', 'In since {{date}}', {\n date: formatShortDate(latestGrazing.enteredAt),\n })\n : t('healthybowl.livestock.depth.detail.grazingOut', 'Left {{date}} — no paddock since', {\n date: formatShortDate(latestGrazing.exitedAt),\n })}\n </span>\n </>\n ) : (\n <span className=\"font-normal text-text-secondary\">\n {t('healthybowl.livestock.depth.detail.grazingNone', 'No move recorded in the grazing log yet.')}\n </span>\n )}\n <button\n type=\"button\"\n className=\"text-xs font-normal text-text-secondary underline hover:text-text-primary\"\n onClick={() => navigate(buildPath('livestock/grazing'))}\n >\n {t('healthybowl.livestock.depth.detail.grazingLink', 'Open grazing — moves, rest and stocking rate')}\n </button>\n </span>\n }\n />\n {/* LEGACY grazing fields (BOFF-2890). `rotationDate` is a single scalar, so writing the\n next rotation overwrote the previous one — no duration, rest period or stocking rate\n could ever be derived from it. BOFF-5970 replaced this with a grazing EVENT, and moves\n recorded there never write back here, so once an event exists this pair is a frozen\n snapshot. The VALUE says so, not just the label: the label is not what gets read off\n the row. Shown at all only when there is something in it. */}\n {a.grazingPaddock ? (\n <DetailRow\n label={t('healthybowl.livestock.depth.detail.grazing', 'Grazing / Rotation (legacy)')}\n value={\n <span className=\"inline-flex flex-col items-end gap-0.5\">\n <span className={latestGrazing ? 'font-normal text-text-secondary line-through' : undefined}>\n {`${a.grazingPaddock}${a.rotationDate ? ` (rotates ${formatShortDate(a.rotationDate)})` : ''}`}\n </span>\n <span className=\"max-w-[320px] text-xs font-normal text-text-secondary\">\n {latestGrazing\n ? t(\n 'healthybowl.livestock.depth.detail.grazingSuperseded',\n 'Recorded before the grazing log and never updated since — the row above is where this animal is now.'\n )\n : grazingError || grazingLoading\n ? t(\n 'healthybowl.livestock.depth.detail.grazingUnchecked',\n 'A single free-text paddock and one rotation date, with no time in or out. Whether the grazing log has superseded it could not be checked.'\n )\n : t(\n 'healthybowl.livestock.depth.detail.grazingOnlyRecord',\n 'A single free-text paddock and one rotation date, with no time in or out. Record a move on the Grazing page and this animal joins the history.'\n )}\n </span>\n </span>\n }\n />\n ) : null}\n <DetailRow\n label={t('healthybowl.livestock.depth.detail.genealogy', 'Genealogy — Dam · Sire')}\n value={\n <span className=\"inline-flex flex-wrap items-center justify-end gap-x-1\">\n <ParentTag\n role={t('healthybowl.livestock.depth.detail.dam', 'Dam')}\n tag={a.damTag}\n archived={a.damArchived}\n />\n <span className=\"text-text-secondary\">·</span>\n <ParentTag\n role={t('healthybowl.livestock.depth.detail.sire', 'Sire')}\n tag={a.sireTag}\n archived={a.sireArchived}\n />\n </span>\n }\n />\n <DetailRow\n label={t('healthybowl.livestock.depth.detail.adg', 'Average Daily Gain (ADG)')}\n value={\n <span className=\"inline-flex items-center gap-1\">\n {a.adgKgPerDay !== null ? <TrendingUp className=\"h-4 w-4 text-accent-teal\" /> : null}\n {formatAdg(a.adgKgPerDay)}\n </span>\n }\n />\n <DetailRow\n label={t('healthybowl.livestock.depth.detail.latestWeight', 'Latest Weight')}\n value={formatWeight(a.latestWeightKg, a.latestWeightAt)}\n />\n {a.grazingNotes ? (\n <DetailRow label={t('healthybowl.livestock.depth.detail.notes', 'Grazing notes')} value={a.grazingNotes} />\n ) : null}\n </div>\n\n <div className=\"rounded-xl border border-border-subtle bg-bg-surface p-5\">\n <div className=\"mb-3 flex items-center justify-between\">\n <h3 className=\"text-sm font-semibold text-text-primary\">\n {t('healthybowl.livestock.depth.detail.weightHistory', 'Weight history')}\n </h3>\n <Button variant=\"outline\" size=\"sm\" onClick={() => setWeightOpen(true)}>\n <Scale className=\"h-3.5 w-3.5\" />\n {t('healthybowl.livestock.depth.detail.add', 'Add')}\n </Button>\n </div>\n {a.weightHistory.length === 0 ? (\n <p className=\"text-sm text-text-secondary\">\n {t(\n 'healthybowl.livestock.depth.detail.noWeights',\n 'No weights logged yet — record two or more to compute ADG.'\n )}\n </p>\n ) : (\n <ul className=\"space-y-2\">\n {a.weightHistory.map((w) => (\n <li key={w.id} className=\"flex items-center justify-between rounded-md bg-bg-sunken px-3 py-2 text-sm\">\n <span className=\"tabular-nums text-text-primary\">{w.weightKg} kg</span>\n <span className=\"text-text-secondary\">{formatShortDate(w.measuredAt)}</span>\n <button\n type=\"button\"\n onClick={() => void handleDeleteWeight(w.id)}\n className=\"text-xs text-text-secondary hover:text-status-error-text\"\n >\n {t('common.remove', 'Remove')}\n </button>\n </li>\n ))}\n </ul>\n )}\n </div>\n\n <div className=\"rounded-xl border border-border-subtle bg-bg-surface p-5 lg:col-span-3\">\n <h3 className=\"mb-3 flex items-center gap-2 text-sm font-semibold text-text-primary\">\n <GitBranch className=\"h-4 w-4 text-text-secondary\" />\n {t('healthybowl.livestock.depth.detail.pedigree', 'Pedigree')}\n </h3>\n <PedigreeTree pedigree={pedigree} loading={loading.pedigree} error={errors.pedigree} />\n </div>\n </div>\n\n <AnimalDepthFormModal\n open={editOpen}\n onClose={() => setEditOpen(false)}\n animal={a}\n groups={groups}\n animalOptions={animalOptions}\n onSubmit={handleEdit}\n />\n <RecordWeightModal\n open={weightOpen}\n onClose={() => setWeightOpen(false)}\n animalName={a.name}\n onSubmit={handleWeight}\n />\n </Page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thybowl/pages/livestock/AnimalDepthPage.tsx"],"sourcesContent":["/**\n * Single-animal deep record (BOFF-2890 · L-1).\n * EID/RFID, body-condition score, group, grazing/rotation, dam/sire genealogy, ADG, latest\n * weight and weight history, plus the medication-withdrawal compliance badge (reused from\n * BOFF-2885). Edit the record or log a new weight in place. No fabricated data.\n */\nimport { useMemo, useState } from 'react';\nimport { useNavigate, useParams } from 'react-router';\nimport { AlertTriangle, ArrowLeft, Pencil, Scale, TrendingUp } from 'lucide-react';\nimport { Button } from '@burdenoff/fe-libs/ui';\nimport { useI18n } from '@burdenoff/fe-libs/shared/providers/shell/I18nProvider';\nimport { PageLayout, StatusBadge, ErrorState, PageLoader, Breadcrumbs, useConfirm } from '../../components';\nimport { useToast } from '../../hooks/useToast';\nimport { useBasePath } from '../../hooks/useBasePath';\nimport { useHealthyBowlLivestockDepth } from '../../hooks/useHealthyBowlLivestockDepth';\nimport { useHealthyBowlGrazingEvents } from '../../hooks/useHealthyBowlGrazing';\nimport { AnimalDepthFormModal, type AnimalOption } from './AnimalDepthFormModal';\nimport { RecordWeightModal } from './RecordWeightModal';\nimport { formatAdg, formatBcs, formatShortDate, formatWeight, withdrawalBadgeVariant } from './depthLabels';\n\nconst DetailRow = ({ label, value }: { label: string; value: React.ReactNode }) => (\n <div className=\"flex items-center justify-between gap-4 border-b border-border-subtle py-3 last:border-0\">\n <span className=\"text-sm text-text-secondary\">{label}</span>\n <span className=\"text-end text-sm font-medium text-text-primary\">{value}</span>\n </div>\n);\n\nexport const AnimalDepthPage = () => {\n const { t } = useI18n();\n const navigate = useNavigate();\n const { buildPath } = useBasePath();\n const { toast } = useToast();\n const confirm = useConfirm();\n const { animalId } = useParams<{ animalId: string }>();\n\n const { animalDepth, herd, groups, loading, errors, refetchAnimal, updateAnimalDepth, recordWeight, deleteWeight } =\n useHealthyBowlLivestockDepth({ animalId: animalId ?? null, herd: true, groups: true });\n\n /**\n * Where this animal actually is (BOFF-5970).\n *\n * `recordHealthyBowlGrazingMove` writes a grazing EVENT and never touches the animal's legacy\n * `grazingPaddock` / `rotationDate` columns, so after any move recorded on the Grazing page those\n * two are a frozen snapshot of a previous model — and rendering them as a plain current fact made\n * this page and the Grazing page give two different answers to the same question. The event is\n * the live answer whenever one exists; the legacy pair is annotated in the VALUE, not only in its\n * label, because the label is not what a farmer reads off the row.\n */\n const {\n latest: latestGrazing,\n loading: grazingLoading,\n error: grazingError,\n } = useHealthyBowlGrazingEvents({ animalId: animalId ?? null, limit: 5 });\n\n const [editOpen, setEditOpen] = useState(false);\n const [weightOpen, setWeightOpen] = useState(false);\n\n const animalOptions = useMemo<AnimalOption[]>(\n () => (herd?.rows ?? []).map((r) => ({ animalId: r.animalId, tagNumber: r.tagNumber, name: r.name })),\n [herd]\n );\n\n if (loading.animal && !animalDepth) {\n return <PageLoader />;\n }\n if ((errors.animal && !animalDepth) || !animalDepth) {\n return (\n <PageLayout title={t('healthybowl.livestock.depth.detail.title', 'Animal Record')}>\n <ErrorState\n description={errors.animal?.message ?? t('healthybowl.livestock.depth.detail.notFound', 'Animal not found.')}\n onRetry={() => void refetchAnimal()}\n />\n </PageLayout>\n );\n }\n\n const a = animalDepth;\n const initials = a.name.slice(0, 2).toUpperCase();\n\n const handleEdit = async (input: Record<string, unknown>) => {\n await updateAnimalDepth(input);\n toast({\n title: t('healthybowl.livestock.depth.toast.updated', 'Record updated'),\n description: a.name,\n variant: 'success',\n });\n };\n\n const handleWeight = async (input: Record<string, unknown>) => {\n await recordWeight({ ...input, animalId: a.animalId });\n toast({\n title: t('healthybowl.livestock.depth.toast.weightSaved', 'Weight recorded'),\n description: `${String(input.weightKg)} kg`,\n variant: 'success',\n });\n };\n\n const handleDeleteWeight = async (id: string) => {\n if (\n !(await confirm({\n title: t('healthybowl.livestock.depth.confirm.delWeightTitle', 'Delete weight?'),\n message: t('healthybowl.livestock.depth.confirm.delWeight', 'Remove this weight measurement?'),\n }))\n ) {\n return;\n }\n try {\n await deleteWeight(id);\n toast({ title: t('healthybowl.livestock.depth.toast.weightDeleted', 'Weight removed'), variant: 'success' });\n } catch (err) {\n toast({\n title: t('healthybowl.livestock.depth.toast.error', 'Something went wrong'),\n description: err instanceof Error ? err.message : String(err),\n variant: 'error',\n });\n }\n };\n\n return (\n <PageLayout\n title={a.name}\n description={`${a.type} · ${a.tagNumber}`}\n actions={\n <div className=\"flex items-center gap-2\">\n <Button variant=\"outline\" onClick={() => setWeightOpen(true)}>\n <Scale className=\"h-4 w-4\" />\n {t('healthybowl.livestock.depth.detail.logWeight', 'Record weight')}\n </Button>\n <Button onClick={() => setEditOpen(true)}>\n <Pencil className=\"h-4 w-4\" />\n {t('healthybowl.livestock.depth.detail.edit', 'Edit')}\n </Button>\n </div>\n }\n >\n <Breadcrumbs\n items={[\n { label: t('healthybowl.livestock.depth.title', 'Livestock Records'), href: buildPath('livestock/records') },\n { label: a.name },\n ]}\n />\n\n <div className=\"mt-2\">\n <Button variant=\"ghost\" size=\"sm\" onClick={() => navigate(buildPath('livestock/records'))}>\n <ArrowLeft className=\"h-4 w-4\" />\n {t('common.back', 'Back')}\n </Button>\n </div>\n\n {a.withdrawal.blocked ? (\n <div\n role=\"alert\"\n className=\"mt-3 flex items-center gap-3 rounded-lg border border-status-error-border bg-status-error-bg px-4 py-3 text-status-error-text\"\n >\n <AlertTriangle className=\"h-5 w-5 shrink-0\" />\n <span className=\"text-sm font-semibold\">\n {t(\n 'healthybowl.livestock.depth.detail.withdrawalBanner',\n 'In medication withdrawal — Withdrawal ends {{date}} · do not sell milk or meat',\n {\n date: formatShortDate(a.withdrawal.endDate),\n }\n )}\n </span>\n </div>\n ) : null}\n\n <div className=\"mt-4 grid grid-cols-1 gap-4 lg:grid-cols-3\">\n <div className=\"rounded-xl border border-border-subtle bg-bg-surface p-5 lg:col-span-2\">\n <div className=\"mb-2 flex items-center gap-3\">\n <div className=\"flex h-14 w-14 items-center justify-center rounded-full bg-accent-teal/10 text-lg font-semibold text-accent-teal\">\n {initials}\n </div>\n <div>\n <div className=\"text-lg font-semibold text-text-primary\">{a.name}</div>\n <div className=\"text-sm text-text-secondary\">\n {a.type} #{a.tagNumber}\n </div>\n </div>\n <div className=\"ms-auto\">\n <StatusBadge\n variant={withdrawalBadgeVariant(a.withdrawal.status)}\n label={\n a.withdrawal.blocked\n ? t('healthybowl.livestock.depth.detail.inWithdrawal', 'In withdrawal')\n : t('healthybowl.livestock.depth.detail.clear', 'Clear to sell')\n }\n dot\n />\n </div>\n </div>\n\n <DetailRow label={t('healthybowl.livestock.depth.detail.eid', 'EID / RFID Tag')} value={a.eidTag ?? '—'} />\n <DetailRow\n label={t('healthybowl.livestock.depth.detail.bcs', 'Body Condition Score')}\n value={formatBcs(a.bodyConditionScore)}\n />\n <DetailRow label={t('healthybowl.livestock.depth.detail.group', 'Group')} value={a.groupName ?? '—'} />\n {/* The live answer, from the grazing event model (BOFF-5970). Error before empty: \"no\n move recorded\" is a claim about this animal and must not stand in for a failed read. */}\n <DetailRow\n label={t('healthybowl.livestock.depth.detail.grazingNow', 'Grazing — where this animal is')}\n value={\n <span className=\"inline-flex flex-col items-end gap-0.5\">\n {grazingError ? (\n <span className=\"text-status-error-text\">\n {t(\n 'healthybowl.livestock.depth.detail.grazingFailed',\n 'The grazing log could not be read — {{message}}',\n { message: grazingError.message }\n )}\n </span>\n ) : grazingLoading && !latestGrazing ? (\n <span className=\"font-normal text-text-secondary\">\n {t('healthybowl.livestock.depth.detail.grazingLoading', 'Reading the grazing log…')}\n </span>\n ) : latestGrazing ? (\n <>\n <span>{latestGrazing.paddockName}</span>\n <span className=\"text-xs font-normal text-text-secondary\">\n {latestGrazing.active\n ? t('healthybowl.livestock.depth.detail.grazingIn', 'In since {{date}}', {\n date: formatShortDate(latestGrazing.enteredAt),\n })\n : t('healthybowl.livestock.depth.detail.grazingOut', 'Left {{date}} — no paddock since', {\n date: formatShortDate(latestGrazing.exitedAt),\n })}\n </span>\n </>\n ) : (\n <span className=\"font-normal text-text-secondary\">\n {t('healthybowl.livestock.depth.detail.grazingNone', 'No move recorded in the grazing log yet.')}\n </span>\n )}\n <button\n type=\"button\"\n className=\"text-xs font-normal text-text-secondary underline hover:text-text-primary\"\n onClick={() => navigate(buildPath('livestock/grazing'))}\n >\n {t('healthybowl.livestock.depth.detail.grazingLink', 'Open grazing — moves, rest and stocking rate')}\n </button>\n </span>\n }\n />\n {/* LEGACY grazing fields (BOFF-2890). `rotationDate` is a single scalar, so writing the\n next rotation overwrote the previous one — no duration, rest period or stocking rate\n could ever be derived from it. BOFF-5970 replaced this with a grazing EVENT, and moves\n recorded there never write back here, so once an event exists this pair is a frozen\n snapshot. The VALUE says so, not just the label: the label is not what gets read off\n the row. Shown at all only when there is something in it. */}\n {a.grazingPaddock ? (\n <DetailRow\n label={t('healthybowl.livestock.depth.detail.grazing', 'Grazing / Rotation (legacy)')}\n value={\n <span className=\"inline-flex flex-col items-end gap-0.5\">\n <span className={latestGrazing ? 'font-normal text-text-secondary line-through' : undefined}>\n {`${a.grazingPaddock}${a.rotationDate ? ` (rotates ${formatShortDate(a.rotationDate)})` : ''}`}\n </span>\n <span className=\"max-w-[320px] text-xs font-normal text-text-secondary\">\n {latestGrazing\n ? t(\n 'healthybowl.livestock.depth.detail.grazingSuperseded',\n 'Recorded before the grazing log and never updated since — the row above is where this animal is now.'\n )\n : grazingError || grazingLoading\n ? t(\n 'healthybowl.livestock.depth.detail.grazingUnchecked',\n 'A single free-text paddock and one rotation date, with no time in or out. Whether the grazing log has superseded it could not be checked.'\n )\n : t(\n 'healthybowl.livestock.depth.detail.grazingOnlyRecord',\n 'A single free-text paddock and one rotation date, with no time in or out. Record a move on the Grazing page and this animal joins the history.'\n )}\n </span>\n </span>\n }\n />\n ) : null}\n <DetailRow\n label={t('healthybowl.livestock.depth.detail.genealogy', 'Genealogy — Dam · Sire')}\n value={`${a.damTag ? `Dam ${a.damTag}` : 'Dam —'} · ${a.sireTag ? `Sire ${a.sireTag}` : 'Sire —'}`}\n />\n <DetailRow\n label={t('healthybowl.livestock.depth.detail.adg', 'Average Daily Gain (ADG)')}\n value={\n <span className=\"inline-flex items-center gap-1\">\n {a.adgKgPerDay !== null ? <TrendingUp className=\"h-4 w-4 text-accent-teal\" /> : null}\n {formatAdg(a.adgKgPerDay)}\n </span>\n }\n />\n <DetailRow\n label={t('healthybowl.livestock.depth.detail.latestWeight', 'Latest Weight')}\n value={formatWeight(a.latestWeightKg, a.latestWeightAt)}\n />\n {a.grazingNotes ? (\n <DetailRow label={t('healthybowl.livestock.depth.detail.notes', 'Grazing notes')} value={a.grazingNotes} />\n ) : null}\n </div>\n\n <div className=\"rounded-xl border border-border-subtle bg-bg-surface p-5\">\n <div className=\"mb-3 flex items-center justify-between\">\n <h3 className=\"text-sm font-semibold text-text-primary\">\n {t('healthybowl.livestock.depth.detail.weightHistory', 'Weight history')}\n </h3>\n <Button variant=\"outline\" size=\"sm\" onClick={() => setWeightOpen(true)}>\n <Scale className=\"h-3.5 w-3.5\" />\n {t('healthybowl.livestock.depth.detail.add', 'Add')}\n </Button>\n </div>\n {a.weightHistory.length === 0 ? (\n <p className=\"text-sm text-text-secondary\">\n {t(\n 'healthybowl.livestock.depth.detail.noWeights',\n 'No weights logged yet — record two or more to compute ADG.'\n )}\n </p>\n ) : (\n <ul className=\"space-y-2\">\n {a.weightHistory.map((w) => (\n <li key={w.id} className=\"flex items-center justify-between rounded-md bg-bg-sunken px-3 py-2 text-sm\">\n <span className=\"tabular-nums text-text-primary\">{w.weightKg} kg</span>\n <span className=\"text-text-secondary\">{formatShortDate(w.measuredAt)}</span>\n <button\n type=\"button\"\n onClick={() => void handleDeleteWeight(w.id)}\n className=\"text-xs text-text-secondary hover:text-status-error-text\"\n >\n {t('common.remove', 'Remove')}\n </button>\n </li>\n ))}\n </ul>\n )}\n </div>\n </div>\n\n <AnimalDepthFormModal\n open={editOpen}\n onClose={() => setEditOpen(false)}\n animal={a}\n groups={groups}\n animalOptions={animalOptions}\n onSubmit={handleEdit}\n />\n <RecordWeightModal\n open={weightOpen}\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KAAS;;QACtE,kBAAC,QAAD;SAAM,WAAU;mBAAuB,EAAgB,EAAE,UAAU;QAAQ,CAAA;QAC3E,kBAAC,UAAD;SACE,MAAK;SACL,eAAe,KAAK,GAAmB,EAAE,EAAE;SAC3C,WAAU;mBAET,EAAE,iBAAiB,QAAQ;QACtB,CAAA;OACN;SAVK,EAAE,EAUP,CACL;KACC,CAAA,CAEH;MACF;;GAEL,kBAAC,GAAD;IACE,MAAM;IACN,eAAe,EAAY,EAAK;IAChC,QAAQ;IACA;IACO;IACf,UAAU;GACX,CAAA;GACD,kBAAC,GAAD;IACE,MAAM;IACN,eAAe,EAAc,EAAK;IAClC,YAAY,EAAE;IACd,UAAU;GACX,CAAA;EACS;;AAEhB"}
|
|
@@ -472,7 +472,6 @@ var xe = 300, y = "rounded-md border border-border-subtle bg-bg-surface px-3 py-
|
|
|
472
472
|
animals: Ne,
|
|
473
473
|
groupsState: Pe,
|
|
474
474
|
animalsState: Fe,
|
|
475
|
-
animalsTruncated: K?.truncated ?? !1,
|
|
476
475
|
animalSearch: L,
|
|
477
476
|
onAnimalSearchChange: R,
|
|
478
477
|
defaultPaddockId: E,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GrazingPage.js","names":[],"sources":["../../../../src/healthybowl/pages/livestock/GrazingPage.tsx"],"sourcesContent":["/**\n * Grazing management page (BOFF-5970).\n *\n * The backend for this shipped with no frontend at all, and the only grazing surface in the app was\n * the animal deep record's legacy `grazingPaddock` + `rotationDate` pair — one free-text name and\n * ONE scalar date, so recording the next rotation overwrote the previous one and grazing history\n * was destroyed on every move. This page consumes the event model that replaced it: a move has an\n * entry and an exit, duration is derived from those two timestamps on every read, and rest and\n * stocking rate follow from them.\n *\n * Deliberate choices:\n * - **No chart.** The grazing decision is \"which paddock next\", which is a comparison across four\n * states and two clocks, not a trend. A distribution chart of four counts would occupy the space\n * the rest bars and the coverage caveats need to do actual work; the state tiles carry the same\n * four numbers in less room. The turnover chart lives on the herd-statistics card, where a time\n * series is genuinely what the data is.\n * - **NEVER_GRAZED is styled as its own state, not as READY.** An ungrazed paddock is *unmeasured*,\n * not *recovered*. The tiles, the badges and the one-line meanings in `utils/grazing.ts` keep\n * them apart, because collapsing them is what would let unmeasured ground pass for observed\n * recovery and send a herd onto it.\n * - **Every nullable metric renders through `optionalMetric`.** `animalUnits: null` means nobody in\n * the mob has been weighed; rendered as 0 it would claim an empty paddock. Same for\n * `stockingRateAuPerHa`, `totalHectares` and `areaHectares` — and where the backend can explain\n * the null (an area unit with no defined size, an unweighed mob), the explanation is shown\n * instead of a blank.\n * - **`animalsWithoutWeight` sits against the stocking rate it qualifies.** A rate computed from 3\n * of 12 weighed animals and one computed from 12 of 12 are the same number on screen and are not\n * the same claim.\n * - **`restDaysIsDefault` is labelled.** A workspace default is not a decision about this paddock.\n * - **`truncated` gets an action, not just a notice** — a partial paddock list under-reports\n * occupancy with no other sign that it is wrong. The date range that narrows it is a control on\n * this page, and the notice names only remedies the page actually offers: naming one it does not\n * is worse than naming none, because it reads as user error.\n * - **An imported occupancy is badged wherever it is shown as current.** A `MIGRATED_LEGACY` event\n * was reconstructed from the legacy columns with `exited_at = NULL` because no exit was ever\n * recorded — not because a mob is standing there. Badging it only in the move list while the\n * paddock table showed it as an observed mob made the page contradict itself twenty lines apart.\n * - **Only columns backed by a real field are sortable.** `DataTable` sorts by `row[col.key]`, so a\n * render-only key gives a header with an active chevron that does nothing at all. `comparePaddocks`\n * stays the default order — it ranks by what needs a decision, which no column sort reproduces.\n * - **Error state precedes the empty state.** \"No paddocks yet\" is a statement about the farm and\n * must never be shown when the truth is \"the query failed\".\n */\n\nimport { useEffect, useMemo, useState, type FC } from 'react';\nimport { useNavigate } from 'react-router';\nimport { ArrowRight, Fence, LogOut, Plus, Timer } from 'lucide-react';\nimport { Button } from '@burdenoff/fe-libs/ui';\nimport { useI18n } from '@burdenoff/fe-libs/shared/providers/shell/I18nProvider';\nimport { DataTable, EmptyState, ErrorState, PageLayout, PageLoader, StatCard, StatusBadge } from '../../components';\nimport type { Column } from '../../components';\nimport { ToastContainer } from '../../components/Toast';\nimport { useToast } from '../../hooks/useToast';\nimport { useBasePath } from '../../hooks/useBasePath';\nimport { formatDate } from '../../utils/helpers';\nimport { NOT_MEASURED, optionalMetric } from '../../utils/optionalMetric';\nimport {\n PADDOCK_STATES,\n comparePaddocks,\n grazingWindow,\n importedMoveNote,\n isImportedMove,\n paddockStateOption,\n restProgressPct,\n restTargetSource,\n weighedCoverage,\n} from '../../utils/grazing';\nimport {\n useHealthyBowlGrazing,\n type GrazingEvent,\n type PaddockGrazing,\n type RecordGrazingMoveInput,\n type EndGrazingMoveInput,\n type SetPaddockRestInput,\n} from '../../hooks/useHealthyBowlGrazing';\nimport { useHealthyBowlLivestockDepth } from '../../hooks/useHealthyBowlLivestockDepth';\nimport { RecordGrazingMoveModal } from './grazing/RecordGrazingMoveModal';\nimport { EndGrazingMoveModal } from './grazing/EndGrazingMoveModal';\nimport { SetPaddockRestModal } from './grazing/SetPaddockRestModal';\n\n/** Typing a tag should not fire a herd read per keystroke; the server does the filtering. */\nconst ANIMAL_SEARCH_DEBOUNCE_MS = 300;\n\nconst dateControl =\n 'rounded-md border border-border-subtle bg-bg-surface px-3 py-1.5 text-sm text-text-primary focus:outline-none focus:ring-2 focus:ring-[var(--color-focus-ring)]';\n\n/** Badge tone per state, kept in the vocabulary module so the UI cannot invent a fifth meaning. */\nconst TONE_TO_BADGE = {\n info: 'info',\n warning: 'warning',\n success: 'success',\n muted: 'muted',\n} as const;\n\nexport const GrazingPage: FC = () => {\n const { t } = useI18n();\n const navigate = useNavigate();\n const { buildPath } = useBasePath();\n const { toasts, toast, dismiss } = useToast();\n\n const [moveOpen, setMoveOpen] = useState(false);\n const [movePaddockId, setMovePaddockId] = useState<string | null>(null);\n const [endTarget, setEndTarget] = useState<PaddockGrazing | null>(null);\n const [restTarget, setRestTarget] = useState<PaddockGrazing | null>(null);\n\n // The window the `truncated` notice tells the farmer to narrow. `from`/`to` are the query\n // arguments the hook already accepts; without controls behind them the notice named a remedy\n // nobody could perform.\n const [from, setFrom] = useState('');\n const [to, setTo] = useState('');\n const window_ = useMemo(() => grazingWindow(from, to), [from, to]);\n\n // `animalSearch` drives the input; `debouncedAnimalSearch` drives the herd read, which filters\n // on tag / name / EID server-side.\n const [animalSearch, setAnimalSearch] = useState('');\n const [debouncedAnimalSearch, setDebouncedAnimalSearch] = useState('');\n useEffect(() => {\n const id = globalThis.setTimeout(() => setDebouncedAnimalSearch(animalSearch), ANIMAL_SEARCH_DEBOUNCE_MS);\n return () => globalThis.clearTimeout(id);\n }, [animalSearch]);\n\n const {\n paddocks,\n recentMoves,\n summary,\n truncated,\n unmigratedLegacyAnimals,\n loading,\n error,\n refetch,\n recordMove,\n endMove,\n setPaddockRest,\n // An inverted range resolves to nulls rather than being sent: the service silently replaces an\n // empty window with its own default, so issuing it would look like a filter that does nothing.\n // The page says so instead — see the notice under the controls.\n } = useHealthyBowlGrazing({ from: window_.from, to: window_.to });\n\n /**\n * Both mob sources come from the herd-depth read.\n *\n * The animal list used to be `useHealthyBowlData().animals`, which the service caps at the 200\n * OLDEST rows (`take: DEFAULT_LIST_LIMIT`, `orderBy: createdAt asc`). Past 200 head the newest\n * animals were unreachable AND the picker asserted they did not exist. `healthyBowlHerdDepth`\n * reads by tag number and takes the search server-side; the herd half is fetched only while the\n * modal is open, because it is a far heavier read than a picker warrants on page load.\n */\n const {\n herd,\n groups,\n loading: depthLoading,\n errors: depthErrors,\n } = useHealthyBowlLivestockDepth({\n groups: true,\n herd: moveOpen,\n herdSearch: debouncedAnimalSearch.trim() || null,\n });\n\n const sortedPaddocks = useMemo(() => [...paddocks].sort(comparePaddocks), [paddocks]);\n\n const paddockOptions = useMemo(\n () => sortedPaddocks.map((p) => ({ paddockId: p.paddockId, name: p.name, state: p.state })),\n [sortedPaddocks]\n );\n const groupOptions = useMemo(\n () => groups.map((g) => ({ id: g.id, name: g.name, animalCount: g.animalCount })),\n [groups]\n );\n const animalOptions = useMemo(\n () => (herd?.rows ?? []).map((r) => ({ id: r.animalId, tagNumber: r.tagNumber, name: r.name })),\n [herd]\n );\n const groupsState = useMemo(\n () => ({ loading: depthLoading.groups, error: depthErrors.groups }),\n [depthLoading.groups, depthErrors.groups]\n );\n const animalsState = useMemo(\n () => ({ loading: depthLoading.herd, error: depthErrors.herd }),\n [depthLoading.herd, depthErrors.herd]\n );\n\n const openMoveFor = (paddockId: string | null) => {\n setMovePaddockId(paddockId);\n setAnimalSearch('');\n setDebouncedAnimalSearch('');\n setMoveOpen(true);\n };\n\n const handleRecordMove = async (input: RecordGrazingMoveInput) => {\n const event = await recordMove(input);\n toast({\n title: t('healthybowl.livestock.grazing.toast.moved', 'Grazing move recorded'),\n description: event\n ? t('healthybowl.livestock.grazing.toast.movedDesc', '{{n}} animal(s) onto {{paddock}}.', {\n n: String(event.headCount),\n paddock: event.paddockName,\n })\n : undefined,\n variant: 'success',\n });\n };\n\n const handleEndMove = async (input: EndGrazingMoveInput) => {\n const event = await endMove(input);\n toast({\n title: t('healthybowl.livestock.grazing.toast.ended', 'Exit recorded — the rest clock has started'),\n description: event\n ? t('healthybowl.livestock.grazing.toast.endedDesc', '{{paddock}} · {{days}} days grazed.', {\n paddock: event.paddockName,\n days: optionalMetric(event.durationDays, { decimals: 1 }),\n })\n : undefined,\n variant: 'success',\n });\n };\n\n const handleSetRest = async (input: SetPaddockRestInput) => {\n const updated = await setPaddockRest(input);\n toast({\n title:\n input.restDays === null\n ? t(\n 'healthybowl.livestock.grazing.toast.restCleared',\n 'Rest target cleared — following the workspace default'\n )\n : t('healthybowl.livestock.grazing.toast.restSet', 'Rest target updated'),\n description: updated\n ? t('healthybowl.livestock.grazing.toast.restDesc', '{{paddock}} now rests {{days}} days.', {\n paddock: updated.name,\n days: String(updated.restDays),\n })\n : undefined,\n variant: 'success',\n });\n };\n\n const mobLabel = (event: GrazingEvent | null): string => {\n if (!event) return NOT_MEASURED;\n if (event.groupName) return `${event.groupName} (${event.headCount})`;\n return t('healthybowl.livestock.grazing.table.adHocMob', '{{n}} animal(s)', { n: String(event.headCount) });\n };\n\n const imported = importedMoveNote();\n\n /**\n * `DataTable` sorts by `row[col.key]` and treats every column as sortable unless told otherwise,\n * so a key that is not a field on `PaddockGrazing` yields a header with a live sort chevron and\n * no effect. Content columns are keyed to the real field they show; the ones assembled from\n * several fields say `sortable: false` rather than pretending.\n *\n * `state` is deliberately NOT sortable: it is a real field, but sorting it is alphabetical, and\n * alphabetical order discards `comparePaddocks` — which ranks paddocks by what the grazier can\n * act on first (a mob to move off, then ground to move it onto).\n */\n const columns: Column<PaddockGrazing>[] = [\n {\n key: 'name',\n header: t('healthybowl.livestock.grazing.table.paddock', 'Paddock'),\n render: (p) => (\n <div>\n <div className=\"font-medium text-text-primary\">{p.name}</div>\n <div className=\"text-xs text-text-secondary\">\n {p.areaHectares === null\n ? t(\n 'healthybowl.livestock.grazing.table.areaUnconvertible',\n '{{area}} {{unit}} — no defined size in ha',\n {\n area: optionalMetric(p.area),\n unit: p.areaUnit,\n }\n )\n : t('healthybowl.livestock.grazing.table.area', '{{ha}} ha', {\n ha: optionalMetric(p.areaHectares, { decimals: 2 }),\n })}\n </div>\n </div>\n ),\n },\n {\n key: 'state',\n sortable: false,\n header: t('healthybowl.livestock.grazing.table.state', 'State'),\n render: (p) => {\n const option = paddockStateOption(p.state);\n const isImported = p.current !== null && isImportedMove(p.current.source);\n return (\n <div>\n <div className=\"flex flex-wrap items-center gap-1\">\n <StatusBadge\n variant={TONE_TO_BADGE[option.tone]}\n label={t(option.label.key, option.label.defaultValue)}\n dot\n />\n {/* The same badge the Recent moves list gives this row. Occupancy reconstructed by\n the backfill is not occupancy anybody observed. */}\n {isImported && (\n <StatusBadge variant=\"muted\" label={t('healthybowl.livestock.grazing.moves.imported', 'Imported')} />\n )}\n </div>\n <div className=\"mt-1 max-w-[220px] text-xs text-text-secondary\">\n {t(option.meaning.key, option.meaning.defaultValue)}\n </div>\n {isImported && (\n <div className=\"mt-1 max-w-[220px] text-xs text-text-secondary\">\n {t(imported.key, imported.defaultValue)}\n </div>\n )}\n </div>\n );\n },\n },\n {\n key: 'mob',\n sortable: false,\n header: t('healthybowl.livestock.grazing.table.mob', 'On it now'),\n render: (p) =>\n p.current ? (\n <div>\n <div className=\"text-text-primary\">{mobLabel(p.current)}</div>\n <div className=\"text-xs text-text-secondary\">\n {isImportedMove(p.current.source)\n ? t('healthybowl.livestock.grazing.table.daysInImported', '{{days}} days since the imported date', {\n days: optionalMetric(p.daysIn, { decimals: 1 }),\n })\n : t('healthybowl.livestock.grazing.table.daysIn', '{{days}} days in', {\n days: optionalMetric(p.daysIn, { decimals: 1 }),\n })}\n </div>\n </div>\n ) : (\n <span className=\"text-text-secondary\">{NOT_MEASURED}</span>\n ),\n },\n {\n key: 'daysRested',\n header: t('healthybowl.livestock.grazing.table.rest', 'Rest'),\n render: (p) => {\n const progress = restProgressPct(p.daysRested, p.restDays);\n const source = restTargetSource(p.restDaysIsDefault);\n return (\n <div className=\"min-w-[150px]\">\n <div className=\"text-text-primary\">\n {p.daysRested === null\n ? t('healthybowl.livestock.grazing.table.restNotRunning', 'Not resting')\n : t('healthybowl.livestock.grazing.table.restedOf', '{{rested}} of {{target}} days', {\n rested: optionalMetric(p.daysRested, { decimals: 1 }),\n target: String(p.restDays),\n })}\n </div>\n {/* No bar at all when there is nothing to measure — an empty bar reads as 0% rested. */}\n {progress !== null && (\n <div className=\"mt-1 h-1.5 w-full rounded-full bg-bg-sunken\">\n <div className=\"h-1.5 rounded-full bg-action-primary-bg\" style={{ width: `${progress}%` }} />\n </div>\n )}\n <div className=\"mt-1 text-xs text-text-secondary\">{t(source.key, source.defaultValue)}</div>\n {p.readyAt && (\n <div className=\"text-xs text-text-secondary\">\n {t('healthybowl.livestock.grazing.table.readyAt', 'Ready {{date}}', { date: formatDate(p.readyAt) })}\n </div>\n )}\n </div>\n );\n },\n },\n {\n key: 'stockingRateAuPerHa',\n header: t('healthybowl.livestock.grazing.table.stocking', 'Stocking'),\n render: (p) => {\n const coverage = weighedCoverage(p.current?.headCount ?? 0, p.animalsWithoutWeight);\n return (\n <div className=\"min-w-[150px]\">\n <div className=\"tabular-nums text-text-primary\">\n {optionalMetric(p.stockingRateAuPerHa, { decimals: 2, unit: ' AU/ha' })}\n </div>\n <div className=\"text-xs tabular-nums text-text-secondary\">\n {optionalMetric(p.animalUnits, { decimals: 2, unit: ' AU' })}\n </div>\n {/* The coverage gap behind `animalUnits` — without it a rate from 3 of 12 weighed\n animals reads exactly like one from 12 of 12. */}\n {coverage.hasMob && (\n <div className=\"text-xs text-text-secondary\">\n {coverage.complete\n ? t('healthybowl.livestock.grazing.table.allWeighed', 'all {{total}} weighed', {\n total: String(coverage.total),\n })\n : t('healthybowl.livestock.grazing.table.someWeighed', '{{weighed}} of {{total}} weighed', {\n weighed: String(coverage.weighed),\n total: String(coverage.total),\n })}\n </div>\n )}\n </div>\n );\n },\n },\n {\n key: 'actions',\n sortable: false,\n header: t('healthybowl.livestock.grazing.table.actions', 'Actions'),\n render: (p) => (\n <div className=\"flex flex-wrap gap-1\">\n {p.current ? (\n <Button variant=\"outline\" size=\"sm\" onClick={() => setEndTarget(p)}>\n <LogOut className=\"h-3.5 w-3.5\" />\n {t('healthybowl.livestock.grazing.actions.end', 'End move')}\n </Button>\n ) : (\n <Button variant=\"outline\" size=\"sm\" onClick={() => openMoveFor(p.paddockId)}>\n <ArrowRight className=\"h-3.5 w-3.5\" />\n {t('healthybowl.livestock.grazing.actions.moveIn', 'Move a mob in')}\n </Button>\n )}\n <Button variant=\"ghost\" size=\"sm\" onClick={() => setRestTarget(p)}>\n <Timer className=\"h-3.5 w-3.5\" />\n {t('healthybowl.livestock.grazing.actions.rest', 'Rest target')}\n </Button>\n </div>\n ),\n },\n ];\n\n if (loading && paddocks.length === 0 && !error) {\n return <PageLoader />;\n }\n\n const stateTiles = PADDOCK_STATES.map((state) => {\n const option = paddockStateOption(state);\n const value =\n state === 'OCCUPIED'\n ? (summary?.occupied ?? 0)\n : state === 'RESTING'\n ? (summary?.resting ?? 0)\n : state === 'READY'\n ? (summary?.ready ?? 0)\n : (summary?.neverGrazed ?? 0);\n return { state, option, value };\n });\n\n return (\n <PageLayout\n title={t('healthybowl.livestock.grazing.title', 'Grazing')}\n description={t(\n 'healthybowl.livestock.grazing.description',\n 'Which mob is on which paddock, how long the ground has rested, and how heavily it is stocked.'\n )}\n purpose=\"Rotational grazing, recorded as moves rather than as a single date. Every move has a time in and a time out, so duration, rest period and stocking rate are all derived from what actually happened — and past rotations are never overwritten by the next one.\"\n actions={\n <Button onClick={() => openMoveFor(null)}>\n <Plus className=\"h-4 w-4\" />\n {t('healthybowl.livestock.grazing.actions.record', 'Record a move')}\n </Button>\n }\n >\n {/* Error BEFORE empty: a failed query must never render as \"no paddocks yet\". */}\n {error && paddocks.length === 0 ? (\n <ErrorState\n title={t('healthybowl.livestock.grazing.error.title', 'Could not load grazing')}\n description={error.message}\n onRetry={() => void refetch()}\n />\n ) : (\n <>\n {/* Data on screen, but the last refresh failed. Silently serving the stale list would let\n a mob that has already been moved keep reading as standing on a paddock. */}\n {error && (\n <div className=\"mt-4 flex flex-wrap items-center justify-between gap-2 rounded-lg border border-status-error-border bg-status-error-bg px-4 py-3 text-sm text-status-error-text\">\n <span>\n {t(\n 'healthybowl.livestock.grazing.error.stale',\n 'The last refresh failed, so what you see below may be out of date: {{message}}',\n { message: error.message }\n )}\n </span>\n <Button variant=\"outline\" size=\"sm\" onClick={() => void refetch()}>\n {t('healthybowl.livestock.grazing.error.retry', 'Try again')}\n </Button>\n </div>\n )}\n\n {/* The window the truncation notice points at. `from`/`to` are query arguments, so this is\n wiring rather than client-side filtering — narrowing them makes the service read fewer\n move rows. Rest state is computed from a paddock's whole history and is NOT windowed,\n so narrowing here cannot make a paddock look ungrazed. */}\n <div className=\"mt-4 flex flex-wrap items-end gap-3 rounded-lg border border-border-subtle bg-bg-surface px-4 py-3\">\n <div>\n <label className=\"mb-1 block text-xs font-medium text-text-primary\" htmlFor=\"grazing-from\">\n {t('healthybowl.livestock.grazing.window.from', 'Moves from')}\n </label>\n <input\n id=\"grazing-from\"\n type=\"date\"\n value={from}\n onChange={(e) => setFrom(e.target.value)}\n className={dateControl}\n />\n </div>\n <div>\n <label className=\"mb-1 block text-xs font-medium text-text-primary\" htmlFor=\"grazing-to\">\n {t('healthybowl.livestock.grazing.window.to', 'Moves to')}\n </label>\n <input\n id=\"grazing-to\"\n type=\"date\"\n value={to}\n onChange={(e) => setTo(e.target.value)}\n className={dateControl}\n />\n </div>\n {(from || to) && (\n <Button\n variant=\"ghost\"\n size=\"sm\"\n onClick={() => {\n setFrom('');\n setTo('');\n }}\n >\n {t('healthybowl.livestock.grazing.window.clear', 'Clear')}\n </Button>\n )}\n <p className=\"basis-full text-xs text-text-secondary\">\n {summary?.windowFrom && summary.windowTo\n ? t(\n 'healthybowl.livestock.grazing.window.applied',\n 'Moves shown: {{from}} to {{to}}. Rest and occupancy are read from each paddock’s whole history, not from this window.',\n { from: formatDate(summary.windowFrom), to: formatDate(summary.windowTo) }\n )\n : t(\n 'healthybowl.livestock.grazing.window.default',\n 'Leave both blank for the service’s default window. Rest and occupancy are read from each paddock’s whole history, not from this window.'\n )}\n </p>\n {!window_.valid && (\n <p className=\"basis-full text-xs text-status-error-text\">\n {t(\n 'healthybowl.livestock.grazing.window.inverted',\n 'The end date is before the start date, so this range has not been applied — the default window is shown instead.'\n )}\n </p>\n )}\n </div>\n\n {truncated && (\n <div className=\"mt-4 rounded-lg border border-status-warning-border bg-status-warning-bg px-4 py-3 text-sm text-status-warning-text\">\n {t(\n 'healthybowl.livestock.grazing.truncated',\n 'This farm has more paddocks or moves than one view can load, so the list below is incomplete and under-reports occupancy. Narrowing the date range above loads fewer moves; if this notice stays, the paddock list itself is at its limit and everything below covers only part of the farm.'\n )}\n </div>\n )}\n\n {unmigratedLegacyAnimals > 0 && (\n <div className=\"mt-4 rounded-lg border border-border-subtle bg-bg-sunken/50 px-4 py-3 text-sm text-text-secondary\">\n {t(\n 'healthybowl.livestock.grazing.unmigrated',\n '{{n}} animal(s) still carry a legacy grazing paddock with no rotation date. An entry with no time cannot become a move — record their next move here and they join the history.',\n { n: String(unmigratedLegacyAnimals) }\n )}\n <Button\n variant=\"ghost\"\n size=\"sm\"\n className=\"ms-2\"\n onClick={() => navigate(buildPath('livestock/records'))}\n >\n {t('healthybowl.livestock.grazing.unmigrated.action', 'Open herd records')}\n </Button>\n </div>\n )}\n\n {/* Paddocks by state. Four counts, four meanings — NEVER_GRAZED is never folded into READY. */}\n <div className=\"mt-4 grid grid-cols-2 gap-3 lg:grid-cols-4\">\n {stateTiles.map(({ state, option, value }) => (\n <div key={state} className=\"rounded-lg border border-border-subtle bg-bg-surface p-3\">\n <div className=\"flex items-center justify-between gap-2\">\n <StatusBadge\n variant={TONE_TO_BADGE[option.tone]}\n label={t(option.label.key, option.label.defaultValue)}\n dot\n />\n <span className=\"text-xl font-bold tabular-nums text-text-primary\">{value}</span>\n </div>\n <p className=\"mt-1 text-xs text-text-secondary\">{t(option.meaning.key, option.meaning.defaultValue)}</p>\n </div>\n ))}\n </div>\n\n {/* Herd-wide roll-up. Every one of these can legitimately be null. */}\n <div className=\"mt-4 grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-4\">\n <StatCard\n label={t('healthybowl.livestock.grazing.stats.paddocks', 'Paddocks')}\n value={summary?.paddocks ?? 0}\n icon={<Fence className=\"h-4 w-4\" />}\n />\n <StatCard\n label={t('healthybowl.livestock.grazing.stats.animalUnits', 'Animal units grazing')}\n value={optionalMetric(summary?.totalAnimalUnits ?? null, { decimals: 2 })}\n />\n <StatCard\n label={t('healthybowl.livestock.grazing.stats.hectares', 'Hectares under grazing')}\n value={optionalMetric(summary?.totalHectares ?? null, { decimals: 2 })}\n />\n <StatCard\n hero\n label={t('healthybowl.livestock.grazing.stats.stockingRate', 'Herd stocking rate')}\n value={optionalMetric(summary?.stockingRateAuPerHa ?? null, { decimals: 2, unit: ' AU/ha' })}\n />\n </div>\n\n {summary && (\n <p className=\"mt-2 text-xs text-text-secondary\">\n {t(\n 'healthybowl.livestock.grazing.stats.basis',\n 'One animal unit is {{kg}} kg of liveweight. Paddocks that do not set their own target rest {{days}} days.',\n { kg: String(summary.kgPerAnimalUnit), days: String(summary.defaultRestDays) }\n )}\n {summary.totalHectares === null && summary.occupied > 0\n ? ` ${t(\n 'healthybowl.livestock.grazing.stats.hectaresNull',\n 'Hectares under grazing is unavailable because at least one occupied paddock records its area in a unit with no defined size — a short denominator would overstate the stocking rate.'\n )}`\n : ''}\n {summary.totalAnimalUnits === null && summary.occupied > 0\n ? ` ${t(\n 'healthybowl.livestock.grazing.stats.unitsNull',\n 'Animal units are unavailable because none of the grazing mob has a weight record.'\n )}`\n : ''}\n </p>\n )}\n\n <div className=\"mt-6\">\n <h2 className=\"mb-3 text-lg font-semibold text-text-primary\">\n {t('healthybowl.livestock.grazing.paddocks.title', 'Paddocks')}\n </h2>\n {sortedPaddocks.length === 0 ? (\n <EmptyState\n illustration=\"empty-generic\"\n title={t('healthybowl.livestock.grazing.paddocks.empty.title', 'No paddocks yet')}\n description={t(\n 'healthybowl.livestock.grazing.paddocks.empty.description',\n 'A paddock is a field whose grow location is \"Pasture\". Create one on the Fields page, or record a move onto any field and it appears here.'\n )}\n />\n ) : (\n <DataTable\n columns={columns}\n data={sortedPaddocks}\n keyField=\"paddockId\"\n pageSize={20}\n emptyMessage={t('healthybowl.livestock.grazing.paddocks.none', 'No paddocks match.')}\n />\n )}\n </div>\n\n <div className=\"mt-6\">\n <h2 className=\"mb-3 text-lg font-semibold text-text-primary\">\n {t('healthybowl.livestock.grazing.moves.title', 'Recent moves')}\n </h2>\n {recentMoves.length === 0 ? (\n <p className=\"rounded-lg border border-border-subtle bg-bg-surface px-4 py-6 text-center text-sm text-text-secondary\">\n {t(\n 'healthybowl.livestock.grazing.moves.empty',\n 'No moves recorded in this period. Record one and the duration, rest period and stocking rate all follow from it.'\n )}\n </p>\n ) : (\n <div className=\"flex flex-col gap-2\">\n {recentMoves.map((move) => (\n <div\n key={move.id}\n className=\"flex flex-wrap items-center justify-between gap-2 rounded-md border border-border-subtle bg-bg-surface p-3\"\n >\n <div>\n <p className=\"text-sm font-medium text-text-primary\">\n {mobLabel(move)} → {move.paddockName}\n </p>\n <p className=\"text-xs text-text-secondary\">\n {t('healthybowl.livestock.grazing.moves.window', 'In {{in}} · Out {{out}}', {\n in: formatDate(move.enteredAt),\n out: move.exitedAt\n ? formatDate(move.exitedAt)\n : t('healthybowl.livestock.grazing.moves.stillIn', 'still in'),\n })}\n </p>\n {isImportedMove(move.source) && (\n <p className=\"mt-1 max-w-prose text-xs text-text-secondary\">\n {t(imported.key, imported.defaultValue)}\n </p>\n )}\n {move.notes ? <p className=\"mt-1 text-xs text-text-secondary\">{move.notes}</p> : null}\n </div>\n <div className=\"flex items-center gap-2\">\n {/* Reconstructed legacy rows are labelled as imported, never as observed. */}\n {isImportedMove(move.source) && (\n <StatusBadge\n variant=\"muted\"\n label={t('healthybowl.livestock.grazing.moves.imported', 'Imported')}\n />\n )}\n <span className=\"text-xs tabular-nums text-text-secondary\">\n {t('healthybowl.livestock.grazing.moves.duration', '{{days}} days', {\n days: optionalMetric(move.durationDays, { decimals: 1 }),\n })}\n </span>\n {move.active && (\n <StatusBadge\n variant=\"info\"\n label={t('healthybowl.livestock.grazing.moves.active', 'Open')}\n dot\n />\n )}\n </div>\n </div>\n ))}\n </div>\n )}\n </div>\n </>\n )}\n\n <RecordGrazingMoveModal\n open={moveOpen}\n onClose={() => setMoveOpen(false)}\n paddocks={paddockOptions}\n groups={groupOptions}\n animals={animalOptions}\n groupsState={groupsState}\n animalsState={animalsState}\n animalsTruncated={herd?.truncated ?? false}\n animalSearch={animalSearch}\n onAnimalSearchChange={setAnimalSearch}\n defaultPaddockId={movePaddockId}\n onSubmit={handleRecordMove}\n />\n\n <EndGrazingMoveModal\n open={endTarget !== null}\n onClose={() => setEndTarget(null)}\n event={endTarget?.current ?? null}\n paddockName={endTarget?.name ?? ''}\n onSubmit={handleEndMove}\n />\n\n <SetPaddockRestModal\n open={restTarget !== null}\n onClose={() => setRestTarget(null)}\n paddock={restTarget}\n defaultRestDays={summary?.defaultRestDays ?? 21}\n onSubmit={handleSetRest}\n />\n\n <ToastContainer toasts={toasts} onDismiss={dismiss} />\n </PageLayout>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAiFA,IAAM,KAA4B,KAE5B,IACJ,mKAGI,IAAgB;CACpB,MAAM;CACN,SAAS;CACT,SAAS;CACT,OAAO;AACT,GAEa,UAAwB;CACnC,IAAM,EAAE,SAAM,GAAQ,GAChB,KAAW,GAAY,GACvB,EAAE,kBAAc,EAAY,GAC5B,EAAE,YAAQ,UAAO,eAAY,GAAS,GAEtC,CAAC,GAAU,KAAe,EAAS,EAAK,GACxC,CAAC,GAAe,KAAoB,EAAwB,IAAI,GAChE,CAAC,GAAW,KAAgB,EAAgC,IAAI,GAChE,CAAC,GAAY,KAAiB,EAAgC,IAAI,GAKlE,CAAC,GAAM,KAAW,EAAS,EAAE,GAC7B,CAAC,GAAI,KAAS,EAAS,EAAE,GACzB,IAAU,QAAc,EAAc,GAAM,CAAE,GAAG,CAAC,GAAM,CAAE,CAAC,GAI3D,CAAC,GAAc,KAAmB,EAAS,EAAE,GAC7C,CAAC,IAAuB,KAA4B,EAAS,EAAE;CACrE,SAAgB;EACd,IAAM,IAAK,WAAW,iBAAiB,EAAyB,CAAY,GAAG,EAAyB;EACxG,aAAa,WAAW,aAAa,CAAE;CACzC,GAAG,CAAC,CAAY,CAAC;CAEjB,IAAM,EACJ,aACA,gBACA,YACA,eACA,4BACA,aACA,UACA,YACA,gBACA,aACA,uBAIE,GAAsB;EAAE,MAAM,EAAQ;EAAM,IAAI,EAAQ;CAAG,CAAC,GAW1D,EACJ,SACA,WACA,SAAS,GACT,QAAQ,MACN,GAA6B;EAC/B,QAAQ;EACR,MAAM;EACN,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ock/GrazingPage.tsx"],"sourcesContent":["/**\n * Grazing management page (BOFF-5970).\n *\n * The backend for this shipped with no frontend at all, and the only grazing surface in the app was\n * the animal deep record's legacy `grazingPaddock` + `rotationDate` pair — one free-text name and\n * ONE scalar date, so recording the next rotation overwrote the previous one and grazing history\n * was destroyed on every move. This page consumes the event model that replaced it: a move has an\n * entry and an exit, duration is derived from those two timestamps on every read, and rest and\n * stocking rate follow from them.\n *\n * Deliberate choices:\n * - **No chart.** The grazing decision is \"which paddock next\", which is a comparison across four\n * states and two clocks, not a trend. A distribution chart of four counts would occupy the space\n * the rest bars and the coverage caveats need to do actual work; the state tiles carry the same\n * four numbers in less room. The turnover chart lives on the herd-statistics card, where a time\n * series is genuinely what the data is.\n * - **NEVER_GRAZED is styled as its own state, not as READY.** An ungrazed paddock is *unmeasured*,\n * not *recovered*. The tiles, the badges and the one-line meanings in `utils/grazing.ts` keep\n * them apart, because collapsing them is what would let unmeasured ground pass for observed\n * recovery and send a herd onto it.\n * - **Every nullable metric renders through `optionalMetric`.** `animalUnits: null` means nobody in\n * the mob has been weighed; rendered as 0 it would claim an empty paddock. Same for\n * `stockingRateAuPerHa`, `totalHectares` and `areaHectares` — and where the backend can explain\n * the null (an area unit with no defined size, an unweighed mob), the explanation is shown\n * instead of a blank.\n * - **`animalsWithoutWeight` sits against the stocking rate it qualifies.** A rate computed from 3\n * of 12 weighed animals and one computed from 12 of 12 are the same number on screen and are not\n * the same claim.\n * - **`restDaysIsDefault` is labelled.** A workspace default is not a decision about this paddock.\n * - **`truncated` gets an action, not just a notice** — a partial paddock list under-reports\n * occupancy with no other sign that it is wrong. The date range that narrows it is a control on\n * this page, and the notice names only remedies the page actually offers: naming one it does not\n * is worse than naming none, because it reads as user error.\n * - **An imported occupancy is badged wherever it is shown as current.** A `MIGRATED_LEGACY` event\n * was reconstructed from the legacy columns with `exited_at = NULL` because no exit was ever\n * recorded — not because a mob is standing there. Badging it only in the move list while the\n * paddock table showed it as an observed mob made the page contradict itself twenty lines apart.\n * - **Only columns backed by a real field are sortable.** `DataTable` sorts by `row[col.key]`, so a\n * render-only key gives a header with an active chevron that does nothing at all. `comparePaddocks`\n * stays the default order — it ranks by what needs a decision, which no column sort reproduces.\n * - **Error state precedes the empty state.** \"No paddocks yet\" is a statement about the farm and\n * must never be shown when the truth is \"the query failed\".\n */\n\nimport { useEffect, useMemo, useState, type FC } from 'react';\nimport { useNavigate } from 'react-router';\nimport { ArrowRight, Fence, LogOut, Plus, Timer } from 'lucide-react';\nimport { Button } from '@burdenoff/fe-libs/ui';\nimport { useI18n } from '@burdenoff/fe-libs/shared/providers/shell/I18nProvider';\nimport { DataTable, EmptyState, ErrorState, PageLayout, PageLoader, StatCard, StatusBadge } from '../../components';\nimport type { Column } from '../../components';\nimport { ToastContainer } from '../../components/Toast';\nimport { useToast } from '../../hooks/useToast';\nimport { useBasePath } from '../../hooks/useBasePath';\nimport { formatDate } from '../../utils/helpers';\nimport { NOT_MEASURED, optionalMetric } from '../../utils/optionalMetric';\nimport {\n PADDOCK_STATES,\n comparePaddocks,\n grazingWindow,\n importedMoveNote,\n isImportedMove,\n paddockStateOption,\n restProgressPct,\n restTargetSource,\n weighedCoverage,\n} from '../../utils/grazing';\nimport {\n useHealthyBowlGrazing,\n type GrazingEvent,\n type PaddockGrazing,\n type RecordGrazingMoveInput,\n type EndGrazingMoveInput,\n type SetPaddockRestInput,\n} from '../../hooks/useHealthyBowlGrazing';\nimport { useHealthyBowlLivestockDepth } from '../../hooks/useHealthyBowlLivestockDepth';\nimport { RecordGrazingMoveModal } from './grazing/RecordGrazingMoveModal';\nimport { EndGrazingMoveModal } from './grazing/EndGrazingMoveModal';\nimport { SetPaddockRestModal } from './grazing/SetPaddockRestModal';\n\n/** Typing a tag should not fire a herd read per keystroke; the server does the filtering. */\nconst ANIMAL_SEARCH_DEBOUNCE_MS = 300;\n\nconst dateControl =\n 'rounded-md border border-border-subtle bg-bg-surface px-3 py-1.5 text-sm text-text-primary focus:outline-none focus:ring-2 focus:ring-[var(--color-focus-ring)]';\n\n/** Badge tone per state, kept in the vocabulary module so the UI cannot invent a fifth meaning. */\nconst TONE_TO_BADGE = {\n info: 'info',\n warning: 'warning',\n success: 'success',\n muted: 'muted',\n} as const;\n\nexport const GrazingPage: FC = () => {\n const { t } = useI18n();\n const navigate = useNavigate();\n const { buildPath } = useBasePath();\n const { toasts, toast, dismiss } = useToast();\n\n const [moveOpen, setMoveOpen] = useState(false);\n const [movePaddockId, setMovePaddockId] = useState<string | null>(null);\n const [endTarget, setEndTarget] = useState<PaddockGrazing | null>(null);\n const [restTarget, setRestTarget] = useState<PaddockGrazing | null>(null);\n\n // The window the `truncated` notice tells the farmer to narrow. `from`/`to` are the query\n // arguments the hook already accepts; without controls behind them the notice named a remedy\n // nobody could perform.\n const [from, setFrom] = useState('');\n const [to, setTo] = useState('');\n const window_ = useMemo(() => grazingWindow(from, to), [from, to]);\n\n // `animalSearch` drives the input; `debouncedAnimalSearch` drives the herd read, which filters\n // on tag / name / EID server-side.\n const [animalSearch, setAnimalSearch] = useState('');\n const [debouncedAnimalSearch, setDebouncedAnimalSearch] = useState('');\n useEffect(() => {\n const id = globalThis.setTimeout(() => setDebouncedAnimalSearch(animalSearch), ANIMAL_SEARCH_DEBOUNCE_MS);\n return () => globalThis.clearTimeout(id);\n }, [animalSearch]);\n\n const {\n paddocks,\n recentMoves,\n summary,\n truncated,\n unmigratedLegacyAnimals,\n loading,\n error,\n refetch,\n recordMove,\n endMove,\n setPaddockRest,\n // An inverted range resolves to nulls rather than being sent: the service silently replaces an\n // empty window with its own default, so issuing it would look like a filter that does nothing.\n // The page says so instead — see the notice under the controls.\n } = useHealthyBowlGrazing({ from: window_.from, to: window_.to });\n\n /**\n * Both mob sources come from the herd-depth read.\n *\n * The animal list used to be `useHealthyBowlData().animals`, which the service caps at the 200\n * OLDEST rows (`take: DEFAULT_LIST_LIMIT`, `orderBy: createdAt asc`). Past 200 head the newest\n * animals were unreachable AND the picker asserted they did not exist. `healthyBowlHerdDepth`\n * reads by tag number and takes the search server-side; the herd half is fetched only while the\n * modal is open, because it is a far heavier read than a picker warrants on page load.\n */\n const {\n herd,\n groups,\n loading: depthLoading,\n errors: depthErrors,\n } = useHealthyBowlLivestockDepth({\n groups: true,\n herd: moveOpen,\n herdSearch: debouncedAnimalSearch.trim() || null,\n });\n\n const sortedPaddocks = useMemo(() => [...paddocks].sort(comparePaddocks), [paddocks]);\n\n const paddockOptions = useMemo(\n () => sortedPaddocks.map((p) => ({ paddockId: p.paddockId, name: p.name, state: p.state })),\n [sortedPaddocks]\n );\n const groupOptions = useMemo(\n () => groups.map((g) => ({ id: g.id, name: g.name, animalCount: g.animalCount })),\n [groups]\n );\n const animalOptions = useMemo(\n () => (herd?.rows ?? []).map((r) => ({ id: r.animalId, tagNumber: r.tagNumber, name: r.name })),\n [herd]\n );\n const groupsState = useMemo(\n () => ({ loading: depthLoading.groups, error: depthErrors.groups }),\n [depthLoading.groups, depthErrors.groups]\n );\n const animalsState = useMemo(\n () => ({ loading: depthLoading.herd, error: depthErrors.herd }),\n [depthLoading.herd, depthErrors.herd]\n );\n\n const openMoveFor = (paddockId: string | null) => {\n setMovePaddockId(paddockId);\n setAnimalSearch('');\n setDebouncedAnimalSearch('');\n setMoveOpen(true);\n };\n\n const handleRecordMove = async (input: RecordGrazingMoveInput) => {\n const event = await recordMove(input);\n toast({\n title: t('healthybowl.livestock.grazing.toast.moved', 'Grazing move recorded'),\n description: event\n ? t('healthybowl.livestock.grazing.toast.movedDesc', '{{n}} animal(s) onto {{paddock}}.', {\n n: String(event.headCount),\n paddock: event.paddockName,\n })\n : undefined,\n variant: 'success',\n });\n };\n\n const handleEndMove = async (input: EndGrazingMoveInput) => {\n const event = await endMove(input);\n toast({\n title: t('healthybowl.livestock.grazing.toast.ended', 'Exit recorded — the rest clock has started'),\n description: event\n ? t('healthybowl.livestock.grazing.toast.endedDesc', '{{paddock}} · {{days}} days grazed.', {\n paddock: event.paddockName,\n days: optionalMetric(event.durationDays, { decimals: 1 }),\n })\n : undefined,\n variant: 'success',\n });\n };\n\n const handleSetRest = async (input: SetPaddockRestInput) => {\n const updated = await setPaddockRest(input);\n toast({\n title:\n input.restDays === null\n ? t(\n 'healthybowl.livestock.grazing.toast.restCleared',\n 'Rest target cleared — following the workspace default'\n )\n : t('healthybowl.livestock.grazing.toast.restSet', 'Rest target updated'),\n description: updated\n ? t('healthybowl.livestock.grazing.toast.restDesc', '{{paddock}} now rests {{days}} days.', {\n paddock: updated.name,\n days: String(updated.restDays),\n })\n : undefined,\n variant: 'success',\n });\n };\n\n const mobLabel = (event: GrazingEvent | null): string => {\n if (!event) return NOT_MEASURED;\n if (event.groupName) return `${event.groupName} (${event.headCount})`;\n return t('healthybowl.livestock.grazing.table.adHocMob', '{{n}} animal(s)', { n: String(event.headCount) });\n };\n\n const imported = importedMoveNote();\n\n /**\n * `DataTable` sorts by `row[col.key]` and treats every column as sortable unless told otherwise,\n * so a key that is not a field on `PaddockGrazing` yields a header with a live sort chevron and\n * no effect. Content columns are keyed to the real field they show; the ones assembled from\n * several fields say `sortable: false` rather than pretending.\n *\n * `state` is deliberately NOT sortable: it is a real field, but sorting it is alphabetical, and\n * alphabetical order discards `comparePaddocks` — which ranks paddocks by what the grazier can\n * act on first (a mob to move off, then ground to move it onto).\n */\n const columns: Column<PaddockGrazing>[] = [\n {\n key: 'name',\n header: t('healthybowl.livestock.grazing.table.paddock', 'Paddock'),\n render: (p) => (\n <div>\n <div className=\"font-medium text-text-primary\">{p.name}</div>\n <div className=\"text-xs text-text-secondary\">\n {p.areaHectares === null\n ? t(\n 'healthybowl.livestock.grazing.table.areaUnconvertible',\n '{{area}} {{unit}} — no defined size in ha',\n {\n area: optionalMetric(p.area),\n unit: p.areaUnit,\n }\n )\n : t('healthybowl.livestock.grazing.table.area', '{{ha}} ha', {\n ha: optionalMetric(p.areaHectares, { decimals: 2 }),\n })}\n </div>\n </div>\n ),\n },\n {\n key: 'state',\n sortable: false,\n header: t('healthybowl.livestock.grazing.table.state', 'State'),\n render: (p) => {\n const option = paddockStateOption(p.state);\n const isImported = p.current !== null && isImportedMove(p.current.source);\n return (\n <div>\n <div className=\"flex flex-wrap items-center gap-1\">\n <StatusBadge\n variant={TONE_TO_BADGE[option.tone]}\n label={t(option.label.key, option.label.defaultValue)}\n dot\n />\n {/* The same badge the Recent moves list gives this row. Occupancy reconstructed by\n the backfill is not occupancy anybody observed. */}\n {isImported && (\n <StatusBadge variant=\"muted\" label={t('healthybowl.livestock.grazing.moves.imported', 'Imported')} />\n )}\n </div>\n <div className=\"mt-1 max-w-[220px] text-xs text-text-secondary\">\n {t(option.meaning.key, option.meaning.defaultValue)}\n </div>\n {isImported && (\n <div className=\"mt-1 max-w-[220px] text-xs text-text-secondary\">\n {t(imported.key, imported.defaultValue)}\n </div>\n )}\n </div>\n );\n },\n },\n {\n key: 'mob',\n sortable: false,\n header: t('healthybowl.livestock.grazing.table.mob', 'On it now'),\n render: (p) =>\n p.current ? (\n <div>\n <div className=\"text-text-primary\">{mobLabel(p.current)}</div>\n <div className=\"text-xs text-text-secondary\">\n {isImportedMove(p.current.source)\n ? t('healthybowl.livestock.grazing.table.daysInImported', '{{days}} days since the imported date', {\n days: optionalMetric(p.daysIn, { decimals: 1 }),\n })\n : t('healthybowl.livestock.grazing.table.daysIn', '{{days}} days in', {\n days: optionalMetric(p.daysIn, { decimals: 1 }),\n })}\n </div>\n </div>\n ) : (\n <span className=\"text-text-secondary\">{NOT_MEASURED}</span>\n ),\n },\n {\n key: 'daysRested',\n header: t('healthybowl.livestock.grazing.table.rest', 'Rest'),\n render: (p) => {\n const progress = restProgressPct(p.daysRested, p.restDays);\n const source = restTargetSource(p.restDaysIsDefault);\n return (\n <div className=\"min-w-[150px]\">\n <div className=\"text-text-primary\">\n {p.daysRested === null\n ? t('healthybowl.livestock.grazing.table.restNotRunning', 'Not resting')\n : t('healthybowl.livestock.grazing.table.restedOf', '{{rested}} of {{target}} days', {\n rested: optionalMetric(p.daysRested, { decimals: 1 }),\n target: String(p.restDays),\n })}\n </div>\n {/* No bar at all when there is nothing to measure — an empty bar reads as 0% rested. */}\n {progress !== null && (\n <div className=\"mt-1 h-1.5 w-full rounded-full bg-bg-sunken\">\n <div className=\"h-1.5 rounded-full bg-action-primary-bg\" style={{ width: `${progress}%` }} />\n </div>\n )}\n <div className=\"mt-1 text-xs text-text-secondary\">{t(source.key, source.defaultValue)}</div>\n {p.readyAt && (\n <div className=\"text-xs text-text-secondary\">\n {t('healthybowl.livestock.grazing.table.readyAt', 'Ready {{date}}', { date: formatDate(p.readyAt) })}\n </div>\n )}\n </div>\n );\n },\n },\n {\n key: 'stockingRateAuPerHa',\n header: t('healthybowl.livestock.grazing.table.stocking', 'Stocking'),\n render: (p) => {\n const coverage = weighedCoverage(p.current?.headCount ?? 0, p.animalsWithoutWeight);\n return (\n <div className=\"min-w-[150px]\">\n <div className=\"tabular-nums text-text-primary\">\n {optionalMetric(p.stockingRateAuPerHa, { decimals: 2, unit: ' AU/ha' })}\n </div>\n <div className=\"text-xs tabular-nums text-text-secondary\">\n {optionalMetric(p.animalUnits, { decimals: 2, unit: ' AU' })}\n </div>\n {/* The coverage gap behind `animalUnits` — without it a rate from 3 of 12 weighed\n animals reads exactly like one from 12 of 12. */}\n {coverage.hasMob && (\n <div className=\"text-xs text-text-secondary\">\n {coverage.complete\n ? t('healthybowl.livestock.grazing.table.allWeighed', 'all {{total}} weighed', {\n total: String(coverage.total),\n })\n : t('healthybowl.livestock.grazing.table.someWeighed', '{{weighed}} of {{total}} weighed', {\n weighed: String(coverage.weighed),\n total: String(coverage.total),\n })}\n </div>\n )}\n </div>\n );\n },\n },\n {\n key: 'actions',\n sortable: false,\n header: t('healthybowl.livestock.grazing.table.actions', 'Actions'),\n render: (p) => (\n <div className=\"flex flex-wrap gap-1\">\n {p.current ? (\n <Button variant=\"outline\" size=\"sm\" onClick={() => setEndTarget(p)}>\n <LogOut className=\"h-3.5 w-3.5\" />\n {t('healthybowl.livestock.grazing.actions.end', 'End move')}\n </Button>\n ) : (\n <Button variant=\"outline\" size=\"sm\" onClick={() => openMoveFor(p.paddockId)}>\n <ArrowRight className=\"h-3.5 w-3.5\" />\n {t('healthybowl.livestock.grazing.actions.moveIn', 'Move a mob in')}\n </Button>\n )}\n <Button variant=\"ghost\" size=\"sm\" onClick={() => setRestTarget(p)}>\n <Timer className=\"h-3.5 w-3.5\" />\n {t('healthybowl.livestock.grazing.actions.rest', 'Rest target')}\n </Button>\n </div>\n ),\n },\n ];\n\n if (loading && paddocks.length === 0 && !error) {\n return <PageLoader />;\n }\n\n const stateTiles = PADDOCK_STATES.map((state) => {\n const option = paddockStateOption(state);\n const value =\n state === 'OCCUPIED'\n ? (summary?.occupied ?? 0)\n : state === 'RESTING'\n ? (summary?.resting ?? 0)\n : state === 'READY'\n ? (summary?.ready ?? 0)\n : (summary?.neverGrazed ?? 0);\n return { state, option, value };\n });\n\n return (\n <PageLayout\n title={t('healthybowl.livestock.grazing.title', 'Grazing')}\n description={t(\n 'healthybowl.livestock.grazing.description',\n 'Which mob is on which paddock, how long the ground has rested, and how heavily it is stocked.'\n )}\n purpose=\"Rotational grazing, recorded as moves rather than as a single date. Every move has a time in and a time out, so duration, rest period and stocking rate are all derived from what actually happened — and past rotations are never overwritten by the next one.\"\n actions={\n <Button onClick={() => openMoveFor(null)}>\n <Plus className=\"h-4 w-4\" />\n {t('healthybowl.livestock.grazing.actions.record', 'Record a move')}\n </Button>\n }\n >\n {/* Error BEFORE empty: a failed query must never render as \"no paddocks yet\". */}\n {error && paddocks.length === 0 ? (\n <ErrorState\n title={t('healthybowl.livestock.grazing.error.title', 'Could not load grazing')}\n description={error.message}\n onRetry={() => void refetch()}\n />\n ) : (\n <>\n {/* Data on screen, but the last refresh failed. Silently serving the stale list would let\n a mob that has already been moved keep reading as standing on a paddock. */}\n {error && (\n <div className=\"mt-4 flex flex-wrap items-center justify-between gap-2 rounded-lg border border-status-error-border bg-status-error-bg px-4 py-3 text-sm text-status-error-text\">\n <span>\n {t(\n 'healthybowl.livestock.grazing.error.stale',\n 'The last refresh failed, so what you see below may be out of date: {{message}}',\n { message: error.message }\n )}\n </span>\n <Button variant=\"outline\" size=\"sm\" onClick={() => void refetch()}>\n {t('healthybowl.livestock.grazing.error.retry', 'Try again')}\n </Button>\n </div>\n )}\n\n {/* The window the truncation notice points at. `from`/`to` are query arguments, so this is\n wiring rather than client-side filtering — narrowing them makes the service read fewer\n move rows. Rest state is computed from a paddock's whole history and is NOT windowed,\n so narrowing here cannot make a paddock look ungrazed. */}\n <div className=\"mt-4 flex flex-wrap items-end gap-3 rounded-lg border border-border-subtle bg-bg-surface px-4 py-3\">\n <div>\n <label className=\"mb-1 block text-xs font-medium text-text-primary\" htmlFor=\"grazing-from\">\n {t('healthybowl.livestock.grazing.window.from', 'Moves from')}\n </label>\n <input\n id=\"grazing-from\"\n type=\"date\"\n value={from}\n onChange={(e) => setFrom(e.target.value)}\n className={dateControl}\n />\n </div>\n <div>\n <label className=\"mb-1 block text-xs font-medium text-text-primary\" htmlFor=\"grazing-to\">\n {t('healthybowl.livestock.grazing.window.to', 'Moves to')}\n </label>\n <input\n id=\"grazing-to\"\n type=\"date\"\n value={to}\n onChange={(e) => setTo(e.target.value)}\n className={dateControl}\n />\n </div>\n {(from || to) && (\n <Button\n variant=\"ghost\"\n size=\"sm\"\n onClick={() => {\n setFrom('');\n setTo('');\n }}\n >\n {t('healthybowl.livestock.grazing.window.clear', 'Clear')}\n </Button>\n )}\n <p className=\"basis-full text-xs text-text-secondary\">\n {summary?.windowFrom && summary.windowTo\n ? t(\n 'healthybowl.livestock.grazing.window.applied',\n 'Moves shown: {{from}} to {{to}}. Rest and occupancy are read from each paddock’s whole history, not from this window.',\n { from: formatDate(summary.windowFrom), to: formatDate(summary.windowTo) }\n )\n : t(\n 'healthybowl.livestock.grazing.window.default',\n 'Leave both blank for the service’s default window. Rest and occupancy are read from each paddock’s whole history, not from this window.'\n )}\n </p>\n {!window_.valid && (\n <p className=\"basis-full text-xs text-status-error-text\">\n {t(\n 'healthybowl.livestock.grazing.window.inverted',\n 'The end date is before the start date, so this range has not been applied — the default window is shown instead.'\n )}\n </p>\n )}\n </div>\n\n {truncated && (\n <div className=\"mt-4 rounded-lg border border-status-warning-border bg-status-warning-bg px-4 py-3 text-sm text-status-warning-text\">\n {t(\n 'healthybowl.livestock.grazing.truncated',\n 'This farm has more paddocks or moves than one view can load, so the list below is incomplete and under-reports occupancy. Narrowing the date range above loads fewer moves; if this notice stays, the paddock list itself is at its limit and everything below covers only part of the farm.'\n )}\n </div>\n )}\n\n {unmigratedLegacyAnimals > 0 && (\n <div className=\"mt-4 rounded-lg border border-border-subtle bg-bg-sunken/50 px-4 py-3 text-sm text-text-secondary\">\n {t(\n 'healthybowl.livestock.grazing.unmigrated',\n '{{n}} animal(s) still carry a legacy grazing paddock with no rotation date. An entry with no time cannot become a move — record their next move here and they join the history.',\n { n: String(unmigratedLegacyAnimals) }\n )}\n <Button\n variant=\"ghost\"\n size=\"sm\"\n className=\"ms-2\"\n onClick={() => navigate(buildPath('livestock/records'))}\n >\n {t('healthybowl.livestock.grazing.unmigrated.action', 'Open herd records')}\n </Button>\n </div>\n )}\n\n {/* Paddocks by state. Four counts, four meanings — NEVER_GRAZED is never folded into READY. */}\n <div className=\"mt-4 grid grid-cols-2 gap-3 lg:grid-cols-4\">\n {stateTiles.map(({ state, option, value }) => (\n <div key={state} className=\"rounded-lg border border-border-subtle bg-bg-surface p-3\">\n <div className=\"flex items-center justify-between gap-2\">\n <StatusBadge\n variant={TONE_TO_BADGE[option.tone]}\n label={t(option.label.key, option.label.defaultValue)}\n dot\n />\n <span className=\"text-xl font-bold tabular-nums text-text-primary\">{value}</span>\n </div>\n <p className=\"mt-1 text-xs text-text-secondary\">{t(option.meaning.key, option.meaning.defaultValue)}</p>\n </div>\n ))}\n </div>\n\n {/* Herd-wide roll-up. Every one of these can legitimately be null. */}\n <div className=\"mt-4 grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-4\">\n <StatCard\n label={t('healthybowl.livestock.grazing.stats.paddocks', 'Paddocks')}\n value={summary?.paddocks ?? 0}\n icon={<Fence className=\"h-4 w-4\" />}\n />\n <StatCard\n label={t('healthybowl.livestock.grazing.stats.animalUnits', 'Animal units grazing')}\n value={optionalMetric(summary?.totalAnimalUnits ?? null, { decimals: 2 })}\n />\n <StatCard\n label={t('healthybowl.livestock.grazing.stats.hectares', 'Hectares under grazing')}\n value={optionalMetric(summary?.totalHectares ?? null, { decimals: 2 })}\n />\n <StatCard\n hero\n label={t('healthybowl.livestock.grazing.stats.stockingRate', 'Herd stocking rate')}\n value={optionalMetric(summary?.stockingRateAuPerHa ?? null, { decimals: 2, unit: ' AU/ha' })}\n />\n </div>\n\n {summary && (\n <p className=\"mt-2 text-xs text-text-secondary\">\n {t(\n 'healthybowl.livestock.grazing.stats.basis',\n 'One animal unit is {{kg}} kg of liveweight. Paddocks that do not set their own target rest {{days}} days.',\n { kg: String(summary.kgPerAnimalUnit), days: String(summary.defaultRestDays) }\n )}\n {summary.totalHectares === null && summary.occupied > 0\n ? ` ${t(\n 'healthybowl.livestock.grazing.stats.hectaresNull',\n 'Hectares under grazing is unavailable because at least one occupied paddock records its area in a unit with no defined size — a short denominator would overstate the stocking rate.'\n )}`\n : ''}\n {summary.totalAnimalUnits === null && summary.occupied > 0\n ? ` ${t(\n 'healthybowl.livestock.grazing.stats.unitsNull',\n 'Animal units are unavailable because none of the grazing mob has a weight record.'\n )}`\n : ''}\n </p>\n )}\n\n <div className=\"mt-6\">\n <h2 className=\"mb-3 text-lg font-semibold text-text-primary\">\n {t('healthybowl.livestock.grazing.paddocks.title', 'Paddocks')}\n </h2>\n {sortedPaddocks.length === 0 ? (\n <EmptyState\n illustration=\"empty-generic\"\n title={t('healthybowl.livestock.grazing.paddocks.empty.title', 'No paddocks yet')}\n description={t(\n 'healthybowl.livestock.grazing.paddocks.empty.description',\n 'A paddock is a field whose grow location is \"Pasture\". Create one on the Fields page, or record a move onto any field and it appears here.'\n )}\n />\n ) : (\n <DataTable\n columns={columns}\n data={sortedPaddocks}\n keyField=\"paddockId\"\n pageSize={20}\n emptyMessage={t('healthybowl.livestock.grazing.paddocks.none', 'No paddocks match.')}\n />\n )}\n </div>\n\n <div className=\"mt-6\">\n <h2 className=\"mb-3 text-lg font-semibold text-text-primary\">\n {t('healthybowl.livestock.grazing.moves.title', 'Recent moves')}\n </h2>\n {recentMoves.length === 0 ? (\n <p className=\"rounded-lg border border-border-subtle bg-bg-surface px-4 py-6 text-center text-sm text-text-secondary\">\n {t(\n 'healthybowl.livestock.grazing.moves.empty',\n 'No moves recorded in this period. Record one and the duration, rest period and stocking rate all follow from it.'\n )}\n </p>\n ) : (\n <div className=\"flex flex-col gap-2\">\n {recentMoves.map((move) => (\n <div\n key={move.id}\n className=\"flex flex-wrap items-center justify-between gap-2 rounded-md border border-border-subtle bg-bg-surface p-3\"\n >\n <div>\n <p className=\"text-sm font-medium text-text-primary\">\n {mobLabel(move)} → {move.paddockName}\n </p>\n <p className=\"text-xs text-text-secondary\">\n {t('healthybowl.livestock.grazing.moves.window', 'In {{in}} · Out {{out}}', {\n in: formatDate(move.enteredAt),\n out: move.exitedAt\n ? formatDate(move.exitedAt)\n : t('healthybowl.livestock.grazing.moves.stillIn', 'still in'),\n })}\n </p>\n {isImportedMove(move.source) && (\n <p className=\"mt-1 max-w-prose text-xs text-text-secondary\">\n {t(imported.key, imported.defaultValue)}\n </p>\n )}\n {move.notes ? <p className=\"mt-1 text-xs text-text-secondary\">{move.notes}</p> : null}\n </div>\n <div className=\"flex items-center gap-2\">\n {/* Reconstructed legacy rows are labelled as imported, never as observed. */}\n {isImportedMove(move.source) && (\n <StatusBadge\n variant=\"muted\"\n label={t('healthybowl.livestock.grazing.moves.imported', 'Imported')}\n />\n )}\n <span className=\"text-xs tabular-nums text-text-secondary\">\n {t('healthybowl.livestock.grazing.moves.duration', '{{days}} days', {\n days: optionalMetric(move.durationDays, { decimals: 1 }),\n })}\n </span>\n {move.active && (\n <StatusBadge\n variant=\"info\"\n label={t('healthybowl.livestock.grazing.moves.active', 'Open')}\n dot\n />\n )}\n </div>\n </div>\n ))}\n </div>\n )}\n </div>\n </>\n )}\n\n <RecordGrazingMoveModal\n open={moveOpen}\n onClose={() => setMoveOpen(false)}\n paddocks={paddockOptions}\n groups={groupOptions}\n animals={animalOptions}\n groupsState={groupsState}\n animalsState={animalsState}\n animalSearch={animalSearch}\n onAnimalSearchChange={setAnimalSearch}\n defaultPaddockId={movePaddockId}\n onSubmit={handleRecordMove}\n />\n\n <EndGrazingMoveModal\n open={endTarget !== null}\n onClose={() => setEndTarget(null)}\n event={endTarget?.current ?? null}\n paddockName={endTarget?.name ?? ''}\n onSubmit={handleEndMove}\n />\n\n <SetPaddockRestModal\n open={restTarget !== null}\n onClose={() => setRestTarget(null)}\n paddock={restTarget}\n defaultRestDays={summary?.defaultRestDays ?? 21}\n onSubmit={handleSetRest}\n />\n\n <ToastContainer toasts={toasts} onDismiss={dismiss} />\n </PageLayout>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAiFA,IAAM,KAA4B,KAE5B,IACJ,mKAGI,IAAgB;CACpB,MAAM;CACN,SAAS;CACT,SAAS;CACT,OAAO;AACT,GAEa,UAAwB;CACnC,IAAM,EAAE,SAAM,GAAQ,GAChB,KAAW,GAAY,GACvB,EAAE,kBAAc,EAAY,GAC5B,EAAE,YAAQ,UAAO,eAAY,GAAS,GAEtC,CAAC,GAAU,KAAe,EAAS,EAAK,GACxC,CAAC,GAAe,KAAoB,EAAwB,IAAI,GAChE,CAAC,GAAW,KAAgB,EAAgC,IAAI,GAChE,CAAC,GAAY,KAAiB,EAAgC,IAAI,GAKlE,CAAC,GAAM,KAAW,EAAS,EAAE,GAC7B,CAAC,GAAI,KAAS,EAAS,EAAE,GACzB,IAAU,QAAc,EAAc,GAAM,CAAE,GAAG,CAAC,GAAM,CAAE,CAAC,GAI3D,CAAC,GAAc,KAA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,IAAD;IACE,MAAM,MAAc;IACpB,eAAe,EAAa,IAAI;IAChC,OAAO,GAAW,WAAW;IAC7B,aAAa,GAAW,QAAQ;IAChC,UAAU;GACX,CAAA;GAED,kBAAC,IAAD;IACE,MAAM,MAAe;IACrB,eAAe,EAAc,IAAI;IACjC,SAAS;IACT,iBAAiB,GAAS,mBAAmB;IAC7C,UAAU;GACX,CAAA;GAED,kBAAC,IAAD;IAAwB;IAAQ,WAAW;GAAU,CAAA;EAC3C;;AAEhB"}
|
|
@@ -160,10 +160,6 @@ var D = () => {
|
|
|
160
160
|
})
|
|
161
161
|
]
|
|
162
162
|
}),
|
|
163
|
-
I?.truncated ? /* @__PURE__ */ C("div", {
|
|
164
|
-
className: "mt-4 rounded-lg border border-status-warning-border bg-status-warning-bg px-4 py-3 text-sm text-status-warning-text",
|
|
165
|
-
children: D("healthybowl.livestock.depth.truncated", "This herd has more animals than one view can load, so the table below is only part of it. Narrow the search or pick a group — the counts on the chips above still cover the whole herd.")
|
|
166
|
-
}) : null,
|
|
167
163
|
B.length === 0 ? /* @__PURE__ */ C(a, {
|
|
168
164
|
icon: /* @__PURE__ */ C(b, { className: "h-8 w-8 text-text-secondary" }),
|
|
169
165
|
title: D("healthybowl.livestock.depth.empty.title", "No animals to show"),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HerdDepthPage.js","names":[],"sources":["../../../../src/healthybowl/pages/livestock/HerdDepthPage.tsx"],"sourcesContent":["/**\n * Deep herd records view (BOFF-2890 · L-1).\n * One row per animal with group, body-condition score, medication-withdrawal end-date and ADG,\n * plus a red \"do not sell milk or meat\" compliance banner whenever any animal is inside its\n * withdrawal window. Every value is a real record from the backend — no fabricated data.\n */\nimport { useState } from 'react';\nimport { useNavigate } from 'react-router';\nimport { AlertTriangle, Network, Settings2, ShieldCheck, Users } from 'lucide-react';\nimport { Button, Input } from '@burdenoff/fe-libs/ui';\nimport { useI18n } from '@burdenoff/fe-libs/shared/providers/shell/I18nProvider';\nimport { PageLayout, StatCard, DataTable, StatusBadge, EmptyState, ErrorState, PageLoader } from '../../components';\nimport type { Column } from '../../components';\nimport { useBasePath } from '../../hooks/useBasePath';\nimport { useHealthyBowlLivestockDepth, type HerdDepthRow } from '../../hooks/useHealthyBowlLivestockDepth';\nimport { formatAdg, formatBcs, formatShortDate, withdrawalBadgeVariant } from './depthLabels';\nimport { AnimalGroupModal } from './AnimalGroupModal';\n\nexport const HerdDepthPage = () => {\n const { t } = useI18n();\n const navigate = useNavigate();\n const { buildPath } = useBasePath();\n\n const [groupId, setGroupId] = useState<string | null>(null);\n const [search, setSearch] = useState('');\n const [groupsOpen, setGroupsOpen] = useState(false);\n\n const { herd, loading, errors, refetchHerd } = useHealthyBowlLivestockDepth({\n herd: true,\n herdGroupId: groupId,\n herdSearch: search.trim() || null,\n });\n\n const rows = herd?.rows ?? [];\n const summary = herd?.summary;\n const groups = herd?.groups ?? [];\n\n const columns: Column<HerdDepthRow>[] = [\n {\n key: 'tag',\n header: t('healthybowl.livestock.depth.table.tag', 'Tag / EID'),\n render: (a) => (\n <div>\n <div className=\"font-medium text-text-primary\">{a.tagNumber}</div>\n {a.eidTag ? <div className=\"text-xs text-text-secondary tabular-nums\">{a.eidTag}</div> : null}\n </div>\n ),\n },\n {\n key: 'animal',\n header: t('healthybowl.livestock.depth.table.animal', 'Animal'),\n render: (a) => (\n <div>\n <div className=\"text-text-primary\">{a.name}</div>\n <div className=\"text-xs text-text-secondary\">{a.type}</div>\n </div>\n ),\n },\n {\n key: 'group',\n header: t('healthybowl.livestock.depth.table.group', 'Group'),\n render: (a) => <span className=\"text-text-primary\">{a.groupName ?? '—'}</span>,\n },\n {\n key: 'bcs',\n header: t('healthybowl.livestock.depth.table.bcs', 'Body Condition'),\n render: (a) => <span className=\"tabular-nums text-text-primary\">{formatBcs(a.bodyConditionScore)}</span>,\n },\n {\n key: 'withdrawal',\n header: t('healthybowl.livestock.depth.table.withdrawal', 'Med. Withdrawal Ends'),\n render: (a) =>\n a.withdrawal.blocked ? (\n <StatusBadge\n variant={withdrawalBadgeVariant(a.withdrawal.status)}\n label={t('healthybowl.livestock.depth.table.withdrawalEnds', 'Withdrawal ends {{date}}', {\n date: formatShortDate(a.withdrawal.endDate),\n })}\n dot\n />\n ) : (\n <span className=\"text-text-secondary\">{t('healthybowl.livestock.depth.table.none', 'none')}</span>\n ),\n },\n {\n key: 'adg',\n header: t('healthybowl.livestock.depth.table.adg', 'ADG'),\n render: (a) => <span className=\"tabular-nums text-text-primary\">{formatAdg(a.adgKgPerDay)}</span>,\n },\n ];\n\n if (loading.herd && !herd) {\n return <PageLoader />;\n }\n\n return (\n <PageLayout\n title={t('healthybowl.livestock.depth.title', 'Livestock Records')}\n titleAccent={t('healthybowl.livestock.depth.titleAccent', 'Records')}\n description={t(\n 'healthybowl.livestock.depth.description',\n 'Deep herd view — body condition, groups, ear-tag/EID, genealogy, ADG and medication-withdrawal compliance.'\n )}\n actions={\n <Button variant=\"outline\" onClick={() => setGroupsOpen(true)}>\n <Settings2 className=\"h-4 w-4\" />\n {t('healthybowl.livestock.depth.groups.manageAction', 'Manage Groups')}\n </Button>\n }\n >\n {errors.herd && !herd ? (\n <ErrorState description={errors.herd.message} onRetry={() => void refetchHerd()} />\n ) : (\n <>\n {summary && summary.animalsInWithdrawal > 0 ? (\n <div\n role=\"alert\"\n className=\"mt-4 flex items-center gap-3 rounded-lg border border-status-error-border bg-status-error-bg px-4 py-3 text-status-error-text\"\n >\n <AlertTriangle className=\"h-5 w-5 shrink-0\" />\n <span className=\"text-sm font-semibold\">{summary.complianceMessage}</span>\n </div>\n ) : null}\n\n <div className=\"mt-4 grid grid-cols-1 gap-3 sm:grid-cols-3\">\n <StatCard\n label={t('healthybowl.livestock.depth.stats.total', 'Animals')}\n value={summary?.totalAnimals ?? 0}\n icon={<Users className=\"h-5 w-5\" />}\n hero\n />\n <StatCard\n label={t('healthybowl.livestock.depth.stats.withdrawal', 'In withdrawal')}\n value={summary?.animalsInWithdrawal ?? 0}\n icon={<AlertTriangle className=\"h-5 w-5\" />}\n />\n <StatCard\n label={t('healthybowl.livestock.depth.stats.clear', 'Clear to sell')}\n value={summary?.animalsClear ?? 0}\n icon={<ShieldCheck className=\"h-5 w-5\" />}\n />\n </div>\n\n <div className=\"mt-4 flex flex-wrap items-center gap-2\">\n <button\n type=\"button\"\n onClick={() => setGroupId(null)}\n className={`rounded-full px-3 py-1 text-sm ${groupId === null ? 'bg-accent-teal text-white' : 'bg-bg-sunken text-text-secondary'}`}\n >\n {t('healthybowl.livestock.depth.groups.all', 'All groups')}\n </button>\n {groups.map((g) => (\n <button\n key={g.id}\n type=\"button\"\n onClick={() => setGroupId(g.id)}\n className={`flex items-center gap-1 rounded-full px-3 py-1 text-sm ${groupId === g.id ? 'bg-accent-teal text-white' : 'bg-bg-sunken text-text-secondary'}`}\n >\n {g.kind === 'SMART' ? <Network className=\"h-3.5 w-3.5\" /> : null}\n {g.name}\n <span className=\"tabular-nums opacity-80\">({g.animalCount})</span>\n </button>\n ))}\n <div className=\"ms-auto w-full sm:w-64\">\n <Input\n value={search}\n onChange={(e) => setSearch(e.target.value)}\n placeholder={t('healthybowl.livestock.depth.searchPlaceholder', 'Search tag, name or EID…')}\n />\n </div>\n </div>\n\n {/* The cap is stated, not discovered (BOFF-6012). No hard-coded row count: duplicating the\n server constant into a second file is how the grazing modal's copy went stale. */}\n {herd?.truncated ? (\n <div className=\"mt-4 rounded-lg border border-status-warning-border bg-status-warning-bg px-4 py-3 text-sm text-status-warning-text\">\n {t(\n 'healthybowl.livestock.depth.truncated',\n 'This herd has more animals than one view can load, so the table below is only part of it. Narrow the search or pick a group — the counts on the chips above still cover the whole herd.'\n )}\n </div>\n ) : null}\n\n {rows.length === 0 ? (\n <EmptyState\n icon={<Users className=\"h-8 w-8 text-text-secondary\" />}\n title={t('healthybowl.livestock.depth.empty.title', 'No animals to show')}\n description={t(\n 'healthybowl.livestock.depth.empty.description',\n 'Register animals in the Livestock module, then their deep records appear here.'\n )}\n action={\n <Button variant=\"outline\" onClick={() => navigate(buildPath('livestock/animals'))}>\n {t('healthybowl.livestock.depth.empty.action', 'Go to Animal Registry')}\n </Button>\n }\n />\n ) : (\n <DataTable\n columns={columns}\n data={rows}\n keyField=\"animalId\"\n pageSize={12}\n onRowClick={(a) => navigate(buildPath(`livestock/records/${a.animalId}`))}\n />\n )}\n </>\n )}\n\n <AnimalGroupModal open={groupsOpen} onClose={() => setGroupsOpen(false)} onChanged={() => void refetchHerd()} />\n </PageLayout>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAkBA,IAAa,UAAsB;CACjC,IAAM,EAAE,SAAM,EAAQ,GAChB,IAAW,EAAY,GACvB,EAAE,iBAAc,EAAY,GAE5B,CAAC,GAAS,KAAc,EAAwB,IAAI,GACpD,CAAC,GAAQ,KAAa,EAAS,EAAE,GACjC,CAAC,GAAY,KAAiB,EAAS,EAAK,GAE5C,EAAE,SAAM,YAAS,WAAQ,mBAAgB,EAA6B;EAC1E,MAAM;EACN,aAAa;EACb,YAAY,EAAO,KAAK,KAAK;CAC/B,CAAC,GAEK,IAAO,GAAM,QAAQ,CAAC,GACtB,IAAU,GAAM,SAChB,IAAS,GAAM,UAAU,CAAC,GAE1B,IAAkC;EACtC;GACE,KAAK;GACL,QAAQ,EAAE,yCAAyC,WAAW;GAC9D,SAAS,MACP,kBAAC,OAAD,EAAA,UAAA,CACE,kBAAC,OAAD;IAAK,WAAU;cAAiC,EAAE;GAAe,CAAA,GAChE,EAAE,SAAS,kBAAC,OAAD;IAAK,WAAU;cAA4C,EAAE;GAAY,CAAA,IAAI,IACtF,EAAA,CAAA;EAET;EACA;GACE,KAAK;GACL,QAAQ,EAAE,4CAA4C,QAAQ;GAC9D,SAAS,MACP,kBAAC,OAAD,EAAA,UAAA,CACE,kBAAC,OAAD;IAAK,WAAU;cAAqB,EAAE;GAAU,CAAA,GAChD,kBAAC,OAAD;IAAK,WAAU;cAA+B,EAAE;GAAU,CAAA,CACvD,E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zC,aAAa,EAAE,iDAAiD,0BAA0B;MAC3F,CAAA;KACE,CAAA;IACF;;GAIJ,GAAM,YACL,kBAAC,OAAD;IAAK,WAAU;cACZ,EACC,yCACA,yLACF;GACG,CAAA,IACH;GAEH,EAAK,WAAW,IACf,kBAAC,GAAD;IACE,MAAM,kBAAC,GAAD,EAAO,WAAU,8BAA+B,CAAA;IACtD,OAAO,EAAE,2CAA2C,oBAAoB;IACxE,aAAa,EACX,iDACA,gFACF;IACA,QACE,kBAAC,GAAD;KAAQ,SAAQ;KAAU,eAAe,EAAS,EAAU,mBAAmB,CAAC;eAC7E,EAAE,4CAA4C,uBAAuB;IAChE,CAAA;GAEX,CAAA,IAED,kBAAC,GAAD;IACW;IACT,MAAM;IACN,UAAS;IACT,UAAU;IACV,aAAa,MAAM,EAAS,EAAU,qBAAqB,EAAE,UAAU,CAAC;GACzE,CAAA;EAEH,EAAA,CAAA,GAGJ,kBAAC,GAAD;GAAkB,MAAM;GAAY,eAAe,EAAc,EAAK;GAAG,iBAAiB,KAAK,EAAY;EAAI,CAAA,CACrG;;AAEhB"}
|
|
1
|
+
{"version":3,"file":"HerdDepthPage.js","names":[],"sources":["../../../../src/healthybowl/pages/livestock/HerdDepthPage.tsx"],"sourcesContent":["/**\n * Deep herd records view (BOFF-2890 · L-1).\n * One row per animal with group, body-condition score, medication-withdrawal end-date and ADG,\n * plus a red \"do not sell milk or meat\" compliance banner whenever any animal is inside its\n * withdrawal window. Every value is a real record from the backend — no fabricated data.\n */\nimport { useState } from 'react';\nimport { useNavigate } from 'react-router';\nimport { AlertTriangle, Network, Settings2, ShieldCheck, Users } from 'lucide-react';\nimport { Button, Input } from '@burdenoff/fe-libs/ui';\nimport { useI18n } from '@burdenoff/fe-libs/shared/providers/shell/I18nProvider';\nimport { PageLayout, StatCard, DataTable, StatusBadge, EmptyState, ErrorState, PageLoader } from '../../components';\nimport type { Column } from '../../components';\nimport { useBasePath } from '../../hooks/useBasePath';\nimport { useHealthyBowlLivestockDepth, type HerdDepthRow } from '../../hooks/useHealthyBowlLivestockDepth';\nimport { formatAdg, formatBcs, formatShortDate, withdrawalBadgeVariant } from './depthLabels';\nimport { AnimalGroupModal } from './AnimalGroupModal';\n\nexport const HerdDepthPage = () => {\n const { t } = useI18n();\n const navigate = useNavigate();\n const { buildPath } = useBasePath();\n\n const [groupId, setGroupId] = useState<string | null>(null);\n const [search, setSearch] = useState('');\n const [groupsOpen, setGroupsOpen] = useState(false);\n\n const { herd, loading, errors, refetchHerd } = useHealthyBowlLivestockDepth({\n herd: true,\n herdGroupId: groupId,\n herdSearch: search.trim() || null,\n });\n\n const rows = herd?.rows ?? [];\n const summary = herd?.summary;\n const groups = herd?.groups ?? [];\n\n const columns: Column<HerdDepthRow>[] = [\n {\n key: 'tag',\n header: t('healthybowl.livestock.depth.table.tag', 'Tag / EID'),\n render: (a) => (\n <div>\n <div className=\"font-medium text-text-primary\">{a.tagNumber}</div>\n {a.eidTag ? <div className=\"text-xs text-text-secondary tabular-nums\">{a.eidTag}</div> : null}\n </div>\n ),\n },\n {\n key: 'animal',\n header: t('healthybowl.livestock.depth.table.animal', 'Animal'),\n render: (a) => (\n <div>\n <div className=\"text-text-primary\">{a.name}</div>\n <div className=\"text-xs text-text-secondary\">{a.type}</div>\n </div>\n ),\n },\n {\n key: 'group',\n header: t('healthybowl.livestock.depth.table.group', 'Group'),\n render: (a) => <span className=\"text-text-primary\">{a.groupName ?? '—'}</span>,\n },\n {\n key: 'bcs',\n header: t('healthybowl.livestock.depth.table.bcs', 'Body Condition'),\n render: (a) => <span className=\"tabular-nums text-text-primary\">{formatBcs(a.bodyConditionScore)}</span>,\n },\n {\n key: 'withdrawal',\n header: t('healthybowl.livestock.depth.table.withdrawal', 'Med. Withdrawal Ends'),\n render: (a) =>\n a.withdrawal.blocked ? (\n <StatusBadge\n variant={withdrawalBadgeVariant(a.withdrawal.status)}\n label={t('healthybowl.livestock.depth.table.withdrawalEnds', 'Withdrawal ends {{date}}', {\n date: formatShortDate(a.withdrawal.endDate),\n })}\n dot\n />\n ) : (\n <span className=\"text-text-secondary\">{t('healthybowl.livestock.depth.table.none', 'none')}</span>\n ),\n },\n {\n key: 'adg',\n header: t('healthybowl.livestock.depth.table.adg', 'ADG'),\n render: (a) => <span className=\"tabular-nums text-text-primary\">{formatAdg(a.adgKgPerDay)}</span>,\n },\n ];\n\n if (loading.herd && !herd) {\n return <PageLoader />;\n }\n\n return (\n <PageLayout\n title={t('healthybowl.livestock.depth.title', 'Livestock Records')}\n titleAccent={t('healthybowl.livestock.depth.titleAccent', 'Records')}\n description={t(\n 'healthybowl.livestock.depth.description',\n 'Deep herd view — body condition, groups, ear-tag/EID, genealogy, ADG and medication-withdrawal compliance.'\n )}\n actions={\n <Button variant=\"outline\" onClick={() => setGroupsOpen(true)}>\n <Settings2 className=\"h-4 w-4\" />\n {t('healthybowl.livestock.depth.groups.manageAction', 'Manage Groups')}\n </Button>\n }\n >\n {errors.herd && !herd ? (\n <ErrorState description={errors.herd.message} onRetry={() => void refetchHerd()} />\n ) : (\n <>\n {summary && summary.animalsInWithdrawal > 0 ? (\n <div\n role=\"alert\"\n className=\"mt-4 flex items-center gap-3 rounded-lg border border-status-error-border bg-status-error-bg px-4 py-3 text-status-error-text\"\n >\n <AlertTriangle className=\"h-5 w-5 shrink-0\" />\n <span className=\"text-sm font-semibold\">{summary.complianceMessage}</span>\n </div>\n ) : null}\n\n <div className=\"mt-4 grid grid-cols-1 gap-3 sm:grid-cols-3\">\n <StatCard\n label={t('healthybowl.livestock.depth.stats.total', 'Animals')}\n value={summary?.totalAnimals ?? 0}\n icon={<Users className=\"h-5 w-5\" />}\n hero\n />\n <StatCard\n label={t('healthybowl.livestock.depth.stats.withdrawal', 'In withdrawal')}\n value={summary?.animalsInWithdrawal ?? 0}\n icon={<AlertTriangle className=\"h-5 w-5\" />}\n />\n <StatCard\n label={t('healthybowl.livestock.depth.stats.clear', 'Clear to sell')}\n value={summary?.animalsClear ?? 0}\n icon={<ShieldCheck className=\"h-5 w-5\" />}\n />\n </div>\n\n <div className=\"mt-4 flex flex-wrap items-center gap-2\">\n <button\n type=\"button\"\n onClick={() => setGroupId(null)}\n className={`rounded-full px-3 py-1 text-sm ${groupId === null ? 'bg-accent-teal text-white' : 'bg-bg-sunken text-text-secondary'}`}\n >\n {t('healthybowl.livestock.depth.groups.all', 'All groups')}\n </button>\n {groups.map((g) => (\n <button\n key={g.id}\n type=\"button\"\n onClick={() => setGroupId(g.id)}\n className={`flex items-center gap-1 rounded-full px-3 py-1 text-sm ${groupId === g.id ? 'bg-accent-teal text-white' : 'bg-bg-sunken text-text-secondary'}`}\n >\n {g.kind === 'SMART' ? <Network className=\"h-3.5 w-3.5\" /> : null}\n {g.name}\n <span className=\"tabular-nums opacity-80\">({g.animalCount})</span>\n </button>\n ))}\n <div className=\"ms-auto w-full sm:w-64\">\n <Input\n value={search}\n onChange={(e) => setSearch(e.target.value)}\n placeholder={t('healthybowl.livestock.depth.searchPlaceholder', 'Search tag, name or EID…')}\n />\n </div>\n </div>\n\n {rows.length === 0 ? (\n <EmptyState\n icon={<Users className=\"h-8 w-8 text-text-secondary\" />}\n title={t('healthybowl.livestock.depth.empty.title', 'No animals to show')}\n description={t(\n 'healthybowl.livestock.depth.empty.description',\n 'Register animals in the Livestock module, then their deep records appear here.'\n )}\n action={\n <Button variant=\"outline\" onClick={() => navigate(buildPath('livestock/animals'))}>\n {t('healthybowl.livestock.depth.empty.action', 'Go to Animal Registry')}\n </Button>\n }\n />\n ) : (\n <DataTable\n columns={columns}\n data={rows}\n keyField=\"animalId\"\n pageSize={12}\n onRowClick={(a) => navigate(buildPath(`livestock/records/${a.animalId}`))}\n />\n )}\n </>\n )}\n\n <AnimalGroupModal open={groupsOpen} onClose={() => setGroupsOpen(false)} onChanged={() => void refetchHerd()} />\n </PageLayout>\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAkBA,IAAa,UAAsB;CACjC,IAAM,EAAE,SAAM,EAAQ,GAChB,IAA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S,EAAU,qBAAqB,EAAE,UAAU,CAAC;GACzE,CAAA;EAEH,EAAA,CAAA,GAGJ,kBAAC,GAAD;GAAkB,MAAM;GAAY,eAAe,EAAc,EAAK;GAAG,iBAAiB,KAAK,EAAY;EAAI,CAAA,CACrG;;AAEhB"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { Modal as e } from "../../../components/Modal.js";
|
|
2
2
|
import "../../../components/index.js";
|
|
3
3
|
import { paddockStateOption as t } from "../../../utils/grazing.js";
|
|
4
|
-
import { useEffect as n, useMemo as
|
|
5
|
-
import { useI18n as
|
|
4
|
+
import { useEffect as n, useMemo as r, useRef as ee, useState as i } from "react";
|
|
5
|
+
import { useI18n as te } from "@burdenoff/fe-libs/shared/providers/shell/I18nProvider";
|
|
6
6
|
import { Fragment as a, jsx as o, jsxs as s } from "react/jsx-runtime";
|
|
7
7
|
import { Button as c, Input as ne, Select as l, SelectContent as u, SelectItem as d, SelectTrigger as f, SelectValue as p, Textarea as re } from "@burdenoff/fe-libs/ui";
|
|
8
|
-
|
|
8
|
+
//#region src/healthybowl/pages/livestock/grazing/RecordGrazingMoveModal.tsx
|
|
9
|
+
var ie = 2e3, m = {
|
|
9
10
|
loading: !1,
|
|
10
11
|
error: null
|
|
11
12
|
}, h = "mb-1 block text-sm font-medium text-text-primary", g = "w-full rounded-md border border-border-subtle bg-bg-surface px-3 py-2 text-sm text-text-primary focus:outline-none focus:ring-2 focus:ring-[var(--color-focus-ring)]";
|
|
@@ -18,8 +19,8 @@ function v(e) {
|
|
|
18
19
|
let t = new Date(e);
|
|
19
20
|
return Number.isNaN(t.getTime()) ? null : t.toISOString();
|
|
20
21
|
}
|
|
21
|
-
var y = ({ open: y, onClose: b, paddocks: x, groups: S, animals: C, groupsState: w = m, animalsState: T = m,
|
|
22
|
-
let { t: O } =
|
|
22
|
+
var y = ({ open: y, onClose: b, paddocks: x, groups: S, animals: C, groupsState: w = m, animalsState: T = m, animalSearch: E, onAnimalSearchChange: ae, defaultPaddockId: D = null, onSubmit: oe }) => {
|
|
23
|
+
let { t: O } = te(), [k, A] = i(""), [j, M] = i("GROUP"), [N, P] = i(""), [F, I] = i([]), [L, R] = i(_()), [z, B] = i(!1), [V, H] = i(""), [U, W] = i(!0), [G, K] = i(""), [q, J] = i(!1), [Y, X] = i(null), Z = ee({
|
|
23
24
|
count: 0,
|
|
24
25
|
loading: !1
|
|
25
26
|
});
|
|
@@ -31,7 +32,7 @@ var y = ({ open: y, onClose: b, paddocks: x, groups: S, animals: C, groupsState:
|
|
|
31
32
|
let { count: e, loading: t } = Z.current;
|
|
32
33
|
A(D ?? ""), M(e > 0 || t ? "GROUP" : "ANIMALS"), P(""), I([]), R(_()), B(!1), H(""), W(!0), K(""), X(null);
|
|
33
34
|
}, [y, D]);
|
|
34
|
-
let Q =
|
|
35
|
+
let Q = r(() => {
|
|
35
36
|
let e = E.trim().toLowerCase();
|
|
36
37
|
if (!e) return C;
|
|
37
38
|
let t = C.filter((t) => `${t.tagNumber} ${t.name}`.toLowerCase().includes(e));
|
|
@@ -200,9 +201,9 @@ var y = ({ open: y, onClose: b, paddocks: x, groups: S, animals: C, groupsState:
|
|
|
200
201
|
className: "border-t border-border-subtle px-2 py-1.5 text-xs text-text-secondary",
|
|
201
202
|
children: O("healthybowl.livestock.grazing.move.selectedCount", "{{n}} selected", { n: String(F.length) })
|
|
202
203
|
}),
|
|
203
|
-
|
|
204
|
+
/* @__PURE__ */ o("div", {
|
|
204
205
|
className: "border-t border-border-subtle px-2 py-1.5 text-xs text-text-secondary",
|
|
205
|
-
children: O("healthybowl.livestock.grazing.move.animalCap", "
|
|
206
|
+
children: O("healthybowl.livestock.grazing.move.animalCap", "Searching filters the whole herd on the server, across the first {{n}} animals by tag number. A herd larger than that is not fully reachable here — move it as a group instead.", { n: new Intl.NumberFormat("en-US").format(ie) })
|
|
206
207
|
})
|
|
207
208
|
]
|
|
208
209
|
})
|