<?php
$refereeRecord = $refereeRecord ?? null;
$formErrors = $formErrors ?? [];
$fieldValue = static function (string $field, mixed $default = '') use ($refereeRecord) {
    if (isset($_SESSION['_old']) && array_key_exists($field, $_SESSION['_old'])) {
        return old($field, $default);
    }

    return $refereeRecord[$field] ?? $default;
};
?>
<div class="row g-3">
    <div class="col-md-6">
        <label class="form-label" for="full_name">Full name</label>
        <input class="form-control <?php echo validation_error($formErrors, 'full_name') ? 'is-invalid' : ''; ?>" id="full_name" name="full_name" value="<?php echo e((string) $fieldValue('full_name')); ?>" required>
        <?php if (validation_error($formErrors, 'full_name')): ?><div class="invalid-feedback"><?php echo e((string) validation_error($formErrors, 'full_name')); ?></div><?php endif; ?>
    </div>
    <div class="col-md-6">
        <label class="form-label" for="level">Level</label>
        <select class="form-select <?php echo validation_error($formErrors, 'level') ? 'is-invalid' : ''; ?>" id="level" name="level" required>
            <?php foreach (referee_level_options() as $level): ?>
                <option value="<?php echo e($level); ?>" <?php echo (string) $fieldValue('level', 'local') === $level ? 'selected' : ''; ?>><?php echo e(ucfirst($level)); ?></option>
            <?php endforeach; ?>
        </select>
        <?php if (validation_error($formErrors, 'level')): ?><div class="invalid-feedback"><?php echo e((string) validation_error($formErrors, 'level')); ?></div><?php endif; ?>
    </div>
    <div class="col-md-4">
        <label class="form-label" for="phone">Phone</label>
        <input class="form-control <?php echo validation_error($formErrors, 'phone') ? 'is-invalid' : ''; ?>" id="phone" name="phone" value="<?php echo e((string) $fieldValue('phone')); ?>">
        <?php if (validation_error($formErrors, 'phone')): ?><div class="invalid-feedback"><?php echo e((string) validation_error($formErrors, 'phone')); ?></div><?php endif; ?>
    </div>
    <div class="col-md-4">
        <label class="form-label" for="email">Email</label>
        <input class="form-control <?php echo validation_error($formErrors, 'email') ? 'is-invalid' : ''; ?>" id="email" name="email" type="email" value="<?php echo e((string) $fieldValue('email')); ?>">
        <?php if (validation_error($formErrors, 'email')): ?><div class="invalid-feedback"><?php echo e((string) validation_error($formErrors, 'email')); ?></div><?php endif; ?>
    </div>
    <div class="col-md-4">
        <label class="form-label" for="status">Status</label>
        <select class="form-select <?php echo validation_error($formErrors, 'status') ? 'is-invalid' : ''; ?>" id="status" name="status" required>
            <?php foreach (referee_status_options() as $status): ?>
                <option value="<?php echo e($status); ?>" <?php echo (string) $fieldValue('status', 'active') === $status ? 'selected' : ''; ?>><?php echo e(ucfirst($status)); ?></option>
            <?php endforeach; ?>
        </select>
        <?php if (validation_error($formErrors, 'status')): ?><div class="invalid-feedback"><?php echo e((string) validation_error($formErrors, 'status')); ?></div><?php endif; ?>
    </div>
</div>