<?php
require __DIR__ . '/includes/bootstrap.php';

if (is_logged_in()) {
    redirect('admin/dashboard.php');
}

function landing_stat(string $sql, string $default = '0'): string
{
    try {
        $pdo = db();
        $stmt = $pdo->query($sql);
        $value = $stmt->fetchColumn();
        if ($value === false || $value === null) {
            return $default;
        }

        return number_format((int) $value);
    } catch (Throwable) {
        return $default;
    }
}

$activeStudents = landing_stat('SELECT COUNT(*) FROM students WHERE status = 1', '0');
$courseCount = landing_stat('SELECT COUNT(*) FROM courses WHERE status = 1', '12');
$todayCheckins = landing_stat('SELECT COUNT(*) FROM attendance WHERE DATE(created_at) = CURDATE()', '0');
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>QR Attendance System</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css">
    <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap" rel="stylesheet">
    <style>
        :root {
            --primary-color: #167c16;
            --secondary-color: #aebe22;
            --accent-color: #0a5e0a;
            --light-green: #e8f5e8;
            --dark-green: #0c4d0c;
        }

        body {
            font-family: 'Poppins', sans-serif;
            background-color: #f8f9fc;
            min-height: 100vh;
        }

        .navbar {
            background: white;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
            padding: 15px 0;
            transition: all 0.3s ease;
        }

        .navbar.scrolled {
            padding: 10px 0;
        }

        .navbar-brand {
            font-weight: 700;
            color: var(--primary-color) !important;
            font-size: 1.5rem;
        }

        .nav-link {
            color: #333 !important;
            font-weight: 500;
            padding: 8px 16px !important;
            transition: color 0.3s;
        }

        .nav-link:hover {
            color: var(--primary-color) !important;
        }

        .hero-section {
            background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
            color: white;
            padding: 120px 0 80px;
            position: relative;
            overflow: hidden;
        }

        .hero-section::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: url('assets/images/ACbackground.png') no-repeat center center/cover;
            opacity: 0.1;
        }

        .hero-title {
            font-size: 3rem;
            font-weight: 700;
            margin-bottom: 1.5rem;
            text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
        }

        .hero-subtitle {
            font-size: 1.25rem;
            opacity: 0.95;
            margin-bottom: 2rem;
            line-height: 1.6;
        }

        .features-section {
            padding: 80px 0;
            background-color: var(--light-green);
        }

        .section-title {
            color: var(--dark-green);
            font-weight: 700;
            margin-bottom: 3rem;
            text-align: center;
        }

        .feature-card {
            background: white;
            border: none;
            border-radius: 15px;
            padding: 30px;
            text-align: center;
            box-shadow: 0 5px 20px rgba(0, 0, 0, 0.05);
            transition: all 0.3s ease;
            height: 100%;
        }

        .feature-card:hover {
            transform: translateY(-10px);
            box-shadow: 0 15px 30px rgba(0, 0, 0, 0.1);
        }

        .feature-icon {
            width: 80px;
            height: 80px;
            background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            margin: 0 auto 25px;
            color: white;
            font-size: 2rem;
        }

        .feature-title {
            color: var(--dark-green);
            font-weight: 600;
            margin-bottom: 15px;
        }

        .stats-section {
            padding: 60px 0;
            background: white;
        }

        .stat-card {
            text-align: center;
            padding: 30px 20px;
        }

        .stat-number {
            font-size: 3rem;
            font-weight: 700;
            color: var(--primary-color);
            margin-bottom: 10px;
            line-height: 1;
        }

        .stat-label {
            color: #666;
            font-size: 1rem;
            text-transform: uppercase;
            letter-spacing: 1px;
        }

        .about-section {
            padding: 80px 0;
            background-color: #f8f9fa;
        }

        .ac-logo {
            max-width: 300px;
            height: auto;
            margin-bottom: 30px;
        }

        .btn-primary {
            background: var(--primary-color);
            border: none;
            padding: 12px 30px;
            border-radius: 50px;
            font-weight: 600;
            transition: all 0.3s ease;
        }

        .btn-primary:hover {
            background: var(--dark-green);
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(10, 94, 10, 0.3);
        }

        .btn-outline-primary {
            color: var(--primary-color);
            border: 2px solid var(--primary-color);
            background: transparent;
            padding: 12px 30px;
            border-radius: 50px;
            font-weight: 600;
            transition: all 0.3s ease;
        }

        .btn-outline-primary:hover {
            background: var(--primary-color);
            color: white;
            transform: translateY(-2px);
        }

        .footer {
            background: var(--dark-green);
            color: white;
            padding: 40px 0 20px;
        }

        .footer-links a {
            color: rgba(255, 255, 255, 0.8);
            text-decoration: none;
            transition: color 0.3s;
        }

        .footer-links a:hover {
            color: white;
        }

        .footer-links li {
            margin-bottom: 10px;
        }

        .copyright {
            border-top: 1px solid rgba(255, 255, 255, 0.1);
            padding-top: 20px;
            margin-top: 40px;
        }

        @media (max-width: 768px) {
            .hero-title {
                font-size: 2.2rem;
            }

            .hero-subtitle {
                font-size: 1.1rem;
            }

            .hero-section {
                padding: 100px 0 60px;
            }

            .stat-number {
                font-size: 2.5rem;
            }
        }

        @media (max-width: 576px) {
            .hero-title {
                font-size: 1.8rem;
            }

            .navbar-brand {
                font-size: 1.2rem;
            }
        }

        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        .animate-fade-in-up {
            animation: fadeInUp 0.6s ease-out forwards;
        }
    </style>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light fixed-top">
    <div class="container">
        <a class="navbar-brand d-flex align-items-center" href="#">
            <span>QR Attendance System</span>
        </a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarNav">
            <ul class="navbar-nav ms-auto">
                <li class="nav-item">
                    <a class="nav-link" href="#features">Features</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#about">About</a>
                </li>
                <li class="nav-item ms-2">
                    <a href="auth/login.php" class="btn btn-primary">
                        <i class="bi bi-box-arrow-in-right me-2"></i>Login
                    </a>
                </li>
            </ul>
        </div>
    </div>
