@extends('layouts.admin')

@section('title', 'Downloads')

@section('content')
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h5 class="page-title mb-0">Downloads</h5>
        <a href="{{ route('admin.downloads.create') }}" class="btn btn-primary"><i class="bi bi-plus-lg me-1"></i> Add Download</a>
    </div>

    <div class="card">
        <div class="card-body p-0">
            <table class="table table-hover align-middle mb-0">
                <thead>
                    <tr><th>#</th><th>Title</th><th>Category</th><th>File</th><th>Status</th><th class="text-end">Actions</th></tr>
                </thead>
                <tbody>
                    @forelse($downloads as $download)
                        <tr>
                            <td>{{ $loop->iteration }}</td>
                            <td class="fw-semibold">{{ $download->title }}</td>
                            <td><span class="badge bg-light text-dark">{{ $download->category }}</span></td>
                            <td>
                                @if($download->file)
                                    <a href="{{ \App\Services\FileUploadService::url($download->file) }}" target="_blank" class="btn btn-sm btn-outline-secondary"><i class="bi bi-paperclip"></i></a>
                                @endif
                            </td>
                            <td>@if($download->status)<span class="badge bg-success">Active</span>@else<span class="badge bg-secondary">Inactive</span>@endif</td>
                            <td class="text-end">
                                <a href="{{ route('admin.downloads.edit', $download) }}" class="btn btn-sm btn-outline-primary">Edit</a>
                                <form action="{{ route('admin.downloads.destroy', $download) }}" method="POST" class="d-inline" data-confirm="Delete this download?">
                                    @csrf @method('DELETE')
                                    <button type="submit" class="btn btn-sm btn-outline-danger">Delete</button>
                                </form>
                            </td>
                        </tr>
                    @empty
                        <tr><td colspan="6" class="text-center text-muted py-4">No downloads yet.</td></tr>
                    @endforelse
                </tbody>
            </table>
        </div>
    </div>
    <div class="mt-3">{{ $downloads->links() }}</div>
@endsection
