@burdenoff/microfe-healthybowl 2026.902.27 → 2026.902.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,88 @@
1
+ import { useHealthyBowl as e } from "../context/HealthyBowlContext.js";
2
+ import { useEffect as t, useMemo as n, useState as r } from "react";
3
+ import { gql as i } from "@apollo/client";
4
+ import { useQuery as a } from "@apollo/client/react";
5
+ //#region src/healthybowl/hooks/usePlantingEstimate.ts
6
+ var o = i`
7
+ query GetHealthyBowlPlantingEstimate($context: ContextInput!, $input: HealthyBowlPlantingEstimateInput!) {
8
+ healthyBowlPlantingEstimate(context: $context, input: $input) {
9
+ appliesToBedGeometry
10
+ notApplicableReason
11
+ spacingPresetLabel
12
+ capacity {
13
+ areaSqm
14
+ cultivableAreaSqm
15
+ bedCount
16
+ bedLengthM
17
+ rowsPerBed
18
+ plantsPerRow
19
+ plantsPerBed
20
+ totalPlants
21
+ seedlingTarget
22
+ plantSpacingCm
23
+ rowSpacingCm
24
+ bedWidthM
25
+ pathWidthM
26
+ densityPlantsPerSqm
27
+ }
28
+ seedRate {
29
+ seedlingsToRaise
30
+ seedsNeeded
31
+ seedGrams
32
+ trays
33
+ }
34
+ }
35
+ }
36
+ `;
37
+ function s(e) {
38
+ let t = { fieldId: e.fieldId }, n = [
39
+ ["plantCatalogId", e.plantCatalogId],
40
+ ["cropId", e.cropId],
41
+ ["areaOverride", e.areaOverride],
42
+ ["plantSpacingCm", e.plantSpacingCm],
43
+ ["rowSpacingCm", e.rowSpacingCm],
44
+ ["bedWidthM", e.bedWidthM],
45
+ ["pathWidthM", e.pathWidthM]
46
+ ];
47
+ for (let [e, r] of n) r != null && (t[e] = r);
48
+ return t;
49
+ }
50
+ function c(e, n) {
51
+ let [i, a] = r(e);
52
+ return t(() => {
53
+ let t = window.setTimeout(() => a(e), n);
54
+ return () => window.clearTimeout(t);
55
+ }, [e, n]), i;
56
+ }
57
+ function l(t) {
58
+ let { workspaceId: r } = e(), i = n(() => ({ workspaceId: r }), [r]), l = n(() => s(t), [
59
+ t.fieldId,
60
+ t.plantCatalogId,
61
+ t.cropId,
62
+ t.areaOverride,
63
+ t.plantSpacingCm,
64
+ t.rowSpacingCm,
65
+ t.bedWidthM,
66
+ t.pathWidthM
67
+ ]), u = c(l, 250), d = JSON.stringify(l), f = JSON.stringify(u), { data: p, loading: m, error: h } = a(o, {
68
+ variables: {
69
+ context: i,
70
+ input: u
71
+ },
72
+ skip: !t.fieldId,
73
+ fetchPolicy: "network-only"
74
+ });
75
+ return {
76
+ estimate: p?.healthyBowlPlantingEstimate ?? null,
77
+ loading: m,
78
+ error: h,
79
+ ready: d === f && !m && p !== void 0
80
+ };
81
+ }
82
+ function u(e, t, n) {
83
+ return e ? t ?? null : n;
84
+ }
85
+ //#endregion
86
+ export { u as preferServer, l as usePlantingEstimate };
87
+
88
+ //# sourceMappingURL=usePlantingEstimate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePlantingEstimate.js","names":[],"sources":["../../../src/healthybowl/hooks/usePlantingEstimate.ts"],"sourcesContent":["/**\n * Server-derived planting capacity and seed rate (BOFF-6100).\n *\n * ### Why the client still computes this too\n *\n * `plantingCapacity.ts` and `seedRate.ts` are not going away. A farmer dragging a bed-width or\n * spacing input expects the numbers to move as they type, and a round trip per keystroke would make\n * the panel feel broken. So the client's maths stays as the **instant preview**, and this hook\n * supplies the **authoritative** figures — the same ones `createPlantingPlan` will persist.\n *\n * `preferServer` below is the whole contract: show the server's numbers the moment they arrive, and\n * the local estimate only until then. If the two ever disagree, the farmer sees the number that\n * will actually be written, which is the disagreement spec 02 §3.8 exists to end.\n *\n * Inline `gql` rather than an entry under `src/operations/`: this op is newer than the committed\n * `graphql/wspace.graphql` snapshot codegen validates against — the escape hatch documented in\n * `useSuccessionPlanning.ts`.\n *\n * @module healthybowl\n */\nimport { useEffect, useMemo, useState } from 'react';\nimport { gql } from '@apollo/client';\nimport { useQuery } from '@apollo/client/react';\nimport { useHealthyBowl } from '../context/HealthyBowlContext';\n\nexport interface PlantingCapacityFigures {\n areaSqm: number;\n cultivableAreaSqm: number;\n bedCount: number;\n bedLengthM: number;\n rowsPerBed: number;\n plantsPerRow: number;\n plantsPerBed: number;\n totalPlants: number;\n seedlingTarget: number;\n plantSpacingCm: number;\n rowSpacingCm: number;\n bedWidthM: number;\n pathWidthM: number;\n densityPlantsPerSqm: number;\n}\n\nexport interface SeedRateFigures {\n seedlingsToRaise: number;\n seedsNeeded: number;\n seedGrams: number | null;\n trays: number | null;\n}\n\nexport interface PlantingEstimate {\n appliesToBedGeometry: boolean;\n notApplicableReason: string | null;\n capacity: PlantingCapacityFigures | null;\n seedRate: SeedRateFigures | null;\n spacingPresetLabel: string;\n}\n\nconst PLANTING_ESTIMATE_QUERY = gql`\n query GetHealthyBowlPlantingEstimate($context: ContextInput!, $input: HealthyBowlPlantingEstimateInput!) {\n healthyBowlPlantingEstimate(context: $context, input: $input) {\n appliesToBedGeometry\n notApplicableReason\n spacingPresetLabel\n capacity {\n areaSqm\n cultivableAreaSqm\n bedCount\n bedLengthM\n rowsPerBed\n plantsPerRow\n plantsPerBed\n totalPlants\n seedlingTarget\n plantSpacingCm\n rowSpacingCm\n bedWidthM\n pathWidthM\n densityPlantsPerSqm\n }\n seedRate {\n seedlingsToRaise\n seedsNeeded\n seedGrams\n trays\n }\n }\n }\n`;\n\nexport interface PlantingEstimateArgs {\n fieldId?: string | null;\n plantCatalogId?: string | null;\n cropId?: string | null;\n /** Positive unsaved boundary area in the field unit; used only for the estimate read. */\n areaOverride?: number | null;\n plantSpacingCm?: number | null;\n rowSpacingCm?: number | null;\n bedWidthM?: number | null;\n pathWidthM?: number | null;\n}\n\n/** Drop nulls so an unset control does not override a catalog value with an explicit null. */\nfunction buildInput(args: PlantingEstimateArgs): Record<string, unknown> {\n const input: Record<string, unknown> = { fieldId: args.fieldId };\n const optional: [keyof PlantingEstimateArgs, unknown][] = [\n ['plantCatalogId', args.plantCatalogId],\n ['cropId', args.cropId],\n ['areaOverride', args.areaOverride],\n ['plantSpacingCm', args.plantSpacingCm],\n ['rowSpacingCm', args.rowSpacingCm],\n ['bedWidthM', args.bedWidthM],\n ['pathWidthM', args.pathWidthM],\n ];\n for (const [key, value] of optional) {\n if (value !== null && value !== undefined) input[key] = value;\n }\n return input;\n}\n\nfunction useDebouncedValue<T>(value: T, delayMs: number): T {\n const [debounced, setDebounced] = useState(value);\n\n useEffect(() => {\n const timer = window.setTimeout(() => setDebounced(value), delayMs);\n return () => window.clearTimeout(timer);\n }, [value, delayMs]);\n\n return debounced;\n}\n\nexport function usePlantingEstimate(args: PlantingEstimateArgs): {\n estimate: PlantingEstimate | null;\n loading: boolean;\n /** Network/GraphQL error. Caller can surface it without pretending a local preview was authoritative. */\n error: Error | undefined;\n /** True once the server has answered — the point at which its numbers replace the local ones. */\n ready: boolean;\n} {\n const { workspaceId } = useHealthyBowl();\n const context = useMemo(() => ({ workspaceId }), [workspaceId]);\n // Depends on the FIELDS, not on `args`: every caller passes an object literal, so a `[args]`\n // dependency compares a fresh reference each render and the memo never caches — which in turn\n // hands Apollo a new `variables` object every render.\n const input = useMemo(\n () => buildInput(args),\n // eslint-disable-next-line react-hooks/exhaustive-deps -- the fields ARE the identity of `args`.\n [\n args.fieldId,\n args.plantCatalogId,\n args.cropId,\n args.areaOverride,\n args.plantSpacingCm,\n args.rowSpacingCm,\n args.bedWidthM,\n args.pathWidthM,\n ]\n );\n\n const debouncedInput = useDebouncedValue(input, 250);\n const inputKey = JSON.stringify(input);\n const debouncedInputKey = JSON.stringify(debouncedInput);\n\n const { data, loading, error } = useQuery<{ healthyBowlPlantingEstimate: PlantingEstimate | null }>(\n PLANTING_ESTIMATE_QUERY,\n {\n variables: { context, input: debouncedInput },\n // Without a field there is nothing to estimate, and firing the query would only produce a\n // NOT_FOUND the page would have to swallow.\n skip: !args.fieldId,\n fetchPolicy: 'network-only',\n }\n );\n\n const estimate = data?.healthyBowlPlantingEstimate ?? null;\n // A slider change must stay on the local optimistic preview until its debounced server request\n // comes back. Otherwise Apollo's old data would masquerade as the answer for the new geometry.\n const ready = inputKey === debouncedInputKey && !loading && data !== undefined;\n return { estimate, loading, error, ready };\n}\n\n/**\n * Pick which figures to show.\n *\n * The server wins **the moment it answers**, including when its answer is `null`.\n *\n * That distinction is the whole point and the first version got it wrong. `serverValue ?? local`\n * cannot tell \"the server has not replied yet\" from \"the server replied `null`\" — and `null` is\n * exactly what a greenhouse, orchard or pasture returns, because bed geometry does not describe\n * them. Falling back to the local estimate there would print bed and seed counts for a greenhouse:\n * the precise failure the refusal exists to prevent, and worse than never having built it, since\n * the numbers would look authoritative.\n *\n * So readiness is passed explicitly rather than inferred from the value.\n */\nexport function preferServer<T>(ready: boolean, serverValue: T | null | undefined, localValue: T): T | null {\n if (!ready) return localValue;\n return serverValue ?? null;\n}\n"],"mappings":";;;;;AAyDA,IAAM,IAA0B,CAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CnC,SAAS,EAAW,GAAqD;CACvE,IAAM,IAAiC,EAAE,SAAS,EAAK,QAAQ,GACzD,IAAoD;EACxD,CAAC,kBAAkB,EAAK,cAAc;EACtC,CAAC,UAAU,EAAK,MAAM;EACtB,CAAC,gBAAgB,EAAK,YAAY;EAClC,CAAC,kBAAkB,EAAK,cAAc;EACtC,CAAC,gBAAgB,EAAK,YAAY;EAClC,CAAC,aAAa,EAAK,SAAS;EAC5B,CAAC,cAAc,EAAK,UAAU;CAChC;CACA,KAAK,IAAM,CAAC,GAAK,MAAU,GACzB,AAAI,KAAU,SAA6B,EAAM,KAAO;CAE1D,OAAO;AACT;AAEA,SAAS,EAAqB,GAAU,GAAoB;CAC1D,IAAM,CAAC,GAAW,KAAgB,EAAS,CAAK;CAOhD,OALA,QAAgB;EACd,IAAM,IAAQ,OAAO,iBAAiB,EAAa,CAAK,GAAG,CAAO;EAClE,aAAa,OAAO,aAAa,CAAK;CACxC,GAAG,CAAC,GAAO,CAAO,CAAC,GAEZ;AACT;AAEA,SAAgB,EAAoB,GAOlC;CACA,IAAM,EAAE,mBAAgB,EAAe,GACjC,IAAU,SAAe,EAAE,eAAY,IAAI,CAAC,CAAW,CAAC,GAIxD,IAAQ,QACN,EAAW,CAAI,GAErB;EACE,EAAK;EACL,EAAK;EACL,EAAK;EACL,EAAK;EACL,EAAK;EACL,EAAK;EACL,EAAK;EACL,EAAK;CACP,CACF,GAEM,IAAiB,EAAkB,GAAO,GAAG,GAC7C,IAAW,KAAK,UAAU,CAAK,GAC/B,IAAoB,KAAK,UAAU,CAAc,GAEjD,EAAE,SAAM,YAAS,aAAU,EAC/B,GACA;EACE,WAAW;GAAE;GAAS,OAAO;EAAe;EAG5C,MAAM,CAAC,EAAK;EACZ,aAAa;CACf,CACF;CAMA,OAAO;EAAE,UAJQ,GAAM,+BAA+B;EAInC;EAAS;EAAO,OADrB,MAAa,KAAqB,CAAC,KAAW,MAAS,KAAA;CAC5B;AAC3C;AAgBA,SAAgB,EAAgB,GAAgB,GAAmC,GAAyB;CAE1G,OADK,IACE,KAAe,OADH;AAErB"}
@@ -3,7 +3,7 @@ import { useCallback as t, useMemo as n } from "react";
3
3
  import { gql as r } from "@apollo/client";
