 <?php
if (!isset($reportData)) {
    $reportData = [];
}
?>

<table class="table table-striped">
    <thead>
        <tr>
            <th>Date</th>
            <th>Item Name</th>
            <th>Code</th>
            <th>Amount</th>
            <th>Status</th>
           <!-- <th>Action</th> -->
        </tr>
    </thead>
    <tbody>
        <?php if (!empty($reportData) && is_array($reportData)): ?>
            <?php foreach ($reportData as $sale): ?>
                <tr>
                    <td><?php echo htmlspecialchars(date('Y-m-d', strtotime($sale['date'] ?? 'now'))); ?></td>
                    <td><?php echo htmlspecialchars(trim((string)($sale['item_name'] ?? 'N/A') . (!empty($sale['item_details']) ? ' - ' . $sale['item_details'] : ''))); ?></td>
                    <td><?php echo htmlspecialchars($sale['unique_code'] ?? 'N/A'); ?></td>
                    <td>MWK <?php echo number_format($sale['amount'] ?? 0, 2); ?></td>
                    <td><?php echo htmlspecialchars(strpos($sale['transaction_id'] ?? '', '_VERIFIED_') !== false ? 'Verified' : 'Unverified'); ?></td>
                    <td>
                        <?php if (strpos($sale['transaction_id'] ?? '', '_VERIFIED_') === false && isset($sale['sale_id']) && !empty($sale['sale_id'])): ?>
                           <!-- <a href="edit_sale.php?id=<?php echo htmlspecialchars($sale['sale_id']); ?>" class="btn btn-sm btn-primary me-1"><i class="fas fa-edit"></i> Edit</a>
                            <form action="process_sale_action.php" method="POST" style="display:inline;" onsubmit="return confirmDelete('sale');">
                                <input type="hidden" name="transaction_id" value="<?php echo htmlspecialchars($sale['transaction_id']); ?>">
                                <button type="submit" name="delete_sale" class="btn btn-sm btn-danger"><i class="fas fa-trash"></i> Delete</button>
                            </form> -->
                        <?php else: ?>
                            <span class="text-muted">N/A</span>
                        <?php endif; ?>
                    </td>
                </tr>
            <?php endforeach; ?>
        <?php else: ?>
            <tr><td colspan="6" class="text-center">No unverified sales found</td></tr>
        <?php endif; ?>
    </tbody>
</table>