</nav>

<section class="hero-section">
    <div class="container">
        <div class="row align-items-center">
            <div class="col-lg-6">
                <h1 class="hero-title animate-fade-in-up">QR Attendance Management</h1>
                <p class="hero-subtitle animate-fade-in-up" style="animation-delay: 0.1s;">
                    A modern, efficient, and contactless attendance system using QR code technology
                    to streamline every campus check-in.
                </p>
                <div class="animate-fade-in-up" style="animation-delay: 0.2s;">
                    <a href="auth/login.php" class="btn btn-primary me-3">
                        <i class="bi bi-box-arrow-in-right me-2"></i>Get Started
                    </a>
                    <a href="#features" class="btn btn-outline-primary text-white border-white">
                        <i class="bi bi-info-circle me-2"></i>Learn More
                    </a>
                </div>
            </div>
            <div class="col-lg-6">
                <div class="text-center mt-5 mt-lg-0">
                    <img src="assets/images/aldersgate.png"
                         alt="Campus Logo"
                         class="img-fluid animate-fade-in-up"
                         style="max-height: 300px; animation-delay: 0.3s;">
                </div>
            </div>
        </div>
    </div>
</section>

<section class="stats-section">
    <div class="container">
        <div class="row text-center">
            <div class="col-md-3 col-6 mb-4">
                <div class="stat-card">
                    <div class="stat-number"><?= sanitize($activeStudents) ?></div>
                    <div class="stat-label">Active Students</div>
                </div>
            </div>
            <div class="col-md-3 col-6 mb-4">
                <div class="stat-card">
                    <div class="stat-number"><?= sanitize($courseCount) ?></div>
                    <div class="stat-label">Courses</div>
                </div>
            </div>
            <div class="col-md-3 col-6 mb-4">
                <div class="stat-card">
                    <div class="stat-number"><?= sanitize($todayCheckins) ?></div>
                    <div class="stat-label">Today's Check-ins</div>
                </div>
            </div>
            <div class="col-md-3 col-6 mb-4">
                <div class="stat-card">
                    <div class="stat-number">99.9%</div>
                    <div class="stat-label">Accuracy Rate</div>
                </div>
            </div>
        </div>
    </div>
</section>

