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

<div class="d-flex justify-content-between align-items-start mb-3">
    <h1 class="h3 mb-0"><?= esc($client->company_name) ?></h1>
    <a href="<?= site_url('event-clients/' . $client->id . '/edit') ?>" class="btn btn-outline-secondary">Edit</a>
</div>

<div class="row">
    <div class="col-md-4 mb-3">
        <div class="card shadow-sm">
            <div class="card-body">
                <h2 class="h6">Contact</h2>
                <dl class="row mb-0 small">
                    <dt class="col-5">Contact</dt><dd class="col-7"><?= esc($client->contact_name ?: '—') ?></dd>
                    <dt class="col-5">Phone</dt><dd class="col-7"><?= esc($client->phone ?: '—') ?></dd>
                    <dt class="col-5">Email</dt><dd class="col-7"><?= esc($client->email ?: '—') ?></dd>
                </dl>
            </div>
        </div>
        <div class="card shadow-sm mt-3">
            <div class="card-body">
                <h2 class="h6">Catering Preferences</h2>
                <p class="small mb-0"><?= nl2br(esc($client->catering_preferences ?: 'None on file.')) ?></p>
            </div>
        </div>
    </div>
    <div class="col-md-8">
        <div class="card shadow-sm">
            <div class="card-body">
                <div class="d-flex justify-content-between align-items-center mb-2">
                    <h2 class="h6 mb-0">Event History</h2>
                    <a href="<?= site_url('events/new?event_client_id=' . $client->id) ?>" class="btn btn-sm btn-primary">New Event</a>
                </div>
                <?php if (empty($events)): ?>
                    <p class="text-muted small">This company has held 0 events with us.</p>
                <?php else: ?>
                    <p class="text-muted small">This company has held <?= count($events) ?> event(s) with us.</p>
                    <table class="table table-sm align-middle">
                        <thead class="table-light"><tr><th>Date</th><th>Event</th><th>Headcount</th><th>Status</th></tr></thead>
                        <tbody>
                            <?php foreach ($events as $event): ?>
                                <tr style="cursor:pointer" onclick="window.location='<?= site_url('events/' . $event->id) ?>'">
                                    <td><?= esc($event->event_date) ?></td>
                                    <td><?= esc($event->event_name) ?></td>
                                    <td><?= esc($event->expected_headcount) ?></td>
                                    <td><?= esc(ucfirst($event->status)) ?></td>
                                </tr>
                            <?php endforeach; ?>
                        </tbody>
                    </table>
                <?php endif; ?>
            </div>
        </div>
    </div>
</div>

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