<?php
declare(strict_types=1);

/*
|--------------------------------------------------------------------------
| Teacher Login
|--------------------------------------------------------------------------
*/

require_once __DIR__ . '/../includes/config.php';
require_once __DIR__ . '/../includes/db.php';
require_once __DIR__ . '/../includes/functions.php';
require_once __DIR__ . '/../includes/teacher-auth.php';

$pdo = db();

$error = '';

if (isPost()) {

    requirePostCsrf();

    $email =
        trim($_POST['email'] ?? '');

    $password =
        trim($_POST['password'] ?? '');

    if (
        teacherLogin(
            $pdo,
            $email,
            $password
        )
    ) {

        redirectTo(
            'teacher/dashboard.php'
        );

    } else {

        $error =
            'Invalid login credentials.';
    }
}

?>

<!DOCTYPE html>
<html lang="en">

<head>

<meta charset="UTF-8">

<meta
name="viewport"
content="width=device-width, initial-scale=1.0">

<title>
Teacher Login
</title>

<link
href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&display=swap"
rel="stylesheet">

<style>

*{
    margin:0;
    padding:0;
    box-sizing:border-box;
}

body{

    font-family:'Inter',sans-serif;

    background:
    linear-gradient(
        135deg,
        #0f172a,
        #1d4ed8
    );

    min-height:100vh;

    display:flex;

    align-items:center;

    justify-content:center;

    padding:25px;
}

.card{

    width:100%;
    max-width:520px;

    background:#fff;

    border-radius:34px;

    padding:45px;

    box-shadow:
    0 35px 80px rgba(0,0,0,0.20);
}

.logo{

    text-align:center;

    margin-bottom:28px;
}

.logo h1{

    font-size:40px;

    color:#2563eb;

    margin-bottom:10px;

    font-weight:900;
}

.logo p{

    color:#64748b;

    line-height:1.9;
}

.error{

    background:#fef2f2;

    color:#dc2626;

    padding:18px;

    border-radius:18px;

    margin-bottom:22px;

    font-weight:700;
}

.group{

    margin-bottom:22px;
}

.group label{

    display:block;

    margin-bottom:10px;

    color:#0f172a;

    font-weight:800;
}

.group input{

    width:100%;

    padding:18px;

    border-radius:18px;

    border:1px solid #dbeafe;

    background:#fff;

    font-size:15px;
}

.group input:focus{

    outline:none;

    border-color:#2563eb;

    box-shadow:
    0 0 0 5px rgba(37,99,235,0.10);
}

.btn{

    width:100%;

    border:none;

    background:
    linear-gradient(
        135deg,
        #2563eb,
        #1d4ed8
    );

    color:#fff;

    padding:20px;

    border-radius:20px;

    font-size:16px;

    font-weight:900;

    cursor:pointer;

    transition:0.25s;
}

.btn:hover{

    transform:translateY(-2px);

    box-shadow:
    0 18px 35px rgba(37,99,235,0.20);
}

.footer{

    text-align:center;

    margin-top:24px;

    color:#64748b;

    line-height:1.8;
}

</style>

</head>

<body>

<div class="card">

    <div class="logo">

        <h1>

            Teacher Portal

        </h1>

        <p>

            SMI Student Gateway —
            Teacher Control Panel

        </p>

    </div>

    <?php if($error): ?>

        <div class="error">

            <?php
            echo e($error);
            ?>

        </div>

    <?php endif; ?>

    <form method="POST">

        <?php echo csrfField(); ?>

        <div class="group">

            <label>

                Teacher Email

            </label>

            <input
            type="email"
            name="email"
            required>

        </div>

        <div class="group">

            <label>

                Password

            </label>

            <input
            type="password"
            name="password"
            required>

        </div>

        <button
        type="submit"
        class="btn">

            Login To Teacher Dashboard

        </button>

    </form>

    <div class="footer">

        Superior Multiskills Institute
        <br>
        Teacher Academic System

    </div>

</div>

</body>
</html>