<section id="features" class="features-section">
    <div class="container">
        <h2 class="section-title">Key Features</h2>
        <div class="row">
            <div class="col-lg-4 col-md-6 mb-4">
                <div class="feature-card animate-fade-in-up">
                    <div class="feature-icon">
                        <i class="bi bi-qr-code-scan"></i>
                    </div>
                    <h4 class="feature-title">QR Code Attendance</h4>
                    <p class="text-muted mb-0">
                        Quick and contactless attendance marking with unique student QR codes.
                    </p>
                </div>
            </div>
            <div class="col-lg-4 col-md-6 mb-4">
                <div class="feature-card animate-fade-in-up" style="animation-delay: 0.1s;">
                    <div class="feature-icon">
                        <i class="bi bi-graph-up"></i>
                    </div>
                    <h4 class="feature-title">Real-time Analytics</h4>
                    <p class="text-muted mb-0">
                        Comprehensive dashboards and detailed attendance reports.
                    </p>
                </div>
            </div>
            <div class="col-lg-4 col-md-6 mb-4">
                <div class="feature-card animate-fade-in-up" style="animation-delay: 0.2s;">
                    <div class="feature-icon">
                        <i class="bi bi-people-fill"></i>
                    </div>
                    <h4 class="feature-title">Student Management</h4>
                    <p class="text-muted mb-0">
                        Manage profiles, courses, and departments with bulk import.
                    </p>
                </div>
            </div>
            <div class="col-lg-4 col-md-6 mb-4">
                <div class="feature-card animate-fade-in-up">
                    <div class="feature-icon">
                        <i class="bi bi-calendar-event"></i>
                    </div>
                    <h4 class="feature-title">Activity Scheduling</h4>
                    <p class="text-muted mb-0">
                        Schedule classes, seminars, and events with specific time slots.
                    </p>
                </div>
            </div>
            <div class="col-lg-4 col-md-6 mb-4">
                <div class="feature-card animate-fade-in-up" style="animation-delay: 0.1s;">
                    <div class="feature-icon">
                        <i class="bi bi-bell-fill"></i>
                    </div>
                    <h4 class="feature-title">Smart Notifications</h4>
                    <p class="text-muted mb-0">
                        Automated alerts for attendance, events, and announcements.
                    </p>
                </div>
            </div>
            <div class="col-lg-4 col-md-6 mb-4">
                <div class="feature-card animate-fade-in-up" style="animation-delay: 0.2s;">
                    <div class="feature-icon">
                        <i class="bi bi-shield-check"></i>
                    </div>
                    <h4 class="feature-title">Secure & Reliable</h4>
                    <p class="text-muted mb-0">
                        Role-based access control with enterprise-grade security.
                    </p>
                </div>
            </div>
        </div>
    </div>
</section>

<section id="about" class="about-section">
    <div class="container">
        <div class="row align-items-center">
            <div class="col-lg-6 text-center mb-5 mb-lg-0">
                <img src="assets/images/aldersgate.png" alt="Campus Logo" class="ac-logo">
                <h3 class="mb-3" style="color: var(--dark-green);">Campus Ready</h3>
                <p class="text-muted mb-4">
                    Built for institutions that need reliable QR-based attendance tracking.
                </p>
            </div>
            <div class="col-lg-6">
                <h2 class="mb-4" style="color: var(--dark-green);">About This System</h2>
                <p class="mb-4">
                    Crafted to streamline attendance across departments and activities,
                    this platform combines QR scanning, manual overrides, and analytics in a single hub.
                </p>
                <div class="row mb-4">
                    <div class="col-md-6 mb-3">
                        <div class="d-flex align-items-start">
                            <i class="bi bi-check-circle-fill text-success me-3 mt-1"></i>
                            <div>
                                <h6 class="mb-1">Contactless Operation</h6>
                                <small class="text-muted">No physical contact required</small>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-6 mb-3">
                        <div class="d-flex align-items-start">
                            <i class="bi bi-check-circle-fill text-success me-3 mt-1"></i>
                            <div>
                                <h6 class="mb-1">Real-time Tracking</h6>
                                <small class="text-muted">Live attendance monitoring</small>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-6 mb-3">
                        <div class="d-flex align-items-start">
                            <i class="bi bi-check-circle-fill text-success me-3 mt-1"></i>
                            <div>
                                <h6 class="mb-1">Easy Integration</h6>
                                <small class="text-muted">Works with existing systems</small>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-6 mb-3">
                        <div class="d-flex align-items-start">
                            <i class="bi bi-check-circle-fill text-success me-3 mt-1"></i>
                            <div>
                                <h6 class="mb-1">Mobile Ready</h6>
                                <small class="text-muted">Accessible on all devices</small>
                            </div>
                        </div>
                    </div>
                </div>
                <div>
                    <a href="auth/login.php" class="btn btn-primary">
                        <i class="bi bi-box-arrow-in-right me-2"></i>Access System
                    </a>
                </div>
            </div>
        </div>
    </div>
