<?php
require_once "../config/auth.php";
require_once "../config/db.php";
require_once "../config/helpers.php";

$pageTitle = "Customers";

require_once "../includes/header.php";
require_once "../includes/sidebar.php";
require_once "../includes/topbar.php";



// ================= DATA =================
$result = $conn->query("
SELECT * FROM customers 
ORDER BY id DESC
LIMIT 20
");
?>

<div class="main-content">
<div class="col-lg-12">

<div class="p-4">

<div class="d-flex justify-content-between mb-3">

    <input type="text" id="customerSearch" 
           class="form-control w-50" 
           placeholder="Search customer...">

    <a href="add_customer.php" class="btn btn-primary">
        + Add Customer
    </a>

</div>

<div class="table-responsive">

<table class="table table-bordered table-striped">

<thead class="table-dark">
<tr>
    
    <th>Name</th>
    <th>Email</th>
    <th>Phone</th>
    <th>Address</th>
    <th>Action</th>
</tr>
</thead>

<tbody id="customerTable">

<?php if($result->num_rows > 0){ ?>
<?php while($row = $result->fetch_assoc()){ ?>

<tr>

<td><?= e($row['name']) ?></td>
<td><?= e($row['email']) ?></td>
<td><?= e($row['phone']) ?></td>
<td><?= e($row['address']) ?></td>

<td>

<a href="edit_customer.php?id=<?= $row['id'] ?>" 
class="btn btn-warning btn-sm">Edit</a>

<a href="#"
   class="btn btn-danger btn-sm deleteBtn"
   data-id="<?= $row['id'] ?>"
   data-url="../actions/delete_customer.php"
>
   Delete
</a>

</td>

</tr>

<?php } ?>
<?php } else { ?>
<tr>
<td colspan="6" class="text-center">No customers found</td>
</tr>
<?php } ?>

</tbody>

</table>

</div>

</div>
</div>
</div>

<?php require_once "../includes/footer.php"; ?>