"use client" import type { ReactNode } from "react" import { useAuth } from "@/lib/auth-context" import { Button } from "@/components/ui/button" import { Avatar, AvatarFallback } from "@/components/ui/avatar" import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, DropdownMenuSub, DropdownMenuSubTrigger, DropdownMenuSubContent, DropdownMenuCheckboxItem, } from "@/components/ui/dropdown-menu" import { LogOut, User, Building2, Cpu } from "lucide-react" import { ModeToggle } from "@/components/mode-toggle" // Defines props for the AppShell component interface AppShellProps { children: ReactNode // React children to be rendered within the shell } // AppShell component provides the main layout structure for the application export function AppShell({ children }: AppShellProps) { // Access authentication context for user info, logout function, room data, and room update function const { user, logout, rooms, updateRooms } = useAuth() // Generates user initials for the avatar fallback const initials = user?.name ?.split(" ") .map((n) => n[0]) .join("") .toUpperCase() .slice(0, 2) || "" // Fallback to empty string if user name is not available return (
{/* Header section with sticky positioning, blur effect, and responsiveness */}
{/* Application logo and title */}
Elektronikschule IT-Support-Portal
{/* User actions and theme toggle */}
{/* Display user role for larger screens */}
{user?.role === "LEHRKRAFT" ? ( ) : ( )} {user?.role === "LEHRKRAFT" ? "Lehrkraft" : "Raumbetreuer"}
{/* Dropdown menu for user profile and settings */}

{user?.name}

{user?.email}

{/* Display user role in the dropdown */} {user?.role === "LEHRKRAFT" ? "Lehrkraft" : "Raumbetreuer"} {/* Room supervision management for 'RAUMBETREUER' role */} {user?.role === "RAUMBETREUER" && user.supervisedRooms && ( {user.supervisedRooms.length} Betreute Räume Räume verwalten {rooms.map((room) => { // Determine if the current room is supervised by the user const isChecked = user.supervisedRooms?.some((r) => r.id === room.id) ?? false return ( { const currentIds = user.supervisedRooms?.map((r) => r.id) || [] let newIds if (checked) { // Add room to supervised list newIds = [...currentIds, room.id] } else { // Remove room from supervised list newIds = currentIds.filter((id) => id !== room.id) } updateRooms(newIds) // Update the list of supervised rooms }} onSelect={(e) => e.preventDefault()} // Prevent closing dropdown on selection > {room.name} ) })} )} {/* Logout button */} Abmelden
{/* Theme toggle component */}
{/* Main content area */}
{children}
) }