<?php
    if($_SESSION['TipoUsuarioId'] != 1 && $_SESSION['TipoUsuarioId'] != 2){
        header("Location: " . URL_PATH . "/ViewData");
        exit();
    }
?>

<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <title>Importar CSV</title>
    <link rel="stylesheet" href="/UdLosesSubjects/public/colors.css">
    <link rel="stylesheet" href="/UdLosesSubjects/public/menu.css">
    <link rel="stylesheet" href="/UdLosesSubjects/public/app.css">
    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
    <?php require_once APP_PATH.'/utilities/sessions.php'; ?>
</head>
<body>
    <?php include APP_PATH . '/views/components/navbar.php'; ?>
    <div class="app-container">
        <h2 class="app-container">Importar estudiantes desde CSV</h2>
        <form class="app-form" action="<?php echo URL_PATH; ?>/UploadFile/send" method="post" enctype="multipart/form-data">
            <label for="csvFile">Seleccione archivo CSV:</label>
            <div class="custom-file-input">
                <input type="file" id="csvFile" name="csvFile" accept=".csv" required hidden>
                <label for="csvFile" id="csvFileLabel">Seleccionar archivo</label>
                <span id="csvFileName">Ningún archivo seleccionado</span>
            </div>
            <button type="submit">Subir y guardar</button>
        </form>
    </div>
    <?php
    if (isset($_GET['msg'])) {
        $msg = $_GET['msg'];
        $type = $_GET['type'];
        echo "<script>
            Swal.fire({
                icon: '$type',
                title: '". ($type === "success" ? "Éxito" : "Error") ."',
                text: '$msg'
            });
        </script>";
    }
    ?>
    <?php include APP_PATH . '/views/components/footer.php'; ?>
    <script>
    document.getElementById('csvFile').addEventListener('change', function(e) {
        const fileName = e.target.files.length ? e.target.files[0].name : 'Ningún archivo seleccionado';
        document.getElementById('csvFileName').textContent = fileName;
    });
    </script>
</body>
</html>
