"use client"
import { useState } from "react"
import {
ChevronLeft,
ChevronRight,
Plus,
LogOut,
Users,
DoorOpen,
Layers,
Crown,
Shield,
} from "lucide-react"
import type { Room } from "@/lib/types"
import type { User } from "@/lib/types"
import { getRoomColor } from "@/lib/room-theme"
import { addDays, isSameDay, startOfWeek, formatMonthYear } from "@/lib/date-utils"
interface SidebarProps {
rooms: Room[]
activeRoomId: number | null
onSelectRoom: (id: number | null) => void
selectedDate: Date
onSelectDate: (d: Date) => void
onCreateEvent: () => void
onCreateRoom: () => void
onJoinRoom: () => void
user: User | null
onLogout: () => void
onOpenAccountSettings: () => void
}
const WEEKDAY_MINI = ["S", "M", "T", "W", "T", "F", "S"]
function RoleBadge({ role }: { role: Room["role"] }) {
if (role === "owner")
return
if (role === "admin")
return
return null
}
export function Sidebar({
rooms,
activeRoomId,
onSelectRoom,
selectedDate,
onSelectDate,
onCreateEvent,
onCreateRoom,
onJoinRoom,
user,
onLogout,
onOpenAccountSettings,
}: SidebarProps) {
const [miniMonth, setMiniMonth] = useState(() => {
const d = new Date(selectedDate)
d.setDate(1)
return d
})
const weekStart = startOfWeek(selectedDate)
const weekEnd = addDays(weekStart, 6)
// Build mini-calendar grid for miniMonth.
const firstDay = new Date(miniMonth.getFullYear(), miniMonth.getMonth(), 1)
const offset = firstDay.getDay()
const daysInMonth = new Date(miniMonth.getFullYear(), miniMonth.getMonth() + 1, 0).getDate()
const cells: (Date | null)[] = []
for (let i = 0; i < offset; i++) cells.push(null)
for (let d = 1; d <= daysInMonth; d++) {
cells.push(new Date(miniMonth.getFullYear(), miniMonth.getMonth(), d))
}
const today = new Date()
const shiftMonth = (delta: number) => {
setMiniMonth((m) => new Date(m.getFullYear(), m.getMonth() + delta, 1))
}
const inSelectedWeek = (d: Date) => d >= weekStart && d <= weekEnd
return (
{/* Mini Calendar */}
{formatMonthYear(miniMonth)}
{WEEKDAY_MINI.map((day, i) => (
{day}
))}
{cells.map((date, i) => {
if (!date) return
const selected = isSameDay(date, selectedDate)
const isToday = isSameDay(date, today)
const highlightWeek = inSelectedWeek(date) && !selected
return (
)
})}
{/* Rooms */}
Rooms
{rooms.map((room) => {
const color = getRoomColor(room.id)
const active = activeRoomId === room.id
return (
)
})}
{rooms.length === 0 && (
No rooms yet. Create or join one to get started.
)}
{/* User footer */}
)
}