<?php
session_start();
error_reporting(0);
include('includes/config.php');
date_default_timezone_set('Asia/Kolkata');
// Check if student is logged in
if (strlen($_SESSION['login']) == 0) {
    header('location:index.php');
} else {
    ?>
    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">

    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
        <link rel="icon" type="image/x-icon" href="<?php echo $_SESSION['logo']; ?>">
        <title>Online Library Management System | Student Dashboard</title>
        <!-- <link href="assets/css/bootstrap.css" rel="stylesheet" /> -->
        <!-- <link href="assets/css/font-awesome.css" rel="stylesheet" /> -->
        <!-- <link href="assets/css/style.css" rel="stylesheet" /> -->
        <link href='http://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css' />
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css">
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" />
    </head>
    <style>
        /* Main content area */
        .main-content {
            margin-left: 180px;
            margin-top: 50px;
            padding: 20px;
        }

        /* Dashboard wrapper */
        .dashboard-wrapper {
            max-width: 1100px;
            margin: 30px auto;
            padding: 30px;
            background: linear-gradient(135deg, #f8f9fa, #e3f2fd);
            border-radius: 20px;
            box-shadow: 0 12px 30px rgba(0, 0, 0, 0.1);
        }

        /* Card styles */
        .info-card {
            background-color: #ffffff;
            border-radius: 15px;
            box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
            transition: 0.3s ease;
            padding: 20px;
        }

        .info-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 12px 30px rgba(0, 0, 0, 0.15);
            cursor: pointer;
        }

        /* Border styles */
        .border-left-primary {
            border-left: 5px solid #007bff;
        }

        .border-left-danger {
            border-left: 5px solid #dc3545;
        }

        .border-left-success {
            border-left: 5px solid #28a745;
        }

        /* Card headings */
        .info-card h6 {
            text-transform: uppercase;
            font-size: 14px;
            color: #555;
            margin-top: 10px;
        }

        .info-card h3 {
            font-size: 2rem;
            font-weight: 600;
            color: #333;
        }

        /* Title heading */
        .col-md-12 h5 {
            color: #0d6efd;
            font-size: 20px;
        }

        /* Carousel responsiveness */
        @media (max-width: 768px) {
            #carousel-example {
                display: none;
            }
        }
    </style>

    <body>
        <div class="d-flex flex-column min-vh-100">
            <?php include('includes/header.php'); ?>

            <div class="main-content flex-grow-1">
                <div class="row pad-botm mb-4">
                    <div class="col-md-12">
                        <h5 class="header-line">STUDENT DASHBOARD</h5>
                    </div>
                </div>

                <div class="row">
                    <!-- Books Issued -->
                    <div class="col-md-4 mb-4">
                        <a href="my-profile.php" style="text-decoration:none; color:inherit;">
                            <div class="info-card border-left-primary text-center">
                                <i class="fa fa-user fa-4x text-primary"></i>
                                <h6>MY PROFILE</h6>
                            </div>
                        </a>
                    </div>

                    <!-- Books Not Returned -->
                    <?php
                    $sid = $_SESSION['stdid'];

                    $sql2 = "SELECT id 
         FROM tblissuedbookdetails 
         WHERE BorrowerID = :sid 
         AND BorrowerType = 'student'
         AND ReturnDate IS NULL";

                    $query2 = $dbh->prepare($sql2);
                    $query2->bindParam(':sid', $sid, PDO::PARAM_INT);
                    $query2->execute();

                    $notReturned = $query2->rowCount();
                    ?>

                    <div class="col-md-4 mb-4">
                        <a href="issued-books.php" style="text-decoration:none; color:inherit;">
                            <div class="info-card border-left-danger text-center">
                                <div class="position-relative d-inline-block">
                                    <i class="fas fa-bell fa-4x text-danger"></i>
                                    <span class="fw-bold h4 text-danger position-absolute top-0 start-100 translate-middle">
                                        <?php echo htmlentities($notReturned); ?>
                                    </span>
                                </div>

                                <h6>BOOKS NOT RETURNED: </h6>

                            </div>
                        </a>
                    </div>

                  
                </div>

                <!-- Optional carousel like admin dashboard -->
                <div class="container mt-4">
                    <div id="carousel-example" class="carousel slide" data-ride="carousel"
                        style="max-width: 900px; margin: auto; border-radius: 15px; overflow: hidden; box-shadow: 0 4px 16px rgba(0,0,0,0.1);">
                        <div class="carousel-inner">
                            <div class="carousel-item active">
                                <img class="d-block w-100" src="assets/img/l_img1.jpg" alt="Slide 1"
                                    style="height: 400px; object-fit: cover;">
                            </div>
                            <div class="carousel-item">
                                <img class="d-block w-100" src="assets/img/l_img2.jpg" alt="Slide 2"
                                    style="height: 400px; object-fit: cover;">
                            </div>
                            <div class="carousel-item">
                                <img class="d-block w-100" src="assets/img/l_img3.jpg" alt="Slide 3"
                                    style="height: 400px; object-fit: cover;">
                            </div>
                        </div>
                        <a class="carousel-control-prev" href="#carousel-example" role="button" data-slide="prev">
                            <span class="carousel-control-prev-icon" aria-hidden="true"></span>
                            <span class="sr-only">Previous</span>
                        </a>
                        <a class="carousel-control-next" href="#carousel-example" role="button" data-slide="next">
                            <span class="carousel-control-next-icon" aria-hidden="true"></span>
                            <span class="sr-only">Next</span>
                        </a>
                    </div>
                </div>
            </div>

            <?php include('includes/footer.php'); ?>
        </div>

        <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
        <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.bundle.min.js"></script>
        <script>
            document.addEventListener("visibilitychange", function () {
                if (document.visibilityState === "hidden") {
                    navigator.sendBeacon("auto-logout.php");
                }
            });
        </script>
    </body>

    </html>
<?php } ?>