<div class="card card-modern p-4">
<h4 class="mb-3">إدارة البيانات</h4>

<button class="btn btn-primary mb-3" data-bs-toggle="modal" data-bs-target="#createModal">
<i class="fa fa-plus"></i> إضافة
</button>

<table class="table table-bordered table-hover">
<thead class="table-light">
<tr>
<?php if(isset($rows[0])): foreach(array_keys($rows[0]) as $col): ?>
<th><?= $col ?></th>
<?php endforeach; ?>
<th>إدارة</th>
</tr>
</thead>
<tbody>
<?php foreach($rows as $r): ?>
<tr>
<?php foreach($r as $val): ?>
<td><?= htmlspecialchars($val) ?></td>
<?php endforeach; ?>
<td>
<button class="btn btn-sm btn-danger deleteBtn" data-id="<?= $r['id'] ?>">
<i class="fa fa-trash"></i>
</button>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>

<?php endif; ?>
</div>

<script>
$('.deleteBtn').click(function(){
    let id = $(this).data('id');
    $.post('',{id:id},function(){
        location.reload();
    });
});
</script>
