<?php
session_start();
include('include/config.php');
if(strlen($_SESSION['alogin'])==0){	
    header('location:index.php');
} else {
    date_default_timezone_set('Asia/Kolkata');
    $currentTime = date('d-m-Y h:i:s A', time());
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Admin | In Process Complaints</title>

<!-- ✅ Bootstrap + Icons -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap" rel="stylesheet">

<style>
body {
    font-family: 'Inter', sans-serif;
    background-color: #f7f8fa;
}
.navbar {
    background: #1f1f1f;
    color: #fff;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
.sidebar {
    background: linear-gradient(180deg, #ff7a00, #ffb366);
    color: #fff;
    min-height: 100vh;
    padding-top: 1rem;
    position: fixed;
    width: 250px;
    border-top-right-radius: 20px;
    border-bottom-right-radius: 20px;
}
.sidebar a {
    display: block;
    color: #fff;
    padding: 12px 20px;
    text-decoration: none;
    border-radius: 10px;
    transition: 0.3s;
}
.sidebar a:hover, .sidebar a.active {
    background: rgba(255,255,255,0.25);
}
.content {
    margin-left: 260px;
    padding: 40px;
}
.card {
    border: none;
    border-radius: 12px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.08);
}
.table thead th {
    background: #ff7a00;
    color: #fff;
    border: none;
}
.table-striped tbody tr:nth-of-type(odd) {
    background-color: #fff5ec;
}
.table tbody tr:hover {
    background-color: #ffe3c4;
    transition: 0.2s ease-in-out;
}
footer {
    margin-left: 260px;
    background: #fff;
    padding: 10px;
    border-top: 1px solid #ddd;
    text-align: center;
    color: #666;
}
@media (max-width: 991px) {
    .sidebar {
        position: relative;
        width: 100%;
        min-height: auto;
        border-radius: 0;
    }
    .content, footer {
        margin-left: 0;
    }
}
</style>
</head>
<body>

<!-- ✅ Header -->
<?php include('include/header.php');?>

<div class="d-flex">
    <!-- ✅ Sidebar -->
    <div class="sidebar">
        <?php include('include/sidebar.php');?>
    </div>

    <!-- ✅ Main Content -->
    <div class="content flex-fill">
        <div class="card p-4">
            <div class="d-flex justify-content-between align-items-center mb-3">
                <h4 class="mb-0 fw-semibold text-dark">
                    <i class="bi bi-hourglass-split text-warning"></i> In Process Complaints
                </h4>
                <span class="text-muted small"><?php echo $currentTime; ?></span>
            </div>

            <div class="table-responsive">
                <table class="table table-striped table-bordered align-middle">
                    <thead>
                        <tr>
                            <th>Complaint No</th>
                            <th>Complainant Name</th>
                            <th>Reg Date</th>
                            <th>Status</th>
                            <th>Action</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php 
                        $st = 'in process';
                        $query = mysqli_query($bd, "SELECT tblcomplaints.*, users.fullName AS name 
                                                    FROM tblcomplaints 
                                                    JOIN users ON users.id = tblcomplaints.userId 
                                                    WHERE tblcomplaints.status = '$st'");
                        while($row = mysqli_fetch_array($query)) {
                            $status = $row['status'];
                            if ($status == "" || $status == NULL) {
                                $badge = '<span class="badge bg-danger"><i class="bi bi-x-circle-fill"></i> Not Processed</span>';
                            } elseif (strtolower($status) == "in process") {
                                $badge = '<span class="badge bg-warning text-dark"><i class="bi bi-hourglass-split"></i> In Process</span>';
                            } elseif (strtolower($status) == "closed") {
                                $badge = '<span class="badge bg-success"><i class="bi bi-check-circle-fill"></i> Closed</span>';
                            } else {
                                $badge = '<span class="badge bg-secondary"><i class="bi bi-question-circle"></i> Unknown</span>';
                            }
                        ?>
                        <tr>
                            <td><?php echo htmlentities($row['complaintNumber']); ?></td>
                            <td><?php echo htmlentities($row['name']); ?></td>
                            <td><?php echo htmlentities($row['regDate']); ?></td>
                            <td><?= $badge ?></td>
                            <td>
                                <a href="complaint-details.php?cid=<?php echo htmlentities($row['complaintNumber']); ?>" 
                                   class="btn btn-sm btn-primary">
                                   <i class="bi bi-eye"></i> View Details
                                </a>
                            </td>
                        </tr>
                        <?php } ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

<!-- ✅ Footer -->
<footer>
    <small>© <?php echo date("Y"); ?> Admin Dashboard. All rights reserved.</small>
</footer>

<!-- ✅ Scripts -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
<?php } ?>
