@extends('adminlte::page')
@section('content_header')
    @notifyCss
    @notifyJs
@stop
@section('content')
    <div class="row">
        <div class="col-12">
            <div class="card card-primary">
                    <div class="card-header">
                        <h3 class="card-title">Assign Content</h3>
                    </div>
                    @include('notify::messages')
                    <!-- /.card-header -->
                    <!-- form start -->
                        <div class="card-body">
                            <div class="col-12">
                                <div id="listroledata" style="padding: 10px;">
                                    <table class="table table-hover table-bordered table-striped datatable" id="dept_details" width="100%">
                                        <thead>
                                            <tr>
                                              <th>Slno</th>
                                              <th>Content Type</th>
                                              <th>Content Subject</th>
                                              <th>Description</th>
                                              <th>Topics Assigned</th>
                                              <th>Actions</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                          @php
                                            $n= 0;
                                          @endphp
                                          @foreach($contents as $content)
                                            @php
                                              $n++;
                                              $content_topic_name ="";
                                              $topic_name ="";
                                            @endphp
                                            <tr>
                                              <td>{{$n}}</td>
                                              <td>{{$content->content_type->content_type_name}}</td>
                                              <td>{{$content->content_subject}}</td>
                                              <td>{{$content->description}}</td>
                                              <td>
                                                @if(isset($content->content_assignment))
                                                  @foreach($content->content_assignment as $content_assignment)
                                                    @php
                                                      $topic_name = $content_assignment->topic->topic_name;
                                                      if($content_topic_name)
                                                      {
                                                          $content_topic_name = $content_topic_name.", ".$topic_name;
                                                      }
                                                      else
                                                      {
                                                          $content_topic_name = $topic_name;
                                                      }
                                                    @endphp 
                                                  @endforeach
                                                @endif
                                                {{$content_topic_name}}
                                              </td>
                                              <td>
                                                <form action="{{URL::to('/assign_content_show')}}" method="post" autocomplete="off">
                                                  {{ csrf_field() }}
                                                    <input type="hidden" name="content_id" id="content_id" value="{{$content->id}}">
                                                    <button type="submit" class="btn btn-xs btn-primary">Assign</button>
                                                </form>
                                                <a href="{{URL::to('/view_content_assignments')}}/{{$content->id}}" class="btn btn-xs btn-info">View</a>
                                              </td>
                                            </tr>
                                          @endforeach
                                        </tbody>
                                    </table>
                                </div>
                          </div>
                        </div>
                        <!-- /.card-body -->
                   
            </div>
        </div>
    </div>
    <script type="text/javascript">
      $(document).ready(function(){  
          $('#dept_details').DataTable();  
     }); 
    </script>
@stop
