# Function Definitions

## PHP Functions

### templ.php
1. `isAjaxRequest(): bool`
   - Detects AJAX mode via `X-Requested-With` header or `ajax` query parameter.
2. `resolveContentFile(string $page): string`
   - Maps a route key to a whitelisted fragment file path.
   - Returns empty string when route is not allowed or file is missing.
3. `renderErrorFragment(string $title, string $msg): string`
   - Returns standardized HTML fragment for request errors.

### sidebar.php
1. `navLink(string $page, string $label, string $icon, ?array $badge = null): string`
   - Returns one sidebar nav item with active-state support and optional badge.

### mainContent.php
1. `simulateExport(): void` (inline JS)
   - Demo export action that shows spinner and success toast.

### content2.php
1. `initChart(): void` (inner function in IIFE JS block)
   - Creates or re-creates Chart.js line chart on analytics canvas.
2. `generateReport(): void` (inline JS)
   - Demo report action that shows spinner and success toast.

## JavaScript Functions and Modules (assets/app.js)

### Module: ProgressBar
1. `set(pct)`
   - Updates width and visibility of top loading bar.
2. `start()`
   - Starts incremental progress animation.
3. `finish()`
   - Completes and fades out progress bar.
4. `fail()`
   - Completes with error color and resets.

### Module: Spinner
1. `show(msg = "Loading…")`
   - Displays overlay spinner and sets message.
2. `hide()`
   - Hides overlay spinner.
3. `showDelayed(msg = "Loading…")`
   - Delays spinner to avoid flicker for short operations.
4. `cancelDelayed()`
   - Cancels pending spinner and hides if visible.

### Module: Toast
1. `show(message, type = "info", duration = TOAST_DURATION)`
   - Renders dismissible toast and auto-removes after duration.

### Navigation Runtime
1. `loadContent(page, pushState = true, label = "")`
   - Fetches fragment HTML, injects content, updates history/title/breadcrumb/nav.
2. `window.App.navigate(page, label)`
   - Public wrapper to trigger AJAX route navigation.

### Internal Helpers
1. `_setActiveNav(page)`
   - Applies `.active` class to matching nav link and opens parent sub-nav.
2. `_updateScrollBtns()`
   - Toggles visibility of scroll top/bottom buttons.
3. `_initDynamicContent(container)`
   - Re-runs post-injection animations and behavior hooks.
4. `_capitalise(str)`
   - Converts camel-like route key into display text.
5. `_escapeHtml(str)`
   - Escapes text for safe HTML insertion.
6. `_buildErrorHTML(page, msg)`
   - Returns client-side fallback error fragment.
