<?php
include 'includes/header.php';
include 'includes/sidebar.php';

$teacher_id = $_SESSION['teacher_id'];

// Summary Data
$total_classes = $pdo->prepare("SELECT COUNT(*) FROM live_classes WHERE teacher_id = ?");
$total_classes->execute([$teacher_id]);
$t_count = $total_classes->fetchColumn();

$upcoming = $pdo->prepare("SELECT COUNT(*) FROM live_classes WHERE teacher_id = ? AND class_date >= CURDATE()");
$upcoming->execute([$teacher_id]);
$u_count = $upcoming->fetchColumn();

$current_date = date('d F Y, l');
?>

<style>
    .dashboard-header { background: #fff; padding: 20px 30px; border-radius: 15px; box-shadow: 0 5px 20px rgba(0,0,0,0.03); margin-bottom: 25px; border-left: 6px solid var(--theme-green); }
    .stat-card { background: #fff; padding: 25px; border-radius: 20px; box-shadow: 0 10px 30px rgba(0,0,0,0.03); border-top: 5px solid var(--theme-green); transition: 0.3s; height: 100%; }
    .stat-card:hover { transform: translateY(-5px); }
    .icon-box { width: 55px; height: 55px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 22px; margin-bottom: 15px; }
    
    /* Square Menu Button Fix */
    #sidebarToggle { width: 42px !important; height: 42px !important; padding: 0; display: inline-flex !important; align-items: center; justify-content: center; flex-shrink: 0; border-radius: 8px; border: 1px solid #e2e8f0; background: #fff; }
    
    @media (max-width: 991px) {
        .dashboard-header { flex-direction: column; align-items: flex-start !important; gap: 15px; padding: 15px 20px; }
        .dashboard-header .d-flex { width: 100%; align-items: center; }
    }
</style>

<div class="main-content">
    <div class="container-fluid">
        <div class="dashboard-header d-flex justify-content-between align-items-center fade-up">
            <div class="d-flex align-items-center">
                <button class="btn btn-light d-lg-none me-3 shadow-sm" id="sidebarToggle">
                    <i class="fas fa-bars text-dark"></i>
                </button>
                <div>
                    <h4 class="mb-0 fw-bold text-dark">Welcome, <?= htmlspecialchars($_SESSION['teacher_name']) ?>!</h4>
                    <p class="text-muted small mb-0 fw-bold d-none d-md-block">Manage your live sessions and students efficiently.</p>
                </div>
            </div>
            <div class="text-end">
                <span class="badge bg-light text-dark border px-3 py-2 rounded-pill fw-bold" style="font-size: 12px;">
                    <i class="far fa-calendar-alt me-2" style="color: var(--theme-gold);"></i> <?= $current_date ?>
                </span>
            </div>
        </div>

        <div class="row g-4 fade-up" style="animation-delay: 0.1s;">
            <div class="col-md-4">
                <div class="stat-card">
                    <div class="icon-box" style="background: rgba(6, 78, 59, 0.08); color: var(--theme-green);"><i class="fas fa-chalkboard-teacher"></i></div>
                    <h2 class="fw-bold mb-1" style="color: var(--theme-dark);"><?= sprintf("%02d", $t_count) ?></h2>
                    <p class="text-muted fw-bold small text-uppercase mb-0">Total Classes</p>
                </div>
            </div>
            <div class="col-md-4">
                <div class="stat-card" style="border-top-color: var(--theme-gold);">
                    <div class="icon-box" style="background: rgba(212, 175, 55, 0.1); color: var(--theme-gold);"><i class="fas fa-video"></i></div>
                    <h2 class="fw-bold mb-1" style="color: var(--theme-dark);"><?= sprintf("%02d", $u_count) ?></h2>
                    <p class="text-muted fw-bold small text-uppercase mb-0">Upcoming Sessions</p>
                </div>
            </div>
            <div class="col-md-4">
                <div class="stat-card" style="border-top-color: #3b82f6;">
                    <div class="icon-box" style="background: rgba(59, 130, 246, 0.08); color: #3b82f6;"><i class="fas fa-user-graduate"></i></div>
                    <h2 class="fw-bold mb-1" style="color: var(--theme-dark);">00</h2>
                    <p class="text-muted fw-bold small text-uppercase mb-0">Active Students</p>
                </div>
            </div>
        </div>

        <div class="mt-5 fade-up" style="animation-delay: 0.2s;">
            <h5 class="fw-bold mb-3 text-dark"><i class="fas fa-clock me-2" style="color: var(--theme-green);"></i> Today's Schedule</h5>
            <div class="card border-0 shadow-sm rounded-4 p-5 text-center">
                <div class="py-4">
                    <i class="fas fa-calendar-day fa-3x mb-3" style="color: #cbd5e1;"></i>
                    <h6 class="text-muted fw-bold">No classes scheduled for today.</h6>
                    <p class="small text-muted mb-0">Check the 'Live Classes' section to add or manage your sessions.</p>
                </div>
            </div>
        </div>
    </div>
</div>

<?php include 'includes/footer.php'; ?>