{"version":3,"names":["createMemo","createSignal","useBaseUiId","createStableCallback","EMPTY","Object","freeze","useCheckboxGroupParent","params","id","disabledStates","Map","uncontrolledState","value","status","setStatus","ownedWrite","onValueChange","checked","values","all","allValues","length","indeterminate","getParentProps","map","v","join","onCheckedChange","_next","details","currentUncontrolled","none","filter","get","includes","allEnabled","allOnOrOff","phase","getChildProps","childValue","nextChecked","nextValue","slice","push","idx","indexOf","splice"],"sources":["use-checkbox-group-parent.ts"],"sourcesContent":["import { type Accessor, createMemo, createSignal } from \"solid-js\";\nimport { useBaseUiId } from \"../internals/base-ui-id\";\nimport type {\n\tBaseUIChangeEventDetails,\n\tBaseUIEventReasons,\n} from \"../internals/change-event-details\";\nimport { createStableCallback } from \"../internals/stable-callback\";\n\ntype ParentChangeEventDetails = BaseUIChangeEventDetails<\n\tBaseUIEventReasons[\"none\"]\n>;\n\nexport interface UseCheckboxGroupParentParameters {\n\t/** All child values that participate in the parent-indicator math. */\n\tallValues: Accessor<readonly string[] | undefined>;\n\t/** Current group value (array of ticked child values). */\n\tvalue: Accessor<readonly string[] | undefined>;\n\t/** Group setter — invoked when the parent checkbox flips. */\n\tonValueChange: (next: string[], details: ParentChangeEventDetails) => void;\n}\n\n/**\n * Props the parent-checkbox consumer splats on `<Checkbox.Root parent>`. The\n * Solid port accepts them as a plain props bag (no accessors) because they're\n * consumed inside the checkbox-root's reactive scope — reads re-track on every\n * call.\n */\nexport interface UseCheckboxGroupParentParentProps {\n\tid: string;\n\tindeterminate: boolean;\n\tchecked: boolean;\n\t\"aria-controls\": string;\n\tonCheckedChange: (\n\t\tchecked: boolean,\n\t\tdetails: ParentChangeEventDetails,\n\t) => void;\n}\n\n/**\n * Props the per-child consumer splats on each non-parent `<Checkbox.Root>`.\n */\nexport interface UseCheckboxGroupParentChildProps {\n\tchecked: boolean;\n\tonCheckedChange: (\n\t\tchecked: boolean,\n\t\tdetails: ParentChangeEventDetails,\n\t) => void;\n}\n\nexport interface UseCheckboxGroupParentReturnValue {\n\t/** Stable id for the parent checkbox (used by `aria-controls`). */\n\tid: string;\n\t/** Whether the parent is currently indeterminate (mixed). */\n\tindeterminate: Accessor<boolean>;\n\t/** Whether the parent is fully checked (`value.length === allValues.length`). */\n\tchecked: Accessor<boolean>;\n\t/**\n\t * Plain mutable map of child value → disabled state. Populated by children\n\t * during setup so the parent's `onCheckedChange` math can skip disabled\n\t * entries (mirrors React's `disabledStatesRef`).\n\t */\n\tdisabledStates: Map<string, boolean>;\n\t/** Props factory for the parent checkbox. Call inside a reactive scope. */\n\tgetParentProps: () => UseCheckboxGroupParentParentProps;\n\t/** Props factory for a child checkbox keyed by its `value`. */\n\tgetChildProps: (childValue: string) => UseCheckboxGroupParentChildProps;\n}\n\nconst EMPTY: readonly string[] = Object.freeze([]);\n\n/**\n * \"Parent checkbox\" helper. Matches Base UI React's `useCheckboxGroupParent`.\n *\n * The parent checkbox reflects the aggregate of its children:\n *\n * - all children checked → parent is checked\n * - no children checked  → parent is unchecked\n * - mixed               → parent is indeterminate\n *\n * Clicking the parent cycles through all-on / all-off (with an uncontrolled\n * stash so the user's mixed state can be \"remembered\" when cycling back).\n * Clicking a child flips just that child and resets the parent cycle back to\n * `\"mixed\"`.\n *\n * Solid 2 adaptations:\n *\n * - `id` is generated once via `useBaseUiId`. Mirrors React's single-render\n *   id and stays stable for the component's lifetime.\n * - `indeterminate` / `checked` are derived via `createMemo` over the group\n *   value + `allValues` — no manual recomputation, no stale closures.\n * - `onValueChange` is wrapped in `createStableCallback` so the child/parent\n *   prop factories can be captured into closures without re-wiring.\n * - `disabledStates` is a plain `Map` (not a store / signal). Children push\n *   into it during setup — it's a coordination side-channel, not reactive\n *   state; the React port does the same via `disabledStatesRef`.\n * - `status` tracks the cycle phase (`\"on\" | \"off\" | \"mixed\"`). Declared\n *   with `ownedWrite: true` because the parent's `onCheckedChange` runs in\n *   owned scope (it's invoked from the checkbox-root's event handler chain\n *   which is itself called from inside a reactive merge proxy read — Solid\n *   doesn't mark event callbacks as unowned by default).\n * - `uncontrolledState` is a plain `let` binding (not a signal). It's a\n *   sticky last-seen \"mixed\" snapshot used for the cycle-back-to-mixed\n *   branch — no reactivity needed.\n */\nexport function useCheckboxGroupParent(\n\tparams: UseCheckboxGroupParentParameters,\n): UseCheckboxGroupParentReturnValue {\n\tconst id = useBaseUiId();\n\tconst disabledStates = new Map<string, boolean>();\n\n\t// Snapshot of the value at the time of the last child-driven change.\n\t// The parent's cycle uses this when returning to the \"mixed\" phase so the\n\t// user's custom mix is restored instead of losing it to the on/off cycle.\n\tlet uncontrolledState: readonly string[] = params.value() ?? EMPTY;\n\n\tconst [status, setStatus] = createSignal<\"on\" | \"off\" | \"mixed\">(\"mixed\", {\n\t\townedWrite: true,\n\t});\n\n\tconst onValueChange = createStableCallback<\n\t\t(next: string[], details: ParentChangeEventDetails) => void\n\t>(() => params.onValueChange);\n\n\tconst checked = createMemo((): boolean => {\n\t\tconst values = params.value() ?? EMPTY;\n\t\tconst all = params.allValues() ?? EMPTY;\n\t\treturn values.length === all.length && all.length > 0;\n\t});\n\n\tconst indeterminate = createMemo((): boolean => {\n\t\tconst values = params.value() ?? EMPTY;\n\t\tconst all = params.allValues() ?? EMPTY;\n\t\treturn values.length > 0 && values.length !== all.length;\n\t});\n\n\tfunction getParentProps(): UseCheckboxGroupParentParentProps {\n\t\tconst values = params.value() ?? EMPTY;\n\t\tconst all = params.allValues() ?? EMPTY;\n\t\treturn {\n\t\t\tid,\n\t\t\tindeterminate: indeterminate(),\n\t\t\tchecked: checked(),\n\t\t\t// TODO: custom `id` on child checkboxes breaks this — matches the\n\t\t\t// React port's known limitation (base-ui#2691).\n\t\t\t\"aria-controls\": all.map((v) => `${id}-${v}`).join(\" \"),\n\t\t\tonCheckedChange(_next, details) {\n\t\t\t\tconst currentUncontrolled = uncontrolledState;\n\n\t\t\t\t// None: disabled children that happen to be checked stay on.\n\t\t\t\tconst none = all.filter(\n\t\t\t\t\t(v) => disabledStates.get(v) && currentUncontrolled.includes(v),\n\t\t\t\t);\n\t\t\t\t// All: enabled children + disabled-but-checked children.\n\t\t\t\tconst allEnabled = all.filter(\n\t\t\t\t\t(v) =>\n\t\t\t\t\t\t!disabledStates.get(v) ||\n\t\t\t\t\t\t(disabledStates.get(v) && currentUncontrolled.includes(v)),\n\t\t\t\t);\n\n\t\t\t\tconst allOnOrOff =\n\t\t\t\t\tcurrentUncontrolled.length === allEnabled.length ||\n\t\t\t\t\tcurrentUncontrolled.length === 0;\n\n\t\t\t\tif (allOnOrOff) {\n\t\t\t\t\tif (values.length === allEnabled.length) {\n\t\t\t\t\t\tonValueChange(none, details);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tonValueChange(allEnabled, details);\n\t\t\t\t\t}\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst phase = status();\n\t\t\t\tif (phase === \"mixed\") {\n\t\t\t\t\tonValueChange(allEnabled, details);\n\t\t\t\t\tsetStatus(\"on\");\n\t\t\t\t} else if (phase === \"on\") {\n\t\t\t\t\tonValueChange(none, details);\n\t\t\t\t\tsetStatus(\"off\");\n\t\t\t\t} else {\n\t\t\t\t\t// \"off\" → restore the remembered mix.\n\t\t\t\t\tonValueChange([...currentUncontrolled], details);\n\t\t\t\t\tsetStatus(\"mixed\");\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\t}\n\n\tfunction getChildProps(childValue: string): UseCheckboxGroupParentChildProps {\n\t\tconst values = params.value() ?? EMPTY;\n\t\treturn {\n\t\t\tchecked: values.includes(childValue),\n\t\t\tonCheckedChange(nextChecked, details) {\n\t\t\t\tconst nextValue = values.slice();\n\t\t\t\tif (nextChecked) {\n\t\t\t\t\tnextValue.push(childValue);\n\t\t\t\t} else {\n\t\t\t\t\tconst idx = nextValue.indexOf(childValue);\n\t\t\t\t\tif (idx >= 0) nextValue.splice(idx, 1);\n\t\t\t\t}\n\t\t\t\tuncontrolledState = nextValue;\n\t\t\t\tonValueChange(nextValue, details);\n\t\t\t\tsetStatus(\"mixed\");\n\t\t\t},\n\t\t};\n\t}\n\n\treturn {\n\t\tid,\n\t\tindeterminate,\n\t\tchecked,\n\t\tdisabledStates,\n\t\tgetParentProps,\n\t\tgetChildProps,\n\t};\n}\n"],"mappings":"AAAA,SAAwBA,UAAU,EAAEC,YAAY,QAAQ,UAAU;AAClE,SAASC,WAAW,QAAQ,yBAAyB;AAKrD,SAASC,oBAAoB,QAAQ,8BAA8B;;AAenE;AACA;AACA;AACA;AACA;AACA;;AAYA;AACA;AACA;;AA4BA,MAAMC,KAAwB,GAAGC,MAAM,CAACC,MAAM,CAAC,EAAE,CAAC;;AAElD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,sBAAsBA,CACrCC,MAAwC,EACJ;EACpC,MAAMC,EAAE,GAAGP,WAAW,CAAC,CAAC;EACxB,MAAMQ,cAAc,GAAG,IAAIC,GAAG,CAAkB,CAAC;;EAEjD;EACA;EACA;EACA,IAAIC,iBAAoC,GAAGJ,MAAM,CAACK,KAAK,CAAC,CAAC,IAAIT,KAAK;EAElE,MAAM,CAACU,MAAM,EAAEC,SAAS,CAAC,GAAGd,YAAY,CAAyB,OAAO,EAAE;IACzEe,UAAU,EAAE;EACb,CAAC,CAAC;EAEF,MAAMC,aAAa,GAAGd,oBAAoB,CAExC,MAAMK,MAAM,CAACS,aAAa,CAAC;EAE7B,MAAMC,OAAO,GAAGlB,UAAU,CAAC,MAAe;IACzC,MAAMmB,MAAM,GAAGX,MAAM,CAACK,KAAK,CAAC,CAAC,IAAIT,KAAK;IACtC,MAAMgB,GAAG,GAAGZ,MAAM,CAACa,SAAS,CAAC,CAAC,IAAIjB,KAAK;IACvC,OAAOe,MAAM,CAACG,MAAM,KAAKF,GAAG,CAACE,MAAM,IAAIF,GAAG,CAACE,MAAM,GAA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