<?php require_once __DIR__ . '/../layout.php'; ?>

<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 2rem;">
    <div>
        <h3 style="margin: 0 0 0.5rem; color: white;">Units of Measure Directory</h3>
        <p style="color: var(--text-muted); margin: 0;">Manage unit of measurement tokens associated with items inside the pharmacy inventory.</p>
    </div>
    <a href="/superadmin/uomCreate" class="btn-gold">
        <i class="ph ph-plus" style="font-weight: bold;"></i> Add Unit of Measure
    </a>
</div>

<div class="card responsive-table-container" style="padding: 0; overflow-x: auto; border: none; margin-bottom: 2rem; border-radius: 12px;">
    <table class="data-table" style="width: 100%; border-collapse: collapse;">
        <thead>
            <tr>
                <th style="width: 15%;">ID</th>
                <th style="width: 50%;">Name</th>
                <th style="width: 25%;">Created At</th>
                <th style="width: 10%; text-align: center;">Actions</th>
            </tr>
        </thead>
        <tbody>
            <?php if (empty($records)): ?>
                <tr>
                    <td colspan="4" style="text-align: center; color: var(--text-muted); padding: 2rem;">No units of measure defined yet.</td>
                </tr>
            <?php else: ?>
                <?php foreach ($records as $rec): ?>
                    <tr>
                        <td style="color: var(--text-muted);"><?php echo htmlspecialchars($rec['id']); ?></td>
                        <td><strong style="color: white;"><?php echo htmlspecialchars($rec['name']); ?></strong></td>
                        <td style="color: var(--text-muted);"><?php echo htmlspecialchars($rec['created_at']); ?></td>
                        <td style="text-align: center; white-space: nowrap;">
                            <a href="/superadmin/uomEdit/<?php echo $rec['id']; ?>" class="action-icon edit" title="Edit">
                                <i class="ph ph-pencil-simple"></i>
                            </a>
                            <a href="/superadmin/uomDelete/<?php echo $rec['id']; ?>" class="action-icon delete" title="Delete" onclick="return confirm('Are you sure you want to delete this Unit of Measure? Medicines linked to this unit will be set to NULL (no unit).');">
                                <i class="ph ph-trash"></i>
                            </a>
                        </td>
                    </tr>
                <?php endforeach; ?>
            <?php endif; ?>
        </tbody>
    </table>
</div>

</div> <!-- main-content -->
</div> <!-- dashboard-layout -->
</body>
</html>
