<?php

require 'config.php';
session_start();
session_write_close();

$userId = intval($_SESSION['user_id']);

$res = $conn->query("
SELECT

a.asset_name,
a.asset_tag,
a.category,

aa.assigned_date,
aa.status

FROM asset_assignments aa

LEFT JOIN assets a
ON a.id=aa.asset_id

WHERE aa.employee_id=$userId

ORDER BY aa.assigned_date DESC
");
?>

<!DOCTYPE html>
<html>
<head>
<title>My Assets</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>

<body class="flex bg-gray-100 min-h-screen">

<?php include 'sidebar.php'; ?>

<div class="flex-1 p-8" id="main-content">

<h1 class="text-3xl font-bold mb-6">
My Assigned Assets
</h1>

<div class="bg-white rounded-xl shadow overflow-hidden">

<table class="w-full">

<thead class="bg-gray-100">

<tr>

<th class="p-4 text-left">Asset</th>
<th class="p-4">Tag</th>
<th class="p-4">Category</th>
<th class="p-4">Assigned Date</th>
<th class="p-4">Status</th>

</tr>

</thead>

<tbody>

<?php while($row=$res->fetch_assoc()): ?>

<tr class="border-b hover:bg-gray-50">

<td class="p-4">
<?= htmlspecialchars($row['asset_name']) ?>
</td>

<td class="p-4 text-center">
<?= htmlspecialchars($row['asset_tag']) ?>
</td>

<td class="p-4 text-center">
<?= htmlspecialchars($row['category']) ?>
</td>

<td class="p-4 text-center">
<?= $row['assigned_date'] ?>
</td>

<td class="p-4 text-center">

<span class="bg-green-100 text-green-700 px-3 py-1 rounded-full">

<?= htmlspecialchars($row['status']) ?>

</span>

</td>

</tr>

<?php endwhile; ?>

</tbody>

</table>

</div>

</div>

</body>
</html>