import { View } from "../core/base/view"; import { Libs } from "../utils/libs"; import type { GroupViewTags, GroupViewResult, } from "../types/views/view.group.type"; import { SelectiveOptions } from "../types/utils/selective.type"; /** * GroupView * * View implementation for rendering grouped collections of selectable items. * * ### Responsibility * - Renders a semantic group structure: header (label) + items container. * - Manages group-level visibility based on child item state. * - Supports collapse/expand interactions with accessibility annotations. * - Provides typed access to DOM structure via {@link view}. * * ### Structure * ``` * GroupView (root) * ├─ GroupHeader (label, role="presentation") * └─ GroupItems (container, role="group") * ``` * * ### Lifecycle (View-based FSM) * - **Construction**: Accepts parent container, transitions `NEW → INITIALIZED`. * - **{@link mount}**: Creates DOM structure, appends to parent, transitions `INITIALIZED → MOUNTED`. * - **{@link update}**: Refreshes group header label, transitions `MOUNTED → UPDATED → MOUNTED`. * - **{@link destroy}**: Removes DOM nodes, transitions to `DESTROYED`. * * ### Visibility semantics * - {@link updateVisibility} hides the entire group when all child items are hidden. * - Checks for `"hide"` class on children (does not inspect `display` or `visibility` styles). * * ### Accessibility * - Root container: `role="group"`, `aria-labelledby` points to header. * - Header: `role="presentation"`, unique ID for labeling. * - Items container: `role="group"` (nested group). * - Collapse state: `aria-expanded` attribute on header (managed by {@link setCollapsed}). * * ### DOM side effects * - {@link mount} creates and appends DOM structure. * - {@link updateLabel} mutates header `textContent`. * - {@link setCollapsed} toggles CSS classes and ARIA attributes. * - {@link updateVisibility} toggles `"hide"` class on root. * * ### No-op / Idempotency * - {@link updateLabel}, {@link updateVisibility}, {@link setCollapsed} are no-ops if not mounted (early return guards). * - Safe to call multiple times without side effects beyond DOM state updates. * * @extends View * @template GroupViewTags - Type descriptor for the group's DOM structure. * @see {@link GroupViewResult} * @see {@link View} */ export class GroupView extends View { /** * Strongly-typed reference to the mounted group view structure. * * Structure: * - **view**: Root container element. * - **tags**: Named references to header and items container. * * Lifecycle: * - `null` until {@link mount} completes. * - Cleared during {@link destroy}. * * @public */ public view?: GroupViewResult; /** * Parsed configuration (bound from the `