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

$teacher_id = $_SESSION['teacher_id'];

// টিচারের নিজের ক্লাসগুলো আনা
$query = "SELECT l.*, c.title as course_name 
          FROM live_classes l 
          JOIN courses c ON l.course_id = c.id 
          WHERE l.teacher_id = ? 
          ORDER BY l.class_date DESC, l.class_time DESC";
$stmt = $pdo->prepare($query);
$stmt->execute([$teacher_id]);
$classes = $stmt->fetchAll();
?>

<div class="main-content">
    <div class="container-fluid">
        <div class="d-flex justify-content-between align-items-center mb-4">
            <h4 class="fw-bold">আমার লাইভ ক্লাসসমূহ</h4>
            <a href="add_class.php" class="btn btn-success btn-sm rounded-pill px-4 shadow-sm">
                <i class="fas fa-plus me-1"></i> নতুন ক্লাস
            </a>
        </div>

        <div class="card border-0 shadow-sm rounded-4 overflow-hidden">
            <div class="table-responsive">
                <table class="table table-hover align-middle mb-0">
                    <thead class="bg-light">
                        <tr>
                            <th class="ps-4 py-3">Topic</th>
                            <th>Course</th>
                            <th>Schedule</th>
                            <th>Status</th>
                            <th class="text-center pe-4">Action</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach($classes as $row): ?>
                        <tr>
                            <td class="ps-4 fw-bold text-dark"><?= htmlspecialchars($row['topic']) ?></td>
                            <td><span class="badge bg-light text-dark border"><?= htmlspecialchars($row['course_name']) ?></span></td>
                            <td>
                                <div class="small fw-bold"><?= date('d M, Y', strtotime($row['class_date'])) ?></div>
                                <div class="small text-muted"><?= date('h:i A', strtotime($row['class_time'])) ?></div>
                            </td>
                            <td>
                                <span class="badge rounded-pill bg-<?= $row['status'] == 'live' ? 'danger' : ($row['status'] == 'completed' ? 'secondary' : 'success') ?> px-3">
                                    <?= strtoupper($row['status']) ?>
                                </span>
                            </td>
                            <td class="text-center pe-4">
                                <a href="<?= $row['meeting_link'] ?>" target="_blank" class="btn btn-sm btn-outline-primary rounded-pill px-3">
                                    <i class="fas fa-external-link-alt me-1"></i> Start
                                </a>
                            </td>
                        </tr>
                        <?php endforeach; ?>
                        <?php if(empty($classes)): ?>
                            <tr><td colspan="5" class="text-center py-5 text-muted">আপনার কোনো ক্লাস পাওয়া যায়নি।</td></tr>
                        <?php endif; ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

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