4
4
  import { useMutation as i, useQuery as a } from "@apollo/client/react";
5
5
  //#region src/healthybowl/hooks/useSuccessionPlanning.ts
6
- var o = "\n id\n cropId\n fieldId\n cropName\n season\n startDate\n sowDate\n status\n bedId\n plantCatalogId\n plantsNeeded\n seedGrams\n seedlingsToRaise\n successionGroupId\n successionIndex\n", s = r`
6
+ var o = "\n id\n cropId\n fieldId\n cropName\n season\n startDate\n sowDate\n status\n bedId\n plantCatalogId\n plantsNeeded\n seedGrams\n seedlingsToRaise\n density\n successionGroupId\n successionIndex\n", s = r`
7
7
  query HealthyBowlSuccessionPlans($context: ContextInput!) {
8
8
  getHealthyBowlCropsData(context: $context) {
9
9
  plantingPlans {
@@ -1 +1 @@
1
- {"version":3,"file":"useSuccessionPlanning.js","names":[],"sources":["../../../src/healthybowl/hooks/useSuccessionPlanning.ts"],"sourcesContent":["/**\n * Succession-planting data hook (roadmap I-6).\n *\n * The offline codegen doesn't type the succession/bed operations, so — mirroring\n * the raw-gql pattern used for the Master Plant List and field boundaries — these\n * are hand-written `gql` documents executed directly against the live gateway.\n *\n * Existing plans are read from `getHealthyBowlCropsData.plantingPlans` (the only\n * place plantingPlans is exposed) and filtered to this field client-side.\n * @module healthybowl\n */\nimport { useCallback, useMemo } from 'react';\nimport { gql } from '@apollo/client';\nimport { useMutation, useQuery } from '@apollo/client/react';\nimport { useHealthyBowl } from '../context/HealthyBowlContext';\n\n/** A planting plan row with the succession + seed-rate fields we care about. */\nexport interface SuccessionPlan {\n id: string;\n cropId?: string | null;\n fieldId?: string | null;\n cropName: string;\n season: string;\n startDate: string;\n sowDate?: string | null;\n status: string;\n bedId?: string | null;\n plantCatalogId?: string | null;\n plantsNeeded?: number | null;\n seedGrams?: number | null;\n seedlingsToRaise?: number | null;\n successionGroupId?: string | null;\n successionIndex?: number | null;\n}\n\n/** A bed on this field, for the optional succession bed selector. */\nexport interface FieldBed {\n id: string;\n name: string;\n}\n\n/** Input for a succession series (context is attached from the hook). */\nexport interface SuccessionInput {\n fieldId: string;\n bedId?: string | null;\n cropId?: string | null;\n plantCatalogId?: string | null;\n season?: string | null;\n year: number;\n startDate: string;\n intervalDays: number;\n count: number;\n plantsNeeded?: number | null;\n seedGrams?: number | null;\n seedlingsToRaise?: number | null;\n density?: number | null;\n notes?: string | null;\n}\n\nconst PLAN_FIELDS = `\n id\n cropId\n fieldId\n cropName\n season\n startDate\n sowDate\n status\n bedId\n plantCatalogId\n plantsNeeded\n seedGrams\n seedlingsToRaise\n successionGroupId\n successionIndex\n`;\n\nconst PLANS_QUERY = gql`\n query HealthyBowlSuccessionPlans($context: ContextInput!) {\n getHealthyBowlCropsData(context: $context) {\n plantingPlans {\n ${PLAN_FIELDS}\n }\n }\n }\n`;\n\nconst BEDS_QUERY = gql`\n query HealthyBowlBedsForSuccession($context: ContextInput!, $fieldId: ID) {\n healthyBowlBeds(context: $context, fieldId: $fieldId) {\n id\n name\n }\n }\n`;\n\nconst CREATE_SUCCESSION = gql`\n mutation CreateHealthyBowlSuccessionPlan($input: CreateHealthyBowlSuccessionPlanInput!) {\n createHealthyBowlSuccessionPlan(input: $input) {\n ${PLAN_FIELDS}\n }\n }\n`;\n\nconst DELETE_PLAN = gql`\n mutation DeleteHealthyBowlPlantingPlanFromSuccession($id: ID!, $context: ContextInput!) {\n deleteHealthyBowlPlantingPlan(id: $id, context: $context)\n }\n`;\n\ninterface PlansQueryData {\n getHealthyBowlCropsData: { plantingPlans: SuccessionPlan[] };\n}\ninterface BedsQueryData {\n healthyBowlBeds: FieldBed[];\n}\n\n/**\n * Loads succession plans + beds for one field and exposes create/delete helpers.\n * Only plans with a `successionGroupId` that belong to `fieldId` are returned,\n * already sorted by group then by succession index.\n */\nexport function useSuccessionPlanning(fieldId: string | undefined) {\n const { workspaceId } = useHealthyBowl();\n const context = { workspaceId };\n\n const {\n data: plansData,\n loading,\n error,\n refetch,\n } = useQuery<PlansQueryData>(PLANS_QUERY, {\n variables: { context },\n skip: !workspaceId,\n fetchPolicy: 'cache-and-network',\n notifyOnNetworkStatusChange: true,\n });\n\n const { data: bedsData } = useQuery<BedsQueryData>(BEDS_QUERY, {\n variables: { context, fieldId },\n skip: !workspaceId || !fieldId,\n fetchPolicy: 'cache-and-network',\n });\n\n const [createMutation] = useMutation(CREATE_SUCCESSION);\n const [deleteMutation] = useMutation(DELETE_PLAN);\n\n const successionPlans = useMemo(() => {\n const all = plansData?.getHealthyBowlCropsData?.plantingPlans ?? [];\n return all\n .filter((p) => p.fieldId === fieldId && p.successionGroupId != null)\n .sort((a, b) => {\n const group = String(a.successionGroupId).localeCompare(String(b.successionGroupId));\n if (group !== 0) return group;\n return (a.successionIndex ?? 0) - (b.successionIndex ?? 0);\n });\n }, [plansData, fieldId]);\n\n const createSuccession = useCallback(\n async (input: SuccessionInput): Promise<SuccessionPlan[]> => {\n const result = await createMutation({ variables: { input: { ...input, context } } });\n await refetch();\n const data = result.data as { createHealthyBowlSuccessionPlan?: SuccessionPlan[] } | null | undefined;\n return data?.createHealthyBowlSuccessionPlan ?? [];\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [createMutation, refetch, workspaceId]\n );\n\n const deletePlan = useCallback(\n async (id: string) => {\n await deleteMutation({ variables: { id, context } });\n await refetch();\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [deleteMutation, refetch, workspaceId]\n );\n\n return {\n successionPlans,\n beds: bedsData?.healthyBowlBeds ?? [],\n loading,\n error,\n refetch,\n createSuccession,\n deletePlan,\n };\n}\n"],"mappings":";;;;;AA2DA,IAAM,IAAc,6MAkBd,IAAc,CAAG;;;;UAIb,EAAY;;;;GAMhB,IAAa,CAAG;;;;;;;GAShB,IAAoB,CAAG;;;QAGrB,EAAY;;;GAKd,IAAc,CAAG;;;;;AAkBvB,SAAgB,EAAsB,GAA6B;CACjE,IAAM,EAAE,mBAAgB,EAAe,GACjC,IAAU,EAAE,eAAY,GAExB,EACJ,MAAM,GACN,YACA,UACA,eACE,EAAyB,GAAa;EACxC,WAAW,EAAE,WAAQ;EACrB,MAAM,CAAC;EACP,aAAa;EACb,6BAA6B;CAC/B,CAAC,GAEK,EAAE,MAAM,MAAa,EAAwB,GAAY;EAC7D,WAAW;GAAE;GAAS;EAAQ;EAC9B,MAAM,CAAC,KAAe,CAAC;EACvB,aAAa;CACf,CAAC,GAEK,CAAC,KAAkB,EAAY,CAAiB,GAChD,CAAC,KAAkB,EAAY,CAAW,GAE1C,IAAkB,SACV,GAAW,yBAAyB,iBAAiB,CAAC,GAE/D,QAAQ,MAAM,EAAE,YAAY,KAAW,EAAE,qBAAqB,IAAI,EAClE,MAAM,GAAG,MAAM;EACd,IAAM,IAAQ,OAAO,EAAE,iBAAiB,EAAE,cAAc,OAAO,EAAE,iBAAiB,CAAC;EAEnF,OADI,MAAU,KACN,EAAE,mBAAmB,MAAM,EAAE,mBAAmB,KADhC;CAE1B,CAAC,GACF,CAAC,GAAW,CAAO,CAAC,GAEjB,IAAmB,EACvB,OAAO,MAAsD;EAC3D,IAAM,IAAS,MAAM,EAAe,EAAE,WAAW,EAAE,OAAO;GAAE,GAAG;GAAO;EAAQ,EAAE,EAAE,CAAC;EAGnF,OAFA,MAAM,EAAQ,GACD,EAAO,MACP,mCAAmC,CAAC;CACnD,GAEA;EAAC;EAAgB;EAAS;CAAW,CACvC,GAEM,IAAa,EACjB,OAAO,MAAe;EAEpB,AADA,MAAM,EAAe,EAAE,WAAW;GAAE;GAAI;EAAQ,EAAE,CAAC,GACnD,MAAM,EAAQ;CAChB,GAEA;EAAC;EAAgB;EAAS;CAAW,CACvC;CAEA,OAAO;EACL;EACA,MAAM,GAAU,mBAAmB,CAAC;EACpC;EACA;EACA;EACA;EACA;CACF;AACF"}
1
+ {"version":3,"file":"useSuccessionPlanning.js","names":[],"sources":["../../../src/healthybowl/hooks/useSuccessionPlanning.ts"],"sourcesContent":["/**\n * Succession-planting data hook (roadmap I-6).\n *\n * The offline codegen doesn't type the succession/bed operations, so — mirroring\n * the raw-gql pattern used for the Master Plant List and field boundaries — these\n * are hand-written `gql` documents executed directly against the live gateway.\n *\n * Existing plans are read from `getHealthyBowlCropsData.plantingPlans` (the only\n * place plantingPlans is exposed) and filtered to this field client-side.\n * @module healthybowl\n */\nimport { useCallback, useMemo } from 'react';\nimport { gql } from '@apollo/client';\nimport { useMutation, useQuery } from '@apollo/client/react';\nimport { useHealthyBowl } from '../context/HealthyBowlContext';\n\n/** A planting plan row with the succession + seed-rate fields we care about. */\nexport interface SuccessionPlan {\n id: string;\n cropId?: string | null;\n fieldId?: string | null;\n cropName: string;\n season: string;\n startDate: string;\n sowDate?: string | null;\n status: string;\n bedId?: string | null;\n plantCatalogId?: string | null;\n plantsNeeded?: number | null;\n seedGrams?: number | null;\n seedlingsToRaise?: number | null;\n density?: number | null;\n successionGroupId?: string | null;\n successionIndex?: number | null;\n}\n\n/** A bed on this field, for the optional succession bed selector. */\nexport interface FieldBed {\n id: string;\n name: string;\n}\n\n/** Input for a succession series (context is attached from the hook). */\nexport interface SuccessionInput {\n fieldId: string;\n bedId?: string | null;\n cropId?: string | null;\n plantCatalogId?: string | null;\n season?: string | null;\n year: number;\n startDate: string;\n intervalDays: number;\n count: number;\n plantsNeeded?: number | null;\n seedGrams?: number | null;\n seedlingsToRaise?: number | null;\n density?: number | null;\n plantSpacingCm?: number | null;\n rowSpacingCm?: number | null;\n bedWidthM?: number | null;\n pathWidthM?: number | null;\n notes?: string | null;\n}\n\nconst PLAN_FIELDS = `\n id\n cropId\n fieldId\n cropName\n season\n startDate\n sowDate\n status\n bedId\n plantCatalogId\n plantsNeeded\n seedGrams\n seedlingsToRaise\n density\n successionGroupId\n successionIndex\n`;\n\nconst PLANS_QUERY = gql`\n query HealthyBowlSuccessionPlans($context: ContextInput!) {\n getHealthyBowlCropsData(context: $context) {\n plantingPlans {\n ${PLAN_FIELDS}\n }\n }\n }\n`;\n\nconst BEDS_QUERY = gql`\n query HealthyBowlBedsForSuccession($context: ContextInput!, $fieldId: ID) {\n healthyBowlBeds(context: $context, fieldId: $fieldId) {\n id\n name\n }\n }\n`;\n\nconst CREATE_SUCCESSION = gql`\n mutation CreateHealthyBowlSuccessionPlan($input: CreateHealthyBowlSuccessionPlanInput!) {\n createHealthyBowlSuccessionPlan(input: $input) {\n ${PLAN_FIELDS}\n }\n }\n`;\n\nconst DELETE_PLAN = gql`\n mutation DeleteHealthyBowlPlantingPlanFromSuccession($id: ID!, $context: ContextInput!) {\n deleteHealthyBowlPlantingPlan(id: $id, context: $context)\n }\n`;\n\ninterface PlansQueryData {\n getHealthyBowlCropsData: { plantingPlans: SuccessionPlan[] };\n}\ninterface BedsQueryData {\n healthyBowlBeds: FieldBed[];\n}\n\n/**\n * Loads succession plans + beds for one field and exposes create/delete helpers.\n * Only plans with a `successionGroupId` that belong to `fieldId` are returned,\n * already sorted by group then by succession index.\n */\nexport function useSuccessionPlanning(fieldId: string | undefined) {\n const { workspaceId } = useHealthyBowl();\n const context = { workspaceId };\n\n const {\n data: plansData,\n loading,\n error,\n refetch,\n } = useQuery<PlansQueryData>(PLANS_QUERY, {\n variables: { context },\n skip: !workspaceId,\n fetchPolicy: 'cache-and-network',\n notifyOnNetworkStatusChange: true,\n });\n\n const { data: bedsData } = useQuery<BedsQueryData>(BEDS_QUERY, {\n variables: { context, fieldId },\n skip: !workspaceId || !fieldId,\n fetchPolicy: 'cache-and-network',\n });\n\n const [createMutation] = useMutation(CREATE_SUCCESSION);\n const [deleteMutation] = useMutation(DELETE_PLAN);\n\n const successionPlans = useMemo(() => {\n const all = plansData?.getHealthyBowlCropsData?.plantingPlans ?? [];\n return all\n .filter((p) => p.fieldId === fieldId && p.successionGroupId != null)\n .sort((a, b) => {\n const group = String(a.successionGroupId).localeCompare(String(b.successionGroupId));\n if (group !== 0) return group;\n return (a.successionIndex ?? 0) - (b.successionIndex ?? 0);\n });\n }, [plansData, fieldId]);\n\n const createSuccession = useCallback(\n async (input: SuccessionInput): Promise<SuccessionPlan[]> => {\n const result = await createMutation({ variables: { input: { ...input, context } } });\n await refetch();\n const data = result.data as { createHealthyBowlSuccessionPlan?: SuccessionPlan[] } | null | undefined;\n return data?.createHealthyBowlSuccessionPlan ?? [];\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [createMutation, refetch, workspaceId]\n );\n\n const deletePlan = useCallback(\n async (id: string) => {\n await deleteMutation({ variables: { id, context } });\n await refetch();\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [deleteMutation, refetch, workspaceId]\n );\n\n return {\n successionPlans,\n beds: bedsData?.healthyBowlBeds ?? [],\n loading,\n error,\n refetch,\n createSuccession,\n deletePlan,\n };\n}\n"],"mappings":";;;;;AAgEA,IAAM,IAAc,wNAmBd,IAAc,CAAG;;;;UAIb,EAAY;;;;GAMhB,IAAa,CAAG;;;;;;;GAShB,IAAoB,CAAG;;;QAGrB,EAAY;;;GAKd,IAAc,CAAG;;;;;AAkBvB,SAAgB,EAAsB,GAA6B;CACjE,IAAM,EAAE,mBAAgB,EAAe,GACjC,IAAU,EAAE,eAAY,GAExB,EACJ,MAAM,GACN,YACA,UACA,eACE,EAAyB,GAAa;EACxC,WAAW,EAAE,WAAQ;EACrB,MAAM,CAAC;EACP,aAAa;EACb,6BAA6B;CAC/B,CAAC,GAEK,EAAE,MAAM,MAAa,EAAwB,GAAY;EAC7D,WAAW;GAAE;GAAS;EAAQ;EAC9B,MAAM,CAAC,KAAe,CAAC;EACvB,aAAa;CACf,CAAC,GAEK,CAAC,KAAkB,EAAY,CAAiB,GAChD,CAAC,KAAkB,EAAY,CAAW,GAE1C,IAAkB,SACV,GAAW,yBAAyB,iBAAiB,CAAC,GAE/D,QAAQ,MAAM,EAAE,YAAY,KAAW,EAAE,qBAAqB,IAAI,EAClE,MAAM,GAAG,MAAM;EACd,IAAM,IAAQ,OAAO,EAAE,iBAAiB,EAAE,cAAc,OAAO,EAAE,iBAAiB,CAAC;EAEnF,OADI,MAAU,KACN,EAAE,mBAAmB,MAAM,EAAE,mBAAmB,KADhC;CAE1B,CAAC,GACF,CAAC,GAAW,CAAO,CAAC,GAEjB,IAAmB,EACvB,OAAO,MAAsD;EAC3D,IAAM,IAAS,MAAM,EAAe,EAAE,WAAW,EAAE,OAAO;GAAE,GAAG;GAAO;EAAQ,EAAE,EAAE,CAAC;EAGnF,OAFA,MAAM,EAAQ,GACD,EAAO,MACP,mCAAmC,CAAC;CACnD,GAEA;EAAC;EAAgB;EAAS;CAAW,CACvC,GAEM,IAAa,EACjB,OAAO,MAAe;EAEpB,AADA,MAAM,EAAe,EAAE,WAAW;GAAE;GAAI;EAAQ,EAAE,CAAC,GACnD,MAAM,EAAQ;CAChB,GAEA;EAAC;EAAgB;EAAS;CAAW,CACvC;CAEA,OAAO;EACL;EACA,MAAM,GAAU,mBAAmB,CAAC;EACpC;EACA;EACA;EACA;EACA;CACF;AACF"}