@extends('layouts.app')
@section('title','Create New Remark | ')
@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">New Remark</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">Remarks</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">Create New Remark</h3>
            </div>
            <!-- /.card-header -->

            <div class="card-body">
                <div class="row">
                    <div class="col-md-6 offset-md-3">
                        @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
                    </div>
                </div>

                <form action="{{ route('store.remark') }}" method="post" autocomplete="off">
                    @csrf
                    <input type="hidden" name="parent_id" value="{{ $data->claim_id }}">
                    <input type="hidden" name="type" value="{{ $type }}">
                    <div class="row">
                        <div class="col-md-6 offset-md-3">
                            <div class="row">
                                <div class="col-md-6">
                                    <div class="form-group">
                                        <label for="remark_for">Remark For</label>
                                        <input type="text" name="remark_for"
                                            class="form-control @if( $errors->has('remark_for')) is-invalid border-danger  @endif"
                                            id="remark_for" value="{{ ($type == 1) ? 'Claim' : 'Case' }}"
                                            placeholder="Remark For" readonly>
                                        @if ($errors->has('remark_for'))
                                        <span id="remark_for-error"
                                            class="error text-danger invalid-feedback">{{ $errors->first('remark_for') }}</span>
                                        <small></small>
                                        @endif
                                    </div>
                                </div>
                                @if($type == 1)
                                <div class="col-md-6">
                                    <div class="form-group">
                                        <label for="claimed_for">Claimed For</label>
                                        <input type="text" name="claimed_for"
                                            class="form-control @if( $errors->has('claimed_for')) is-invalid border-danger  @endif"
                                            id="claimed_for" value="{{ $data->claim_category }}"
                                            placeholder="Claimed For" readonly>
                                        @if ($errors->has('claimed_for'))
                                        <span id="claimed_for-error"
                                            class="error text-danger invalid-feedback">{{ $errors->first('claimed_for') }}</span>
                                        <small></small>
                                        @endif
                                    </div>
                                </div>
                                @endif
                            </div>
                        </div>
                        <div class="col-md-6 offset-md-3">
                            <div class="form-group">
                                <label for="status">Status</label>
                                <select name="status" id="status"
                                    class="custom-select  @if( $errors->has('status')) is-invalid border-danger  @endif"  {{ ($data->status == '3') ? 'onclick="return false" disabled' : '' }}>
                                    <option value="" {{ ($data->status == '') ? 'selected' : '' }}>-- Select Status --
                                    </option>
                                    <option value="1" {{ ($data->status == '1') ? 'selected' : '' }}>Pending</option>
                                    <option value="2" {{ ($data->status == '2') ? 'selected' : '' }}>Processing</option>
                                    <option value="4" {{ ($data->status == '4') ? 'selected' : '' }}>Rejected</option>
                                    <option value="5" {{ ($data->status == '5') ? 'selected' : '' }}>Partial Amount Paid</option>
                                    <option value="3" {{ ($data->status == '3') ? 'selected' : '' }}>Done</option>
                                </select>
                                @if ($errors->has('status'))
                                <span id="status-error"
                                    class="error text-danger invalid-feedback">{{ $errors->first('status') }}</span>
                                <small></small>
                                @endif
                            </div>
                        </div>
                        <div class="col-md-6 offset-md-3 show_partial_amount">
                            <div class="form-group">
                                <label for="partial_amount">Partial Amount</label>
                                <input type="number" name="partial_amount" id="partial_amount" class="form-control @if($errors->has('partial_amount')) is-invalid border-danger  @endif" placeholder="Partial Amount" value="{{ $data->partial_amount }}" {{ ($data->status == '3') ? 'readonly' : '' }}>
                                @if ($errors->has('partial_amount'))
                                <span id="partial_amount-error"
                                    class="error text-danger invalid-feedback">{{ $errors->first('partial_amount') }}</span>
                                <small></small>
                                @endif
                            </div>
                        </div>
                        <div class="col-md-6 offset-md-3 show_on_done">
                            <div class="form-group">
                                <label for="claim_amount">Claim Amount</label>
                                <input type="number" name="claim_amount" id="claim_amount" class="form-control @if($errors->has('claim_amount')) is-invalid border-danger  @endif" placeholder="Claim Amount" value="{{ $data->claim_amount }}" {{ ($data->status == '3') ? 'readonly' : '' }}>
                                @if ($errors->has('claim_amount'))
                                <span id="claim_amount-error"
                                    class="error text-danger invalid-feedback">{{ $errors->first('claim_amount') }}</span>
                                <small></small>
                                @endif
                            </div>
                        </div>
                        <div class="col-md-6 offset-md-3 show_on_done">
                            <div class="form-group">
                                <label for="claim_received_date">Claim Received Date</label>
                                <input type="date" name="claim_received_date" id="claim_received_date" class="form-control @if($errors->has('claim_received_date')) is-invalid border-danger  @endif" placeholder="Claim Amount" value="{{ $data->claim_received_date }}" {{ ($data->status == '3') ? 'readonly' : '' }}>
                                @if ($errors->has('claim_received_date'))
                                <span id="claim_received_date-error"
                                    class="error text-danger invalid-feedback">{{ $errors->first('claim_received_date') }}</span>
                                <small></small>
                                @endif
                            </div>
                        </div>
                        <div class="col-md-6 offset-md-3 show_on_done">
                            <div class="form-group">
                                <label for="payment_type">Claim Payment Type</label>
                                <select name="payment_type" id="payment_type"
                                    class="custom-select  @if( $errors->has('payment_type')) is-invalid border-danger  @endif"  {{ ($data->status == '3') ? 'onclick="return false" disabled' : '' }}>
                                    <option value="" {{ ($data->claim_payment_type == '') ? 'selected' : '' }}>-- Select Payment Type --
                                    </option>
                                    <option value="Cash" {{ ($data->claim_payment_type == 'Cash') ? 'selected' : '' }}>Cash</option>
                                    <option value="Check" {{ ($data->claim_payment_type == 'Check') ? 'selected' : '' }}>Check</option>
                                    <option value="Online" {{ ($data->claim_payment_type == 'Online') ? 'selected' : '' }}>Online</option>
                                </select>
                                @if ($errors->has('payment_type'))
                                <span id="payment_type-error"
                                    class="error text-danger invalid-feedback">{{ $errors->first('payment_type') }}</span>
                                <small></small>
                                @endif
                            </div>
                        </div>
                        <!-- <div class="col-md-6 offset-md-3 show_on_reject">
                            <div class="form-group">
                                <label for="gpa_hand_over_date">Date of hand over the lawyer</label>
                                <input type="date" name="gpa_hand_over_date"
                                    class="form-control @if($errors->has('gpa_hand_over_date')) is-invalid border-danger  @endif"
                                    id="gpa_hand_over_date" value="{{ old('gpa_hand_over_date') }}"
                                    max="{{ date('Y-m-d') }}">
                                @if ($errors->has('gpa_hand_over_date'))
                                <span id="gpa_hand_over_date-error"
                                    class="error text-danger invalid-feedback">{{ $errors->first('gpa_hand_over_date') }}</span>
                                <small></small>
                                @endif
                            </div>
                        </div>  -->
                        <div class="col-md-6 offset-md-3">
                            <div class="form-group">
                                <label for="remark">Remark</label>
                                <textarea name="remark" id="remark"
                                    class="form-control @if( $errors->has('remark')) is-invalid border-danger  @endif"
                                    rows="4" placeholder="Remark" {{ ($data->status == '3') ? 'readonly' : '' }}>{{ old('remark') }}</textarea>
                                @if ($errors->has('remark'))
                                <small class="text-danger remark_error">{{ $errors->first('remark') }}</small>
                                @endif
                            </div>
                        </div>
                        @if($data->status != 3)
                        <div class="col-md-6 offset-md-3">
                            <div class="form-group">
                            @if($type == 1)
                                <a class="btn btn-secondary m-1" href="{{ route('list.all.claims') }}">Back</a>
                            @else 
                                <a class="btn btn-secondary m-1" href="{{ route('list.all.cases') }}">Back</a>
                            @endif
                                <input type="submit" value="Save Remark" class="btn btn-primary">
                            @if($data->status == 4)
                            @if(!empty($data->rejected_claim_id))
                                <a class="btn btn-secondary m-1" href="{{ route('view.cases.details',$data->case_id) }}" data-toggle="tooltip" data-placement="top" title="Case Already Opend Click to View Case Details" >Case already Opened</a>
                            @else
                                <a class="btn btn-secondary m-1" href="{{ route('create.new.case',[1,$data->claim_id]) }}" data-toggle="tooltip" data-placement="top" title="Open Case" >Open Case</a>
                            @endif
                            @endif
                            </div>
                        </div>
                        @else 
                        <div class="col-md-6 offset-md-3">
                        <p class="p-0 m-0 text-secondary border-muted">
                            <strong>Already Closed</strong>
                        </p>
                            @if($type == 1)
                                <a class="btn btn-secondary m-1" href="{{ route('list.all.claims') }}">Back</a>
                            @else 
                                <a class="btn btn-secondary m-1" href="{{ route('list.all.cases') }}">Back</a>
                            @endif
                        </div>   
                        @endif
                    </div>
                </form>
            </div>
        </div>
        <!-- /.card -->
    </div>
    <!--/. container-fluid -->
</section>
<!-- /.content -->
@endsection
@push('js')
<script>
$('#status').change(function() {
    hideShowFields();
});
$('#status').ready(function() {
    hideShowFields();
});
// Hide/Show Claim Amount and Claim Recieved Date fields
function hideShowFields() 
{
    let status = $('#status').find('option:selected').val();
    let claim_for = $('#claimed_for').val();

    // get hide/show fields
    let show_on_done = $(".show_on_done");
    let show_partial_amount = $('.show_partial_amount');
    show_on_done.hide();
    show_partial_amount.hide();

    if(status == '3') {
        show_on_done.show();
    }
    if(status == '5') {
        show_partial_amount.show();
    }
}
</script>
@endpush