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

<h1 class="h3 mb-3"><?= $account ? 'Edit Corporate Account' : 'New Corporate Account' ?></h1>

<div class="card shadow-sm" style="max-width: 560px;">
    <div class="card-body">
        <form action="<?= $account ? site_url('corporate-accounts/' . $account->id) : site_url('corporate-accounts') ?>" method="post">
            <?= csrf_field() ?>

            <div class="mb-3">
                <label class="form-label">Company Name</label>
                <input type="text" class="form-control" name="company_name" required value="<?= esc(old('company_name', $account->company_name ?? '')) ?>">
            </div>
            <div class="mb-3">
                <label class="form-label">Contact Name</label>
                <input type="text" class="form-control" name="contact_name" value="<?= esc(old('contact_name', $account->contact_name ?? '')) ?>">
            </div>
            <div class="row">
                <div class="col-md-6 mb-3">
                    <label class="form-label">Phone</label>
                    <input type="text" class="form-control" name="phone" value="<?= esc(old('phone', $account->phone ?? '')) ?>">
                </div>
                <div class="col-md-6 mb-3">
                    <label class="form-label">Email</label>
                    <input type="email" class="form-control" name="email" value="<?= esc(old('email', $account->email ?? '')) ?>">
                </div>
            </div>
            <div class="mb-3">
                <label class="form-label">Billing Address</label>
                <textarea class="form-control" name="billing_address" rows="3"><?= esc(old('billing_address', $account->billing_address ?? '')) ?></textarea>
            </div>
            <div class="mb-3">
                <label class="form-label">Negotiated Rate Plan <span class="text-muted small">(optional)</span></label>
                <select class="form-select" name="default_rate_plan_id">
                    <option value="0">No negotiated rate — standard pricing</option>
                    <?php foreach ($ratePlans as $plan): ?>
                        <option value="<?= $plan->id ?>" <?= (int) old('default_rate_plan_id', $account->default_rate_plan_id ?? 0) === (int) $plan->id ? 'selected' : '' ?>><?= esc($plan->name) ?> (<?= $plan->adjustment_type === 'flat' ? format_money($plan->adjustment_value) : $plan->adjustment_value . '%' ?>)</option>
                    <?php endforeach; ?>
                </select>
                <div class="form-text">When set, the New Booking wizard applies this plan's rate for this company's stays instead of the standard date-based rate.</div>
            </div>

            <div class="d-flex gap-2">
                <button type="submit" class="btn btn-primary">Save</button>
                <a href="<?= site_url('corporate-accounts') ?>" class="btn btn-outline-secondary">Cancel</a>
            </div>
        </form>
    </div>
</div>

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