@extends('layouts.adminlte')
@section('title', $data['title'] ?? 'Report')
@section('page_title', $data['title'] ?? 'Risultato Report')

@section('content')

<div class="card">
    <div class="card-header">
        <h3 class="card-title"><i class="fas fa-chart-bar mr-2"></i>{{ $data['title'] ?? 'Report' }}</h3>
        <div class="card-tools">
            <a href="{{ route('report.index') }}" class="btn btn-sm btn-secondary mr-2">
                <i class="fas fa-arrow-left mr-1"></i> Torna ai Report
            </a>
            @php
                $printParams = isset($report) ? ['custom_id' => $report->id] : ['report' => $reportType ?? ''];
                $exportParams = isset($report) ? ['custom_id' => $report->id] : ['report' => $reportType ?? ''];
            @endphp
            <a href="{{ route('report.print-preview', $printParams) }}" class="btn btn-sm btn-info mr-2" target="_blank">
                <i class="fas fa-print mr-1"></i> Stampa Report
            </a>
            <a href="{{ route('report.export', $exportParams) }}" class="btn btn-sm btn-success">
                <i class="fas fa-file-csv mr-1"></i> Esporta CSV
            </a>
        </div>
    </div>
    <div class="card-body">
        @if(!empty($data['summary']))
        <div class="alert alert-info">
            <i class="fas fa-info-circle mr-2"></i>
            <strong>{{ $data['summary'] }}</strong>
        </div>
        @endif

        @if(!empty($data['headers']) && !empty($data['rows']))
        <div class="table-responsive">
            <table class="table table-bordered table-striped table-hover">
                <thead class="thead-light">
                    <tr>
                        @foreach($data['headers'] as $header)
                        <th>{{ $header }}</th>
                        @endforeach
                    </tr>
                </thead>
                <tbody>
                    @foreach($data['rows'] as $row)
                    <tr>
                        @foreach($row as $cell)
                        <td>{{ is_array($cell) ? json_encode($cell) : $cell }}</td>
                        @endforeach
                    </tr>
                    @endforeach
                </tbody>
            </table>
        </div>
        @else
        <div class="text-center text-muted py-5">
            <i class="fas fa-inbox fa-3x mb-3"></i>
            <p>Nessun dato disponibile per questo report.</p>
        </div>
        @endif
    </div>
    <div class="card-footer">
        <div class="row">
            <div class="col-md-6">
                <a href="{{ route('report.index') }}" class="btn btn-secondary">
                    <i class="fas fa-arrow-left mr-1"></i> Torna ai Report
                </a>
            </div>
            <div class="col-md-6 text-right">
                <small class="text-muted">Generato il {{ now()->format('d/m/Y H:i:s') }}</small>
            </div>
        </div>
    </div>
</div>
@endsection
