<div class="row justify-content-center">
    <div class="col-lg-8">
        <div class="card">
            <div class="card-header"><h5 class="mb-0"><?= e($title) ?></h5></div>
            <div class="card-body">
                <form method="POST" action="<?= e($formAction) ?>" data-ajax="true">
                    <?= csrf_field() ?>
                    <div class="row g-3">
                        <div class="col-md-4">
                            <label class="form-label">Code <span class="text-danger">*</span></label>
                            <input type="text" name="type_code" class="form-control" value="<?= e($type['type_code'] ?? '') ?>" required>
                            <div class="invalid-feedback" data-field="type_code"></div>
                        </div>
                        <div class="col-md-4">
                            <label class="form-label">Name (EN) <span class="text-danger">*</span></label>
                            <input type="text" name="name_en" class="form-control" value="<?= e($type['name_en'] ?? '') ?>" required>
                            <div class="invalid-feedback" data-field="name_en"></div>
                        </div>
                        <div class="col-md-4">
                            <label class="form-label">Name (AR) <span class="text-danger">*</span></label>
                            <input type="text" name="name_ar" class="form-control" value="<?= e($type['name_ar'] ?? '') ?>" required dir="rtl">
                            <div class="invalid-feedback" data-field="name_ar"></div>
                        </div>
                        <div class="col-md-4">
                            <label class="form-label">Fee Type <span class="text-danger">*</span></label>
                            <select name="fee_type" class="form-select" required>
                                <option value="none" <?= selected('none', $type['fee_type'] ?? 'none') ?>>None</option>
                                <option value="fixed" <?= selected('fixed', $type['fee_type'] ?? '') ?>>Fixed</option>
                                <option value="percentage_of_subscription" <?= selected('percentage_of_subscription', $type['fee_type'] ?? '') ?>>% of Subscription</option>
                            </select>
                        </div>
                        <div class="col-md-4">
                            <label class="form-label">Fee Amount</label>
                            <input type="number" name="fee_amount" class="form-control" value="<?= e($type['fee_amount'] ?? '0') ?>" step="0.01" min="0">
                        </div>
                        <div class="col-md-4">
                            <label class="form-label">Fee %</label>
                            <input type="number" name="fee_percentage" class="form-control" value="<?= e($type['fee_percentage'] ?? '') ?>" step="0.01" min="0" max="100">
                        </div>
                        <div class="col-md-6">
                            <label class="form-label">Description (EN)</label>
                            <textarea name="description_en" class="form-control" rows="3"><?= e($type['description_en'] ?? '') ?></textarea>
                        </div>
                        <div class="col-md-6">
                            <label class="form-label">Description (AR)</label>
                            <textarea name="description_ar" class="form-control" rows="3" dir="rtl"><?= e($type['description_ar'] ?? '') ?></textarea>
                        </div>
                        <div class="col-12">
                            <div class="form-check"><input type="checkbox" name="requires_board_approval" class="form-check-input" value="1" <?= checked(1, $type['requires_board_approval'] ?? 1) ?>><label class="form-check-label">Requires Board Approval</label></div>
                        </div>
                        <?php if ($type): ?>
                        <div class="col-12">
                            <div class="form-check"><input type="checkbox" name="is_active" class="form-check-input" value="1" <?= checked(1, $type['is_active'] ?? 1) ?>><label class="form-check-label">Active</label></div>
                        </div>
                        <?php endif; ?>
                    </div>
                    <div class="mt-4 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="/transfer-types" class="btn btn-secondary"><?= lang('common.cancel') ?></a>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>