@extends('layouts.default')
@section('title', $page_title)
@section('content')
<div class="container-fluid">
    @include('admin.partials.page-header')

    @if(session('success'))<div class="alert alert-success">{{ session('success') }}</div>@endif
    @if(session('error'))<div class="alert alert-danger">{{ session('error') }}</div>@endif

    <div class="card">
        <div class="card-header d-flex justify-content-between align-items-center">
            <h4 class="card-title mb-0">Müşteri Seç</h4>
            <a href="{{ route('admin.onboarding.start') }}" class="btn btn-primary btn-sm">Yeni Onboarding</a>
        </div>
        <div class="card-body">
            <div class="alert alert-light border">
                Bu ekran onboarding tamamlandıktan sonra ilk canlı kontrolü yapar: veri önizleme, snapshot çekme, kalite kontrol, ilk rapor, AI özeti ve test maili.
            </div>
            <div class="table-responsive">
                <table class="table table-hover align-middle">
                    <thead>
                        <tr>
                            <th>Müşteri</th>
                            <th>Bağlantı</th>
                            <th>Rapor</th>
                            <th>Plan</th>
                            <th>Varsayılan Tarih</th>
                            <th class="text-end">İşlem</th>
                        </tr>
                    </thead>
                    <tbody>
                    @forelse($clients as $client)
                        <tr>
                            <td>
                                <a href="{{ route('admin.clients.show', $client) }}" class="font-w600 text-black">{{ $client->company_name }}</a><br>
                                <small class="text-muted">{{ $client->email ?: '-' }}</small>
                            </td>
                            <td>{{ $client->platform_connections_count }}</td>
                            <td>{{ $client->generated_reports_count }}</td>
                            <td>{{ $client->report_schedules_count }}</td>
                            <td>{{ $from }} / {{ $to }}</td>
                            <td class="text-end">
                                <a href="{{ route('admin.first-report.show', ['client' => $client->id, 'from' => $from, 'to' => $to]) }}" class="btn btn-sm btn-primary">İlk Raporu Hazırla</a>
                            </td>
                        </tr>
                    @empty
                        <tr><td colspan="6" class="text-center text-muted py-5">Müşteri bulunamadı.</td></tr>
                    @endforelse
                    </tbody>
                </table>
            </div>
            {{ $clients->links() }}
        </div>
    </div>
</div>
@endsection
