@extends('layouts.default')
@section('content')
<div class="container-fluid">
    <div class="row mb-3"><div class="col"><h3>{{ $page_title }}</h3><p class="text-muted mb-0">{{ $page_description }}</p></div></div>
    @include('admin.onboarding._progress')

    <div class="row">
        <div class="col-xl-3 col-sm-6"><div class="card"><div class="card-body"><h3>{{ $summary['connections'] }}</h3><span>Bağlantı</span></div></div></div>
        <div class="col-xl-3 col-sm-6"><div class="card"><div class="card-body"><h3>{{ $summary['active_connections'] }}</h3><span>Aktif Bağlantı</span></div></div></div>
        <div class="col-xl-3 col-sm-6"><div class="card"><div class="card-body"><h3>{{ $summary['brand_kits'] }}</h3><span>Marka Kiti</span></div></div></div>
        <div class="col-xl-3 col-sm-6"><div class="card"><div class="card-body"><h3>{{ $summary['active_report_schedules'] }}</h3><span>Aktif Rapor Planı</span></div></div></div>
    </div>

    <div class="row">
        <div class="col-xl-6">
            <div class="card"><div class="card-body">
                <h5>Bağlantılar</h5>
                <div class="table-responsive"><table class="table table-sm"><thead><tr><th>Platform</th><th>Hesap</th><th>Durum</th><th>İşlem</th></tr></thead><tbody>
                    @forelse($client->platformConnections as $connection)
                        <tr><td>{{ $connection->platform }}</td><td>{{ $connection->account_name ?: $connection->connection_name }}<br><small>{{ $connection->account_id ?: 'ID sonra seçilecek' }}</small></td><td><span class="badge {{ $connection->status === 'active' ? 'badge-success' : 'badge-warning' }}">{{ $connection->status }}</span></td><td><a href="{{ route('admin.integrations.preview.index', ['connection_id' => $connection->id]) }}" class="btn btn-xs btn-outline-dark">Önizle</a></td></tr>
                    @empty
                        <tr><td colspan="4" class="text-muted">Bağlantı yok.</td></tr>
                    @endforelse
                </tbody></table></div>
            </div></div>
        </div>
        <div class="col-xl-6">
            <div class="card"><div class="card-body">
                <h5>Rapor Planları</h5>
                <div class="table-responsive"><table class="table table-sm"><thead><tr><th>Şablon</th><th>Periyot</th><th>Sonraki</th><th>Durum</th></tr></thead><tbody>
                    @forelse($client->reportSchedules as $schedule)
                        <tr><td>{{ $schedule->template?->name ?: '-' }}</td><td>{{ $schedule->frequency }}</td><td>{{ $schedule->next_run_at?->format('d.m.Y H:i') ?: '-' }}</td><td><span class="badge {{ $schedule->is_active ? 'badge-success' : 'badge-secondary' }}">{{ $schedule->is_active ? 'Aktif' : 'Pasif' }}</span></td></tr>
                    @empty
                        <tr><td colspan="4" class="text-muted">Plan yok.</td></tr>
                    @endforelse
                </tbody></table></div>
            </div></div>
        </div>
    </div>

    <div class="card"><div class="card-body d-flex justify-content-between align-items-center">
        <div>
            <h5 class="mb-1">Sonraki önerilen işlemler</h5>
            <p class="text-muted mb-0">Hesap keşfi, veri önizleme, snapshot çekme ve kalite kontrolü tamamlandıktan sonra ilk raporu üretebiliriz.</p>
        </div>
        <div class="text-end">
            <a href="{{ route('admin.integrations.discovery.index') }}" class="btn btn-outline-primary">Hesap Keşfi</a>
            <a href="{{ route('admin.sync.quality') }}" class="btn btn-outline-dark">Kalite Kontrolü</a>
            <form action="{{ route('admin.onboarding.complete', $client) }}" method="POST" class="d-inline">@csrf<button class="btn btn-success">Onboarding Tamamla</button></form>
        </div>
    </div></div>
</div>
@endsection
