@extends('layouts.default')
@section('title', 'Otomatik Rapor Planları')
@section('content')
<div class="container-fluid">
    @include('admin.partials.page-header', ['actions' => new \Illuminate\Support\HtmlString('<a href="'.route('admin.report-schedules.create').'" class="btn btn-primary">Plan Ekle</a>')])
    <div class="card"><div class="card-body"><div class="table-responsive"><table class="table table-responsive-md align-middle"><thead><tr><th>Müşteri</th><th>Şablon</th><th>Frekans</th><th>Kanallar</th><th>Alıcı</th><th>Durum</th><th>Son/Sonraki</th><th class="text-end">İşlem</th></tr></thead><tbody>@forelse($schedules as $schedule)<tr><td><strong>{{ $schedule->client?->company_name }}</strong>@if($schedule->last_error)<span class="d-block small text-danger">{{ \Illuminate\Support\Str::limit($schedule->last_error, 70) }}</span>@endif</td><td>{{ $schedule->template?->name ?? 'Varsayılan' }}</td><td>{{ ['daily'=>'Günlük','weekly'=>'Haftalık','monthly'=>'Aylık'][$schedule->frequency] ?? $schedule->frequency }}<span class="d-block small text-muted">{{ $schedule->daily_time ?: '09:00' }}</span></td><td>@foreach(($schedule->channels ?: []) as $channel)<span class="badge badge-light me-1">{{ str_replace('_',' ', strtoupper($channel)) }}</span>@endforeach</td><td>{{ count($schedule->recipients ?? []) }} kişi</td><td>@include('admin.partials.status-badge', ['status' => $schedule->is_active ? ($schedule->last_status ?: 'active') : 'passive'])</td><td><span class="d-block small">Son: {{ $schedule->last_run_at?->format('d.m.Y H:i') ?? '-' }}</span><span class="d-block small">Sonraki: {{ $schedule->next_run_at?->format('d.m.Y H:i') ?? '-' }}</span></td><td class="text-end"><div class="d-flex justify-content-end gap-1"><a class="btn btn-xs btn-outline-primary" href="{{ route('admin.report-schedules.show', $schedule) }}">Detay</a><a class="btn btn-xs btn-outline-secondary" href="{{ route('admin.report-schedules.edit', $schedule) }}">Düzenle</a><form method="POST" action="{{ route('admin.report-schedules.run', $schedule) }}">@csrf<button class="btn btn-xs btn-primary">Çalıştır</button></form></div></td></tr>@empty<tr><td colspan="8" class="text-center text-muted py-5">Henüz plan yok.</td></tr>@endforelse</tbody></table></div>{{ $schedules->links() }}</div></div>
</div>
@endsection
