<div class="card shadow-sm h-100 border-0">
    <div class="card-body">
        <div class="d-flex align-items-center justify-content-between mb-3">
            <h5 class="text-muted fw-bold mb-0">Communication Preferences</h5>
        </div>

        <div class="mt-3">
            @foreach($availableOptIns as $optIn)
                @php
                    $isOptedIn = isset($optIns[$optIn->id]) && $optIns[$optIn->id];
                @endphp

                <div class="mb-3 p-2 rounded-3 {{ $isOptedIn ? 'bg-soft-light' : 'bg-soft-danger border border-danger-subtle border-dashed' }}">
                    <div class="d-flex justify-content-between align-items-center">
                        <div class="d-flex flex-column">
                            <label class="small fw-bold mb-0 {{ $isOptedIn ? 'text-dark' : 'text-danger' }}">
                                {{ $optIn->display_name }}
                            </label>
                            <span class="extra-small {{ $isOptedIn ? 'text-muted' : 'text-danger' }}">
                                {{ $isOptedIn ? 'Opted In' : 'Not Opted In' }}
                            </span>
                        </div>

                        @can('clients.edit')
                        <div class="form-check form-switch mb-0">
                            <input
                                    class="form-check-input cursor-pointer"
                                    type="checkbox"
                                    role="switch"
                                    id="optIn_{{ $optIn->id }}"
                                    wire:model="optIns.{{ $optIn->id }}"
                                    wire:change="updateOptIn({{ $optIn->id }})"
                            >
                        </div>
                        @endcan
                    </div>
                </div>
            @endforeach
        </div>

        @if($availableOptIns->isEmpty())
            <div class="text-center py-3 text-muted">
                <p class="small italic mb-0">No opt-in types configured in system.</p>
            </div>
        @endif
    </div>
</div>