"use client";
import React from "react";
import Link from "next/link";
import { useAuth } from "@/hooks/useAuth";
import { RoleBadge } from "@/components/shared/RoleBadge";
import { useRouter, usePathname } from "next/navigation";
const navLinks: { href: string; label: string; roles?: string[] }[] = [
{ href: "/dashboard/user", label: "My Events", roles: ["user", "staff", "supervisor", "admin"] },
{ href: "/dashboard/user/profile", label: "Profile & Security", roles: ["user", "staff", "supervisor", "admin"] },
{ href: "/dashboard/staff", label: "Staff", roles: ["staff"] },
{ href: "/dashboard/supervisor", label: "Supervisor", roles: ["supervisor"] },
{ href: "/dashboard/admin", label: "Admin", roles: ["admin"] },
{ href: "/dashboard/admin/settings", label: "Site Settings", roles: ["admin"] }
];
export function Sidebar() {
const { user } = useAuth();
const role = user?.role || "user";
return (
);
}
export function MobileSidebar() {
const { user } = useAuth();
const router = useRouter();
const role = user?.role || "user";
const pathname = usePathname();
const options = navLinks.filter((l) => !l.roles || l.roles.includes(role));
// Determine selected value based on current path or default by role
// Use longest matching href to handle nested paths (e.g. /dashboard/user/profile over /dashboard/user)
const selectedFromPath = options
.filter((o) => pathname?.startsWith(o.href))
.sort((a, b) => b.href.length - a.href.length)[0]?.href;
const roleDefault: Record = {
admin: "/dashboard/admin",
supervisor: "/dashboard/supervisor",
staff: "/dashboard/staff",
user: "/dashboard/user",
};
const selectedValue = selectedFromPath || roleDefault[role] || options[0]?.href || "";
const handleChange = (e: React.ChangeEvent) => {
const value = e.target.value;
if (value && value !== selectedValue) router.push(value);
};
return (
Dashboard
{user && (
{user.name}
)}
);
}