<?php $f = $facility ?? []; ?>
<div class="row g-3">
    <?php if (empty($f)): ?>
    <div class="col-md-4">
        <label class="form-label"><?= lang('facilities.code') ?> <span class="text-danger">*</span></label>
        <input type="text" name="facility_code" class="form-control" value="" required maxlength="20" placeholder="e.g. COURT-01">
        <div class="invalid-feedback" data-field="facility_code"></div>
    </div>
    <?php endif; ?>
    <div class="col-md-4">
        <label class="form-label"><?= lang('facilities.type') ?> <span class="text-danger">*</span></label>
        <select name="facility_type_id" class="form-select" required>
            <option value=""><?= lang('common.search') ?>...</option>
            <?php foreach ($facilityTypes as $ft): ?>
            <option value="<?= $ft['id'] ?>" <?= selected($ft['id'], $f['facility_type_id'] ?? '') ?>><?= e($ft['name_en']) ?> - <?= e($ft['name_ar']) ?></option>
            <?php endforeach; ?>
        </select>
        <div class="invalid-feedback" data-field="facility_type_id"></div>
    </div>
    <div class="col-md-4">
        <label class="form-label"><?= lang('common.status') ?></label>
        <select name="status" class="form-select">
            <option value="active" <?= selected('active', $f['status'] ?? 'active') ?>>Active</option>
            <option value="under_maintenance" <?= selected('under_maintenance', $f['status'] ?? '') ?>>Under Maintenance</option>
            <option value="closed" <?= selected('closed', $f['status'] ?? '') ?>>Closed</option>
            <option value="reserved" <?= selected('reserved', $f['status'] ?? '') ?>>Reserved</option>
        </select>
    </div>
    <div class="col-md-6">
        <label class="form-label"><?= lang('facilities.name') ?> (EN) <span class="text-danger">*</span></label>
        <input type="text" name="name_en" class="form-control" value="<?= e($f['name_en'] ?? '') ?>" required>
        <div class="invalid-feedback" data-field="name_en"></div>
    </div>
    <div class="col-md-6">
        <label class="form-label"><?= lang('facilities.name') ?> (AR) <span class="text-danger">*</span></label>
        <input type="text" name="name_ar" class="form-control" value="<?= e($f['name_ar'] ?? '') ?>" required dir="rtl">
        <div class="invalid-feedback" data-field="name_ar"></div>
    </div>
    <div class="col-md-6">
        <label class="form-label"><?= lang('facilities.location') ?></label>
        <input type="text" name="location" class="form-control" value="<?= e($f['location'] ?? '') ?>">
    </div>
    <div class="col-md-3">
        <label class="form-label"><?= lang('facilities.capacity') ?></label>
        <input type="number" name="capacity" class="form-control" value="<?= e($f['capacity'] ?? '') ?>" min="0">
    </div>
    <div class="col-md-3">
        <label class="form-label"><?= lang('facilities.area_sqm') ?></label>
        <input type="number" name="area_sqm" class="form-control" value="<?= e($f['area_sqm'] ?? '') ?>" step="0.01" min="0">
    </div>
    <div class="col-12"><hr></div>
    <div class="col-md-3">
        <div class="form-check form-switch mt-3">
            <input type="hidden" name="is_indoor" value="0">
            <input class="form-check-input" type="checkbox" name="is_indoor" value="1" id="is_indoor" <?= checked(1, $f['is_indoor'] ?? 1) ?>>
            <label class="form-check-label" for="is_indoor"><?= lang('facilities.indoor') ?></label>
        </div>
    </div>
    <div class="col-md-3">
        <div class="form-check form-switch mt-3">
            <input type="hidden" name="is_bookable" value="0">
            <input class="form-check-input" type="checkbox" name="is_bookable" value="1" id="is_bookable" <?= checked(1, $f['is_bookable'] ?? 1) ?>>
            <label class="form-check-label" for="is_bookable"><?= lang('facilities.bookable') ?></label>
        </div>
    </div>
    <div class="col-12"><hr><h6><?= lang('facilities.booking_settings') ?></h6></div>
    <div class="col-md-3">
        <label class="form-label"><?= lang('facilities.fee_per_hour') ?></label>
        <input type="number" name="booking_fee_per_hour" class="form-control" value="<?= e($f['booking_fee_per_hour'] ?? '0') ?>" step="0.01" min="0">
    </div>
    <div class="col-md-3">
        <label class="form-label"><?= lang('facilities.fee_members') ?></label>
        <input type="number" name="booking_fee_members" class="form-control" value="<?= e($f['booking_fee_members'] ?? '0') ?>" step="0.01" min="0">
    </div>
    <div class="col-md-3">
        <label class="form-label"><?= lang('facilities.fee_guests') ?></label>
        <input type="number" name="booking_fee_guests" class="form-control" value="<?= e($f['booking_fee_guests'] ?? '0') ?>" step="0.01" min="0">
    </div>
    <div class="col-md-3">
        <label class="form-label"><?= lang('facilities.advance_days') ?></label>
        <input type="number" name="advance_booking_days" class="form-control" value="<?= e($f['advance_booking_days'] ?? '7') ?>" min="1">
    </div>
    <div class="col-md-3">
        <label class="form-label"><?= lang('facilities.min_minutes') ?></label>
        <input type="number" name="min_booking_minutes" class="form-control" value="<?= e($f['min_booking_minutes'] ?? '60') ?>" min="15" step="15">
    </div>
    <div class="col-md-3">
        <label class="form-label"><?= lang('facilities.max_minutes') ?></label>
        <input type="number" name="max_booking_minutes" class="form-control" value="<?= e($f['max_booking_minutes'] ?? '120') ?>" min="15" step="15">
    </div>
    <div class="col-md-3">
        <label class="form-label"><?= lang('facilities.operating_start') ?></label>
        <input type="time" name="operating_hours_start" class="form-control" value="<?= e($f['operating_hours_start'] ?? '06:00') ?>">
    </div>
    <div class="col-md-3">
        <label class="form-label"><?= lang('facilities.operating_end') ?></label>
        <input type="time" name="operating_hours_end" class="form-control" value="<?= e($f['operating_hours_end'] ?? '22:00') ?>">
    </div>
</div>