<?php
include 'auth.php';
require_permission('brands_view');
include 'includes/header.php';
?>
<div class="row mb-4">
<div class="col">
<h3 class="fs-4 mb-3">إدارة الماركات (البراندات)</h3>
</div>
<div class="col text-start">
<a href="brand_form.php" class="btn btn-success"><i class="fas fa-plus"></i> إضافة ماركة جديدة</a>
</div>
</div>
<div class="row">
<div class="col">
<div class="glass-card p-3">
<table class="table table-dark table-hover align-middle">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">اللوجو</th>
<th scope="col">اسم الماركة</th>
<th scope="col">الإجراءات</th>
</tr>
</thead>
<tbody>
<?php
$sql = "SELECT * FROM brands ORDER BY name ASC";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$logo_path = !empty($row["logo"]) ? '../uploads/brands/' . htmlspecialchars($row["logo"]) : 'https://via.placeholder.com/100x50';
echo "<tr>";
echo "<th scope='row'>" . $row["id"] . "</th>";
echo "<td><img src='" . $logo_path . "' height='40' class='bg-light p-1 rounded'></td>";
echo "<td>" . htmlspecialchars($row["name"]) . "</td>";
echo "<td>
<a href='brand_form.php?id=" . $row["id"] . "' class='btn btn-primary btn-sm'><i class='fas fa-edit'></i></a>
<a href='brand_delete.php?id=" . $row["id"] . "' class='btn btn-danger btn-sm' onclick='return confirm(\"هل أنت متأكد من حذف هذه الماركة؟ سيؤثر هذا على السيارات المرتبطة بها.\");'><i class='fas fa-trash'></i></a>
</td>";
echo "</tr>";
}
} else {
echo "<tr><td colspan='4' class='text-center'>لا توجد ماركات مضافة حالياً.</td></tr>";
}
?>
</tbody>
</table>
</div>
</div>
</div>
<?php include 'includes/footer.php'; ?>