@php
    $fmt = fn ($value, $decimals = 2) => is_numeric($value) ? number_format((float) $value, $decimals, '.', '') : '';
    $int = fn ($value) => is_numeric($value) ? number_format((float) $value, 0, '.', '') : '';
    $settings = $templateSettings ?? [];
    $sections = $templateSections ?? [];
    $tableLimit = (int) ($settings['table_limit'] ?? 20);
@endphp
<html>
<head><meta charset="utf-8"></head>
<body>
@if($settings['include_excel_summary'] ?? true)
<table border="1">
    <tr><th colspan="2">{{ $settings['agency_name'] ?? 'DW Ads Reporter' }}</th></tr>
    <tr><td>Şablon</td><td>{{ $report->template?->name ?? 'Varsayılan' }}</td></tr>
    <tr><td>Müşteri</td><td>{{ $report->client?->company_name }}</td></tr>
    <tr><td>Tarih</td><td>{{ $report->date_from?->format('Y-m-d') }} - {{ $report->date_to?->format('Y-m-d') }}</td></tr>
</table>
<br>
@endif
@if(($sections['ai_summary'] ?? true) && $report->hasAiInsights())
<table border="1">
    <tr><th colspan="2">AI Yönetici Yorumu</th></tr>
    <tr><td>Yönetici Özeti</td><td>{{ $report->ai_executive_summary }}</td></tr>
    <tr><td>Müşteri Notu</td><td>{{ $report->ai_customer_note }}</td></tr>
    <tr><td>Teknik Not</td><td>{{ $report->ai_technical_note }}</td></tr>
    <tr><td>Riskler</td><td>{{ implode(' | ', $report->ai_risks ?? []) }}</td></tr>
    <tr><td>Fırsatlar</td><td>{{ implode(' | ', $report->ai_opportunities ?? []) }}</td></tr>
    <tr><td>Aksiyonlar</td><td>{{ implode(' | ', $report->ai_actions ?? []) }}</td></tr>
</table>
<br>
@endif
@include('admin.reports.print.sections', ['dataset' => $dataset, 'fmt' => $fmt, 'int' => $int, 'sections' => $sections, 'tableLimit' => $tableLimit])
</body>
</html>
