@extends('admin.clients.tabs._layout')

@section('tab-content')
<div class="card border-0 shadow-sm">
    <div class="card-header border-bottom">
        <h6 class="mb-0">
            <i class="fas fa-shield-alt text-primary me-2"></i>{{ __('admin/clients.tabs_consents') }}
        </h6>
        <small class="text-muted">{{ __('admin/clients.consents_hint') }}</small>
    </div>
    <div class="card-body">
        <div class="row">
            <div class="col-md-4">
                <h6 class="text-muted text-uppercase small mb-3">{{ __('admin/clients.consents_summary') }}</h6>
                <ul class="list-group list-group-flush">
                    @foreach (\App\Enums\ConsentChannel::cases() as $channel)
                        <li class="list-group-item d-flex justify-content-between align-items-center px-0">
                            <span>{{ $channel->label() }}</span>
                            @if (($consentSummary[$channel->value] ?? false))
                                <span class="badge bg-success">{{ __('admin/clients.consent_granted') }}</span>
                            @else
                                <span class="badge bg-secondary">{{ __('admin/clients.consent_not_granted') }}</span>
                            @endif
                        </li>
                    @endforeach
                </ul>
            </div>
            <div class="col-md-8">
                <h6 class="text-muted text-uppercase small mb-3">{{ __('admin/clients.consents_history') }}</h6>
                @if ($consents->isEmpty())
                    <p class="text-muted mb-0">{{ __('admin/clients.consents_history_empty') }}</p>
                @else
                    <div class="table-responsive">
                        <table class="table table-sm table-bordered">
                            <thead>
                                <tr>
                                    <th>{{ __('admin/clients.consent_channel') }}</th>
                                    <th>{{ __('admin/clients.consent_status') }}</th>
                                    <th>{{ __('admin/clients.consent_source') }}</th>
                                    <th>{{ __('admin/clients.consent_locale') }}</th>
                                    <th>{{ __('admin/clients.consent_ip') }}</th>
                                    <th>{{ __('admin/clients.consent_date') }}</th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach ($consents as $row)
                                    <tr>
                                        <td>{{ $row->channel->label() }}</td>
                                        <td>
                                            @if ($row->granted)
                                                <span class="badge bg-success">{{ __('admin/clients.consent_granted') }}</span>
                                            @else
                                                <span class="badge bg-secondary">{{ __('admin/clients.consent_withdrawn') }}</span>
                                            @endif
                                        </td>
                                        <td><code class="small">{{ $row->source->value }}</code></td>
                                        <td>{{ $row->locale ?: '—' }}</td>
                                        <td><code class="small">{{ $row->ip_address ?: '—' }}</code></td>
                                        <td class="small text-muted">{{ format_date($row->created_at, true) }}</td>
                                    </tr>
                                @endforeach
                            </tbody>
                        </table>
                    </div>
                @endif
            </div>
        </div>
    </div>
</div>
@endsection
