File size: 2,215 Bytes
e9d5b7d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55

import { ReactNode } from "react";
import Link from "next/link";
import { Shield, LogOut, Settings, Users, LayoutDashboardIcon, BarChart3 } from "lucide-react"; 
import { Button } from "@/components/ui/button";
import { getLoggedInUser } from "@/lib/actions/auth";
import { redirect } from 'next/navigation';

interface AdminLayoutProps {
  children: ReactNode;
}

export default async function AdminLayout({ children }: AdminLayoutProps) {
  const user = await getLoggedInUser();

  if (!user || user.role !== 'admin') {
    redirect('/admin/login');
  }

  return (
    <div className="flex min-h-screen">
      <aside className="w-64 bg-card border-r p-6 flex flex-col">
        <Link href="/admin/dashboard" className="flex items-center mb-8">
          <Shield className="h-8 w-8 text-primary" />
          <span className="ml-2 text-xl font-semibold text-foreground">Admin Panel</span>
        </Link>
        <nav className="flex flex-col space-y-2 flex-1">
          <Button variant="ghost" className="justify-start" asChild>
            <Link href="/admin/dashboard"><LayoutDashboardIcon className="mr-2 h-4 w-4" /> Dashboard</Link>
          </Button>
           <Button variant="ghost" className="justify-start" asChild>
            <Link href="/admin/stats"><BarChart3 className="mr-2 h-4 w-4" /> Statistics</Link>
          </Button>
          <Button variant="ghost" className="justify-start" asChild>
            <Link href="/admin/dashboard"><Users className="mr-2 h-4 w-4" /> User Management</Link>
          </Button>
          <Button variant="ghost" className="justify-start text-muted-foreground" disabled>
            <Settings className="mr-2 h-4 w-4" /> Site Settings
          </Button>
          {/* Add more admin navigation links here */}
        </nav>
        <div className="mt-auto">
          <Button variant="outline" className="w-full justify-start" asChild>
             {/* This should also call a logout function specific to admin if needed */}
            <Link href="/"><LogOut className="mr-2 h-4 w-4" /> Exit Admin</Link>
          </Button>
        </div>
      </aside>
      <main className="flex-1 p-8 bg-secondary">
        {children}
      </main>
    </div>
  );
}