import DashboardLayout from "@/components/DashboardLayout"
import { auth } from "@/lib/auth"
import { prisma } from "@/lib/prisma"

export default async function ShiftManagerDashboard() {
  const session = await auth()
  const manager = await prisma.shiftManager.findFirst({
    where: { email: session?.user?.email || "" }
  })

  if (!manager) return <div>Manager not found</div>

  const shiftsCount = await prisma.shift.count({
    where: { shiftManagerId: manager.id }
  })

  const activeShifts = await prisma.shift.count({
    where: { shiftManagerId: manager.id, status: "active" }
  })

  return (
    <DashboardLayout requiredRole="shift_manager">
      <div>
        <h1 className="text-3xl font-bold text-gray-800 mb-6">Shift Manager Dashboard</h1>
        <div className="grid grid-cols-1 md:grid-cols-3 gap-6">
          <div className="bg-white p-6 rounded-xl shadow-sm border border-gray-200">
            <div className="text-blue-600 text-3xl mb-2">🕐</div>
            <h3 className="text-gray-600 text-sm">Total Shifts</h3>
            <p className="text-2xl font-bold text-gray-800 mt-1">{shiftsCount}</p>
          </div>
          <div className="bg-white p-6 rounded-xl shadow-sm border border-gray-200">
            <div className="text-green-600 text-3xl mb-2">✓</div>
            <h3 className="text-gray-600 text-sm">Active Shifts</h3>
            <p className="text-2xl font-bold text-gray-800 mt-1">{activeShifts}</p>
          </div>
        </div>
      </div>
    </DashboardLayout>
  )
}
