@extends('layouts.default')
@section('title', $page_title)
@section('content')
<div class="container-fluid">
    @include('admin.partials.page-header', ['actions' => new \Illuminate\Support\HtmlString('<a href="'.route('admin.report-schedules.edit', $reportSchedule).'" class="btn btn-primary">Düzenle</a>')])
    <div class="row">
        <div class="col-xl-8">
            <div class="card"><div class="card-header border-0 pb-0"><h4 class="card-title mb-0">Plan Özeti</h4></div><div class="card-body"><div class="row">
                <div class="col-md-4 mb-3"><span class="text-muted d-block">Müşteri</span><strong>{{ $reportSchedule->client?->company_name }}</strong></div>
                <div class="col-md-4 mb-3"><span class="text-muted d-block">Şablon</span><strong>{{ $reportSchedule->template?->name ?? 'Varsayılan' }}</strong></div>
                <div class="col-md-4 mb-3"><span class="text-muted d-block">Frekans</span><strong>{{ ['daily'=>'Günlük','weekly'=>'Haftalık','monthly'=>'Aylık'][$reportSchedule->frequency] ?? $reportSchedule->frequency }}</strong></div>
                <div class="col-md-4 mb-3"><span class="text-muted d-block">Durum</span>@include('admin.partials.status-badge', ['status' => $reportSchedule->is_active ? ($reportSchedule->last_status ?: 'active') : 'passive'])</div>
                <div class="col-md-4 mb-3"><span class="text-muted d-block">Son Çalışma</span><strong>{{ $reportSchedule->last_run_at?->format('d.m.Y H:i') ?? '-' }}</strong></div>
                <div class="col-md-4 mb-3"><span class="text-muted d-block">Sonraki Çalışma</span><strong>{{ $reportSchedule->next_run_at?->format('d.m.Y H:i') ?? '-' }}</strong></div>
                <div class="col-md-12 mb-3"><span class="text-muted d-block">Alıcılar</span><strong>{{ implode(', ', $reportSchedule->recipients ?? []) ?: '-' }}</strong></div>
            </div>@if($reportSchedule->last_error)<div class="alert alert-danger mb-0">{{ $reportSchedule->last_error }}</div>@endif</div></div>

            <div class="card"><div class="card-header border-0 pb-0"><h4 class="card-title mb-0">Son Üretilen Raporlar</h4></div><div class="card-body"><div class="table-responsive"><table class="table table-responsive-md"><thead><tr><th>Rapor</th><th>Tarih</th><th>Durum</th><th class="text-end">İşlem</th></tr></thead><tbody>@forelse($reportSchedule->generatedReports as $report)<tr><td>#{{ $report->id }}</td><td>{{ $report->date_from?->format('d.m.Y') }} - {{ $report->date_to?->format('d.m.Y') }}</td><td>@include('admin.partials.status-badge', ['status' => $report->status])</td><td class="text-end"><a href="{{ route('admin.reports.show', $report) }}" class="btn btn-xs btn-primary">Aç</a></td></tr>@empty<tr><td colspan="4" class="text-center text-muted py-4">Henüz rapor oluşmadı.</td></tr>@endforelse</tbody></table></div></div></div>
        </div>
        <div class="col-xl-4"><div class="card"><div class="card-body"><form method="POST" action="{{ route('admin.report-schedules.run', $reportSchedule) }}">@csrf<button class="btn btn-primary w-100 mb-2">Şimdi Çalıştır ve Gönder</button></form>@if($reportSchedule->template)<a href="{{ route('admin.report-templates.preview', $reportSchedule->template) }}" class="btn btn-outline-primary w-100 mb-2">Şablonu Önizle</a>@endif<a href="{{ route('admin.report-schedules.index') }}" class="btn btn-light w-100">Listeye Dön</a><p class="text-muted mt-3 mb-0">Bu işlem seçili periyoda göre rapor üretir, dosyaları seçili şablonla hazırlar ve SMTP ile mail gönderir.</p></div></div></div>
    </div>
</div>
@endsection
