<x-app-layout>
    @section('title')
    Blog Management
    @endsection
    <!-- Page Heading -->
    <h1 class="h3 mb-2 text-gray-800">
        @can('Blog create')
            <a href="{{ route('admin.blogs.create') }}" class="btn btn-primary"><i class="fas fa-plus" aria-hidden="true"></i>
                Blog Create
            </a>
        @endcan
    </h1>
    <!-- DataTales Example -->
    <div class="card shadow mb-4">
        <div class="card-header py-3">
            <h6 class="m-0 font-weight-bold text-primary">
                Listing Blog Table
            </h6>
        </div>
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
                    <thead>
                        <tr>
                            <th>SN</th>
                            <th>Title</th>
                            <th>Tags</th>
                            <th>Category</th>
                            <th>Image</th>
                            <th>Status</th>
                            <th>Action</th>
                          </tr>
                    </thead>
                    <tbody>

                        @can('Blog access')
                            @foreach ($data as $row)
                                <tr>
                                    <td>{{ $loop->index + 1 }}</td>
                                    <td>
                                        {{ $row->title }}
                                    </td>
                                    <td>
                                        {{ $row->tags }}
                                    </td>
                                    <td>{{ $row->category->name }}</td>
                                    <td>
                                        <img src="{{ asset($row->image) }}" alt="blog image" class="blog_img_width" />
                                    </td>
                                    <td>
                                        <a onclick="changeStatus(this)" href="{{ route('admin.blogs.status',$row->id) }}">
                                            <input type="checkbox"  {{ $row->status=='1' ? 'checked':'' }}
                                            data-toggle="toggle" data-on="{{ $row->status=='1' ? 'Active':'' }}" data-off="{{ $row->status=='1' ? 'Active':'InActive' }}" data-onstyle="success"
                                            data-offstyle="danger" value="{{ $row->status }}" onclick="changeStatus(this)"/>
                                        </a>
                                    </td>
                                    <td class="d-flex">
                                        @can('Blog edit')
                                            <a href="{{ route('admin.blogs.show', $row->id) }}" class="btn btn-secondary btn-sm mr-1"><i class="fas fa-eye"></i></a>
                                            <a href="{{ route('admin.blogs.edit', $row->id) }}" class="btn btn-primary btn-sm mr-1"><i class="fas fa-edit"></i></a>
                                        @endcan

                                        @can('Blog delete')
                                            <a id="delete" href="{{ route('admin.blogs.destroy',$row->id) }}"class="btn btn-danger btn-sm"><i class="fas fa-trash"></i></a>
                                        @endcan

                                    </td>
                                </tr>
                            @endforeach
                        @endcan
                    </tbody>
                </table>
            </div>
        </div>
    </div>

    <script>
        function changeStatus(e)
        {
            // console.log(e.href);
            location.href=e.href;
        }
    </script>
</x-app-layout>
