
@extends("layouts.metor.admin")
@section("content")
@section("title","Add Leaves")

<div class="row">
    <div class="col-xl-12 col-lg-12">
        <div class="alert alert-success my-3" style="display:none;" id="success"></div>
        
        <div class="card">
            <div class="card-header d-flex justify-content-between align-items-center">
                <h4 class="card-title mb-0">Add Leaves</h4>
                <a href="javascript:history.back()" class="btn btn-sm btn-light">
                    <i class="ri-arrow-left-line"></i> Back
                </a>
            </div>
            
            <div class="card-body">
                <form accept-charset="utf-8" name="add-form" id="add-form" enctype="multipart/form-data">
                    @csrf
                    <div class="row">

<div class="mt-2 col-xs-12 col-sm-12 col-md-4 col-lg-4">        
<label class='form-label'>{{ $dbs_leaves['client_id_req'];}}{{ $dbs_leaves['client_id_title']}}: </label>
 <select name="client_id" id="add-client_id"  class="chosen-select form-control form-select">
    <option value="">{{ $dbs_leaves['client_id_req'];}}Select {{ $dbs_leaves['client_id_title'] }} </option>
    @foreach($client_id as $id => $name)
        @php
    $selected = ($id == '') ? 'selected="selected"' : '';
@endphp
        <option value="{{ $id }}"  {{ $selected }}>{{ $name }}</option>
    @endforeach
</select>
<script>
    $(function() {
        $('#add-client_id').chosen({
              width: '100%',
              search_contains: true
            });
        });
</script>
<span class='text-danger' id='add-client_idError'></span>
</div>

<div class="mt-2 col-xs-12 col-sm-12 col-md-4 col-lg-4">        
<label class='form-label'>{{ $dbs_leaves['employee_id_req'];}}{{ $dbs_leaves['employee_id_title']}}: </label>
 <select name="employee_id" id="add-employee_id"  class="chosen-select form-control form-select">
    <option value="">{{ $dbs_leaves['employee_id_req'];}}Select {{ $dbs_leaves['employee_id_title'] }} </option>
    @foreach($employee_id as $id => $name)
        @php
    $selected = ($id == '') ? 'selected="selected"' : '';
@endphp
        <option value="{{ $id }}"  {{ $selected }}>{{ $name }}</option>
    @endforeach
</select>
<script>
    $(function() {
        $('#add-employee_id').chosen({
              width: '100%',
              search_contains: true
            });
        });
</script>
<span class='text-danger' id='add-employee_idError'></span>
</div>

<div class="mt-2 col-xs-12 col-sm-12 col-md-4 col-lg-4">        
<label class='form-label'>{{ $dbs_leaves['leave_type_id_req'];}}{{ $dbs_leaves['leave_type_id_title']}}: </label>
 <select name="leave_type_id" id="add-leave_type_id"  class="chosen-select form-control form-select">
    <option value="">{{ $dbs_leaves['leave_type_id_req'];}}Select {{ $dbs_leaves['leave_type_id_title'] }} </option>
    @foreach($leave_type_id as $id => $name)
        @php
    $selected = ($id == '') ? 'selected="selected"' : '';
@endphp
        <option value="{{ $id }}"  {{ $selected }}>{{ $name }}</option>
    @endforeach
</select>
<script>
    $(function() {
        $('#add-leave_type_id').chosen({
              width: '100%',
              search_contains: true
            });
        });
</script>
<span class='text-danger' id='add-leave_type_idError'></span>
</div>

<div class="col-lg-4">
    <div class="mb-3">
        <label class='form-label'>{{ $dbs_leaves['from_date_req'];}}{{ $dbs_leaves['from_date_title']; }}:</label>
        <input type = '{{$dbs_leaves['from_date_html5_type'] }}' name = "from_date" id = "add-from_date" autocomplete = 'off' @if($dbs_leaves['from_date_html5_req']!='') {{ $dbs_leaves['from_date_html5_req'] }} = {{$dbs_leaves['from_date_html5_req']}} @endif class= 'form-control dateBox' >
        <span class='text-danger' id='add-from_dateError'></span>
        
        <script>
            $(function() {
                $( '#add-from_date' ).datepicker({
                    changeMonth: true,
                    changeYear: true
                });
                $( '#add-from_date' ).datepicker( 'option', 'yearRange', 'c-100:c+10' );
                $( '#add-from_date' ).datepicker( 'option', 'dateFormat', 'yy-mm-dd' );
                $('#add-from_date').datepicker('setDate', '{{date("y-m-d")}}' );                
            });
        </script>
    </div>
</div>

<div class="col-lg-4">
    <div class="mb-3">
        <label class='form-label'>{{ $dbs_leaves['to_date_req'];}}{{ $dbs_leaves['to_date_title']; }}:</label>
        <input type = '{{$dbs_leaves['to_date_html5_type'] }}' name = "to_date" id = "add-to_date" autocomplete = 'off' @if($dbs_leaves['to_date_html5_req']!='') {{ $dbs_leaves['to_date_html5_req'] }} = {{$dbs_leaves['to_date_html5_req']}} @endif class= 'form-control dateBox' >
        <span class='text-danger' id='add-to_dateError'></span>
        
        <script>
            $(function() {
                $( '#add-to_date' ).datepicker({
                    changeMonth: true,
                    changeYear: true
                });
                $( '#add-to_date' ).datepicker( 'option', 'yearRange', 'c-100:c+10' );
                $( '#add-to_date' ).datepicker( 'option', 'dateFormat', 'yy-mm-dd' );
                $('#add-to_date').datepicker('setDate', '{{date("y-m-d")}}' );                
            });
        </script>
    </div>
