{{Form::model($leave,array('route' => array('leave.update', $leave->id), 'method' => 'PUT', 'class'=>'needs-validation', 'novalidate')) }}
<div class="modal-body">
    {{-- start for ai module--}}
    @php
        $plan= \App\Models\Utility::getChatGPTSettings();
    @endphp
    @if($plan->chatgpt == 1)
    <div class="text-end">
        <a href="#" data-size="md" class="btn  btn-primary btn-icon btn-sm" data-ajax-popup-over="true" data-url="{{ route('generate',['leave']) }}"
           data-bs-placement="top" data-title="{{ __('Generate content with AI') }}">
            <i class="fas fa-robot"></i> <span>{{__('Generate with AI')}}</span>
        </a>
    </div>
    @endif
    {{-- end for ai module--}}

    @if(\Auth::user()->type =='company' || \Auth::user()->type =='HR')
    <div class="row">
        <div class="col-md-12">
            <div class="form-group">
                {{Form::label('employee_id',__('Employee') ,['class'=>'form-label'])}}<x-required></x-required>
                {{Form::select('employee_id',$employees,null,array('class'=>'form-control select','placeholder'=>__('Select Employee'), 'required' => 'required'))}}
            </div>
        </div>
    </div>
    @endif
    <div class="row">
        <div class="col-md-12">
            <div class="form-group">
                {{Form::label('leave_type_id',__('Leave Type'),['class'=>'form-label'])}}<x-required></x-required>
                {{Form::select('leave_type_id',$leavetypes,null,array('class'=>'form-control select','placeholder'=>__('Select Leave Type'),'required' =>'required'))}}
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-md-6">
            <div class="form-group">
                {{Form::label('start_date',__('Start Date'),['class'=>'form-label'])}}<x-required></x-required>
                {{Form::text('start_date', !empty($leave->start_date) ? \Carbon\Carbon::parse($leave->start_date)->format('d/m/Y') : null, array('class'=>'form-control js-ddmmyyyy','required' =>'required', 'autocomplete' => 'off', 'placeholder' => 'DD/MM/YYYY', 'readonly' => 'readonly'))}}
            </div>
        </div>
        <div class="col-md-6">
            <div class="form-group">
                {{Form::label('end_date',__('End Date'),['class'=>'form-label'])}}<x-required></x-required>
                {{Form::text('end_date', !empty($leave->end_date) ? \Carbon\Carbon::parse($leave->end_date)->format('d/m/Y') : null, array('class'=>'form-control js-ddmmyyyy','required' =>'required', 'autocomplete' => 'off', 'placeholder' => 'DD/MM/YYYY', 'readonly' => 'readonly'))}}
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-md-12">
            <div class="form-group">
                {{Form::label('leave_reason',__('Leave Reason'),['class'=>'form-label'])}}<x-required></x-required>
                {{Form::textarea('leave_reason',null,array('class'=>'form-control','placeholder'=>__('Leave Reason'),'required' =>'required'))}}
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-md-12 text-end">
            <a href="#" data-size="md" class="btn btn-primary btn-icon btn-sm text-right" data-ajax-popup-over="true" id="grammarCheck" data-url="{{ route('grammar',['grammar']) }}"
               data-bs-placement="top" data-title="{{ __('Grammar check with AI') }}">
                <i class="ti ti-rotate"></i> <span>{{__('Grammar check with AI')}}</span>
            </a>
        </div>
        <div class="col-md-12">
            <div class="form-group">
                {{Form::label('remark',__('Remark'),['class'=>'form-label'])}}<x-required></x-required>
                {{Form::textarea('remark',null,array('class'=>'form-control grammer_textarea','placeholder'=>__('Leave Remark'),'required' =>'required'))}}
            </div>
        </div>
    </div>
    @role('Company')
    <div class="row">
        <div class="col-md-12">
            <div class="form-group">
                {{Form::label('status',__('Status'))}}
                <select name="status" id="" class="form-control select2">
                    <option value="">{{__('Select Status')}}</option>
                    <option value="Pending" @if(in_array($leave->status, ['Pending', 'pending'])) selected="" @endif>{{__('Pending')}}</option>
                    <option value="Approved" @if(in_array($leave->status, ['Approved', 'Approval', 'approval'])) selected="" @endif>{{__('Approved')}}</option>
                    <option value="Reject" @if(in_array($leave->status, ['Reject', 'reject'])) selected="" @endif>{{__('Reject')}}</option>
                </select>
            </div>
        </div>
    </div>
    @endrole

</div>
<div class="modal-footer">
    <input type="button" value="{{__('Cancel')}}" class="btn  btn-secondary" data-bs-dismiss="modal">
    <input type="submit" value="{{__('Update')}}" class="btn  btn-primary">
</div>
    {{Form::close()}}

<script>
    var employee_id = "{{$employee_id}}";
    var leave_type_id = "{{isset($leave) ? $leave->leave_type_id : null}}";
    leaveCount(employee_id, leave_type_id)

    $(document).ready(function() {
        var $dateInputs = $('.js-ddmmyyyy');
        $dateInputs.on('keydown paste', function (e) {
            e.preventDefault();
        });

        if (typeof flatpickr !== 'undefined') {
            $dateInputs.each(function () {
                if (!this._flatpickr) {
                    flatpickr(this, {
                        dateFormat: 'd/m/Y',
                        allowInput: false,
                        disableMobile: true
                    });
                }
            });
        } else if ($.fn.datepicker) {
            $dateInputs.each(function () {
                if (!$(this).hasClass('hasDatepicker')) {
                    $(this).datepicker({
                        dateFormat: 'dd/mm/yy',
                        changeMonth: true,
                        changeYear: true,
                        yearRange: '1900:+10'
                    });
                }
            });
        }
    });
</script>