</section>

<footer class="footer">
    <div class="container">
        <div class="row">
            <div class="col-lg-6 mb-4">
                <h5 class="mb-3">QR Attendance System</h5>
                <p class="mb-4" style="color: rgba(255, 255, 255, 0.8);">
                    A comprehensive solution for modernizing attendance tracking with QR code technology.
                </p>
                <div class="d-flex gap-3">
                    <a href="https://www.facebook.com/imjohnlloyd26/" class="text-white"><i class="bi bi-facebook"></i></a>
                    <a href="https://www.instagram.com/im_johnlloyd6/" class="text-white"><i class="bi bi-instagram"></i></a>
                </div>
            </div>
            <div class="col-lg-3 col-md-6 mb-4">
                <h5 class="mb-3">Quick Links</h5>
                <ul class="list-unstyled footer-links">
                    <li><a href="#features">Features</a></li>
                    <li><a href="#about">About</a></li>
                    <li><a href="auth/login.php">Login</a></li>
                </ul>
            </div>
            <div class="col-lg-3 col-md-6 mb-4">
                <h5 class="mb-3">Contact Info</h5>
                <ul class="list-unstyled footer-links">
                    <li class="mb-2">
                        <i class="bi bi-geo-alt me-2"></i>
                        Solano, Nueva Vizcaya
                    </li>
                    <li class="mb-2">
                        <i class="bi bi-envelope me-2"></i>
                        johnlloydsumawang04@gmail.com
                    </li>
                </ul>
            </div>
        </div>
        <div class="row copyright">
            <div class="col-md-6">
                <p class="mb-0" style="color: rgba(255, 255, 255, 0.6);">
                    &copy; <?= date('Y') ?> QR Attendance System.
                </p>
            </div>
            <div class="col-md-6 text-md-end">
                <p class="mb-0" style="color: rgba(255, 255, 255, 0.6);">
                    Programmed by <span class="text-white">John Lloyd Sumawang</span>
                </p>
            </div>
        </div>
    </div>
</footer>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
document.addEventListener('DOMContentLoaded', function() {
    document.querySelectorAll('a[href^="#"]').forEach(anchor => {
        anchor.addEventListener('click', function(e) {
            const targetId = this.getAttribute('href');
            if (!targetId || targetId === '#') {
                return;
            }
            e.preventDefault();
            const targetElement = document.querySelector(targetId);
            if (targetElement) {
                window.scrollTo({
                    top: targetElement.offsetTop - 80,
                    behavior: 'smooth'
                });
            }
        });
    });

    const navbar = document.querySelector('.navbar');
    window.addEventListener('scroll', function() {
        if (window.scrollY > 50) {
            navbar.classList.add('scrolled', 'shadow');
        } else {
            navbar.classList.remove('scrolled', 'shadow');
        }
    });

    const animateOnScroll = function() {
        const elements = document.querySelectorAll('.animate-fade-in-up');
        elements.forEach(element => {
            const elementTop = element.getBoundingClientRect().top;
            const elementVisible = 150;
            if (elementTop < window.innerHeight - elementVisible) {
                element.style.opacity = '1';
                element.style.transform = 'translateY(0)';
            }
        });
    };

    document.querySelectorAll('.animate-fade-in-up').forEach(el => {
        el.style.opacity = '0';
        el.style.transform = 'translateY(30px)';
        el.style.transition = 'opacity 0.6s ease, transform 0.6s ease';
    });

    window.addEventListener('load', animateOnScroll);
    window.addEventListener('scroll', animateOnScroll);
});
</script>
</body>
</html>
