
@extends("layouts.metor.admin")
@section("content")
@section("title","Update 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">Update 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="update-form" id="update-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="update-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 == $row->client_id) ? 'selected="selected"' : '';
@endphp
        <option value="{{ $id }}"  {{ $selected }}>{{ $name }}</option>
    @endforeach
</select>
<script>
    $(function() {
        $('#update-client_id').chosen({
              width: '100%',
              search_contains: true
            });
        });
</script>
<span class='text-danger' id='update-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="update-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 == $row->employee_id) ? 'selected="selected"' : '';
@endphp
        <option value="{{ $id }}"  {{ $selected }}>{{ $name }}</option>
    @endforeach
</select>
<script>
    $(function() {
        $('#update-employee_id').chosen({
              width: '100%',
              search_contains: true
            });
        });
</script>
<span class='text-danger' id='update-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="update-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 == $row->leave_type_id) ? 'selected="selected"' : '';
@endphp
        <option value="{{ $id }}"  {{ $selected }}>{{ $name }}</option>
    @endforeach
</select>
<script>
    $(function() {
        $('#update-leave_type_id').chosen({
              width: '100%',
              search_contains: true
            });
        });
</script>
<span class='text-danger' id='update-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 = "update-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='update-from_dateError'></span>
        
        <script>
            $(function() {
                $( '#update-from_date' ).datepicker({
                    changeMonth: true,
                    changeYear: true
                });
                $( '#update-from_date' ).datepicker( 'option', 'yearRange', 'c-100:c+10' );
                $( '#update-from_date' ).datepicker( 'option', 'dateFormat', 'yy-mm-dd' );
                $('#update-from_date').datepicker('setDate', '{{$row->from_date}}' );                
            });
        </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 = "update-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='update-to_dateError'></span>
        
        <script>
            $(function() {
                $( '#update-to_date' ).datepicker({
                    changeMonth: true,
                    changeYear: true
                });
                $( '#update-to_date' ).datepicker( 'option', 'yearRange', 'c-100:c+10' );
                $( '#update-to_date' ).datepicker( 'option', 'dateFormat', 'yy-mm-dd' );
                $('#update-to_date').datepicker('setDate', '{{$row->to_date}}' );                
            });
        </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 = "update-total_days" data-maxlen='{{ $dbs_leaves['total_days_max'] }}' data-scale='{{ $dbs_leaves['total_days_scale'] ?? '' }}' autocomplete = 'off'   value='{{$row->total_days}}' @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='update-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 = "update-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,"update-reasoncharCount")'>{{$row->reason}}</textarea>
        <span class='text-danger' id='update-reasoncharCount'></span> 
        <span class='text-danger' id='update-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="update-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>
        
@if(!empty($row->attachment))
    <a class="underline" href="{{ asset('images/' . $row->attachment) }}" target="_blank" download>
        {{ __('Download attachment') }}
    </a>
@endif
        <input type="hidden" name="previous_attachment" id="previous_attachment" value="{{ $row->attachment }}">
        <span class='text-danger' id='update-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 == $row->status) ? 'checked="checked"' : '';
                @endphp

                <label class="btn btn-outline-primary">
                    <input type="radio" name="status" value="{{ $key }}" id="update-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="update-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 == $row->approved_by) ? 'selected="selected"' : '';
@endphp
        <option value="{{ $id }}"  {{ $selected }}>{{ $name }}</option>
    @endforeach
</select>
<script>
    $(function() {
        $('#update-approved_by').chosen({
              width: '100%',
              search_contains: true
            });
        });
</script>
<span class='text-danger' id='update-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">
                                <div id="edit-mode">
                                    <button type='submit' name='update-submit' id='update-submit' class='btn btn-outline-secondary w-100' data-args1='{{ route("leaves.update", $row->id) }}' data-args2='admin/leaves' onclick='addUpdate(event,"update")'>
                                        <i class="ri-save-line"></i> Save 
                                    </button>
                                </div>
                            </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

