<?php $t = $type ?? null; ?>
<div class="row justify-content-center">
    <div class="col-lg-6">
        <div class="card">
            <div class="card-header"><h5 class="mb-0"><?= $t ? lang('facilities.edit_type') : lang('facilities.create_type') ?></h5></div>
            <div class="card-body">
                <form method="POST" action="<?= $t ? "/facilities/types/{$t['id']}" : '/facilities/types' ?>" data-ajax="true">
                    <?= csrf_field() ?>
                    <div class="mb-3">
                        <label class="form-label">Type Code <span class="text-danger">*</span></label>
                        <input type="text" name="type_code" class="form-control" value="<?= e($t['type_code'] ?? '') ?>" <?= $t ? 'readonly' : 'required' ?> maxlength="20">
                        <div class="invalid-feedback" data-field="type_code"></div>
                    </div>
                    <div class="mb-3">
                        <label class="form-label">Name (EN) <span class="text-danger">*</span></label>
                        <input type="text" name="name_en" class="form-control" value="<?= e($t['name_en'] ?? '') ?>" required>
                        <div class="invalid-feedback" data-field="name_en"></div>
                    </div>
                    <div class="mb-3">
                        <label class="form-label">Name (AR) <span class="text-danger">*</span></label>
                        <input type="text" name="name_ar" class="form-control" value="<?= e($t['name_ar'] ?? '') ?>" required dir="rtl">
                        <div class="invalid-feedback" data-field="name_ar"></div>
                    </div>
                    <div class="mb-3">
                        <label class="form-label">Icon (FontAwesome class)</label>
                        <input type="text" name="icon" class="form-control" value="<?= e($t['icon'] ?? '') ?>" placeholder="e.g. fas fa-swimming-pool">
                    </div>
                    <div class="mb-3">
                        <div class="form-check form-switch">
                            <input type="hidden" name="is_bookable" value="0">
                            <input class="form-check-input" type="checkbox" name="is_bookable" value="1" id="type_bookable" <?= checked(1, $t['is_bookable'] ?? 1) ?>>
                            <label class="form-check-label" for="type_bookable">Bookable</label>
                        </div>
                    </div>
                    <?php if ($t): ?>
                    <div class="mb-3">
                        <div class="form-check form-switch">
                            <input type="hidden" name="is_active" value="0">
                            <input class="form-check-input" type="checkbox" name="is_active" value="1" id="type_active" <?= checked(1, $t['is_active'] ?? 1) ?>>
                            <label class="form-check-label" for="type_active">Active</label>
                        </div>
                    </div>
                    <?php endif; ?>
                    <div class="d-flex gap-2">
                        <button type="submit" class="btn btn-primary"><i class="fas fa-save me-1"></i><?= lang('common.save') ?></button>
                        <a href="/facilities/types" class="btn btn-secondary"><?= lang('common.cancel') ?></a>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>