<?php
include_once '../../controllers/CarreraController.php';
$carreraController = new CarreraController();
$carreras = $carreraController->listarCarreras();

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    if (isset($_POST['agregar'])) {
        $resultado = $carreraController->agregarCarrera(
            $_POST['carrera'],
            $_POST['estado'],
            $_POST['detalle'],
            $_POST['sucursal_varchar'],
            $_POST['tipo']
        );

        if ($resultado) {
            echo "<script>
                document.addEventListener('DOMContentLoaded', function() {
                    Swal.fire({
                        icon: 'success',
                        title: '¡Éxito!',
                        text: 'Carrera agregada correctamente',
                        showConfirmButton: false,
                        timer: 2000,
                        timerProgressBar: true,
                        didClose: () => {
                            window.location.href = 'gestionar_carreras.php';
                        }
                    });
                });
            </script>";
        } else {
            echo "<script>
                document.addEventListener('DOMContentLoaded', function() {
                    Swal.fire({
                        icon: 'error',
                        title: 'Error',
                        text: 'No se pudo agregar la carrera',
                        confirmButtonColor: '#3085d6'
                    });
                });
            </script>";
        }
    }
}
?>

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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Gestionar Carreras</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">
    <script>
        tailwind.config = {
            theme: {
                extend: {
                    colors: {
                        primary: {
                            50: '#f0f9ff',
                            100: '#e0f2fe',
                            200: '#bae6fd',
                            300: '#7dd3fc',
                            400: '#38bdf8',
                            500: '#0ea5e9',
                            600: '#0284c7',
                            700: '#0369a1',
                            800: '#075985',
                            900: '#0c4a6e',
                        },
                        secondary: {
                            50: '#f5f3ff',
                            100: '#ede9fe',
                            200: '#ddd6fe',
                            300: '#c4b5fd',
                            400: '#a78bfa',
                            500: '#8b5cf6',
                            600: '#7c3aed',
                            700: '#6d28d9',
                            800: '#5b21b6',
                            900: '#4c1d95',
                        },
                        accent: {
                            50: '#ecfdf5',
                            100: '#d1fae5',
                            200: '#a7f3d0',
                            300: '#6ee7b7',
                            400: '#34d399',
                            500: '#10b981',
                            600: '#059669',
                            700: '#047857',
                            800: '#065f46',
                            900: '#064e3b',
                        },
                        danger: {
                            50: '#fef2f2',
                            100: '#fee2e2',
                            500: '#ef4444',
                            600: '#dc2626',
                            700: '#b91c1c',
                        }
                    },
                    animation: {
                        'float': 'float 6s ease-in-out infinite',
                        'pulse-slow': 'pulse 3s cubic-bezier(0.4, 0, 0.6, 1) infinite',
                        'bounce-slow': 'bounce 3s infinite',
                        'spin-slow': 'spin 3s linear infinite',
                        'wiggle': 'wiggle 1s ease-in-out infinite',
                        'slide-up': 'slideUp 0.5s ease-out forwards',
                        'slide-down': 'slideDown 0.5s ease-out forwards',
                        'slide-in-right': 'slideInRight 0.5s ease-out forwards',
                        'slide-in-left': 'slideInLeft 0.5s ease-out forwards',
                        'fade-in': 'fadeIn 0.5s ease-out forwards',
                        'scale-in': 'scaleIn 0.3s ease-out forwards',
                        'scale-out': 'scaleOut 0.3s ease-out forwards',
                    },
                    keyframes: {
                        float: {
                            '0%, 100%': { transform: 'translateY(0)' },
                            '50%': { transform: 'translateY(-10px)' },
                        },
                        wiggle: {
                            '0%, 100%': { transform: 'rotate(-3deg)' },
                            '50%': { transform: 'rotate(3deg)' },
                        },
                        slideUp: {
                            '0%': { transform: 'translateY(20px)', opacity: '0' },
                            '100%': { transform: 'translateY(0)', opacity: '1' },
                        },
                        slideDown: {
                            '0%': { transform: 'translateY(-20px)', opacity: '0' },
                            '100%': { transform: 'translateY(0)', opacity: '1' },
                        },
                        slideInRight: {
                            '0%': { transform: 'translateX(20px)', opacity: '0' },
                            '100%': { transform: 'translateX(0)', opacity: '1' },
                        },
                        slideInLeft: {
                            '0%': { transform: 'translateX(-20px)', opacity: '0' },
                            '100%': { transform: 'translateX(0)', opacity: '1' },
                        },
                        fadeIn: {
                            '0%': { opacity: '0' },
                            '100%': { opacity: '1' },
                        },
                        scaleIn: {
                            '0%': { transform: 'scale(0.9)', opacity: '0' },
                            '100%': { transform: 'scale(1)', opacity: '1' },
                        },
                        scaleOut: {
                            '0%': { transform: 'scale(1)', opacity: '1' },
                            '100%': { transform: 'scale(0.9)', opacity: '0' },
                        },
                    },
                    boxShadow: {
                        'neon': '0 0 5px rgba(14, 165, 233, 0.5), 0 0 20px rgba(14, 165, 233, 0.3)',
                        'neon-purple': '0 0 5px rgba(139, 92, 246, 0.5), 0 0 20px rgba(139, 92, 246, 0.3)',
                        'neon-green': '0 0 5px rgba(16, 185, 129, 0.5), 0 0 20px rgba(16, 185, 129, 0.3)',
                        'inner-glow': 'inset 0 0 15px 0 rgba(255, 255, 255, 0.5)',
                        'card-3d': '0 10px 30px -10px rgba(0, 0, 0, 0.3)',
                    }
                }
            }
        }
    </script>
    <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">
            <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 Carreras</h1>
            <p class="text-gray-600 mb-4">Administre las carreras del sistema educativo</p>
            <a href="../superadmin/dashboard.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 al Menú Principal
            </a>
        </div>

        <!-- Formulario para agregar carreras -->
        <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-graduation-cap text-white text-xl"></i>
                </div>
                <div>
                    <h2 class="text-xl font-semibold text-white">Agregar Nueva Carrera</h2>
                    <p class="text-white/80 text-sm">Complete todos los campos para registrar una carrera</p>
                </div>
            </div>
            
            <div class="p-8">
                <form action="gestionar_carreras.php" method="post" class="grid grid-cols-1 md:grid-cols-2 gap-6">
                    <div class="form-section animate__animated animate__fadeInLeft" style="animation-delay: 0.1s">
                        <label for="carrera" class="block text-sm font-medium text-gray-700 mb-2 flex items-center">
                            <i class="fas fa-graduation-cap text-primary-500 mr-2"></i> Carrera
                        </label>
                        <div class="relative">
                            <input type="text" id="carrera" name="carrera" 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-graduation-cap text-gray-400 input-icon"></i>
                            </div>
                        </div>
                    </div>
                    
                    <div class="form-section animate__animated animate__fadeInRight" style="animation-delay: 0.2s">
                        <label for="estado" class="block text-sm font-medium text-gray-700 mb-2 flex items-center">
                            <i class="fas fa-toggle-on text-primary-500 mr-2"></i> Estado
                        </label>
                        <div class="relative">
                            <input type="number" id="estado" name="estado" 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-toggle-on text-gray-400 input-icon"></i>
                            </div>
                        </div>
                    </div>
                    
                    <div class="form-section animate__animated animate__fadeInLeft" style="animation-delay: 0.3s">
                        <label for="detalle" class="block text-sm font-medium text-gray-700 mb-2 flex items-center">
                            <i class="fas fa-info-circle text-primary-500 mr-2"></i> Detalle
                        </label>
                        <div class="relative">
                            <input type="text" id="detalle" name="detalle" 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-info-circle text-gray-400 input-icon"></i>
                            </div>
                        </div>
                    </div>
                    
                    <div class="form-section animate__animated animate__fadeInRight" style="animation-delay: 0.4s">
                        <label for="sucursal_varchar" class="block text-sm font-medium text-gray-700 mb-2 flex items-center">
                            <i class="fas fa-building text-primary-500 mr-2"></i> Sucursal
                        </label>
                        <div class="relative">
                            <input type="text" id="sucursal_varchar" name="sucursal_varchar" 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-building text-gray-400 input-icon"></i>
                            </div>
                        </div>
                    </div>
                    
                    <div class="form-section animate__animated animate__fadeInLeft" style="animation-delay: 0.5s">
                        <label for="tipo" class="block text-sm font-medium text-gray-700 mb-2 flex items-center">
                            <i class="fas fa-layer-group text-primary-500 mr-2"></i> Tipo
                        </label>
                        <div class="relative">
                            <select id="tipo" name="tipo" required
                                class="input-animated w-full pl-10 pr-10 py-3 border border-gray-300 rounded-lg shadow-sm focus:outline-none appearance-none">
                                <option value="curso">Curso</option>
                                <option value="carrera">Carrera</option>
                            </select>
                            <div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
                                <i class="fas fa-layer-group text-gray-400 input-icon"></i>
                            </div>
                            <div class="absolute inset-y-0 right-0 pr-3 flex items-center pointer-events-none">
                                <i class="fas fa-chevron-down text-gray-400"></i>
                            </div>
                        </div>
                    </div>
                    
                    <div class="col-span-full flex justify-center pt-6 animate__animated animate__fadeInUp" style="animation-delay: 0.6s">
                        <button type="submit" name="agregar" 
                            class="btn-success text-white py-3 px-8 rounded-lg flex items-center justify-center shadow-neon-green">
                            <i class="fas fa-save mr-2"></i> Guardar Carrera
                        </button>
                    </div>
                </form>
            </div>
        </div>

        <!-- Lista de Carreras -->
        <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-list-alt text-white text-xl"></i>
                </div>
                <div>
                    <h2 class="text-xl font-semibold text-white">Lista de Carreras</h2>
                    <p class="text-white/80 text-sm">Visualice y gestione todas las carreras registradas</p>
                </div>
            </div>
            
            <div class="p-8">
                <?php if (!empty($carreras)): ?>
                    <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">ID</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">Estado</th>
                                    <th class="px-6 py-3 text-left text-xs font-medium uppercase tracking-wider">Detalle</th>
                                    <th class="px-6 py-3 text-left text-xs font-medium uppercase tracking-wider">Sucursal</th>
                                    <th class="px-6 py-3 text-left text-xs font-medium uppercase tracking-wider">Tipo</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 ($carreras as $carrera): ?>
                                    <tr class="hover:bg-gray-50 transition-colors">
                                        <td class="px-6 py-4 whitespace-nowrap"><?php echo $carrera['id']; ?></td>
                                        <td class="px-6 py-4 whitespace-nowrap"><?php echo $carrera['carrera']; ?></td>
                                        <td class="px-6 py-4 whitespace-nowrap"><?php echo $carrera['estado']; ?></td>
                                        <td class="px-6 py-4 whitespace-nowrap"><?php echo $carrera['detalle']; ?></td>
                                        <td class="px-6 py-4 whitespace-nowrap"><?php echo $carrera['sucursal_varchar']; ?></td>
                                        <td class="px-6 py-4 whitespace-nowrap"><?php echo $carrera['tipo']; ?></td>
                                        <td class="px-6 py-4 whitespace-nowrap">
                                            <a href="editar_carrera.php?id=<?php echo $carrera['id']; ?>"
                                               class="btn-warning text-white px-4 py-2 rounded-lg text-sm flex items-center justify-center w-24 shadow-md">
                                                <i class="fas fa-edit mr-2"></i> Editar
                                            </a>
                                        </td>
                                    </tr>
                                <?php endforeach; ?>
                            </tbody>
                        </table>
                    </div>
                <?php else: ?>
                    <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 carreras</p>
                        <p class="text-sm text-gray-400">Agregue nuevas carreras para comenzar</p>
                    </div>
                <?php endif; ?>
            </div>
        </div>
    </div>
</body>

</html>