# Business Logic Model — packages-block (U3) ## Data flow ```mermaid sequenceDiagram box rgba(99,179,237,0.4) Browser participant V as Visitor participant PS as PackagesSection participant HK as usePackageFilter end box rgba(154,230,180,0.4) CMS API participant A as offerings end PS->>A: GET offerings A-->>PS: package array PS->>HK: split and derive chips HK-->>PS: cards, chips, banner V->>PS: choose a chip PS->>HK: set active chip HK-->>PS: filtered cards V->>PS: click Kies button PS->>PS: set preselect and scroll to contact ``` Text alternative: the section loads the offerings, the filter hook splits cards and banner and derives chips, a chip choice filters the cards, and a Kies button sets the contact preselect and scrolls. ## Pure functions (unit-testable, `src/shared/packages/`) - `splitPackages(packages, bannerSlugs) -> { cards, banners }` - `deriveChips(cards, threshold) -> Chip[] | null` (null = no chips) - `filterCards(cards, activeId) -> PackageCardData[]` - `resultLabel(count, hasBanner) -> string` ("1 pakket ...", "3 pakketten ...") - `initialIndex(visible) -> number` (index of the featured card, else 0) - `activeIndexFromScroll(scrollLeft, itemWidths|itemOffsets, viewportWidth) -> number` (nearest snap position) ## Hooks - `usePackageFilter(packages, settings)`: state `activeId`; returns `{ cards, banners, chips, activeId, setActive, visible, label }`; resets `activeId` to `all` when the chosen category disappears. - `useSwipeRow(itemCount, initialIndex)`: returns `{ ref, activeIndex, scrollToIndex }`; on mount and when `itemCount`/filter key changes scrolls to `initialIndex` (instant); listens to `scroll` (throttled by `requestAnimationFrame`) to update `activeIndex`; uses `scrollTo({behavior})` with `smooth` unless reduced motion. - `useContactPreselect` (context from U3, consumed by U4): `{ subject, key, select(subject) }`. ## Error handling - API error: error state with retry (`refetch`); loading: skeletons; empty list: info text. - Unknown/absent `category`: package only under "Alles". - `bannerSlugs` containing an unknown slug: fallback banner from settings. - No `ResizeObserver`/`IntersectionObserver` required (scroll event + offsets); jsdom-safe.