@php
    $ext = strtolower(pathinfo($file->file_name ?? $file->name, PATHINFO_EXTENSION));
    $icon = 'ri-file-3-line';
    if($ext === 'pdf') $icon = 'ri-file-pdf-line text-danger';
    elseif(in_array($ext, ['doc','docx'])) $icon = 'ri-file-word-line text-primary';
    elseif(in_array($ext, ['xls','xlsx'])) $icon = 'ri-file-excel-line text-success';
    elseif(in_array($ext, ['ppt','pptx'])) $icon = 'ri-file-ppt-line text-warning';
    elseif(in_array($ext, ['jpg','jpeg','png','gif'])) $icon = 'ri-image-line text-info';
@endphp
<div class="folder-grid-item file-grid-item" onclick="viewFileInGrid('{{ $file->id }}', '{{ addslashes($file->file_name ?? $file->name) }}', '{{ addslashes($file->original_name ?? $file->file_name ?? $file->name) }}')">
    <div class="text-center">
        <i class="{{ $icon }} file-icon"></i>
    </div>
    <div class="folder-name text-center">{{ $file->original_name ?? $file->file_name ?? $file->name }}</div>
    <div class="folder-info text-center">
        {{ strtoupper($ext) }} file
    </div>
    <div class="folder-actions">
        <div class="dropdown">
            <button class="btn btn-sm btn-outline-secondary" type="button" data-bs-toggle="dropdown" aria-expanded="false" onclick="event.stopPropagation();">
                <i class="ri-more-2-fill"></i>
            </button>
            <ul class="dropdown-menu dropdown-menu-end shadow-sm">
                <li>
                    <a class="dropdown-item" href="#" onclick="viewFileInGrid('{{ $file->id }}', '{{ addslashes($file->file_name ?? $file->name) }}', '{{ addslashes($file->original_name ?? $file->file_name ?? $file->name) }}'); event.stopPropagation();">
                        <i class="ri-eye-line me-2 text-info"></i>
                        View File
                    </a>
                </li>
                @can('Download Files')
                <li>
                    <a class="dropdown-item" href="{{ url('/files/download?file_name=' . urlencode($file->file_name ?? $file->name) . '&folder_id=' . urlencode($file->folder_id ?? $file->parent_id)) }}" onclick="event.stopPropagation();">
                        <i class="ri-download-2-line me-2 text-success"></i>
                        Download
                    </a>
                </li>
                @endcan
                @can('Delete Files')
                <li>
                    <a class="dropdown-item text-danger" href="#" onclick="deleteFile({{ $file->id }}, '{{ addslashes($file->file_name ?? $file->name) }}'); event.stopPropagation(); return false;">
                        <i class="ri-delete-bin-line me-2"></i>
                        Delete File
                    </a>
                </li>
                @endcan
            </ul>
        </div>
    </div>
</div>
