<div class="row justify-content-center"><div class="col-lg-8"><div class="card">
    <div class="card-header"><h5 class="mb-0"><?= $rule ? lang('cards.edit_access_rule') : lang('cards.create_access_rule') ?></h5></div>
    <div class="card-body">
        <form method="POST" action="<?= $formAction ?>" data-ajax="true"><?= csrf_field() ?>
            <div class="row g-3">
                <div class="col-md-6"><label class="form-label">Rule Name *</label><input type="text" name="rule_name" class="form-control" value="<?= e($rule['rule_name'] ?? '') ?>" required><div class="invalid-feedback" data-field="rule_name"></div></div>
                <div class="col-md-6"><label class="form-label">Access Point *</label><select name="access_point_id" class="form-select" required><option value="">Select</option>
                    <?php foreach($accessPoints as $ap): ?><option value="<?= $ap['id'] ?>" <?= selected($ap['id'], $rule['access_point_id'] ?? '') ?>><?= e($ap['name_en']) ?></option><?php endforeach; ?>
                </select><div class="invalid-feedback" data-field="access_point_id"></div></div>
                <div class="col-md-6"><label class="form-label">Membership Type</label><select name="membership_type_id" class="form-select"><option value="">All Types</option>
                    <?php foreach($membershipTypes as $mt): ?><option value="<?= $mt['id'] ?>" <?= selected($mt['id'], $rule['membership_type_id'] ?? '') ?>><?= e($mt['name_en']) ?></option><?php endforeach; ?>
                </select></div>
                <div class="col-md-3"><label class="form-label">Required Status</label><input type="text" name="member_status_required" class="form-control" value="<?= e($rule['member_status_required'] ?? 'active') ?>"></div>
                <div class="col-md-3"><label class="form-label">Priority</label><input type="number" name="priority" class="form-control" value="<?= e($rule['priority'] ?? '0') ?>" required></div>
                <div class="col-md-3"><label class="form-label">Time Start</label><input type="time" name="allowed_time_start" class="form-control" value="<?= e($rule['allowed_time_start'] ?? '') ?>"></div>
                <div class="col-md-3"><label class="form-label">Time End</label><input type="time" name="allowed_time_end" class="form-control" value="<?= e($rule['allowed_time_end'] ?? '') ?>"></div>
                <div class="col-md-3"><label class="form-label">Max Daily Entries</label><input type="number" name="max_daily_entries" class="form-control" value="<?= e($rule['max_daily_entries'] ?? '') ?>"></div>
                <div class="col-md-9">
                    <div class="d-flex flex-wrap gap-4 mt-4">
                        <div class="form-check"><input type="checkbox" name="subscription_required" class="form-check-input" id="sub_req" <?= checked(1, $rule['subscription_required'] ?? 1) ?>><label class="form-check-label" for="sub_req">Subscription Required</label></div>
                        <div class="form-check"><input type="checkbox" name="card_required" class="form-check-input" id="card_req" <?= checked(1, $rule['card_required'] ?? 1) ?>><label class="form-check-label" for="card_req">Card Required</label></div>
                        <div class="form-check"><input type="checkbox" name="allow_dependents" class="form-check-input" id="allow_dep" <?= checked(1, $rule['allow_dependents'] ?? 1) ?>><label class="form-check-label" for="allow_dep">Allow Dependents</label></div>
                        <div class="form-check"><input type="checkbox" name="allow_guests" class="form-check-input" id="allow_guests" <?= checked(1, $rule['allow_guests'] ?? 0) ?>><label class="form-check-label" for="allow_guests">Allow Guests</label></div>
                        <div class="form-check"><input type="checkbox" name="is_active" class="form-check-input" id="is_active" <?= checked(1, $rule['is_active'] ?? 1) ?>><label class="form-check-label" for="is_active">Active</label></div>
                    </div>
                </div>
            </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="/access-rules" class="btn btn-secondary"><?= lang('common.cancel') ?></a></div>
        </form>
    </div>
</div></div></div>