<?php
include_once '../../controllers/CajaController.php';
$cajaController = new CajaController();
$estudiantes = [];

if (isset($_GET['ci'])) {
    $ci = $_GET['ci'];
    $estudiantes = $cajaController->buscarEstudiantesPorCI($ci);
}
?>

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Pagos</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <!-- SweetAlert2 -->
    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
    <!-- Font Awesome -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap');
        
        body {
            font-family: 'Poppins', sans-serif;
            background-image: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            background-attachment: fixed;
            min-height: 100vh;
            overflow-x: hidden;
        }
        
        .glass-card {
            background: rgba(255, 255, 255, 0.8);
            backdrop-filter: blur(10px);
            border-radius: 1rem;
            border: 1px solid rgba(255, 255, 255, 0.2);
            box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.15);
            transition: all 0.3s ease;
        }
        
        .glass-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 15px 35px 0 rgba(31, 38, 135, 0.2);
        }
        
        .gradient-border {
            position: relative;
            border-radius: 0.75rem;
            z-index: 0;
            overflow: hidden;
        }
        
        .gradient-border::before {
            content: '';
            position: absolute;
            top: -2px;
            left: -2px;
            right: -2px;
            bottom: -2px;
            background: linear-gradient(45deg, #0ea5e9, #8b5cf6, #10b981, #f59e0b);
            z-index: -1;
            border-radius: 0.85rem;
            background-size: 400% 400%;
            animation: gradient 15s ease infinite;
        }
        
        @keyframes gradient {
            0% {
                background-position: 0% 50%;
            }
            50% {
                background-position: 100% 50%;
            }
            100% {
                background-position: 0% 50%;
            }
        }
        
        .input-animated {
            transition: all 0.3s ease;
            border: 2px solid transparent;
            background-color: rgba(255, 255, 255, 0.9);
        }
        
        .input-animated:focus {
            transform: translateY(-2px);
            border-color: #0ea5e9;
            box-shadow: 0 0 0 4px rgba(14, 165, 233, 0.1);
        }
        
        .input-icon {
            transition: all 0.3s ease;
        }
        
        .input-animated:focus + .input-icon {
            color: #0ea5e9;
            transform: scale(1.1);
        }
        
        .btn-primary {
            background-image: linear-gradient(to right, #0ea5e9, #0284c7);
            background-size: 200% auto;
            transition: all 0.3s ease;
            box-shadow: 0 4px 15px 0 rgba(14, 165, 233, 0.4);
        }
        
        .btn-primary:hover {
            background-position: right center;
            transform: translateY(-2px);
            box-shadow: 0 6px 20px 0 rgba(14, 165, 233, 0.6);
        }
        
        .btn-secondary {
            background-image: linear-gradient(to right, #8b5cf6, #6d28d9);
            background-size: 200% auto;
            transition: all 0.3s ease;
            box-shadow: 0 4px 15px 0 rgba(139, 92, 246, 0.4);
        }
        
        .btn-secondary:hover {
            background-position: right center;
            transform: translateY(-2px);
            box-shadow: 0 6px 20px 0 rgba(139, 92, 246, 0.6);
        }
        
        .btn-success {
            background-image: linear-gradient(to right, #10b981, #059669);
            background-size: 200% auto;
            transition: all 0.3s ease;
            box-shadow: 0 4px 15px 0 rgba(16, 185, 129, 0.4);
        }
        
        .btn-success:hover {
            background-position: right center;
            transform: translateY(-2px);
            box-shadow: 0 6px 20px 0 rgba(16, 185, 129, 0.6);
        }
        
        .btn-danger {
            background-image: linear-gradient(to right, #ef4444, #dc2626);
            background-size: 200% auto;
            transition: all 0.3s ease;
            box-shadow: 0 4px 15px 0 rgba(239, 68, 68, 0.4);
        }
        
        .btn-danger:hover {
            background-position: right center;
            transform: translateY(-2px);
            box-shadow: 0 6px 20px 0 rgba(239, 68, 68, 0.6);
        }
        
        .btn-warning {
            background-image: linear-gradient(to right, #f59e0b, #d97706);
            background-size: 200% auto;
            transition: all 0.3s ease;
            box-shadow: 0 4px 15px 0 rgba(245, 158, 11, 0.4);
        }
        
        .btn-warning:hover {
            background-position: right center;
            transform: translateY(-2px);
            box-shadow: 0 6px 20px 0 rgba(245, 158, 11, 0.6);
        }
        
        .floating-shapes div {
            position: absolute;
            width: 60px;
            height: 60px;
            background: rgba(255, 255, 255, 0.1);
            backdrop-filter: blur(5px);
            border: 1px solid rgba(255, 255, 255, 0.2);
            border-radius: 50%;
            animation: float 8s infinite;
        }
        
        .floating-shapes div:nth-child(1) {
            top: 10%;
            left: 10%;
            width: 80px;
            height: 80px;
            animation-delay: 0s;
            background: linear-gradient(45deg, rgba(14, 165, 233, 0.2), rgba(139, 92, 246, 0.2));
        }
        
        .floating-shapes div:nth-child(2) {
            top: 20%;
            right: 15%;
            width: 100px;
            height: 100px;
            animation-delay: 1s;
            background: linear-gradient(45deg, rgba(139, 92, 246, 0.2), rgba(14, 165, 233, 0.2));
        }
        
        .floating-shapes div:nth-child(3) {
            bottom: 15%;
            left: 20%;
            width: 70px;
            height: 70px;
            animation-delay: 2s;
            background: linear-gradient(45deg, rgba(14, 165, 233, 0.2), rgba(139, 92, 246, 0.2));
        }
        
        .floating-shapes div:nth-child(4) {
            bottom: 25%;
            right: 10%;
            width: 120px;
            height: 120px;
            animation-delay: 3s;
            background: linear-gradient(45deg, rgba(139, 92, 246, 0.2), rgba(14, 165, 233, 0.2));
        }
        
        .floating-shapes div:nth-child(5) {
            top: 50%;
            left: 5%;
            width: 90px;
            height: 90px;
            animation-delay: 4s;
            background: linear-gradient(45deg, rgba(14, 165, 233, 0.2), rgba(139, 92, 246, 0.2));
        }
        
        .floating-shapes div:nth-child(6) {
            top: 40%;
            right: 5%;
            width: 60px;
            height: 60px;
            animation-delay: 5s;
            background: linear-gradient(45deg, rgba(139, 92, 246, 0.2), rgba(14, 165, 233, 0.2));
        }
        
        @keyframes float {
            0%, 100% {
                transform: translateY(0) rotate(0deg);
            }
            25% {
                transform: translateY(-20px) rotate(5deg);
            }
            50% {
                transform: translateY(0) rotate(10deg);
            }
            75% {
                transform: translateY(20px) rotate(5deg);
            }
        }
        
        .form-section {
            transition: all 0.3s ease;
        }
        
        .form-section:hover {
            transform: translateY(-2px);
        }
        
        /* Estilos para scrollbar */
        ::-webkit-scrollbar {
            width: 6px;
            height: 6px;
        }
        
        ::-webkit-scrollbar-track {
            background: #f1f1f1;
            border-radius: 10px;
        }
        
        ::-webkit-scrollbar-thumb {
            background: #0ea5e9;
            border-radius: 10px;
        }
        
        ::-webkit-scrollbar-thumb:hover {
            background: #0284c7;
        }
        
        .card-3d {
            transition: transform 0.3s ease, box-shadow 0.3s ease;
        }
        
        .card-3d:hover {
            transform: translateY(-10px) rotateX(2deg) rotateY(2deg);
            box-shadow: 0 30px 60px -15px rgba(0, 0, 0, 0.25);
        }
        
        .card-3d::before {
            content: '';
            position: absolute;
            inset: 0;
            z-index: -1;
            background: linear-gradient(45deg, rgba(255,255,255,0) 0%, rgba(255,255,255,0.1) 100%);
            opacity: 0;
            transition: opacity 0.3s ease;
            border-radius: inherit;
        }
        
        .card-3d:hover::before {
            opacity: 1;
        }
    </style>
</head>

<body class="min-h-screen py-8">
    <!-- Floating shapes background -->
    <div class="floating-shapes fixed inset-0 -z-10 overflow-hidden">
        <div></div>
        <div></div>
        <div></div>
        <div></div>
        <div></div>
        <div></div>
    </div>
    
    <div class="container mx-auto px-4 max-w-7xl">
        <div class="text-center mb-8 animate__animated animate__fadeIn">
            <img src="../../public/images/logo.png" alt="Logo de la Institución" class="mx-auto h-24 object-contain mb-4 animate-float">
            <h1 class="text-3xl font-bold text-gray-800 mb-2 bg-clip-text text-transparent bg-gradient-to-r from-primary-600 to-secondary-600">Gestión de Pagos</h1>
            <p class="text-gray-600 mb-4">Administre los pagos de los estudiantes</p>
            <a href="../caja/dashboard_caja.php" class="inline-flex items-center px-4 py-2 rounded-lg bg-primary-600 text-white hover:bg-primary-700 transition-all duration-300 shadow-md animate__animated animate__fadeInUp">
                <i class="fas fa-arrow-left mr-2"></i> Volver a Gestión de Caja
            </a>
        </div>

        <!-- Formulario para buscar estudiantes por CI -->
        <div class="glass-card gradient-border card-3d animate__animated animate__zoomIn">
            <div class="bg-gradient-to-r from-primary-600 via-secondary-600 to-primary-600 px-6 py-4 rounded-t-xl flex items-center">
                <div class="bg-white/20 p-3 rounded-full mr-4">
                    <i class="fas fa-search text-white text-xl"></i>
                </div>
                <div>
                    <h2 class="text-xl font-semibold text-white">Buscar Estudiante</h2>
                    <p class="text-white/80 text-sm">Ingrese el CI del estudiante para buscar sus pagos</p>
                </div>
            </div>
            
            <div class="p-8">
                <form action="pagos.php" method="get" class="flex items-center gap-4">
                    <div class="flex-grow">
                        <label for="ci" class="block text-sm font-medium text-gray-700 mb-2">CI del Estudiante:</label>
                        <div class="relative">
                            <input type="text" id="ci" name="ci" required
                                class="input-animated w-full pl-10 pr-4 py-3 border border-gray-300 rounded-lg shadow-sm focus:outline-none">
                            <div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
                                <i class="fas fa-id-card text-gray-400 input-icon"></i>
                            </div>
                        </div>
                    </div>
                    <div>
                        <button type="submit"
                            class="btn-primary text-white px-6 py-3 rounded-lg flex items-center justify-center shadow-neon">
                            <i class="fas fa-search mr-2"></i> Buscar
                        </button>
                    </div>
                </form>
            </div>
        </div>

        <!-- Lista de estudiantes encontrados -->
        <?php if (!empty($estudiantes)): ?>
            <div class="glass-card gradient-border card-3d animate__animated animate__zoomIn mt-8">
                <div class="bg-gradient-to-r from-secondary-600 via-primary-600 to-secondary-600 px-6 py-4 rounded-t-xl flex items-center">
                    <div class="bg-white/20 p-3 rounded-full mr-4">
                        <i class="fas fa-users text-white text-xl"></i>
                    </div>
                    <div>
                        <h2 class="text-xl font-semibold text-white">Resultados de la Búsqueda</h2>
                        <p class="text-white/80 text-sm">Estudiantes encontrados con el CI proporcionado</p>
                    </div>
                </div>
                
                <div class="p-8">
                    <div class="overflow-x-auto">
                        <table class="min-w-full bg-white rounded-lg overflow-hidden">
                            <thead class="bg-gradient-to-r from-primary-600 to-secondary-600 text-white">
                                <tr>
                                    <th class="px-6 py-3 text-left text-xs font-medium uppercase tracking-wider">Nombre</th>
                                    <th class="px-6 py-3 text-left text-xs font-medium uppercase tracking-wider">Contacto</th>
                                    <th class="px-6 py-3 text-left text-xs font-medium uppercase tracking-wider">Monto Total</th>
                                    <th class="px-6 py-3 text-left text-xs font-medium uppercase tracking-wider">Balance</th>
                                    <th class="px-6 py-3 text-left text-xs font-medium uppercase tracking-wider">Carrera</th>
                                    <th class="px-6 py-3 text-left text-xs font-medium uppercase tracking-wider">Fecha de Ingreso</th>
                                    <th class="px-6 py-3 text-left text-xs font-medium uppercase tracking-wider">Acciones</th>
                                </tr>
                            </thead>
                            <tbody class="divide-y divide-gray-200">
                                <?php foreach ($estudiantes as $estudiante): ?>
                                    <tr class="hover:bg-gray-50 transition-colors">
                                        <td class="px-6 py-4 whitespace-nowrap text-gray-700"><?php echo $estudiante['sname']; ?></td>
                                        <td class="px-6 py-4 whitespace-nowrap text-gray-700"><?php echo $estudiante['contact']; ?></td>
                                        <td class="px-6 py-4 whitespace-nowrap text-gray-700"><?php echo $estudiante['fees']; ?></td>
                                        <td class="px-6 py-4 whitespace-nowrap text-gray-700"><?php echo $estudiante['balance']; ?></td>
                                        <td class="px-6 py-4 whitespace-nowrap text-gray-700"><?php echo $estudiante['carrera']; ?></td>
                                        <td class="px-6 py-4 whitespace-nowrap text-gray-700"><?php echo $estudiante['joindate']; ?></td>
                                        <td class="px-6 py-4 whitespace-nowrap">
                                            <a href="tomar_pago.php?id=<?php echo $estudiante['idRegistro']; ?>"
                                               class="btn-success text-white px-4 py-2 rounded-lg text-sm flex items-center justify-center w-24 shadow-md">
                                                <i class="fas fa-money-bill-wave mr-2"></i> Pagar
                                            </a>
                                            <a href="otros_pagos.php?id=<?php echo $estudiante['idRegistro']; ?>"
                                               class="btn-warning text-white px-4 py-2 rounded-lg text-sm flex items-center justify-center w-24 shadow-md mt-2">
                                                <i class="fas fa-file-invoice-dollar mr-2"></i> Otros
                                            </a>
                                        </td>
                                    </tr>
                                <?php endforeach; ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        <?php elseif (isset($_GET['ci'])): ?>
            <div class="text-center py-8">
                <i class="fas fa-folder-open text-4xl text-gray-300 mb-3"></i>
                <p class="text-lg font-medium">No se encontraron estudiantes con el CI proporcionado</p>
                <p class="text-sm text-gray-400">Intente con otro CI</p>
            </div>
        <?php endif; ?>
    </div>
</body>

</html>