<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Iniciar Sesión</title>
    <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;500;700&display=swap">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>

    <style>
        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
            font-family: 'Poppins', sans-serif;
        }

        body {
    background: url('{{ asset('img/fondo.jpeg') }}') no-repeat center center fixed;
    background-size: cover;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
}


        .login-container {
            background: white;
            padding: 40px;
            border-radius: 20px;
            box-shadow: 0 10px 30px rgba(0,0,0,0.1);
            width: 100%;
            max-width: 400px;
        }

        .login-container h2 {
            color: #27ae60;
            text-align: center;
            margin-bottom: 30px;
        }

        .login__field {
            position: relative;
            margin-bottom: 20px;
        }

        .login__field input {
            width: 100%;
            padding: 12px 40px 12px 45px;
            border: 1px solid #ccc;
            border-radius: 10px;
            outline: none;
            font-size: 14px;
            transition: 0.3s;
        }

        .login__field input:focus {
            border-color: #27ae60;
            box-shadow: 0 0 5px rgba(39, 174, 96, 0.3);
        }

        .login__icon {
            position: absolute;
            top: 50%;
            left: 15px;
            transform: translateY(-50%);
            color: #27ae60;
        }

        #toggle-password {
            position: absolute;
            right: 15px;
            top: 50%;
            transform: translateY(-50%);
            cursor: pointer;
            color: #aaa;
        }

        .login__submit {
            width: 100%;
            padding: 12px;
            border: none;
            border-radius: 10px;
            background-color: #27ae60;
            color: white;
            font-size: 16px;
            font-weight: 500;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }

        .login__submit:hover {
            background-color: #219150;
        }

        .text-danger {
            font-size: 13px;
            color: #e74c3c;
            margin-top: 5px;
        }

        .social-icons {
            display: flex;
            justify-content: center;
            margin-top: 20px;
        }

        .social-icons a {
            color: #27ae60;
            margin: 0 10px;
            font-size: 20px;
            transition: 0.3s;
        }

        .social-icons a:hover {
            color: #219150;
        }
    </style>
</head>
<body>

<div class="login-container">
    <h2>Iniciar Sesión</h2>
    <form action="{{ route('login') }}" method="POST">
        @csrf
        <div class="login__field">
            <i class="login__icon fas fa-envelope"></i>
            <input type="email" name="email" placeholder="Correo electrónico" value="{{ old('email') }}" required autofocus>
            @error('email')
                <div class="text-danger">{{ $message }}</div>
            @enderror
        </div>

        <div class="login__field">
            <i class="login__icon fas fa-lock"></i>
            <input type="password" id="password" name="password" placeholder="Contraseña" required>
            <i id="toggle-password" class="fas fa-eye"></i>
            @error('password')
                <div class="text-danger">{{ $message }}</div>
            @enderror
        </div>

        <button type="submit" class="login__submit">Ingresar</button>

        
    </form>
</div>

<script>
document.addEventListener('DOMContentLoaded', function () {
    const togglePassword = document.getElementById('toggle-password');
    const passwordField = document.getElementById('password');

    togglePassword.addEventListener('click', function () {
        const type = passwordField.type === 'password' ? 'text' : 'password';
        passwordField.type = type;
        togglePassword.classList.toggle('fa-eye');
        togglePassword.classList.toggle('fa-eye-slash');
    });

    var status = '{{ session('status') }}';
    var message = '{{ session('message') }}';

    if (status === 'success') {
        Swal.fire({
            icon: 'success',
            title: '¡Éxito!',
            text: message,
        }).then(() => {
            window.location.href = '{{ route("dashboard") }}';
        });
    } else if (status === 'error') {
        Swal.fire({
            icon: 'error',
            title: 'Error',
            text: message,
        });
    }
});
</script>

</body>
</html>
