<?php
require 'inc/auth_check.php';
require 'inc/header.php';

$res = $mysqli->query("SELECT * FROM projects ORDER BY created_at DESC");
?>
<h2 class="text-xl font-bold mb-4">Projects <a href="project_add.php" class="ml-4 text-sm bg-teal-600 text-white px-3 py-1 rounded">Tambah</a></h2>
<table class="w-full bg-white shadow rounded">
  <thead><tr class="bg-gray-100"><th class="p-2">#</th><th>Title</th><th>Image</th><th>Actions</th></tr></thead>
  <tbody>
    <?php while($p = $res->fetch_assoc()): ?>
    <tr>
      <td class="p-2"><?php echo e($p['id']); ?></td>
      <td class="p-2"><?php echo e($p['title']); ?></td>
      <td class="p-2"><?php if(!empty($p['image']) && file_exists(__DIR__ . '/../uploads/projects/' . $p['image'])): ?>
        <img src="/uploads/projects/<?php echo e($p['image']); ?>" class="w-24">
      <?php endif; ?></td>
      <td class="p-2">
        <a href="project_edit.php?id=<?php echo e($p['id']); ?>" class="text-teal-600 mr-2">Edit</a>
        <a href="project_delete.php?id=<?php echo e($p['id']); ?>" onclick="return confirm('Hapus project?')" class="text-red-600">Delete</a>
      </td>
    </tr>
    <?php endwhile; ?>
  </tbody>
</table>

</div></body></html>
