<?php $title = 'Edit Rider'; ?>

<div class="d-flex justify-content-between align-items-center mb-4">
    <h4 class="mb-0 fw-bold">Edit Rider</h4>
    <div class="d-flex gap-2">
        <a href="<?= url('riders/'.$rider['id']) ?>" class="btn btn-outline-primary btn-sm">
            <i class="bi bi-eye me-1"></i> View
        </a>
        <a href="<?= url('riders') ?>" class="btn btn-outline-secondary btn-sm">
            <i class="bi bi-arrow-left me-1"></i> Back
        </a>
    </div>
</div>

<div class="row justify-content-center">
<div class="col-lg-7">
<div class="card border-0 shadow-sm">
<div class="card-body p-4">

<form method="POST" action="<?= url('riders/'.$rider['id'].'/update') ?>">
    <?= csrf_field() ?>

    <div class="row g-3">
        <div class="col-12">
            <label class="form-label fw-semibold">Full Name <span class="text-danger">*</span></label>
            <input type="text" name="name" value="<?= e($old['name'] ?? '') ?>"
                   class="form-control <?= isset($errors['name']) ? 'is-invalid' : '' ?>">
            <?php if (isset($errors['name'])): ?>
                <div class="invalid-feedback"><?= e($errors['name']) ?></div>
            <?php endif ?>
        </div>

        <div class="col-md-6">
            <label class="form-label fw-semibold">Email <span class="text-danger">*</span></label>
            <input type="email" name="email" value="<?= e($old['email'] ?? '') ?>"
                   class="form-control <?= isset($errors['email']) ? 'is-invalid' : '' ?>">
            <?php if (isset($errors['email'])): ?>
                <div class="invalid-feedback"><?= e($errors['email']) ?></div>
            <?php endif ?>
        </div>

        <div class="col-md-6">
            <label class="form-label fw-semibold">Phone <span class="text-danger">*</span></label>
            <input type="text" name="phone" value="<?= e($old['phone'] ?? '') ?>"
                   class="form-control <?= isset($errors['phone']) ? 'is-invalid' : '' ?>">
            <?php if (isset($errors['phone'])): ?>
                <div class="invalid-feedback"><?= e($errors['phone']) ?></div>
            <?php endif ?>
        </div>

        <div class="col-md-6">
            <label class="form-label fw-semibold">Vehicle Type</label>
            <select name="vehicle_type" class="form-select">
                <option value="">— Select —</option>
                <?php foreach (['Bike', 'Motorcycle', 'Car', 'Van', 'Bicycle'] as $v): ?>
                    <option value="<?= $v ?>" <?= ($old['vehicle_type'] ?? '') === $v ? 'selected' : '' ?>>
                        <?= $v ?>
                    </option>
                <?php endforeach ?>
            </select>
        </div>

        <div class="col-md-6">
            <label class="form-label fw-semibold">Vehicle Number</label>
            <input type="text" name="vehicle_number" value="<?= e($old['vehicle_number'] ?? '') ?>"
                   placeholder="e.g. ABC-123" class="form-control">
        </div>

        <div class="col-12"><hr class="my-1">
            <small class="text-muted">Leave password blank to keep current password.</small>
        </div>

        <div class="col-md-6">
            <label class="form-label fw-semibold">New Password</label>
            <input type="password" name="password"
                   class="form-control <?= isset($errors['password']) ? 'is-invalid' : '' ?>">
            <?php if (isset($errors['password'])): ?>
                <div class="invalid-feedback"><?= e($errors['password']) ?></div>
            <?php endif ?>
        </div>

        <div class="col-md-6">
            <label class="form-label fw-semibold">Confirm New Password</label>
            <input type="password" name="password_confirm"
                   class="form-control <?= isset($errors['password_confirm']) ? 'is-invalid' : '' ?>">
            <?php if (isset($errors['password_confirm'])): ?>
                <div class="invalid-feedback"><?= e($errors['password_confirm']) ?></div>
            <?php endif ?>
        </div>

        <div class="col-12 d-flex gap-2 mt-2">
            <button type="submit" class="btn btn-primary px-4">
                <i class="bi bi-check-lg me-1"></i> Save Changes
            </button>
            <a href="<?= url('riders') ?>" class="btn btn-outline-secondary px-4">Cancel</a>
        </div>
    </div>
</form>

</div>
</div>
</div>
</div>
