<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <style>
        body { font-family: DejaVu Sans, sans-serif; font-size: 11px; color: #222; }
        h2 { margin: 0 0 8px 0; }
        .meta { margin-bottom: 12px; color: #666; font-size: 10px; }
        .summary { margin-bottom: 12px; }
        .summary span { display: inline-block; margin-right: 18px; }
        table { width: 100%; border-collapse: collapse; }
        th, td { border: 1px solid #ccc; padding: 5px; text-align: left; vertical-align: top; }
        th { background: #f2f2f2; }
    </style>
</head>
<body>
    <h2>Folder & File Statistics</h2>
    <div class="meta">Generated: {{ now()->format('Y-m-d H:i:s') }}</div>
    <div class="summary">
        <span><strong>Total Folders:</strong> {{ $totalFolders }}</span>
        <span><strong>Total Files:</strong> {{ $totalFiles }}</span>
    </div>

    <table>
        <thead>
            <tr>
                <th>Folder ID</th>
                <th>Name</th>
                <th>Path</th>
                <th>Parent</th>
                <th>Created By</th>
                <th>Files</th>
                <th>Created At</th>
            </tr>
        </thead>
        <tbody>
            @forelse($folders as $folder)
                <tr>
                    <td>{{ $folder->id }}</td>
                    <td>{{ $folder->name }}</td>
                    <td>{{ $folder->path }}</td>
                    <td>{{ $folder->parent ? $folder->parent->name : '-' }}</td>
                    <td>
                        @if($folder->creator)
                            {{ trim(($folder->creator->first_name ?? '') . ' ' . ($folder->creator->last_name ?? '')) }}
                        @else
                            -
                        @endif
                    </td>
                    <td>{{ $filesByFolder[$folder->id] ?? 0 }}</td>
                    <td>{{ $folder->created_at ? $folder->created_at->format('Y-m-d H:i') : '-' }}</td>
                </tr>
            @empty
                <tr>
                    <td colspan="7">No folders found</td>
                </tr>
            @endforelse
        </tbody>
    </table>
</body>
</html>
