@extends('admin.masterAdmin')

@section('content')
    <div class="card">
        <div class="card-header d-flex justify-content-between align-items-center">
            <h5 class="mb-0">Research Blogs</h5>
            <a href="{{ route('researchs.create') }}" class="btn btn-sm btn-primary">Add Research</a>
        </div>
        <div class="card-body">
            @include('components.alert')
            <div class="table-responsive">
                <table class="table table-bordered w-100" id="dt-responsive">
                    <thead class="thead-light">
                        <tr>
                            <th>SL</th>
                            <th>Image</th>
                            <th>Title</th>
                            <th>Category</th>
                            <th>Author</th>
                            <th>Status</th>
                            <th>Published At</th>
                            <th>Action</th>
                        </tr>
                    </thead>
                    <tbody>
                        @forelse ($blogs as $blog)
                            <tr>
                                <td>{{ $loop->iteration }}</td>
                                <td>
                                    @if (isset($blog) && $blog->image)
                                        <div class="mt-2">
                                            <img src="{{ asset($blog->image) }}" width="120" alt="Blog Image">
                                        </div>
                                    @else
                                        <img src="{{ asset('images/no-image.png') }}" width="80" alt="No Image">
                                    @endif
                                </td>
                                <td>{{ $blog->title }}</td>
                                <td>{{ $blog->category->name ?? '' }}</td>
                                <td>{{ $blog->author ?? 'Admin' }}</td>
                                <td>{{ ucfirst($blog->status) }}</td>
                                <td>{{ $blog->published_at ? date('Y-m-d', strtotime($blog->published_at)) : '-' }}</td>
                                <td>
                                    <a href="{{ route('researchs.edit', $blog->id) }}" class="btn btn-sm btn-primary">
                                        Edit
                                    </a>
                                    <form action="{{ route('researchs.destroy', $blog->id) }}" method="POST"
                                        class="d-inline-block"
                                        onsubmit="return confirm('Are you sure you want to delete this blog?')">
                                        @csrf
                                        @method('DELETE')
                                        <button class="btn btn-sm btn-danger">Delete</button>
                                    </form>
                                </td>
                            </tr>
                        @empty
                            <tr>
                                <td colspan="8" class="text-center">No Recharge found.</td>
                            </tr>
                        @endforelse
                    </tbody>
                </table>
            </div>
        </div>
    </div>
@endsection
