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

    return $venueRecord[$field] ?? $default;
};
?>
<div class="row g-3">
    <div class="col-md-6">
        <label class="form-label" for="name">Venue name</label>
        <input class="form-control <?php echo validation_error($formErrors, 'name') ? 'is-invalid' : ''; ?>" id="name" name="name" value="<?php echo e((string) $fieldValue('name')); ?>" required>
        <?php if (validation_error($formErrors, 'name')): ?><div class="invalid-feedback"><?php echo e((string) validation_error($formErrors, 'name')); ?></div><?php endif; ?>
    </div>
    <div class="col-md-6">
        <label class="form-label" for="location">Location</label>
        <input class="form-control <?php echo validation_error($formErrors, 'location') ? 'is-invalid' : ''; ?>" id="location" name="location" value="<?php echo e((string) $fieldValue('location')); ?>" required>
        <?php if (validation_error($formErrors, 'location')): ?><div class="invalid-feedback"><?php echo e((string) validation_error($formErrors, 'location')); ?></div><?php endif; ?>
    </div>
    <div class="col-md-4">
        <label class="form-label" for="capacity">Capacity</label>
        <input class="form-control <?php echo validation_error($formErrors, 'capacity') ? 'is-invalid' : ''; ?>" id="capacity" name="capacity" type="number" min="0" value="<?php echo e((string) $fieldValue('capacity')); ?>">
        <?php if (validation_error($formErrors, 'capacity')): ?><div class="invalid-feedback"><?php echo e((string) validation_error($formErrors, 'capacity')); ?></div><?php endif; ?>
    </div>
    <div class="col-md-4">
        <label class="form-label" for="pitch_type">Pitch type</label>
        <input class="form-control" id="pitch_type" name="pitch_type" value="<?php echo e((string) $fieldValue('pitch_type')); ?>" placeholder="Natural grass, turf, hybrid...">
    </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 (venue_status_options() as $status): ?>
                <option value="<?php echo e($status); ?>" <?php echo (string) $fieldValue('status', 'active') === $status ? 'selected' : ''; ?>><?php echo e(ucwords(str_replace('_', ' ', $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>