
@extends("layouts.metor.admin")
@section("content")
@section("title","Update Employees")

<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 Employees</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_employees['client_id_req'];}}{{ $dbs_employees['client_id_title']}}: </label>
 <select name="client_id" id="update-client_id"  class="chosen-select form-control form-select">
    <option value="">{{ $dbs_employees['client_id_req'];}}Select {{ $dbs_employees['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="col-lg-4">
    <div class="mb-3">
        <label class='form-label'>{{ $dbs_employees['employee_code_req'];}}{{ $dbs_employees['employee_code_title']; }}:</label>
        <input type = '{{$dbs_employees['employee_code_html5_type'] }}' name = "employee_code" id = "update-employee_code" autocomplete = 'off' maxlength ='{{  $dbs_employees['employee_code_max'] }}'  value='{{$row->employee_code}}' @if($dbs_employees['employee_code_html5_req']!='') {{ $dbs_employees['employee_code_html5_req'] }} = {{$dbs_employees['employee_code_html5_req']}} @endif class= 'form-control'  >
        <span class='text-danger' id='update-employee_codeError'></span>
    </div>
</div>


<div class="col-lg-4">
    <div class="mb-3">
        <label class='form-label'>{{ $dbs_employees['first_name_req'];}}{{ $dbs_employees['first_name_title']; }}:</label>
        <input type = '{{$dbs_employees['first_name_html5_type'] }}' name = "first_name" id = "update-first_name" autocomplete = 'off' maxlength ='{{  $dbs_employees['first_name_max'] }}'  value='{{$row->first_name}}' @if($dbs_employees['first_name_html5_req']!='') {{ $dbs_employees['first_name_html5_req'] }} = {{$dbs_employees['first_name_html5_req']}} @endif class= 'form-control'  >
        <span class='text-danger' id='update-first_nameError'></span>
    </div>
</div>


<div class="col-lg-4">
    <div class="mb-3">
        <label class='form-label'>{{ $dbs_employees['last_name_req'];}}{{ $dbs_employees['last_name_title']; }}:</label>
        <input type = '{{$dbs_employees['last_name_html5_type'] }}' name = "last_name" id = "update-last_name" autocomplete = 'off' maxlength ='{{  $dbs_employees['last_name_max'] }}'  value='{{$row->last_name}}' @if($dbs_employees['last_name_html5_req']!='') {{ $dbs_employees['last_name_html5_req'] }} = {{$dbs_employees['last_name_html5_req']}} @endif class= 'form-control'  >
        <span class='text-danger' id='update-last_nameError'></span>
    </div>
</div>


<div class="col-lg-4">
    <div class="mb-3">
        <label class='form-label'>{{ $dbs_employees['email_req'];}}{{ $dbs_employees['email_title']; }}:</label>
        <input type = '{{$dbs_employees['email_html5_type'] }}' name = "email" id = "update-email" autocomplete = 'off' maxlength ='{{  $dbs_employees['email_max'] }}'  value='{{$row->email}}' @if($dbs_employees['email_html5_req']!='') {{ $dbs_employees['email_html5_req'] }} = {{$dbs_employees['email_html5_req']}} @endif class= 'form-control'   oninput='validateEmailInput(this)' >
        <span class='text-danger' id='update-emailError'></span>
    </div>
</div>


<div class="col-lg-4">
    <div class="mb-3">
        <label class='form-label'>{{ $dbs_employees['phone_req'];}}{{ $dbs_employees['phone_title']; }}:</label>
        <input type = '{{$dbs_employees['phone_html5_type'] }}' name = "phone" id = "update-phone" autocomplete = 'off' maxlength ='{{  $dbs_employees['phone_max'] }}'  value='{{$row->phone}}' @if($dbs_employees['phone_html5_req']!='') {{ $dbs_employees['phone_html5_req'] }} = {{$dbs_employees['phone_html5_req']}} @endif class= 'form-control'  >
        <span class='text-danger' id='update-phoneError'></span>
    </div>
</div>


<div class="col-lg-4">
    <div class="mb-3">
        <label class='form-label'>{{ $dbs_employees['cnic_req'];}}{{ $dbs_employees['cnic_title']; }}:</label>
        <input type = '{{$dbs_employees['cnic_html5_type'] }}' name = "cnic" id = "update-cnic" autocomplete = 'off' maxlength ='{{  $dbs_employees['cnic_max'] }}'  value='{{$row->cnic}}' @if($dbs_employees['cnic_html5_req']!='') {{ $dbs_employees['cnic_html5_req'] }} = {{$dbs_employees['cnic_html5_req']}} @endif class= 'form-control'  >
        <span class='text-danger' id='update-cnicError'></span>
    </div>
</div>

<div class="col-lg-4">
    <div class="mb-3">
        <label class='form-label'>{{ $dbs_employees['gender_req'];}}{{ $dbs_employees['gender_title']; }}:</label><br/>
        <div class="mt-2">
            @php
            $options = $dbs_employees['gender_array'];
            @endphp

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

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

<div class="col-lg-4">
    <div class="mb-3">
        <label class='form-label'>{{ $dbs_employees['date_of_birth_req'];}}{{ $dbs_employees['date_of_birth_title']; }}:</label>
        <input type = '{{$dbs_employees['date_of_birth_html5_type'] }}' name = "date_of_birth" id = "update-date_of_birth" autocomplete = 'off' @if($dbs_employees['date_of_birth_html5_req']!='') {{ $dbs_employees['date_of_birth_html5_req'] }} = {{$dbs_employees['date_of_birth_html5_req']}} @endif class= 'form-control dateBox' >
        <span class='text-danger' id='update-date_of_birthError'></span>
        
        <script>
            $(function() {
                $( '#update-date_of_birth' ).datepicker({
                    changeMonth: true,
                    changeYear: true
                });
                $( '#update-date_of_birth' ).datepicker( 'option', 'yearRange', 'c-100:c+10' );
                $( '#update-date_of_birth' ).datepicker( 'option', 'dateFormat', 'yy-mm-dd' );
                $('#update-date_of_birth').datepicker('setDate', '{{$row->date_of_birth}}' );                
            });
        </script>
    </div>
</div>

<div class="col-lg-4">
    <div class="mb-3">
        <label class='form-label'>{{ $dbs_employees['joining_date_req'];}}{{ $dbs_employees['joining_date_title']; }}:</label>
        <input type = '{{$dbs_employees['joining_date_html5_type'] }}' name = "joining_date" id = "update-joining_date" autocomplete = 'off' @if($dbs_employees['joining_date_html5_req']!='') {{ $dbs_employees['joining_date_html5_req'] }} = {{$dbs_employees['joining_date_html5_req']}} @endif class= 'form-control dateBox' >
        <span class='text-danger' id='update-joining_dateError'></span>
        
        <script>
            $(function() {
                $( '#update-joining_date' ).datepicker({
                    changeMonth: true,
                    changeYear: true
                });
                $( '#update-joining_date' ).datepicker( 'option', 'yearRange', 'c-100:c+10' );
                $( '#update-joining_date' ).datepicker( 'option', 'dateFormat', 'yy-mm-dd' );
                $('#update-joining_date').datepicker('setDate', '{{$row->joining_date}}' );                
            });
        </script>
    </div>
</div>

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

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

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

<div class="col-lg-4">
    <div class="mb-3">
        <label class='form-label'>{{ $dbs_employees['employment_type_req'];}}{{ $dbs_employees['employment_type_title']; }}:</label><br/>
        <div class="mt-2">
            @php
            $options = $dbs_employees['employment_type_array'];
            @endphp

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

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

<div class="col-lg-4">
    <div class="mb-3">
        <label class='form-label'>{{ $dbs_employees['basic_salary_req'];}}{{ $dbs_employees['basic_salary_title']}}:</label>
        <input type = '{{$dbs_employees['basic_salary_html5_type'] }}' name = "basic_salary" id = "update-basic_salary" data-maxlen='{{ $dbs_employees['basic_salary_max'] }}' data-scale='{{ $dbs_employees['basic_salary_scale'] ?? '' }}' autocomplete = 'off'   value='{{$row->basic_salary}}' @if($dbs_employees['basic_salary_html5_req']!='') {{ $dbs_employees['basic_salary_html5_req'] }} = {{$dbs_employees['basic_salary_html5_req']}} @endif class= 'form-control'   onkeydown='validateFloatInput(event)'  oninput='validateInput(this,{{  $dbs_employees['basic_salary_max'] }})' />
        <span class='text-danger' id='update-basic_salaryError'></span>
    </div>
</div>


<div class="col-lg-4">
    <div class="mb-3">
        <label class='form-label'>{{ $dbs_employees['bank_name_req'];}}{{ $dbs_employees['bank_name_title']; }}:</label>
        <input type = '{{$dbs_employees['bank_name_html5_type'] }}' name = "bank_name" id = "update-bank_name" autocomplete = 'off' maxlength ='{{  $dbs_employees['bank_name_max'] }}'  value='{{$row->bank_name}}' @if($dbs_employees['bank_name_html5_req']!='') {{ $dbs_employees['bank_name_html5_req'] }} = {{$dbs_employees['bank_name_html5_req']}} @endif class= 'form-control'  >
        <span class='text-danger' id='update-bank_nameError'></span>
    </div>
</div>


<div class="col-lg-4">
    <div class="mb-3">
        <label class='form-label'>{{ $dbs_employees['bank_account_number_req'];}}{{ $dbs_employees['bank_account_number_title']; }}:</label>
        <input type = '{{$dbs_employees['bank_account_number_html5_type'] }}' name = "bank_account_number" id = "update-bank_account_number" autocomplete = 'off' maxlength ='{{  $dbs_employees['bank_account_number_max'] }}'  value='{{$row->bank_account_number}}' @if($dbs_employees['bank_account_number_html5_req']!='') {{ $dbs_employees['bank_account_number_html5_req'] }} = {{$dbs_employees['bank_account_number_html5_req']}} @endif class= 'form-control'  >
        <span class='text-danger' id='update-bank_account_numberError'></span>
    </div>
</div>


<div class="col-lg-12">
    <div class="mb-3">
        <label class='form-label'>{{ $dbs_employees['address_req'];}}{{ $dbs_employees['address_title']; }}:</label>
        <textarea type = '{{$dbs_employees['address_html5_type'] }}' name = "address" id = "update-address" autocomplete = 'off' maxlength ='{{  $dbs_employees['address_max'] }}' @if($dbs_employees['address_html5_req']!='') {{ $dbs_employees['address_html5_req'] }} = {{$dbs_employees['address_html5_req']}} @endif class= 'form-control'   oninput='updateCharCount(this,"update-addresscharCount")'>{{$row->address}}</textarea>
        <span class='text-danger' id='update-addresscharCount'></span> 
        <span class='text-danger' id='update-addressError'></span>
    </div>
</div>


<div class="col-lg-4">
    <div class="mb-3">
        <label class='form-label'>{{ $dbs_employees['profile_picture_req'];}}{{ $dbs_employees['profile_picture_title']; }}:</label>
        <input type="file" name="profile_picture" id="update-profile_picture" class="form-control" @if($dbs_employees['profile_picture_html5_req']!='') {{ $dbs_employees['profile_picture_html5_req'] }} = {{$dbs_employees['profile_picture_html5_req']}} @endif >
        <div class="mt-1">{{ $getSettings['allowed_file_formats'] ?? '' }}</div>
        
@if(!empty($row->profile_picture))
    <a class="underline" href="{{ asset('images/' . $row->profile_picture) }}" target="_blank" download>
        {{ __('Download file') }}
    </a>
@endif
        <input type="hidden" name="previous_profile_picture" id="previous_profile_picture" value="{{ $row->profile_picture }}">
        <span class='text-danger' id='update-profile_pictureError'></span>
    </div>
</div>


<div class="col-lg-4">
    <div class="mb-3">
        <label class='form-label'>{{ $dbs_employees['resume_req'];}}{{ $dbs_employees['resume_title']; }}:</label>
        <input type = '{{$dbs_employees['resume_html5_type'] }}' name = "resume" id = "update-resume" autocomplete = 'off' maxlength ='{{  $dbs_employees['resume_max'] }}'  value='{{$row->resume}}' @if($dbs_employees['resume_html5_req']!='') {{ $dbs_employees['resume_html5_req'] }} = {{$dbs_employees['resume_html5_req']}} @endif class= 'form-control'  >
        <span class='text-danger' id='update-resumeError'></span>
    </div>
</div>

<div class="mt-2 col-xs-12 col-sm-12 col-md-12 col-lg-12">
<label class='form-label'>{{ $dbs_employees['skills_req'];}}{{ $dbs_employees['skills_title']}}: </label>
 <select name="skills[]" id="update-skills" class="chosen-select form-control form-select" multiple>
    @php
        $selectedValues = [];
        if (!empty($row->skills)) {
            $selectedValues = is_array($row->skills) ? $row->skills : explode(',', $row->skills);
        }
        $selectedValues = array_filter(array_map('trim', $selectedValues), function($v){ return $v !== ''; });
    @endphp
    @foreach($skills as $id => $name)
        <option value="{{ $id }}" @if(in_array((string)$id, array_map('strval', $selectedValues), true)) selected @endif>{{ $name }}</option>
    @endforeach
</select>
<script>
    $(function() {
        $('#update-skills').chosen({
              width: '100%',
              search_contains: true
            });
        });
</script>
<span class='text-danger' id='update-skillsError'></span>
</div>

<div class="col-lg-4">
    <div class="mb-3">
        <label class='form-label'>{{ $dbs_employees['status_req'];}}{{ $dbs_employees['status_title']; }}:</label><br/>
        <div class="mt-2">
            @php
            $options = $dbs_employees['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>
                    

                    <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("employees.update", $row->id) }}' data-args2='admin/employees' onclick='addUpdate(event,"update")'>
                                        <i class="ri-save-line"></i> Save 
                                    </button>
                                </div>
                            </div>
                            <div class="col-lg-2">
                                <a href="{{ route('employees.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

