@extends('layouts.app')
@section('title','Create New Claim | ')
@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 Claim</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">Claim 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">Register New Claim</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
                <form action="{{ route('store.new.claim') }}" method="post" autocomplete="off">
                    @csrf
                    <div class="row">
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="emp_id">Employee ID</label>
                                <input type="number" name="emp_id"
                                    class="form-control   @if( $errors->has('emp_id')) is-invalid border-danger  @endif"
                                    value="{{ old('emp_id') }}" id="emp_id" placeholder="Employee ID">
                                <small class="text-danger emp_id_error"></small>
                                @if ($errors->has('emp_id'))
                                <span id="emp_id-error"
                                    class="error text-danger invalid-feedback">{{ $errors->first('emp_id') }}</span>
                                <small></small>
                                @endif
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="emp_name">Employee Name</label>
                                <input type="text" name="emp_name"
                                    class="form-control   @if( $errors->has('emp_name')) is-invalid border-danger  @endif"
                                    value="{{ old('emp_name') }}" id="emp_name" placeholder="Employee Name">
                                @if ($errors->has('emp_name'))
                                <span id="emp_name-error"
                                    class="error text-danger invalid-feedback">{{ $errors->first('emp_name') }}</span>
                                <small></small>
                                @endif
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="emp_mobile">Mobile</label>
                                <input type="number" name="emp_mobile"
                                    class="form-control @if( $errors->has('emp_mobile')) is-invalid border-danger  @endif"
                                    id="emp_mobile" value="{{ old('emp_mobile') }}" placeholder="Mobile Number"  min="6000000001" max="9999999999">
                                @if ($errors->has('emp_mobile'))
                                <span id="emp_mobile-error"
                                    class="error text-danger invalid-feedback">{{ $errors->first('emp_mobile') }}</span>
                                <small></small>
                                @endif
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="emp_department">Department</label>
                                <select name="emp_department"
                                    class="custom-select form-control reset_form @if( $errors->has('emp_department')) is-invalid border-danger  @endif"
                                    id="emp_department">
                                    <option value="">Select departments</option>
                                    @if($departments->count() > 0)
                                    @foreach($departments as $department)
                                    <option value="{{ $department->department_master_id }}"
                                        @if(old('emp_department')==$department->department_master_id)
                                        {{ __('selected') }}
                                        @endif>{{ $department->department_name }}</option>
                                    @endforeach
                                    @endif
                                </select>
                                <small class="text-danger department_error"></small>
                                @if($errors->has('emp_department'))
                                <span id="emp_department-error"
                                    class="error text-danger invalid-feedback">{{ $errors->first('emp_department') }}</span>
                                <small></small>
                                @endif
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="scheme">Scheme</label>
                                <select name="scheme"
                                    class="custom-select form-control reset_form @if( $errors->has('scheme')) is-invalid border-danger  @endif"
                                    id="scheme">
                                    <option value="">Select Scheme</option>
                                </select>
                                <small class="text-danger scheme_error"></small>
                                @if($errors->has('scheme'))
                                <span id="scheme-error"
                                    class="error text-danger invalid-feedback">{{ $errors->first('scheme') }}</span>
                                <small></small>
                                @endif
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="emp_division">Division</label>
                                <select name="emp_division"
                                    class="custom-select form-control reset_form @if( $errors->has('emp_division')) is-invalid border-danger  @endif"
                                    id="emp_division">
                                    <option value="">Select Division</option>
                                </select>
                                <small class="text-danger emp_division_error"></small>
                                @if($errors->has('emp_division'))
                                <span id="emp_division-error"
                                    class="error text-danger invalid-feedback">{{ $errors->first('emp_division') }}</span>
                                <small></small>
                                @endif
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="emp_posting_place">Posting Place</label>
                                <select name="emp_posting_place"
                                    class="custom-select form-control reset_form @if( $errors->has('emp_posting_place')) is-invalid border-danger  @endif"
                                    id="emp_posting_place">
                                    <option value="">Select Posting Place</option>

                                </select>
                                <small class="text-danger emp_posting_place_error"></small>
                                @if($errors->has('emp_posting_place'))
                                <span id="emp_posting_place-error"
                                    class="error text-danger invalid-feedback">{{ $errors->first('emp_posting_place') }}</span>
                                <small></small>
                                @endif
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="date_of_joining">Date of Joining</label>
                                <input type="date" name="date_of_joining"
                                    class="form-control @if( $errors->has('date_of_joining')) is-invalid border-danger  @endif"
                                    id="date_of_joining" value="{{ old('date_of_joining') }}" placeholder="Date"
                                    max="{{ date('Y-m-d') }}">
                                @if ($errors->has('date_of_joining'))
                                <span id="date_of_joining-error"
                                    class="error text-danger invalid-feedback">{{ $errors->first('date_of_joining') }}</span>
                                <small></small>
                                @endif
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="father_husband_name">Father/Husband's Name</label>
                                <input type="text" name="father_husband_name"
                                    class="form-control @if( $errors->has('father_husband_name')) is-invalid border-danger  @endif"
                                    id="father_husband_name" value="{{ old('father_husband_name') }}"
                                    placeholder="Father/Husaband's Name">
                                @if ($errors->has('father_husband_name'))
                                <span id="father_husband_name-error"
                                    class="error text-danger invalid-feedback">{{ $errors->first('father_husband_name') }}</span>
                                <small></small>
                                @endif
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="relation_type">Relation Type</label>
                                <select name="relation_type"
                                    class="custom-select form-control reset_form @if( $errors->has('relation_type')) is-invalid border-danger  @endif"
                                    id="relation_type">
                                    <option value="">Select Relation Type</option>
                                    <option value="1" {{ (old('relation_type') == '1') ? 'selected' : '' }}>Father</option>
                                    <option value="2" {{ (old('relation_type') == '2') ? 'selected' : '' }}>Husband</option>
                                </select>
                                <small class="text-danger relation_type_error"></small>
                                @if($errors->has('relation_type'))
                                <span id="relation_type-error"
                                    class="error text-danger invalid-feedback">{{ $errors->first('relation_type') }}</span>
                                <small></small>
                                @endif
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="aadhar_number">Aadhar Number</label>
                                <input type="number" name="aadhar_number"
                                    class="form-control @if( $errors->has('aadhar_number')) is-invalid border-danger  @endif"
                                    id="aadhar_number" value="{{ old('aadhar_number') }}" placeholder="Aadhar Number">
                                <small class="text-danger aadhar_error"></small>
                                @if ($errors->has('aadhar_number'))
                                <span id="aadhar_number-error"
                                    class="error text-danger invalid-feedback">{{ $errors->first('aadhar_number') }}</span>
                                <small></small>
                                @endif
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="claim_type">Claim Type</label>
                                <select name="claim_type"
                                    class="custom-select form-control reset_form @if( $errors->has('claim_type')) is-invalid border-danger  @endif"
                                    id="claim_type">
                                    <option value="" {{ (old('claim_type') == '') ? 'selected' : '' }}>Select Claim Type</option>
                                    <option value="1" {{ (old('claim_type') == '1') ? 'selected' : '' }}>Death</option>
                                    <option value="2" {{ (old('claim_type') == '2') ? 'selected' : '' }}>Accident</option>
                                </select>
                                <small class="text-danger claim_type_error"></small>
                                @if($errors->has('claim_type'))
                                <span id="claim_type-error"
                                    class="error text-danger invalid-feedback">{{ $errors->first('claim_type') }}</span>
                                <small></small>
                                @endif
                            </div>
                        </div>
                        <div class="col-md-6 for_death hide_for_accident">
                            <div class="form-group">
                                <label for="date_of_death">Date of Death</label>
                                <input type="date" name="date_of_death"
                                    class="form-control  @if( $errors->has('date_of_death')) is-invalid border-danger  @endif"
                                    id="date_of_death" value="{{ old('date_of_death') }}" max="{{ date('Y-m-d') }}">
                                @if ($errors->has('date_of_death'))
                                <span id="date_of_death-error"
                                    class="error text-danger invalid-feedback">{{ $errors->first('date_of_death') }}</span>
                                <small></small>
                                @endif
                            </div>
                        </div>
                        <div class="col-md-6 for_death hide_for_accident">
                            <div class="form-group">
                                <label for="cause_of_death">Cause of Death</label>
                                <input type="text" name="cause_of_death"
                                    class="form-control @if( $errors->has('cause_of_death')) is-invalid border-danger  @endif"
                                    id="cause_of_death" value="{{ old('cause_of_death') }}"
                                    placeholder="Cause of Death">
                                @if ($errors->has('cause_of_death'))
                                <span id="cause_of_death-error"
                                    class="error text-danger invalid-feedback">{{ $errors->first('cause_of_death') }}</span>
                                <small></small>
                                @endif
                            </div>
                        </div>
                        <div class="col-md-6 for_both">
                            <div class="form-group">
                                <label for="date_of_accident">Date of Accident</label>
                                <input type="date" name="date_of_accident"
                                    class="form-control @if( $errors->has('date_of_accident')) is-invalid border-danger  @endif"
                                    id="date_of_accident" value="{{ old('date_of_accident') }}"
                                    max="{{ date('Y-m-d') }}">
                                @if ($errors->has('date_of_accident'))
                                <span id="date_of_accident-error"
                                    class="error text-danger invalid-feedback">{{ $errors->first('date_of_accident') }}</span>
                                <small></small>
                                @endif
                            </div>
                        </div>
                        <div class="col-md-6 for_both">
                            <div class="form-group">
                                <label for="accident_time">Time of Accident(Optional) <small class="text-muted">(24 Hours)</small></label>
                                <input type="time" name="accident_time"
                                    class="form-control @if( $errors->has('accident_time')) is-invalid border-danger  @endif"
                                    id="accident_time" value="{{ old('accident_time') }}"
                                    max="{{ date('Y-m-d') }}">
                                @if ($errors->has('accident_time'))
                                <span id="accident_time-error"
                                    class="error text-danger invalid-feedback">{{ $errors->first('accident_time') }}</span>
                                <small></small>
                                @endif
                            </div>
                        </div>
                        <div class="col-md-6 for_both">
                            <div class="form-group">
                                <label for="accident_place">Accident Place</label>
                                <input type="text" name="accident_place"
                                    class="form-control @if( $errors->has('accident_place')) is-invalid border-danger  @endif"
                                    id="accident_place" value="{{ old('accident_place') }}"
                                    placeholder="Accident Place">
                                @if ($errors->has('accident_place'))
                                <span id="accident_place-error"
                                    class="error text-danger invalid-feedback">{{ $errors->first('accident_place') }}</span>
                                <small></small>
                                @endif
                            </div>
                        </div>
                        <div class="col-md-6 for_both">
                            <div class="form-group">
                                <label for="shift_start_time">Shift Start Time(Optional) <small class="text-muted">(24 Hours)</small></label>
                                <input type="time" name="shift_start_time"
                                    class="form-control @if( $errors->has('shift_start_time')) is-invalid border-danger  @endif"
                                    id="shift_start_time" value="{{ old('shift_start_time') }}"
                                    placeholder="Shift Start Time">
                                @if ($errors->has('shift_start_time'))
                                <span id="shift_start_time-error"
                                    class="error text-danger invalid-feedback">{{ $errors->first('shift_start_time') }}</span>
                                <small></small>
                                @endif
                            </div>
                        </div>
                        <div class="col-md-6 for_both">
                            <div class="form-group">
                                <label for="shift_end_time">Shift End Time(Optional) <small class="text-muted">(24 Hours)</small></label>
                                <input type="time" name="shift_end_time"
                                    class="form-control @if( $errors->has('shift_end_time')) is-invalid border-danger  @endif"
                                    id="shift_end_time" value="{{ old('shift_end_time') }}"
                                    placeholder="Shift Start Time">
                                @if ($errors->has('shift_end_time'))
                                <span id="shift_end_time-error"
                                    class="error text-danger invalid-feedback">{{ $errors->first('shift_end_time') }}</span>
                                <small></small>
                                @endif
                            </div>
                        </div>
                        <div class="col-md-6 hide_for_death">
                            <div class="form-group">
                                <label for="permanent_disability">Permanent Disability<small class="text-muted">(Accidental body part)</small></label>
                                <select name="permanent_disability[]" multiple="multiple"
                                    class="custom-select select2 form-control reset_form @if( $errors->has('permanent_disability')) is-invalid border-danger  @endif"
                                    id="permanent_disability" data-placeholder="Select  Disability" style="width: 100%;">
                                    @php $disabilities = loadPermanentDisability(); @endphp
                                    @foreach($disabilities as $key => $value)
                                    <option value="{{$key}}" @if (old("permanent_disability")) {{ (in_array($key, old("permanent_disability")) ? "selected":"") }} @endif>{{ $value }}</option>
                                    @endforeach
                                </select>
                                @if ($errors->has('permanent_disability'))
                                <span id="permanent_disability-error"
                                    class="error text-danger invalid-feedback">{{ $errors->first('permanent_disability') }}</span>
                                <small></small>
                                @endif
                            </div>
                        </div>
                        <div class="col-md-6 for_both">
                            <div class="form-group">
                                <label for="accident_info">Accident Info</label>
                                <textarea name="accident_info"  id="accident_info" class="form-control @if( $errors->has('accident_info')) is-invalid border-danger  @endif" cols="30" rows="4" placeholder="Accident Details">{{ old('accident_info') }}</textarea>
                                @if ($errors->has('accident_info'))
                                <small class="error text-danger">{{ $errors->first('accident_info') }}</small>
                                @endif
                            </div>
                        </div>
                        <div class="col-md-12 for_both">
                            <div class="form-group">
                                <label for="document_for_claim">Document required for Claim</label>
                                <br><small class='text-muted'><strong>Important: </strong>All the documents are required
                                    for claim as mentioned below</small>
                                <!-- <div class="custom-control custom-checkbox for_death hide_for_accident">
                                    <input class="custom-control-input" name="death_intimation_letter" value="1" type="checkbox" id="death_intimation_letter" {{ (old('death_intimation_letter') == '1') ? 'checked' : '' }} >
                                    <label for="death_intimation_letter" class="custom-control-label">Death Certificate</label>
                                </div> -->
                                <div class="custom-control custom-checkbox for_both">
                                    <input class="custom-control-input" name="claimant_statement" value="1" type="checkbox" id="claimant_statement" {{ (old('claimant_statement') == '1') ? 'checked' : '' }} >
                                    <label for="claimant_statement" class="custom-control-label">Claimant's
                                        Statement</label>
                                </div>
                                @if($errors->has('claimant_statement'))
                                    <small  class="error text-danger">{{ $errors->first('claimant_statement') }}</small>
                                @endif
                                <div class="custom-control custom-checkbox for_death hide_for_accident">
                                    <input class="custom-control-input" name="death_certificate" value="1" type="checkbox" id="death_certificate" {{ (old('death_certificate') == '1') ? 'checked' : '' }} >
                                    <label for="death_certificate" class="custom-control-label">Original Death
                                        Certificate from Birth & death registrar office</label>
                                </div>
                                @if($errors->has('death_certificate'))
                                    <small  class="error text-danger">{{ $errors->first('death_certificate') }}</small>
                                @endif
                                
                                <div class="custom-control custom-checkbox for_both">
                                    <input class="custom-control-input" name="fir_report" value="1" type="checkbox" id="fir_report" {{ (old('fir_report') == '1') ? 'checked' : '' }} >
                                    <label for="fir_report" class="custom-control-label">FIR Report</label>
                                </div>
                                @if($errors->has('fir_report'))
                                    <small  class="error text-danger">{{ $errors->first('fir_report') }}</small>
                                @endif
                                <div class="custom-control custom-checkbox for_death hide_for_accident">
                                    <input class="custom-control-input" name="post_mortem_report" value="1" type="checkbox" id="post_mortem_report" {{ (old('post_mortem_report') == '1') ? 'checked' : '' }} >
                                    <label for="post_mortem_report" class="custom-control-label">POST Mortem
                                        Report</label>
                                </div>
                                @if($errors->has('post_mortem_report'))
                                    <small  class="error text-danger">{{ $errors->first('post_mortem_report') }}</small>
                                @endif
                                <div class="custom-control custom-checkbox for_both">
                                    <input class="custom-control-input" name="employer_certificate" value="1" type="checkbox" id="employer_certificate" {{ (old('employer_certificate') == '1') ? 'checked' : '' }} >
                                    <label for="employer_certificate" class="custom-control-label">Employer
                                        Certificate</label>
                                </div>
                                @if($errors->has('employer_certificate'))
                                    <small  class="error text-danger">{{ $errors->first('employer_certificate') }}</small>
                                @endif
                                <div class="custom-control custom-checkbox for_both">
                                    <input class="custom-control-input" name="age_proof" value="1" type="checkbox" id="age_proof" {{ (old('age_proof') == '1') ? 'checked' : '' }} >
                                    <label for="age_proof" class="custom-control-label">Proof of Standard Age. </label>
                                </div>
                                @if($errors->has('age_proof'))
                                    <small  class="error text-danger">{{ $errors->first('age_proof') }}</small>
                                @endif
                                <div class="form-group for_both">
                                    <div class="col-md-6">
                                        <label for="age_proof_doc">Age Proof Document. eg. passport, birth certificate
                                            etc</label>
                                        <select name="age_proof_doc"
                                            class="custom-select form-control reset_form @if( $errors->has('age_proof_doc')) is-invalid border-danger  @endif"
                                            id="age_proof_doc">
                                            <option value="">Select Age Proof Document</option>
                                            @php $ageDocs = loadAgeProofDoc(); @endphp
                                            @foreach($ageDocs as $ageProof)
                                            <option value="{{ $ageProof }}" {{ (old('age_proof_doc') == $ageProof) ? 'selected' : '' }} >{{ $ageProof }}</option>
                                            @endforeach
                                        </select>
                                        <small class="text-danger relation_type_error"></small>
                                        @if($errors->has('age_proof'))
                                            <small  class="error text-danger">{{ $errors->first('age_proof') }}</small>
                                        @endif
                                    </div>
                                </div>
                            </div>
                        </div>
                        @if(Auth::user()->user_role == 1 || Auth::user()->user_role == 2)
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="assign_to">Assign To</label>
                                <select name="assign_to" id="assign_to" class="custom-select  @if($errors->has('assign_to')) is-invalid border-danger  @endif">
                                    <option value="" >-- Select User --</option>    
                                    @foreach($users as $user)
                                        <option value="{{ $user->id }}" {{ (old('assign_to') == $user->id) ? 'selected' : '' }}>{{ $user->full_name }} ({{ getUserType($user->user_role) }})</option>
                                    @endforeach
                                </select>
                                @if ($errors->has('assign_to'))
                                <small class="text-danger ">{{ $errors->first('assign_to') }}</small>
                                @endif
                            </div>
                        </div> 
                        @endif
                        <div class="col-md-12">
                            <div class="form-group">
                                <a class="btn btn-secondary m-1" href="{{ route('list.all.claims') }}">Back</a>
                                <input type="submit" name="save" value="Save Claim" class="btn btn-primary">
                                <!-- <input type="submit" name="next" value="Next" class="btn btn-primary"> -->
                            </div>
                            <small class="text-muted"><strong>Note: </strong>Verify the details entered by you before
                                saving and proceeding with the form</small><br>
                            <small class="text-muted"><strong>नोट: </strong>फॉर्म को सेव और आगे बढ़ाने से पहले आपके
                                द्वारा भरी गई डिटेल्स की पुष्टि कर ले</small>
                        </div>
                    </div>
                </form>
            </div>
        </div>
        <!-- /.card -->
    </div>
    <!--/. container-fluid -->
</section>
<!-- /.content -->
@endsection