<?= $this->extend('layouts/main') ?>
<?= $this->section('content') ?>

<div class="d-flex justify-content-between align-items-center mb-3">
    <h1 class="h3 mb-0">Corporate Accounts</h1>
    <a href="<?= site_url('corporate-accounts/new') ?>" class="btn btn-primary"><i class="bi bi-plus-lg"></i> New Account</a>
</div>

<form action="<?= site_url('corporate-accounts') ?>" method="get" class="mb-3">
    <div class="input-group" style="max-width: 480px;">
        <input type="text" class="form-control" name="q" value="<?= esc($term) ?>" placeholder="Search by company or contact">
        <button type="submit" class="btn btn-outline-secondary">Search</button>
    </div>
</form>

<div class="card shadow-sm">
    <div class="table-scroll">
        <table class="table table-hover mb-0 align-middle">
            <thead class="table-light"><tr><th>Company</th><th>Contact</th><th>Phone</th><th>Email</th></tr></thead>
            <tbody>
                <?php if (empty($accounts)): ?>
                    <tr><td colspan="4" class="text-center text-muted py-4">No corporate accounts yet.</td></tr>
                <?php endif; ?>
                <?php foreach ($accounts as $account): ?>
                    <tr style="cursor:pointer" onclick="window.location='<?= site_url('corporate-accounts/' . $account->id) ?>'">
                        <td class="fw-semibold"><?= esc($account->company_name) ?></td>
                        <td><?= esc($account->contact_name) ?></td>
                        <td><?= esc($account->phone) ?></td>
                        <td><?= esc($account->email) ?></td>
                    </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    </div>
</div>

<?= $this->endSection() ?>
