<?php $pageTitle = 'Brokers / Customers'; ?>
<div class="panel">
    <?php
        $title = 'Broker / Customer Management';
        $eyebrow = 'Accounts';
        $searchAction = url('/brokers');
        $createUrl = url('/brokers/create');
        $createText = 'Add Broker';
        require app_path('Views/components/search_header.php');
    ?>

    <div class="table-wrap">
        <table>
            <thead>
                <tr>
                    <th>Company</th>
                    <th>Contact</th>
                    <th>MC Number</th>
                    <th>Payment Terms</th>
                    <th>Status</th>
                    <th class="text-right">Actions</th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($brokers as $broker): ?>
                    <tr>
                        <td><strong><?= e($broker['company_name']) ?></strong><br><small><?= e($broker['address'] ?? '') ?></small></td>
                        <td><?= e($broker['contact_name'] ?? '-') ?><br><small><?= e($broker['email'] ?? '') ?> <?= e($broker['phone'] ?? '') ?></small></td>
                        <td><?= e($broker['mc_number'] ?? '-') ?></td>
                        <td><?= e($broker['payment_terms'] ?? '-') ?></td>
                        <td><span class="badge badge-<?= status_class($broker['status']) ?>"><?= e(readable_status($broker['status'])) ?></span></td>
                        <td class="text-right table-actions">
                            <a class="btn btn-light btn-sm" href="<?= url('/brokers/edit?id=' . $broker['id']) ?>">Edit</a>
                            <form method="post" action="<?= url('/brokers/delete') ?>" onsubmit="return confirm('Delete this broker/customer?')">
                                <?= csrf_field() ?>
                                <input type="hidden" name="id" value="<?= e((string) $broker['id']) ?>">
                                <button class="btn btn-danger btn-sm" type="submit">Delete</button>
                            </form>
                        </td>
                    </tr>
                <?php endforeach; ?>
                <?php if (!$brokers): ?>
                    <tr><td colspan="6" class="empty">No brokers/customers found.</td></tr>
                <?php endif; ?>
            </tbody>
        </table>
    </div>
</div>
