@extends('layouts.default')
@section('title', $page_title)
@section('content')
<div class="container-fluid">
    @include('admin.partials.page-header', ['actions' => new \Illuminate\Support\HtmlString('<div class="d-flex gap-2"><a href="'.route('admin.report-templates.preview', $reportTemplate).'" class="btn btn-outline-primary">Önizle</a><a href="'.route('admin.report-templates.edit', $reportTemplate).'" class="btn btn-primary">Düzenle</a></div>')])
    @php($settings = $reportTemplate->effectiveSettings())
    @php($sections = $reportTemplate->enabledSections())
    <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">Şablon Özeti</h4></div><div class="card-body"><div class="row">
                <div class="col-md-4 mb-3"><span class="text-muted d-block">Kapsam</span><strong>{{ $reportTemplate->client?->company_name ?? 'Genel' }}</strong></div>
                <div class="col-md-4 mb-3"><span class="text-muted d-block">Tip</span><strong>{{ ['daily'=>'Günlük','weekly'=>'Haftalık','monthly'=>'Aylık','custom'=>'Özel'][$reportTemplate->type] ?? $reportTemplate->type }}</strong></div>
                <div class="col-md-4 mb-3"><span class="text-muted d-block">Durum</span>@include('admin.partials.status-badge', ['status' => $reportTemplate->is_active ? 'active' : 'passive']) @if($reportTemplate->is_default)<span class="badge badge-primary ms-1">Varsayılan</span>@endif</div>
                <div class="col-12 mb-3"><span class="text-muted d-block">Açıklama</span>{{ $reportTemplate->description ?: '-' }}</div>
            </div></div></div>

            <div class="card"><div class="card-header border-0 pb-0"><h4 class="card-title mb-0">Seçili Bölümler</h4></div><div class="card-body"><div class="row">@foreach($sections as $key => $enabled)<div class="col-md-4 mb-2"><span class="badge {{ $enabled ? 'badge-success' : 'badge-light' }} me-1">{{ $enabled ? 'Açık' : 'Kapalı' }}</span>{{ str_replace('_',' ', $key) }}</div>@endforeach</div></div></div>

            <div class="card"><div class="card-header border-0 pb-0"><h4 class="card-title mb-0">Bu Şablonu Kullanan Planlar</h4></div><div class="card-body"><div class="table-responsive"><table class="table table-responsive-md"><thead><tr><th>Müşteri</th><th>Frekans</th><th>Durum</th><th class="text-end">İşlem</th></tr></thead><tbody>@forelse($reportTemplate->schedules as $schedule)<tr><td>{{ $schedule->client?->company_name }}</td><td>{{ $schedule->frequency }}</td><td>@include('admin.partials.status-badge', ['status' => $schedule->is_active ? 'active' : 'passive'])</td><td class="text-end"><a href="{{ route('admin.report-schedules.show', $schedule) }}" class="btn btn-xs btn-primary">Aç</a></td></tr>@empty<tr><td colspan="4" class="text-center text-muted py-4">Bu şablonu kullanan otomatik plan yok.</td></tr>@endforelse</tbody></table></div></div></div>
        </div>
        <div class="col-xl-4">
            <div class="card"><div class="card-header border-0 pb-0"><h4 class="card-title mb-0">Marka Ayarları</h4></div><div class="card-body">
                <div class="mb-3"><span class="text-muted d-block">Ajans Adı</span><strong>{{ $settings['agency_name'] }}</strong></div>
                <div class="mb-3"><span class="text-muted d-block">Ana Renk</span><span class="badge" style="background:{{ $settings['primary_color'] }}">{{ $settings['primary_color'] }}</span></div>
                <div class="mb-3"><span class="text-muted d-block">Vurgu Rengi</span><span class="badge" style="background:{{ $settings['accent_color'] }}">{{ $settings['accent_color'] }}</span></div>
                <div class="mb-3"><span class="text-muted d-block">Kapak Başlığı</span><strong>{{ $settings['cover_title'] }}</strong></div>
                <form method="POST" action="{{ route('admin.report-templates.duplicate', $reportTemplate) }}">@csrf<button class="btn btn-outline-primary w-100 mb-2">Şablonu Kopyala</button></form>
                <form method="POST" action="{{ route('admin.report-templates.destroy', $reportTemplate) }}" onsubmit="return confirm('Şablon silinsin mi?')">@csrf @method('DELETE')<button class="btn btn-outline-danger w-100">Sil</button></form>
            </div></div>
        </div>
    </div>
</div>
@endsection
