@extends('layouts.app')
@section('title','Update Case Hearing | ')
@section('content')
<!-- Content Header (Page header) -->
<div class="content-header">
    <div class="container-fluid">
        <div class="row mb-2">
            <div class="col-sm-6">
                <h1 class="m-0">Update Case Hearing</h1>
            </div><!-- /.col -->
            <div class="col-sm-6">
                <ol class="breadcrumb float-sm-right">
                    <li class="breadcrumb-item"><a href="#">Home</a></li>
                    <li class="breadcrumb-item active">Case Management</li>
                </ol>
            </div><!-- /.col -->
        </div><!-- /.row -->
    </div><!-- /.container-fluid -->
</div>
<!-- /.content-header -->
<!-- Main content -->
<section class="content">
    <div class="container-fluid">
        <div class="card card-default">
            <div class="card-header">
                <h3 class="card-title">Update Case Hearing</h3>
            </div>
            <!-- /.card-header -->
            <div class="card-body">
                @if (session('success'))
                <div class="alert alert-success alert-dismissible fade show" role="alert">
                    <strong>{{ session('success') }}</strong>
                    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                @endif
                @if (session('error'))
                <div class="alert alert-danger alert-dismissible fade show" role="alert">
                    <strong>{{ session('error') }}</strong>
                    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                @endif
                @if (session('warning'))
                <div class="alert alert-warning alert-dismissible fade show" role="alert">
                    <strong>{{ session('warning') }}</strong>
                    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                @endif
                @if(!empty($cases))
                <form action="{{ route('save.case.hearing') }}" method="post" autocomplete="off" enctype="multipart/form-data">
                    @csrf
                    <input type="hidden" name="case_id" value="{{ $cases->id }}">
                    <div class="row">
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="case_number">Case Number</label>
                                <input type="text" name="case_number"
                                    class="form-control   @if( $errors->has('case_number')) is-invalid border-danger  @endif"
                                    value="{{ $cases->case_number }}" id="case_number" placeholder="Case Number"
                                    readonly>
                                <small class="text-danger case_number_error"></small>
                                @if ($errors->has('case_number'))
                                <span id="case_number-error"
                                    class="error text-danger invalid-feedback">{{ $errors->first('case_number') }}</span>
                                <small></small>
                                @endif
                            </div>
                        </div>
                         <div class="col-md-3">
                            <div class="form-group">
                                <label for="next_hearing_date">Previous Hearing Date</label>                               
                                @if (empty($cases->next_hearing_date))
                                <span class="form-control" readonly>{{ $cases->hearing_date }}</span>
                                @endif

                                @if (!empty($cases->next_hearing_date))
                                <span class="form-control" readonly>{{ $cases->next_hearing_date }}</span>
                                @endif
                            </div>
                        </div>
                        <div class="col-md-3">
                            <div class="form-group">
                            @if (empty($cases->next_hearing_date))
                                <input type="hidden" value="{{$cases->hearing_date}}"  id="previous_hearing_date" name="previous_hearing_date">
                                @endif  
                                @if (!empty($cases->next_hearing_date))
                                <input type="hidden" value="{{$cases->next_hearing_date}}"  id="previous_hearing_date" name="previous_hearing_date">
                                @endif
                                <label for="next_hearing_date">Next Hearing Date</label>
                                <input type="date" name="next_hearing_date"
                                    class="form-control   @if( $errors->has('next_hearing_date')) is-invalid border-danger  @endif"
                                    value="{{ old('next_hearing_date') }}" id="next_hearing_date" @if($cases->case_status == 3) disabled  @endif>
                                @if ($errors->has('next_hearing_date'))
                                <span id="next_hearing_date-error"
                                    class="error text-danger invalid-feedback">{{ $errors->first('next_hearing_date') }}</span>
                                <small></small>
                                @endif
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="remark">Current Case Remark <small class="text-muted">(Hearing Remark)</small></label>
                                <textarea name="remark" id="" cols="30"
                                    class="form-control @if( $errors->has('remark')) is-invalid border-danger  @endif"
                                    rows="4" placeholder="Current Remark" @if($cases->case_status == 3) disabled @endif>{{ old('remark') }}</textarea>
                                @if ($errors->has('remark'))
                                <span id="remark-error"
                                    class="error text-danger invalid-feedback">{{ $errors->first('remark') }}</span>
                                <small></small>
                                @endif
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="case_status">Current Case Status</label>
                                <select name="case_status" id="case_status"
                                    class="form-control @if( $errors->has('case_status')) is-invalid border-danger  @endif" @if($cases->case_status == 3) disabled onclick="return false;" @endif>
                                    <option value="">Select Case Status</option>
                                    <option value="1" {{ ($cases->case_status == 1) ? 'selected' : '' }}>Pending
                                    </option>
                                    <option value="2" {{ ($cases->case_status == 2) ? 'selected' : '' }}>Processing
                                    </option>
                                    <option value="3" {{ ($cases->case_status == 3) ? 'selected' : '' }}>Closed</option>
                                </select>
                                @if ($errors->has('case_status'))
                                <span id="case_status-error"
                                    class="error text-danger invalid-feedback">{{ $errors->first('case_status') }}</span>
                                <small></small>
                                @endif
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="case_document">Current Documents(Optional) </label>
                                <input type="file" name="case_document"
                                    class="form-control  @if( $errors->has('case_document')) is-invalid border-danger  @endif"
                                    value="{{ old('case_document') }}" id="case_document" @if($cases->case_status == 3) disabled  @endif>
                                @if ($errors->has('case_document'))
                                <span id="case_document-error"
                                    class="error text-danger invalid-feedback">{{ $errors->first('case_document') }}</span>
                                <small></small>
                                @endif
                            </div>
                        </div>
                        <div class="col-md-12">
                            <div class="form-group">
                                <a href="{{ route('list.all.cases') }}" class="btn btn-secondary">Back</a>
                                @if($cases->case_status != 3)
                                <input type="submit" name="update" value="Update" class="btn btn-primary">
                                @endif
                            </div>
                        </div>
                    </div>
                </form>
                @else
                    <div class="row">
                        <div class="col-md-12">
                            <h5 class="text-muted">No hearings found.</h5>
                        </div>
                    </div>
                @endif
            </div>
        </div>
        <!-- /.card -->
        <!-- Card for list all the hearings updated till now -->
        <div class="card">
            <div class="card-header">
                <h3 class="card-title">All Hearings</h3>
            </div>
            <div class="card-body">
                <table id="hearingListing" class="table table-bordered table-striped">
                    <thead>
                        <tr>
                            <th>Sr No.</th>
                            <th>Case Number</th>
                            <th>Previous Hearing Date</th>
                            <th>Next Hearing Date</th>
                            <th>Date Status</th>
                            <th>Remarks</th>
                            <th>Files</th>
                        </tr>
                    </thead>
                    <tbody>
                        @if(!empty($cases->case_hearings))
                        @if($cases->case_hearings->count() > 0)
                        @php
                        $count = 1;
                        $today = date('Y-m-d');
                        @endphp
                        @foreach($cases->case_hearings as $data)
                        <tr>
                            <td>{{ $count }}</td>
                            <td>{{ $cases->case_number }}</td>
                            <td>
                                {{ (!empty($data->previous_hearing_date)) ? formatDate($data->previous_hearing_date) : '' }}
                            </td>
                            <td>
                                {{ (!empty($data->next_hearing_date)) ? formatDate($data->next_hearing_date) : '' }}
                            </td>
                            <td>
                                {{ ($today > $data->next_hearing_date) ? 'Date Passed' : 'Date Pending' }}
                            </td>
                            <td>{{ $data->current_remark }}</td>
                            <td> 
                             @if(!empty($data->current_file_copy))
                            <a href='{{ url("public/assets/cases/$data->current_file_copy ") }}' class="btn btn-xs btn-primary pl-3 pr-3" download>Download</a>
                            @else

                            @endif
                            </td>
                        </tr>
                        @php
                        $count++;
                        @endphp
                        @endforeach
                        @endif
                        @endif
                    </tbody>
                </table>
            </div>
        </div>
        <!-- /.card -->
    </div>
    <!--/. container-fluid -->
</section>
<!-- /.content -->
@endsection
@push('js')
<script>

// for hearing Listing data table
$(function() {
    $('#hearingListing').DataTable({
        "paging": true,
        "lengthChange": true,
        "searching": true,
        "ordering": true,
        "info": true,
        "autoWidth": false,
        "responsive": true,
        // "buttons": ["copy", "csv", "excel", "pdf", "print", "colvis"]
        // "buttons": ["csv", "excel", "pdf"]
    });
    // .buttons().container().appendTo('#hearingListing_wrapper .col-md-6:eq(0)');
});
</script>
@endpush