</div>

<div class="col-lg-4">
    <div class="mb-3">
        <label class='form-label'>{{ $dbs_leaves['total_days_req'];}}{{ $dbs_leaves['total_days_title']}}:</label>
        <input type = '{{$dbs_leaves['total_days_html5_type'] }}' name = "total_days" id = "add-total_days" data-maxlen='{{ $dbs_leaves['total_days_max'] }}' data-scale='{{ $dbs_leaves['total_days_scale'] ?? '' }}' autocomplete = 'off'   value='' @if($dbs_leaves['total_days_html5_req']!='') {{ $dbs_leaves['total_days_html5_req'] }} = {{$dbs_leaves['total_days_html5_req']}} @endif class= 'form-control'   onkeydown='validateNumericInput(event)'  oninput='validateInput(this,{{  $dbs_leaves['total_days_max'] }})' />
        <span class='text-danger' id='add-total_daysError'></span>
    </div>
</div>


<div class="col-lg-12">
    <div class="mb-3">
        <label class='form-label'>{{ $dbs_leaves['reason_req'];}}{{ $dbs_leaves['reason_title']; }}:</label>
        <textarea type = '{{$dbs_leaves['reason_html5_type'] }}' name = "reason" id = "add-reason" autocomplete = 'off' maxlength ='{{  $dbs_leaves['reason_max'] }}' @if($dbs_leaves['reason_html5_req']!='') {{ $dbs_leaves['reason_html5_req'] }} = {{$dbs_leaves['reason_html5_req']}} @endif class= 'form-control'   oninput='updateCharCount(this,"add-reasoncharCount")'></textarea>
        <span class='text-danger' id='add-reasoncharCount'></span> 
        <span class='text-danger' id='add-reasonError'></span>
    </div>
</div>


<div class="col-lg-4">
    <div class="mb-3">
        <label class='form-label'>{{ $dbs_leaves['attachment_req'];}}{{ $dbs_leaves['attachment_title']; }}:</label>
        <input type="file" name="attachment" id="add-attachment" class="form-control" @if($dbs_leaves['attachment_html5_req']!='') {{ $dbs_leaves['attachment_html5_req'] }} = {{$dbs_leaves['attachment_html5_req']}} @endif >
        <div class="mt-1">{{ $getSettings['allowed_attachment_formats'] ?? '' }}</div>
        
        
        <span class='text-danger' id='add-attachmentError'></span>
    </div>
</div>

<div class="col-lg-4">
    <div class="mb-3">
        <label class='form-label'>{{ $dbs_leaves['status_req'];}}{{ $dbs_leaves['status_title']; }}:</label><br/>
        <div class="mt-2">
            @php
            $options = $dbs_leaves['status_array'];
            @endphp

            @foreach ($options as $key => $value)
                @php
                $checked = ($key == 'Active') ? 'checked="checked"' : '';
                @endphp

                <label class="btn btn-outline-primary">
                    <input type="radio" name="status" value="{{ $key }}" id="add-status" {{ $checked }}/> {{ $value }}
                </label>
            @endforeach
        </div>
    </div>
</div>

<div class="mt-2 col-xs-12 col-sm-12 col-md-4 col-lg-4">        
<label class='form-label'>{{ $dbs_leaves['approved_by_req'];}}{{ $dbs_leaves['approved_by_title']}}: </label>
 <select name="approved_by" id="add-approved_by"  class="chosen-select form-control form-select">
    <option value="">{{ $dbs_leaves['approved_by_req'];}}Select {{ $dbs_leaves['approved_by_title'] }} </option>
    @foreach($approved_by as $id => $name)
        @php
    $selected = ($id == '') ? 'selected="selected"' : '';
@endphp
        <option value="{{ $id }}"  {{ $selected }}>{{ $name }}</option>
    @endforeach
</select>
<script>
    $(function() {
        $('#add-approved_by').chosen({
              width: '100%',
              search_contains: true
            });
        });
</script>
<span class='text-danger' id='add-approved_byError'></span>
</div>

    
                    </div>
                    

                    <div class="p-3 mb-3 rounded">
                        <div class="row justify-content-end g-2">
                            <div class="col-lg-3">
                                <button type='submit' name='add-submit' id='add-submit' class='btn btn-outline-secondary w-100' data-args1='{{ route("leaves.store") }}' data-args2='admin/leaves' onclick='addUpdate(event, "add")'>
                                    <i class="ri-save-line"></i> Save 
                                </button>
                            </div>
                            <div class="col-lg-2">
                                <a href="{{ route('leaves.index') }}" class="btn btn-primary w-100">
                                    <i class="ri-close-circle-line"></i> Cancel
                                </a>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

@endsection

