# State Ownership Map: Extracted Modules

This document outlines the proposed ownership of state variables once extracted from the monolithic `App.tsx`.

## 1. Auth Context (`useAuth`)
**Owner**: `src/contexts/AuthContext.tsx`
- `user`: Firebase User object.
- `isAuthReady`: Boolean indicating if auth state is loaded.

## 2. Business Context (`useBusiness`)
**Owner**: `src/contexts/BusinessContext.tsx`
- `businessState`: The primary `BusinessState` object (inventory, finances, collections, etc.).
- `tasks`: Array of `Task` objects.
- `messages`: Array of `Message` objects.
- `agents`: Array of `Agent` objects.
- `proposedActions`: Array of `ProposedAction` objects.
- `systemLogs`: Array of `SystemLog` objects.

### Associated Logic (to be moved to `useBusiness` hook):
- `addAsset`, `updateTask`, `addLog`, `resetApplication`, `saveProfile`, etc.
- Real-time Firestore sync logic (`onSnapshot`).

## 3. UI Context (`useUI`)
**Owner**: `src/contexts/UIContext.tsx`
- `activeTab`: Current navigation tab.
- `selectedAgentId`: Currently selected agent in workspace.
- `globalSearch`: Current search query.
- `selectedCollectionId`: Currently selected collection for detail view.
- `selectedInventoryId`: Currently selected inventory item.
- `selectedProspectId`: Currently selected prospect.
- `selectedWholesaleClient`: Currently selected wholesale client.
- `selectedAsset`: Currently selected asset for detail view.
- `selectedDate`: Currently selected date in planner.
- `currentMonth`, `currentYear`: Planner navigation state.

## 4. Feature-Specific State (Local to Components)
These states should live within their respective feature components or specialized hooks.

### Production (`useProduction`)
- `newItem`: State for adding inventory.
- `newSupply`: State for adding supplies.
- `newTask`: State for adding tasks.
- `newBatch`: State for adding batches.

### Marketing (`useMarketing`)
- `newCampaign`: State for adding campaigns.
- `newOutreach`: State for logging outreach.
- `newProspect`: State for adding prospects.
- `editingCampaignId`, `newBudgetAmount`: Campaign editing state.

### Finance (`useFinance`)
- `newTransaction`: State for adding transactions.
- `newWholesaleClient`: State for adding clients.
- `newWholesaleOrder`: State for adding orders.
- `costingRecipeId`, `costingIngredients`, `targetRetailPrice`: COGS calculator state.

### Studio (`useStudio`)
- `newAsset`: State for adding assets (recipes, marketing, etc.).
- `newProject`: State for adding collections/projects.
- `newDocument`: State for adding documents.
- `newEvent`: State for adding planner events.

### Calculators (Local State)
- `lyeCalc`: State for lye calculator.
- `fragranceCalc`: State for fragrance calculator.

---

## State Transition Plan
1. **Phase 1**: Create `AuthContext` and move user state.
2. **Phase 2**: Create `BusinessContext` and move the large `businessState` and its sync logic.
3. **Phase 3**: Create `UIContext` and move navigation and selection states.
4. **Phase 4**: Move feature-specific modal states and "new entity" forms into their respective feature components.
