<div class="card shadow-sm">
    <div class="card-body">
        <div class="d-flex align-items-center justify-content-between mb-3">
            <h5 class="text-muted fw-bold mb-0">Accessibility Preferences</h5>
        </div>
        <ul class="list-group list-group-flush">
            @foreach($questions as $key => $label)
                {{-- Only show subsequent questions if the first question is answered 'Yes' --}}
                @if($key === 'diff_format' || ($prefs['diff_format'] ?? '0') == '1')
                    <li class="list-group-item d-flex justify-content-between align-items-center py-3">
                        <span class="text-secondary small fw-medium w-75">{{ $label }}</span>

                        <div class="d-flex gap-4">
                            <div class="form-check">
                                {{-- .live is used to immediately trigger a re-render to show/hide dependent questions --}}
                                <input class="form-check-input" type="radio"
                                       wire:model.live="prefs.{{ $key }}"
                                       id="{{ $key }}_yes" value="1">
                                <label class="form-check-label small" for="{{ $key }}_yes">Yes</label>
                            </div>
                            <div class="form-check">
                                <input class="form-check-input" type="radio"
                                       wire:model.live="prefs.{{ $key }}"
                                       id="{{ $key }}_no" value="0">
                                <label class="form-check-label small" for="{{ $key }}_no">No</label>
                            </div>
                        </div>
                    </li>

                    {{-- If the user selected 'Yes' for another language, show the text input --}}
                    @if($key === 'other_lang' && ($prefs['other_lang'] ?? '0') == '1')
                        <li class="list-group-item py-3 ps-4 bg-light border-top-0">
                            <div class="d-flex flex-column gap-2">
                                <label class="text-secondary small fw-medium" for="language_required">
                                    Please specify the required language:
                                </label>
                                <input type="text" class="form-control form-control-sm w-50"
                                       wire:model="prefs.language_required"
                                       id="language_required"
                                       placeholder="e.g. Spanish, Polish, etc.">
                            </div>
                        </li>
                    @endif
                @endif
            @endforeach
        </ul>
    </div>

    <div class="card-footer bg-white border-top-0 py-3">
        <button wire:click="save" class="btn btn-success px-4 py-2">
            Save
            <span wire:loading wire:target="save" class="spinner-border spinner-border-sm ms-2"></span>
        </button>
    </div>
</div>