<?php
session_start();
include('includes/config.php');

if (strlen($_SESSION['alogin']) == 0) {
    header('location:index.php');
    exit;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Import Students | Library System</title>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<link rel="icon" type="image/x-icon" href="../<?php echo $_SESSION['logo']; ?>">

<link href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">

<style>
.square-card { width: 100%; background-color: #f8f9fa; border: 1px solid #dee2e6; box-shadow: 0 4px 8px rgba(0,0,0,0.05); border-radius: 5px; }
.form-label { font-weight: 600; }
.flash-message { max-width: 300px; margin: 0 auto 15px; }
.main-content { margin-left: 180px; margin-top: 50px; padding: 20px; }
.header-line { color: #2258d5; font-size: 20px; font-weight: 600; margin-bottom: 20px; }
</style>
</head>
<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 mb-4">
            <div class="col-md-12">
                <h5 class="header-line"><i class="fas fa-file-import mr-2"></i>Import Students</h5>
            </div>
        </div>

        <!-- Flash Messages -->
        <div class="row justify-content-center">
            <div class="col-md-8">
                <?php foreach (['error', 'msg'] as $type): ?>
                    <?php if(!empty($_SESSION[$type])): ?>
                        <div class="alert alert-<?php echo ($type == 'error') ? 'danger' : 'success'; ?> flash-message">
                            <strong><?php echo ucfirst($type); ?> :</strong> <?php echo htmlentities($_SESSION[$type]); ?>
                            <?php $_SESSION[$type] = ""; ?>
                        </div>
                    <?php endif; ?>
                <?php endforeach; ?>
            </div>
        </div>

        <!-- Import Form -->
        <div class="row justify-content-center" style="width:1000px;">
            <div class="col-md-8">
                <div class="card square-card mb-4">
                    <div class="card-header bg-secondary text-white">
                        <i class="fa fa-upload mr-2"></i> Import Students from Excel
                    </div>
                    <div class="card-body">
                        <form action="import_students_action.php" method="POST" enctype="multipart/form-data">
                            <div class="form-group">
                                <label for="excel_file" class="form-label">Select Excel File (.xlsx)</label>
                                <input type="file" name="excel_file" id="excel_file" class="form-control" accept=".xlsx" required>
                            </div>

                            <div class="d-flex justify-content-between">
                                <a href="reg-students.php" class="btn btn-secondary">
                                    <i class="fas fa-arrow-left"></i> Back to Students
                                </a>
                                <button type="submit" name="import" class="btn btn-success">
                                    <i class="fas fa-file-import"></i> Import Students
                                </button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>

    </div>
</div>

<?php include('includes/footer.php'); ?>
<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>
</body>
</html>
