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

<div class="mb-3">
    <a href="<?= site_url('group-bookings') ?>" class="text-decoration-none small">&larr; Group Bookings</a>
    <p class="text-muted mb-0 mt-1">Step 1 of 2 &mdash; tell us who this is for, the dates, and how many rooms of each type. You'll pick the exact rooms and enter each guest's name next.</p>
</div>

<div class="card shadow-sm" style="max-width: 820px;">
    <div class="card-body">
        <form action="<?= site_url('group-bookings/rooms') ?>" method="post">
            <?= csrf_field() ?>

            <h6 class="text-muted text-uppercase small fw-bold mb-2">Group Details</h6>
            <div class="row g-3 mb-3">
                <div class="col-md-7">
                    <label class="form-label small fw-semibold">Group Name</label>
                    <input type="text" class="form-control" name="group_name" placeholder="e.g. GhanaTel Conference 2026" value="<?= esc(old('group_name')) ?>" required>
                </div>
                <div class="col-md-5">
                    <label class="form-label small fw-semibold">Corporate Account <span class="text-muted fw-normal">(optional)</span></label>
                    <select class="form-select" name="corporate_account_id">
                        <option value="">&mdash; None / informal group &mdash;</option>
                        <?php foreach ($corporateAccounts as $ca): ?>
                            <option value="<?= $ca->id ?>"><?= esc($ca->company_name) ?></option>
                        <?php endforeach; ?>
                    </select>
                    <div class="form-text">Bills every room's folio to this account automatically.</div>
                </div>
                <div class="col-md-4">
                    <label class="form-label small fw-semibold">Organizer Name <span class="text-muted fw-normal">(optional)</span></label>
                    <input type="text" class="form-control" name="organizer_name" value="<?= esc(old('organizer_name')) ?>">
                </div>
                <div class="col-md-4">
                    <label class="form-label small fw-semibold">Organizer Phone</label>
                    <input type="text" class="form-control" name="organizer_phone" value="<?= esc(old('organizer_phone')) ?>">
                </div>
                <div class="col-md-4">
                    <label class="form-label small fw-semibold">Organizer Email</label>
                    <input type="email" class="form-control" name="organizer_email" value="<?= esc(old('organizer_email')) ?>">
                </div>
            </div>

            <h6 class="text-muted text-uppercase small fw-bold mb-2">Stay Dates</h6>
            <div class="row g-3 mb-3">
                <div class="col-md-6">
                    <label class="form-label small fw-semibold">Check-In</label>
                    <input type="date" class="form-control" name="check_in_date" value="<?= esc(old('check_in_date')) ?>" required>
                </div>
                <div class="col-md-6">
                    <label class="form-label small fw-semibold">Check-Out</label>
                    <input type="date" class="form-control" name="check_out_date" value="<?= esc(old('check_out_date')) ?>" required>
                </div>
            </div>

            <h6 class="text-muted text-uppercase small fw-bold mb-2">Rooms Needed</h6>
            <div class="row g-2 mb-3">
                <?php foreach ($roomTypes as $rt): ?>
                    <div class="col-md-6">
                        <div class="d-flex align-items-center justify-content-between border rounded p-2">
                            <div>
                                <div class="fw-semibold small"><?= esc($rt->name) ?></div>
                                <div class="text-muted small"><?= format_money($rt->base_rate) ?>/night &middot; sleeps <?= (int) $rt->capacity ?></div>
                            </div>
                            <input type="number" min="0" max="99" class="form-control form-control-sm" style="width: 80px;" name="quantity[<?= $rt->id ?>]" value="<?= esc(old('quantity.' . $rt->id) ?: '0') ?>">
                        </div>
                    </div>
                <?php endforeach; ?>
            </div>

            <div class="mb-3">
                <label class="form-label small fw-semibold">Notes <span class="text-muted fw-normal">(optional)</span></label>
                <textarea class="form-control" name="notes" rows="2"><?= esc(old('notes')) ?></textarea>
            </div>

            <button type="submit" class="btn btn-primary"><i class="bi bi-search me-1"></i>Find Available Rooms</button>
        </form>
    </div>
</div>

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