import { useState, useEffect } from 'react' import { Outlet, useLocation } from 'react-router-dom' import InstSidebar from './InstSidebar' import InstControlPanel from './InstControlPanel' import { api } from '../../lib/api' import { useAuthStore } from '../../store/authStore' const ORG_THEMES = { bank: { primary: '#fbbc04', glow: 'rgba(251,188,4,0.08)', container: 'rgba(251,188,4,0.15)' }, sacco: { primary: '#10b981', glow: 'rgba(16,185,129,0.08)', container: 'rgba(16,185,129,0.15)' }, fintech: { primary: '#a855f7', glow: 'rgba(168,85,247,0.08)', container: 'rgba(168,85,247,0.15)' }, mfi: { primary: '#14b8a6', glow: 'rgba(20,184,166,0.08)', container: 'rgba(20,184,166,0.15)' }, insurer: { primary: '#ef4444', glow: 'rgba(239,68,68,0.08)', container: 'rgba(239,68,68,0.15)' }, } export default function InstAppShell() { const { user } = useAuthStore() const [sidebarCollapsed, setSidebarCollapsed] = useState(false) const [orgId, setOrgId] = useState(user?.orgId || 'bank') const [manifest, setManifest] = useState(null) const [selectedEntity, setSelectedEntity] = useState(null) const [entityContext, setEntityContext] = useState(null) const [loadingContext, setLoadingContext] = useState(false) const location = useLocation() const activeModule = location.pathname.split('/')[2] || 'risk' useEffect(() => { api.institutional.getManifest(orgId).then(d => setManifest(d)).catch(console.error) }, [orgId]) useEffect(() => { if (!selectedEntity) { setEntityContext(null); return } setLoadingContext(true) api.institutional.getEntityContext(selectedEntity) .then(d => { setEntityContext(d); setLoadingContext(false) }) .catch(() => setLoadingContext(false)) }, [selectedEntity]) const t = ORG_THEMES[orgId] || ORG_THEMES.bank return (