@extends('layouts.backend')
@section('mainContentArea')
<div class="card card-default">
    <div class="card-header">
        <h4>
            Manage Sub-Sections
            {!! $addBtn !!}
        </h4>
    </div>
    <div class="card-body">
        <table class="table table-bordered data-table">
            <thead>
                <tr>
                    <th>S.No.</th>
                    <th>Name</th>
                    <th>Parent</th>                    
                    <th>Photo</th>
                    <th width="100px">Action</th>
                </tr>
            </thead>
            <tbody>
            </tbody>
        </table>
    </div>
</div>
<!-- The Modal -->
<div class="modal" id="catModal">
  <div class="modal-dialog">
    <div class="modal-content">

      <!-- Modal Header -->
      <div class="modal-header">
        <h4 class="modal-title"></h4>
        <button type="button" class="close" data-dismiss="modal">&times;</button>
      </div>

      <!-- Modal body -->
      <div class="modal-body">
          <form action="{{ route('subsections.store') }}" method="post" name="catFrm" enctype="multipart/form-data">
              @csrf
              <input type="hidden" name="catid" id="catid" value="0">
              <input type="hidden" name="photo" id="photo" value="none.jpg">
              <div class="row">
                <div class="col-md-12">
                    <div class="form-group"><label for="parent_id">Section</label>
                      <select name="parent_id" id="parent_id" class="form-control">
                        <option value="">Select Parent Section</option>
                        @foreach($sections as $section)
                        <option value="{{ $section->id }}">{{ $section->name }}</option>
                          @foreach ($section->childrenCategories as $childCategory)
                            @include('backend.subsections.child_category', ['child_category' => $childCategory])
                          @endforeach
                        @endforeach
                      </select>
                    </div>
                    <div class="form-group"><label for="catname">Name</label><input class="form-control" name="name" id="catname" required value="" placeholder="Enter Section Name"/></div>
                    <div class="form-group"><label for="photo">Photo</label><input type="file" class="form-control" name="photoFile" id="photoFile"/></div>
                    <div class="form-group"><button class="btn btn-block btn-primary">Save Section</button></div>
                </div>
              </div>
          </form>
      </div>

      <!-- Modal footer -->
      <div class="modal-footer">
        <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
      </div>

    </div>
  </div>
</div>
@endsection

@section('extraJs')
<script type="text/javascript">
    $(function () {
      
      var table = $('.data-table').DataTable({
          processing: true,
          serverSide: true,
          pageLength: 50,
          ajax: "{{ route('subsections.index') }}",
          columns: [
              {data: 'DT_RowIndex', name: 'DT_RowIndex'},
              {data: 'name', name: 'name'},
              {data: 'parent_id', name: 'parent_id'},
              {data: 'photo', name: 'photo', render: function(data, type, full, meta) {
                return "<img src=\"{{ asset('uploads/sections') }}/" + data + "\" width=\"100\"/>";
              }},
              {data: 'action', name: 'action', orderable: false, searchable: false},
          ]
      });
      
    });
  </script>
@endsection