@extends('backend.layouts.app')
@section('content')
  <div class="content-wrapper">
    <section class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6 pb-2 pb-sm-0">
            <h1>TV List</h1>
          </div>
          <div class="col-sm-6 text-sm-right">
            <a href="{{ url('admin/tvs/add') }}" class="btn btn-primary">Add New TV</a>
          </div>
        </div>
      </div>
    </section>

    <!-- Main content -->
    <section class="content">
      <div class="container-fluid">
        <div class="row">
          <div class="col-md-12">
            <div class="card">
              <div class="card-body table-responsive p-3">
                <table id="tvTable" style="width: 100%;" class="table table-striped">
                  <thead>
                    <tr>
                      <th style="width: 80px">S. No.</th>
                      <th>Title</th>
                      <th>Category</th>
                      <th>Thumbnail</th>
                      <th>Video Type</th>
                      <th>Status</th>
                      <th>Actions</th>
                    </tr>
                  </thead>
                  <tbody>

                  </tbody>
                </table>
              </div>
            </div>
          </div>
        </div>
      </div>
    </section>
  </div>
@endsection

@push('scripts')
<script>
  $(document).ready(function() {
    var table = $('#tvTable').DataTable({
      processing: true,
      serverSide: true,
      ajax: {
        url: '{{ route('admin.tvs.index') }}',
      },
      columns: [
        {
          data: null, 
          name: 'serial',
          orderable: false,
          searchable: false,
          render: function (data, type, full, meta) {
            return meta.row + 1; 
          }
        },
        { data: 'title', name: 'title' },
        { data: 'category_name', name: 'category_name' },
        { 
          data: 'thumbnail_image', 
          name: 'thumbnail_image',
          render: function(data, type, row, meta) {
            if (data) {
              return '<img src="{{ asset('') }}' + data + '" alt="Thumbnail Image" style="width: 40px; height: 60px;">';
            }
            return 'N/A';
          }
        },
        {
          data: 'video_type', 
          name: 'video_type',
          render: function(data, type, row, meta) {
            if (data == 'upload') {
              return 'Video (Upload)';
            } else if (data == 'youtube') {
              return 'Video (YouTube)';
            } else if (data == 'radio') {
              return 'Video (Radio)';
            } else if (data == 'other') {
              return 'Video (Other)';
            }
          }
        },
        { data: 'status', name: 'status' },
        { data: 'actions', name: 'actions', orderable: false, searchable: false },
      ],
      responsive: true 
    });
    

  });
</script>
@endpush