// app/admin/admin-client.tsx
'use client';
import React from 'react';
import { SidebarProvider, SidebarInset } from '@/components/ui/sidebar';
import { AppSidebar } from '@/components/app-sidebar';
import { SiteHeader } from '@/components/site-header';

import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
import { AdminNotifications } from '@/components/admin-notifications';

import { Button } from '@/components/ui/button';
import Link from 'next/link';
import {
  IconFileUpload,
  IconBooks,
  IconList,
  IconUsers,
  IconUsers as IconUsersManage,
  IconChartBar,
} from '@tabler/icons-react';

function AdminUI() {
  return (
    <div className="flex flex-col gap-6 py-4 md:gap-6 md:py-6 px-4 lg:px-16">
      <div>
        <h1 className="text-3xl font-bold tracking-tight mb-2">Admin Panel</h1>
        <p className="text-muted-foreground">
          Manage your users, courses, playlists, videos, and enrollments.
        </p>
      </div>

      <div className="grid grid-cols-1 lg:grid-cols-3 gap-6">
        <div className="lg:col-span-2">
          <div className="grid grid-cols-1 gap-4 md:grid-cols-2 lg:grid-cols-3">
        <Card className="hover:bg-accent cursor-pointer transition-colors">
          <CardHeader>
            <CardTitle className="flex items-center gap-2">
              <IconChartBar className="w-5 h-5" />
              Video Statistics
            </CardTitle>
          </CardHeader>
          <CardContent>
            <p className="text-sm text-muted-foreground mb-4">
              View video performance metrics and analytics.
            </p>
            <Link href="/admin/stats">
              <Button variant="outline" className="w-full">
                Go to Stats
              </Button>
            </Link>
          </CardContent>
        </Card>

        <Card className="hover:bg-accent cursor-pointer transition-colors">
          <CardHeader>
            <CardTitle className="flex items-center gap-2">
              <IconUsersManage className="w-5 h-5" />
              Manage Users
            </CardTitle>
          </CardHeader>
          <CardContent>
            <p className="text-sm text-muted-foreground mb-4">
              View users and their activity.
            </p>
            <Link href="/admin/users">
              <Button variant="outline" className="w-full">
                Go to Users
              </Button>
            </Link>
          </CardContent>
        </Card>

        <Card className="hover:bg-accent cursor-pointer transition-colors">
          <CardHeader>
            <CardTitle className="flex items-center gap-2">
              <IconBooks className="w-5 h-5" />
              Manage Courses
            </CardTitle>
          </CardHeader>
          <CardContent>
            <p className="text-sm text-muted-foreground mb-4">
              Create and manage courses.
            </p>
            <Link href="/admin/courses">
              <Button variant="outline" className="w-full">
                Go to Courses
              </Button>
            </Link>
          </CardContent>
        </Card>

        <Card className="hover:bg-accent cursor-pointer transition-colors">
          <CardHeader>
            <CardTitle className="flex items-center gap-2">
              <IconList className="w-5 h-5" />
              Manage Playlists
            </CardTitle>
          </CardHeader>
          <CardContent>
            <p className="text-sm text-muted-foreground mb-4">
              Create and manage playlists.
            </p>
            <Link href="/admin/playlists">
              <Button variant="outline" className="w-full">
                Go to Playlists
              </Button>
            </Link>
          </CardContent>
        </Card>

        <Card className="hover:bg-accent cursor-pointer transition-colors">
          <CardHeader>
            <CardTitle className="flex items-center gap-2">
              <IconFileUpload className="w-5 h-5" />
              Manage Videos
            </CardTitle>
          </CardHeader>
          <CardContent>
            <p className="text-sm text-muted-foreground mb-4">
              Upload and manage videos.
            </p>
            <Link href="/admin/videos">
              <Button variant="outline" className="w-full">
                Go to Videos
              </Button>
            </Link>
          </CardContent>
        </Card>

        <Card className="hover:bg-accent cursor-pointer transition-colors">
          <CardHeader>
            <CardTitle className="flex items-center gap-2">
              <IconUsers className="w-5 h-5" />
              Manage Enrollments
            </CardTitle>
          </CardHeader>
          <CardContent>
            <p className="text-sm text-muted-foreground mb-4">
              Manage user enrollments.
            </p>
            <Link href="/admin/enrollments">
              <Button variant="outline" className="w-full">
                Go to Enrollments
              </Button>
            </Link>
          </CardContent>
        </Card>

        <Card className="hover:bg-accent cursor-pointer transition-colors">
          <CardHeader>
            <CardTitle className="flex items-center gap-2">
              <IconUsersManage className="w-5 h-5" />
              Allowed Students
            </CardTitle>
          </CardHeader>
          <CardContent>
            <p className="text-sm text-muted-foreground mb-4">
              Manage whitelisted student access.
            </p>
            <Link href="/admin/allowed-students">
              <Button variant="outline" className="w-full">
                Go to Students
              </Button>
            </Link>
          </CardContent>
        </Card>
          </div>
        </div>

        <div className="lg:col-span-1">
          <Card>
            <CardHeader>
              <CardTitle>Activity Feed</CardTitle>
            </CardHeader>
            <CardContent>
              <AdminNotifications />
            </CardContent>
          </Card>
        </div>
      </div>
    </div>
  );
}

export default function AdminClient() {
  return (
    <SidebarProvider
      style={
        {
          '--sidebar-width': 'calc(var(--spacing) * 72)',
          '--header-height': 'calc(var(--spacing) * 12)',
        } as React.CSSProperties
      }
    >
      <AppSidebar variant="inset" />
      <SidebarInset>
        <SiteHeader />
        <div className="flex flex-1 flex-col">
          <div className="@container/main flex flex-1 flex-col gap-2">
            <div className="flex flex-col gap-4 py-4 md:gap-6 md:py-6">
              <AdminUI />
            </div>
          </div>
        </div>
      </SidebarInset>
    </SidebarProvider>
  );
}
