# Admin extraction prep (refactor/extract-admin-v2)

## Block boundaries

- **app.js lines 2341–4614** = admin block (2,274 lines).
- **Start:** `function loadAdminUsers() {`
- **End:** closing `};` immediately before `function fetchAppNotice() {`

## Init deps defined in this block (must be exposed by runAdmin)

| Symbol | Used by runInit / app.js |
|--------|---------------------------|
| loadAdminGaAuditChecklist | runInit |
| bindAdminTabs | app.js ~2279 |
| loadAdminUsers | app.js ~2199 |
| switchAdminTab | app.js ~2204 |
| loadAdminSettings | app.js (inside block) |
| ensureAdminMetricsPanel | app.js ~1786 |
| resetUserChecklist | runInit |
| resetUserInterviewContent | runInit |
| saveUserChecklistFromForm | runInit |
| saveUserInterviewContentFromForm | runInit |
| buildAdminGaAuditChecklistItemRowHtml | runInit (as buildAdminChecklistItemRowHtml) |
| buildAdminGaAuditChecklistSectionHtml | runInit (if passed) |
| buildAdminGuideStepRowHtml | used in block |

## buildAdmin* from app-admin.js (window)

The block calls `buildAdminChecklistSectionHtml`, `buildAdminThemeBlockHtml`, `buildAdminQuestionRowHtml`, `buildAdminChecklistItemRowHtml` (for implementation checklist). Those are provided by **js/app-admin.js** (window.buildAdmin*). The block also defines its own `buildAdminGaAuditChecklistItemRowHtml`, `buildAdminGaAuditChecklistSectionHtml`, `buildAdminGuideStepRowHtml`, `buildAdminResourcesSectionHtml`, `buildAdminResourcesLinkRowHtml`. So the **module** must expose the GA audit and guide step builders; the checklist/theme/question row builders can stay on window from app-admin.js.

## External refs the block needs from app.js (deps)

- supabaseClient, escapeHtml, showToast
- currentUserId, currentUserRole (get/set)
- getChecklistSections, getStoredProjects, getStoredChecks, getStoredTheme
- getValuedResources, getInterviewQuestionBank, getInterviewTemplates, getGuideTemplates
- PROMO_CONTENT, AI_HELP_PANELS, VALUED_RESOURCES (overrides/config)
- getCurrentSection, updatePromoSidebar, pathnameForSection
- fetchProfile, getAppPlans, fetchPlansFromDB, getResourceLinkIcon
- And more (discover by running and fixing reference errors, or by scanning block).

## Plan

1. **Create js/app-admin-run.js:** `Blueprint.admin.runAdmin(deps)` containing the block (lines 2341–4614), with a deps destructuring at the top for the known external refs.
2. **In app.js:** Remove lines 2341–4614. Before `window.__runAppInit = init`, call `Blueprint.admin.runAdmin(deps)` and assign the returned API to variables used by init and by call sites (bindAdminTabs, loadAdminUsers, switchAdminTab, ensureAdminMetricsPanel). Build the `deps` object for runAdmin from app.js scope.
3. **index.html:** Add `<script src="js/app-admin-run.js"></script>` before app.js (so Blueprint.admin.runAdmin exists when app.js runs).
