'use client'; import React, { useState, useRef, useEffect } from 'react'; import { motion, AnimatePresence } from 'framer-motion'; import { cn } from '../utils/cn'; import { RocketIcon, ChartIcon, TrendingUpIcon, RobotIcon, SettingsIcon, } from '../components/icons'; // --- Types --- export interface NavItem { href: string; label: string; icon: React.ElementType; } export interface User { id: string; name?: string | null; email?: string | null; image?: string | null; } export interface Team { id: string; name: string; } export interface TeamMember { teamId: string; team: Team; } export interface PlatformShellProps { children: React.ReactNode; user: User | null; teams?: TeamMember[]; overallScore?: number | null; activePage?: string; pathname?: string; onNavigate?: (href: string) => void; onSignOut?: () => void; onSwitchTeam?: (teamId: string | 'personal') => void; logoUrl?: string; navItems?: NavItem[]; LinkComponent?: React.ElementType; } // --- Internal Components --- function NavItemComponent({ href, label, icon: Icon, isActive, onClick, LinkComponent = 'a', }: NavItem & { isActive: boolean; onClick?: (e: React.MouseEvent) => void; LinkComponent?: any; }) { const Component = LinkComponent; return (
{label} {isActive && ( )}
); } function UserMenu({ user, teams = [], currentTeamId, onSwitchTeam, onSignOut, }: { user: User; teams: TeamMember[]; currentTeamId: string | 'personal'; onSwitchTeam?: (teamId: string | 'personal') => void; onSignOut?: () => void; }) { const [isOpen, setIsOpen] = useState(false); const dropdownRef = useRef(null); useEffect(() => { function handleClickOutside(event: MouseEvent) { if ( dropdownRef.current && !dropdownRef.current.contains(event.target as Node) ) { setIsOpen(false); } } document.addEventListener('mousedown', handleClickOutside); return () => document.removeEventListener('mousedown', handleClickOutside); }, []); const currentWorkspaceName = currentTeamId === 'personal' ? 'Personal Workspace' : teams.find((t) => t.teamId === currentTeamId)?.team.name || 'Team Workspace'; return (
{isOpen && (

{user.name}

{user.email}

Workspaces

{teams.map((t) => ( ))}
)}
); } // --- Main Shell --- export function PlatformShell({ children, user, teams = [], overallScore, activePage, pathname = '', onNavigate, onSignOut, onSwitchTeam, logoUrl = '/logo-text-transparent-dark-theme.png', navItems = [ { href: '/dashboard', label: 'Dashboard', icon: RocketIcon }, { href: '/strategy', label: 'Scan Strategy', icon: SettingsIcon }, { href: '/trends', label: 'Trends Explorer', icon: TrendingUpIcon }, { href: '/map', label: 'Codebase Map', icon: RobotIcon }, { href: '/metrics', label: 'Methodology', icon: ChartIcon }, ], LinkComponent = 'a', }: PlatformShellProps) { const [currentTeamId, setCurrentTeamId] = useState( 'personal' ); const handleSwitchTeam = (teamId: string | 'personal') => { setCurrentTeamId(teamId); onSwitchTeam?.(teamId); }; const Sidebar = () => ( ); const Navbar = () => (

{activePage || 'Dashboard'}

{user && ( )}
); return (
{user && }
{user && }
{user && ( <>
)} {children}
); }