<?php
@session_start();
include('includes/config.php');

$status_result = null;
$ticket_number = '';

if(isset($_POST['check_status']) || isset($_GET['ticket'])) {
    $ticket_number = isset($_GET['ticket']) ? $_GET['ticket'] : $_POST['ticket_number'];
    $status_result = getTicketStatus($ticket_number);
}

?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="icon" href="./template/tngweb/assets/images/favicon-32x32.png" type="image/png" />
    <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap" rel="stylesheet">
    <link href='https://unpkg.com/boxicons@2.1.4/css/boxicons.min.css' rel='stylesheet'>
    <title><?php echo XyZ_val('brand'); ?> | Check Ticket Status</title>
    
    <!-- ========== ENHANCED MODERN CSS (preserves all original classes) ========== -->
    <style>
        /* Reset & Base */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        body {
            font-family: 'Poppins', sans-serif;
            background: linear-gradient(135deg, #0f0c29 0%, #302b63 50%, #24243e 100%);
            min-height: 100vh;
            display: flex;
            flex-direction: column;
            position: relative;
            overflow-x: hidden;
        }
        /* Animated Background Shapes */
        .bg-shape {
            position: fixed;
            filter: blur(80px);
            opacity: 0.35;
            z-index: 0;
            border-radius: 50%;
            animation: floatBg 18s infinite ease-in-out;
            pointer-events: none;
        }
        .shape-1 { top: -150px; left: -150px; width: 400px; height: 400px; background: radial-gradient(circle, #00ffff, #0080ff); }
        .shape-2 { bottom: -120px; right: -120px; width: 500px; height: 500px; background: radial-gradient(circle, #ff00ff, #ff0080); animation-delay: -6s; }
        .shape-3 { top: 40%; left: -80px; width: 300px; height: 300px; background: radial-gradient(circle, #ffd700, #ff6600); animation-delay: -12s; }
        @keyframes floatBg {
            0% { transform: translate(0, 0) scale(1); }
            50% { transform: translate(40px, 30px) scale(1.1); }
            100% { transform: translate(0, 0) scale(1); }
        }
        
        /* Navbar - original classes, upgraded look */
        .navbar {
            position: relative;
            z-index: 100;
            background: rgba(15, 12, 41, 0.7);
            backdrop-filter: blur(12px);
            border-bottom: 1px solid rgba(255,255,255,0.1);
            padding: 1rem 2rem;
        }
        .nav-container {
            max-width: 1300px;
            margin: 0 auto;
            display: flex;
            justify-content: space-between;
            align-items: center;
            flex-wrap: wrap;
        }
        .logo {
            display: flex;
            align-items: center;
            gap: 12px;
            font-size: 1.5rem;
            font-weight: 700;
            color: white;
            text-decoration: none;
            letter-spacing: -0.5px;
        }
        .logo img {
            height: 40px;
            width: auto;
            filter: drop-shadow(0 2px 5px rgba(0,0,0,0.2));
        }
        .nav-links {
            display: flex;
            gap: 2rem;
            list-style: none;
            align-items: center;
        }
        .nav-links li a {
            color: rgba(255,255,255,0.85);
            text-decoration: none;
            font-weight: 500;
            transition: 0.2s;
            font-size: 0.95rem;
            padding: 0.5rem 0;
        }
        .nav-links li a:hover {
            color: white;
            text-shadow: 0 0 6px rgba(255,255,255,0.5);
        }
        .nav-links li a.active {
            color: #c084fc;
            border-bottom: 2px solid #c084fc;
        }
        @media (max-width: 768px) {
            .navbar { padding: 0.8rem 1.2rem; }
            .nav-links { gap: 1rem; }
        }
        
        /* Status Container & Card - enhanced glassmorphism */
        .status-container {
            flex: 1;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 2rem 1.5rem;
            position: relative;
            z-index: 10;
        }
        .status-card {
            background: rgba(255, 255, 255, 0.07);
            backdrop-filter: blur(14px);
            border-radius: 2rem;
            border: 1px solid rgba(255, 255, 255, 0.2);
            box-shadow: 0 25px 45px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255,255,255,0.1);
            padding: 2rem;
            width: 100%;
            max-width: 700px;
            transition: all 0.3s ease;
            position: relative;
            overflow: hidden;
        }
        .status-card:hover {
            transform: translateY(-4px);
            box-shadow: 0 30px 55px rgba(0, 0, 0, 0.4);
        }
        /* Shine effect on card */
        .status-card::before {
            content: '';
            position: absolute;
            top: 0;
            left: -100%;
            width: 100%;
            height: 100%;
            background: linear-gradient(90deg, transparent, rgba(255,255,255,0.12), transparent);
            transition: left 0.5s;
            pointer-events: none;
        }
        .status-card:hover::before {
            left: 100%;
        }
        
        .status-header {
            text-align: center;
            margin-bottom: 1.8rem;
        }
        .status-header i {
            font-size: 3rem;
            color: #c084fc;
            margin-bottom: 1rem;
            display: inline-block;
        }
        .status-header h1 {
            font-size: 1.8rem;
            font-weight: 700;
            background: linear-gradient(135deg, #fff, #c084fc);
            -webkit-background-clip: text;
            background-clip: text;
            color: transparent;
            margin-bottom: 0.5rem;
        }
        .status-header p {
            color: rgba(255,255,255,0.7);
            font-size: 0.85rem;
        }
        
        .form-group {
            margin-bottom: 1.3rem;
        }
        .form-control {
            width: 100%;
            background: rgba(255,255,255,0.1);
            border: 1px solid rgba(255,255,255,0.2);
            border-radius: 1.2rem;
            padding: 0.85rem 1rem;
            font-size: 0.9rem;
            color: white;
            font-weight: 500;
            transition: 0.2s;
            outline: none;
            font-family: 'Poppins', sans-serif;
        }
        .form-control:focus {
            border-color: rgba(255,255,255,0.6);
            background: rgba(255,255,255,0.15);
            box-shadow: 0 0 10px rgba(255,255,255,0.15);
        }
        .form-control::placeholder {
            color: rgba(255,255,255,0.4);
        }
        
        .submit-btn {
            width: 100%;
            background: linear-gradient(95deg, #7c3aed, #a855f7);
            border: none;
            border-radius: 1.8rem;
            padding: 0.85rem;
            font-weight: 700;
            font-size: 0.95rem;
            color: white;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 0.5rem;
            cursor: pointer;
            transition: 0.2s;
            position: relative;
            overflow: hidden;
            box-shadow: 0 6px 18px rgba(124,58,237,0.3);
        }
        .submit-btn:hover {
            transform: scale(1.02);
            box-shadow: 0 8px 22px rgba(124,58,237,0.5);
        }
        
        /* Ticket Details Section */
        .ticket-details {
            margin-top: 1.8rem;
            background: rgba(255,255,255,0.05);
            border-radius: 1.5rem;
            padding: 1.2rem;
            border: 1px solid rgba(255,255,255,0.1);
        }
        .ticket-details h3 {
            color: #c084fc;
            margin-bottom: 1rem;
            font-size: 1.2rem;
        }
        .detail-row {
            margin-bottom: 0.8rem;
            padding-bottom: 0.8rem;
            border-bottom: 1px solid rgba(255,255,255,0.1);
            color: rgba(255,255,255,0.9);
            font-size: 0.9rem;
        }
        .detail-row strong {
            color: white;
            font-weight: 600;
            min-width: 130px;
            display: inline-block;
        }
        .status-badge {
            display: inline-block;
            padding: 0.2rem 0.8rem;
            border-radius: 2rem;
            font-size: 0.75rem;
            font-weight: 600;
            background: rgba(0,0,0,0.3);
        }
        .status-resolved {
            background: #10b981;
            color: white;
        }
        .status-pending {
            background: #f59e0b;
            color: white;
        }
        .status-processing {
            background: #3b82f6;
            color: white;
        }
        .status-closed {
            background: #ef4444;
            color: white;
        }
        
        .reply-section {
            margin-top: 1.5rem;
            background: linear-gradient(135deg, rgba(124,58,237,0.15), rgba(168,85,247,0.05));
            border-radius: 1.5rem;
            padding: 1.2rem;
            border-left: 3px solid #c084fc;
        }
        .reply-section h4 {
            color: #c084fc;
            display: flex;
            align-items: center;
            gap: 0.5rem;
            margin-bottom: 0.8rem;
        }
        .reply-section p {
            color: rgba(255,255,255,0.85);
            line-height: 1.5;
        }
        
        .no-reply {
            margin-top: 1.5rem;
            text-align: center;
            padding: 1.5rem;
            background: rgba(0,0,0,0.2);
            border-radius: 1rem;
            color: rgba(255,255,255,0.7);
        }
        .no-reply i {
            font-size: 2rem;
            margin-bottom: 0.5rem;
            display: inline-block;
            color: #f59e0b;
        }
        
        /* Footer */
        .footer {
            text-align: center;
            padding: 1.2rem;
            font-size: 0.7rem;
            color: rgba(255,255,255,0.4);
            z-index: 10;
            position: relative;
        }
        
        @media (max-width: 600px) {
            .status-card { padding: 1.5rem; }
            .status-header h1 { font-size: 1.5rem; }
            .detail-row strong { display: block; margin-bottom: 0.3rem; }
        }
    </style>
</head>

<body>
    <!-- Animated background shapes (added for glamour, does not affect functionality) -->
    <div class="bg-shape shape-1"></div>
    <div class="bg-shape shape-2"></div>
    <div class="bg-shape shape-3"></div>

    <!-- Navigation (original HTML unchanged) -->
    <nav class="navbar">
        <div class="nav-container">
            <a href="index.php" class="logo">
                <img src="<?php echo XyZ_val('logo'); ?>" alt="Logo">
                <?php echo XyZ_val('brand'); ?>
            </a>
            
            <ul class="nav-links">
                <li><a href="index.php">Home</a></li>
                <li><a href="contact.php">Contact</a></li>
                <li><a href="check_status.php" class="active">Check Status</a></li>
            </ul>
        </div>
    </nav>

    <div class="status-container">
        <div class="status-card">
            <div class="status-header">
                <i class='bx bx-search-alt'></i>
                <h1>Check Ticket Status</h1>
                <p>Enter your ticket number to check the response status</p>
            </div>
            
            <div class="status-body">
                <form method="POST" action="">
                    <div class="form-group">
                        <input type="text" name="ticket_number" class="form-control" 
                               placeholder="Enter your ticket number (e.g., TNG202312011234)" 
                               value="<?php echo htmlspecialchars($ticket_number); ?>" required>
                    </div>
                    
                    <button type="submit" name="check_status" class="submit-btn">
                        <i class='bx bx-search'></i> Check Status
                    </button>
                </form>
                
                <?php if(isset($_POST['check_status']) || isset($_GET['ticket'])): ?>
                    <?php if($status_result): ?>
                        <div class="ticket-details">
                            <h3>Ticket Details</h3>
                            
                            <div class="detail-row">
                                <strong>Ticket Number:</strong> <?php echo $status_result['ticket_number']; ?>
                            </div>
                            
                            <div class="detail-row">
                                <strong>Status:</strong> 
                                <span class="status-badge status-<?php echo $status_result['status']; ?>">
                                    <?php echo ucfirst($status_result['status']); ?>
                                </span>
                            </div>
                            
                            <div class="detail-row">
                                <strong>Submitted On:</strong> <?php echo date('M j, Y g:i A', strtotime($status_result['created_at'])); ?>
                            </div>
                            
                            <div class="detail-row">
                                <strong>Name:</strong> <?php echo htmlspecialchars($status_result['name']); ?>
                            </div>
                            
                            <div class="detail-row">
                                <strong>Email:</strong> <?php echo htmlspecialchars($status_result['email']); ?>
                            </div>
                            
                            <div class="detail-row">
                                <strong>Message:</strong><br>
                                <?php echo nl2br(htmlspecialchars($status_result['message'])); ?>
                            </div>
                        </div>
                        
                        <?php if($status_result['reply_message']): ?>
                            <div class="reply-section">
                                <h4>
                                    <i class='bx bx-message-check'></i> Admin Response
                                </h4>
                                <p><?php echo nl2br(htmlspecialchars($status_result['reply_message'])); ?></p>
                                <div style="margin-top: 1rem; color: rgba(255,255,255,0.5); font-size: 0.75rem;">
                                    <small>
                                        Replied by: <?php echo $status_result['replied_by']; ?> 
                                        on <?php echo date('M j, Y g:i A', strtotime($status_result['replied_at'])); ?>
                                    </small>
                                </div>
                            </div>
                        <?php else: ?>
                            <div class="no-reply">
                                <i class='bx bx-time'></i>
                                <p>Your query is being processed. Our team will respond soon.</p>
                            </div>
                        <?php endif; ?>
                        
                    <?php else: ?>
                        <div class="no-reply">
                            <i class='bx bx-error'></i>
                            <p>No ticket found with the provided ticket number. Please check and try again.</p>
                        </div>
                    <?php endif; ?>
                <?php endif; ?>
            </div>
        </div>
    </div>

    <footer class="footer">
        <p>&copy; <?php echo date("Y"); ?> <?php echo XyZ_val('brand'); ?>. All rights reserved.</p>
    </footer>
</body>
</html>