@extends('layouts.app-hr')
@section('content')
    <?php Fun::lang()?>
    <div class="top-header">
        <ol class="breadcrumb">
            <li><a href="#">{{__('administrator.Dashboard')}}</a></li>
            <li><a href="#">{{__('administrator.employee')}}</a></li>
            <li><a>{{__('administrator.create')}}</a></li>
        </ol>
    </div>
    <div class="container">
        <div class="top-content">
            <div class="row">
                <div class="col-sm-12 col-xs-12">
                    <div class="title-add">
                        <div class="pull-left">
                            <h3>{{__('administrator.employee')}}</h3>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        {!! Form::open(array('route' => 'hr-employee.store','method'=>'POST','class'=>'jform','enctype'=>'multipart/form-data')) !!}
        <div class="row">
            <div class="col-sm-12">
                <div class="master-form">
                    <div class="title-note">
                        <h3><span class="fa fa-exclamation-triangle"></span> {{__('administrator.employee')}}
                            <i>({{__('administrator.fields_in_red_are_required')}})</i></h3>
                    </div>
                    <div class="form-group col-md-6 col-sm-12 col-xs-12">
                        <div class="form-group ">
                            <strong  for="name">{{__('administrator.code')}}</strong>
                            {!! Form::hidden('code', Globals::increase_employee(), null, array('placeholder' => __('administrator.code'),'class' => 'form-control')) !!}
                            {!! Form::text('code', Globals::increase_employee(), array('placeholder' => __('administrator.code'),'class' => 'form-control', 'disabled')) !!}
                        </div>
                    </div>
                    <div class="form-group col-md-6 col-sm-12 col-xs-12">
                        <div class="form-group">
                            <strong class="required" for="name">{{__('administrator.en_name')}}</strong>
                            {!! Form::text('name', null, array('placeholder' => __('administrator.en_name'),'class' => 'form-control','require')) !!}
                        </div>
                    </div>
                    <div class="form-group col-md-6 col-sm-12 col-xs-12">
                        <div class="form-group">
                            <strong class="required" for="name">{{__('administrator.kh_name')}}</strong>
                            {!! Form::text('name_kh', null, array('placeholder' => __('administrator.kh_name'),'class' => 'form-control', 'autocomplete' => 'off','require')) !!}
                        </div>
                    </div>
                    <div class="form-group col-md-6 col-sm-12 col-xs-12">
                        <div class="form-group">
                            <strong  for="name">{{__('administrator.nationality')}}</strong>
                            {!! Form::text('nationality', null, array('placeholder' => __('administrator.nationality'),'class' => 'form-control')) !!}
                        </div>

                    </div>
                    <div class="form-group col-md-6 col-sm-12 col-xs-12">
                        <div class="form-group">
                            <strong  for="name">{{__('administrator.dob')}}</strong>
                            {!! Form::text('date_of_birth', null, array('placeholder' => __('administrator.dob'),'class' => 'form-control date_picker')) !!}
                        </div>
                    </div>
                    <div class="form-group col-md-6 col-sm-12 col-xs-12">
                        <div class="form-group ">
                            <strong  for="name">{{__('administrator.gender')}}</strong>
                            {!! Form::select('gender',[''=>__('administrator.please_select'),'male'=>__('administrator.male'),'female'=>__('administrator.female')] ,null, array('class' => 'form-control select2')) !!}
                        </div>
                    </div>
                    <div class="form-group col-md-6 col-sm-12 col-xs-12">
                        <div class="form-group">
                            <strong  for="name">{{__('administrator.marital_status')}}</strong>
                            {!! Form::select('marital_status',[''=>__('administrator.please_select'),'single'=>__('administrator.single'),'married'=>__('administrator.married'),'widowed'=>__('administrator.widowed'),'divorced'=>__('administrator.divorced')] ,null, array('class' => 'form-control select2')) !!}
                        </div>
                    </div>
                    <div class="form-group col-md-6 col-sm-12 col-xs-12">
                        <div class="form-group">
                            <strong class="" for="name">{{__('administrator.id_card')}}</strong>
                            {!! Form::text('id_card', null, array('placeholder' => __('administrator.id_card'),'class' => 'form-control')) !!}
                        </div>
                    </div>
                    <div class="form-group col-md-6 col-sm-12 col-xs-12">
                        <div class="form-group">
                            <strong  for="name">{{__('administrator.salary')}}</strong>
                            {!! Form::text('basic_salary', null, array('placeholder' => __('administrator.salary'),'class' => 'form-control number-only', 'autocomplete' => 'off')) !!}
                        </div>
                    </div>
                    <div class="form-group col-md-6 col-sm-12 col-xs-12">
                        <div class="form-group">
                            <strong class="required" for="name">{{__('administrator.joined_date')}}</strong>
                            {!! Form::text('joined_date', null, array('placeholder' => __('administrator.joined_date'),'class' => 'form-control date_picker','required')) !!}
                        </div>
                    </div>
                    <div class="form-group col-md-6 col-sm-12 col-xs-12">
                        <div class="form-group">
                            <strong  for="name">{{__('administrator.email')}}</strong>
                            {!! Form::text('email', null, array('placeholder' => __('administrator.email'),'class' => 'form-control')) !!}
                        </div>
                    </div>
                    <div class="form-group col-md-6 col-sm-12 col-xs-12">
                        <div class="form-group">
                            <strong class="" for="name">{{__('administrator.contact')}}</strong>
                            {!! Form::text('contact', null, array('placeholder' => __('administrator.contact'),'class' => 'form-control')) !!}
                        </div>
                    </div>
                    <div class="form-group col-md-6 col-sm-12 col-xs-12">
                        <strong class="" for="name">{{__('administrator.employment_status')}}</strong>
                        <div class="input-group">
                            {!! Form::select('employment_id',$emp_status ,null, array('placeholder' => __('administrator.please_select'),'class' => 'form-control select2')) !!}
                            <div class="input-group-addon cursor btn_add_status"><a href="#" class=""><i class="fa fa-plus"></i></a> </div>
                        </div>
                    </div>
                    <div class="form-group col-md-6 col-sm-12 col-xs-12">
                        <strong class="required" for="name">{{__('administrator.branch')}}</strong>
                        <div class="input-group">
                            {!! Form::select('branch_id',$branch ,null, array('placeholder' => __('administrator.please_select'),'class' => 'form-control select2', 'required')) !!}
                            <div class="input-group-addon cursor btn_add_branch"><a href="#" class=""><i class="fa fa-plus"></i></a> </div>
                        </div>
                    </div>
                    <div class="form-group col-md-6 col-sm-12 col-xs-12">
                        <strong  for="name">{{__('administrator.department')}}</strong>
                        <div class="input-group">
                            {!! Form::select('department_id',$department ,null, array('placeholder' => __('administrator.please_select'),'class' => 'form-control select2')) !!}
                            <div class="input-group-addon cursor btn_add_department"><a href="#" class=""><i class="fa fa-plus"></i></a> </div>
                        </div>
                    </div>
                    <div class="form-group col-md-6 col-sm-12 col-xs-12">
                        <strong  for="name">{{__('administrator.position')}}</strong>
                        <div class="input-group">
                            {!! Form::select('position_id',$position ,null, array('placeholder' => __('administrator.please_select'),'class' => 'form-control select2')) !!}
                            <div class="input-group-addon cursor btn_add_position"><a href="#" class=""><i class="fa fa-plus"></i></a> </div>
                        </div>
                    </div>
                    <div class="form-group col-md-6 col-sm-12 col-xs-12">
                        <div class="form-group">
                            <strong class="" for="name">{{__('administrator.spouse')}}</strong>
                            {!! Form::text('spouse', null, array('placeholder' => __('administrator.spouse'),'class' => 'form-control number-only','autocomplete'=>'off')) !!}
                        </div>
                    </div>
                    <div class="form-group col-md-6 col-sm-12 col-xs-12">
                        <div class="form-group">
                            <strong class="" for="name">{{__('administrator.child')}}</strong>
                            {!! Form::text('child', null, array('placeholder' => __('administrator.child'),'class' => 'form-control number-only','autocomplete'=>'off')) !!}
                        </div>
                    </div>
                    <div class="form-group col-md-6 col-sm-12 col-xs-12">
                        <div class="form-group">
                            <strong class="" for="name">{{__('administrator.increment')}}</strong>
                            {!! Form::text('increment', null, array('placeholder' => __('administrator.increment'),'class' => 'form-control number-only','autocomplete'=>'off')) !!}
                        </div>
                    </div>
                    <div class="form-group col-md-6 col-sm-12 col-xs-12">
                        <div class="form-group">
                            <strong class="" for="name">{{__('administrator.meal_transport_allowance')}}</strong>
                            {!! Form::text('meal_transport', null, array('placeholder' => __('administrator.meal_transport_allowance'),'class' => 'form-control number-only','autocomplete'=>'off')) !!}
                        </div>
                    </div>
                    <div class="form-group col-md-6 col-sm-12 col-xs-12">
                        <div class="form-group">
                            <strong class="" for="name">{{__('administrator.position_allowance')}}</strong>
                            {!! Form::text('position_allowance', null, array('placeholder' => __('administrator.position_allowance'),'class' => 'form-control number-only','autocomplete'=>'off')) !!}
                        </div>
                    </div>
                    <div class="form-group col-md-6 col-sm-12 col-xs-12">
                        <div class="form-group">
                            <strong class="" for="name">{{__('administrator.other_allowance')}}</strong>
                            {!! Form::text('other_allowance', null, array('placeholder' => __('administrator.other_allowance'),'class' => 'form-control number-only','autocomplete'=>'off')) !!}
                        </div>
                    </div>
                    <div class="form-group col-md-6 col-sm-12 col-xs-12">
                        <div class="form-group">
                            <strong class="" for="name">{{__('administrator.fingerprint_no')}}</strong>
                            {!! Form::text('fingerprint_no', null, array('placeholder' => __('administrator.fingerprint_no'),'class' => 'form-control number-only','autocomplete'=>'off')) !!}
                        </div>
                    </div>
                    <div class="form-group col-md-6 col-sm-12 col-xs-12">
                        <strong class="" for="name">{{__('administrator.time_policy')}}</strong>
                        <div class="input-group">
                            {!! Form::select('time_policy_id', $time_policy, null, array('placeholder' => __('administrator.please_select'),'class' => 'form-control select2','autocomplete'=>'off')) !!}
                            <div class="input-group-addon cursor add_time_policy" ><a href="#" class=""><i class="fa fa-plus"></i></a> </div>
                        </div>
                    </div>
                    <div class="form-group col-sm-12 col-xs-12">
                        <div class="form-group">
                            <strong class="" for="name">{{__('administrator.pob')}}</strong>
                            {!! Form::textarea('place_of_birth', null, array('placeholder' => __('administrator.pob'),'class' => 'form-control no-resize','rows'=>'3')) !!}
                        </div>
                    </div>
                    <div class="form-group col-sm-6 col-xs-12">
                        <div class="form-group">
                            <strong class="" for="name">{{__('administrator.address')}}</strong>
                            {!! Form::textarea('address', null, array('placeholder' => __('administrator.address'),'class' => 'form-control no-resize','rows'=>'3')) !!}
                        </div>
                    </div>

                    <div class="form-group col-sm-6 col-xs-12">
                        <div class="form-group">
                            <strong class="" for="name">{{__('administrator.note')}}</strong>
                            {!! Form::textarea('note', null, array('placeholder' => __('administrator.note'),'class' => 'form-control no-resize','rows'=>'3')) !!}
                        </div>
                    </div>
                    <div class="form-group col-sm-12 col-xs-12">
                        <div class="form-group">
                            <strong class="" for="name">{{__('administrator.photo')}}</strong>
                            <div class="col-sm-12">
                                <input type="file" name="avatar"
                                       onchange="document.getElementById('blah').src = window.URL.createObjectURL(this.files[0])">
                            </div>
                            <div class="col-sm-12">&nbsp;</div>
                            <div class="col-sm-12">
                                <div class="add_img text-left">
                                    <img src="" style="" id="blah" width="30%">
                                </div>
                            </div>
                            <input type="hidden" name="hidden_image_name" value="">
                        </div>
                    </div>
                    {{-- <div class="form-group col-sm-12 col-xs-12">
                        <div class="form-group">
                            <strong class="" for="name">{{__('administrator.educate')}}</strong>
                            @include('hr.employee.script-education')
                        </div>
                    </div>


                    <div class="form-group col-sm-12 col-xs-12">
                        <div class="form-group">
                            <strong class="" for="name">{{__('administrator.work_experience')}}</strong>
                            @include('hr.employee.emp-work-experience-script')
                        </div>
                    </div>
                    <div class="form-group col-sm-12 col-xs-12">
                        <div class="form-group">
                            <strong class="" for="name">{{__('administrator.language')}}</strong>
                            @include('hr.employee.emp-language-script')
                        </div>
                    </div>
                    <div class="form-group col-sm-12 col-xs-12">
                        <div class="form-group">
                            <strong class="" for="name">{{__('administrator.emergency_contact')}}</strong>
                            @include('hr.employee.script-emergency')
                        </div>
                    </div>
                    <div class="form-group col-sm-12 col-xs-12">
                        <div class="form-group">
                            <strong class="" for="name">{{__('administrator.family(only)')}}</strong>
                            @include('hr.employee.emp-family-script')
                        </div>
                    </div>
                    <div class="form-group col-sm-12 col-xs-12">
                        <div class="form-group">
                            <strong class="" for="name">{{__('administrator.family')}}</strong>
                            @include('hr.employee.emp-family-full-script')
                        </div>
                    </div> --}}


                    <div class="form-group col-sm-12 col-xs-12">
                        <div class="form-group">
                            <strong class="" for="name">{{__('administrator.document')}}</strong>
                            <div id="add_attachment">
                                <div class="form-group col-sm-5 col-xs-12">
                                    <input type="text" name="file_title[]" class="form-control file_name_show"
                                           placeholder="File Name">
                                </div>
                                <div class="form-group col-sm-7 col-xs-12">
                                    <input type="file" name="att_file[]" class="">
                                </div>
                                <div class="form-group col-sm-12 col-xs-12">
                                <textarea name="file_note[]" id="" placeholder="Description" rows="2"
                                          class="form-control input-lg no-resize"></textarea>
                                </div>
                                <div class="form-group col-sm-11 col-xs-11"></div>
                            </div>
                            <div class="col-sm-offset-11 form-group col-sm-1 col-xs-12">
                                <a class="pull-right btn  btn-hover btn-primary" id="btn_attachment">
                                    <i class="fa fa-plus"></i>
                                </a>
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-12 col-xs-12">
                        <div class="form-group footer-save">
                            <button type="submit" class=" button_primary pull-right"><span
                                        class="fa fa-save"></span> {{__('administrator.save')}}</button>
                            <button type="button" onClick="history.go(-1)"
                                    class=" button_warning pull-right">
                                <span class=" fa fa-arrow-circle-left"></span> {{__('administrator.back')}}</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        {!! Form::close() !!}
    </div>
@endsection
@section('js')
    <script type="text/javascript">
        var intId = 0;
        $("#btn_attachment").click(function () {

            var lastField = $("#add_attachment div:last");
            intId++;
            var fieldWrapper = $("<div class=\"fieldwrapper\" id=\"field" + intId + "\"/>");
            fieldWrapper.data("idx", intId);
            var fName = $('' +
                '                    <div class="form-group col-sm-5 col-xs-12">' +
                '                       <input type="text" name="file_title[]" class="form-control input-lg file_name_show" placeholder="File Name">' +
                '                    </div>' +
                '                    <div class="form-group col-sm-7 col-xs-12">' +
                '                        <input type="file" name="att_file[]" required class="">' +
                '                    </div>' +
                '                    <div class="form-group col-sm-12 col-xs-12">' +
                '                        <textarea name="file_note[]" id="" placeholder="Description" rows="2" class="form-control input-lg no-resize"></textarea>' +
                '                    </div><div class="form-group col-sm-11 col-xs-11"></div>' +
                '');
            var removeButton = $("<div class=\"form-group col-sm-1 col-xs-1\"><a  class=\"remove btn btn-hover btn-danger pull-right\"><span class=\"fa fa-trash\"></span></a></div>");
            removeButton.click(function () {
                $(this).parent().remove();
            });
            fieldWrapper.append(fName);
            fieldWrapper.append(removeButton);
            $("#add_attachment").append(fieldWrapper);
        });

        $(document).on('click', '.btn_add_status', function () {
            $.confirm({
                title          : ' {{__('administrator.add')}}' + ' {{__('administrator.employment_status')}}',
                content        : `
                                <div class="form-group">
                                    <label>{{__('administrator.name')}}</label>
                                    <input type="text" name="name" class="form-control border-red" required placeholder="1 ខែ, 3 ខែ, 6ខែ ..." maxlength="50" autocomplete="off">
                                </div>
                                <div class="form-group">
                                    <label>{{__('administrator.note')}}</label>
                                    <textarea name="note" rows="5" maxlength="100" class="no-resize form-control" placeholder="{{__('administrator.note')}}" autocomplete="off"></textarea>
                                </div>`
                ,
                theme          : 'modern',
                columnClass    : 'medium',
                type           : 'blue',
                typeAnimated   : true,
                closeAnimation : 'zoom',
                buttons: {
                    cancel: {
                        text     : '{{__('administrator.cancel')}}',
                        btnClass : 'btn-red close_form',
                        keys     : ['esc'],
                        action   : function () {

                        }
                    },
                    submit: {
                        text: '{{__('administrator.submit')}}',
                        btnClass: 'btn-blue',
                        action: function () {
                            let this_  = this;
                            let name   = this_.$content.find('input[name=name]').val();
                            let note   = this_.$content.find('textarea[name=note]').val();

                            this_.buttons.submit.disable();

                            $.ajax({
                                url      : '{{ route("hr-employment-status.store") }}',
                                dataType : 'json',
                                method   : 'post',
                                data: {
                                    "_token"    : "{{ csrf_token() }}",
                                    name        : name,
                                    note        : note,
                                },
                            }).done(function (response) {
                                if (response.status === 200) {
                                    let option = '';
                                    $.each(response.data, function (k, v) {
                                        option += `<option value="${v.id}" ${k === 0 ? 'selected' : ''}>${v.name}</option>`;
                                    });
                                    $('select[name="employment_id"]').html(option).trigger('change');
                                    $(document).find('.close_form').trigger('click');
                                    showSuccessToast(response.message);
                                }
                            }).fail(function (xhr) {
                                alertErrorFormController(xhr);
                                this_.buttons.submit.enable();

                            });
                            return false;
                        }
                    }
                }
            });
        });

        $(document).on('click', '.btn_add_branch', function () {
            $.confirm({
                title          : ' {{__('administrator.add')}}' + ' {{__('administrator.branch')}}',
                content        : `
                                <div class="form-group col-sm-12 col-xs-12">
                                    <div class="col-sm-4 col-xs-12 ">
                                        <label class="required">{{__('administrator.name')}} </label>
                                    </div>
                                    <div class="col-sm-8">
                                        {!! Form::text('name', null, array('placeholder' => __('administrator.name'),'class' => 'form-control')) !!}
                                    </div>
                                </div>
                                <div class="form-group col-sm-12 col-xs-12">
                                    <div class="col-sm-4 col-xs-12 ">
                                        <label class="required">{{__('administrator.contact')}}</label>
                                    </div>
                                    <div class="col-sm-8 col-xs-12">
                                        {!! Form::text('phone', null, array('placeholder' => __('administrator.contact'),'class' => 'form-control')) !!}
                                    </div>
                                </div>`
                ,
                theme          : 'modern',
                columnClass    : 'medium',
                type           : 'blue',
                typeAnimated   : true,
                closeAnimation : 'zoom',
                buttons: {
                    cancel: {
                        text     : '{{__('administrator.cancel')}}',
                        btnClass : 'btn-red close_form',
                        keys     : ['esc'],
                        action   : function () {

                        }
                    },
                    submit: {
                        text: '{{__('administrator.submit')}}',
                        btnClass: 'btn-blue',
                        action: function () {
                            let this_  = this;
                            let name   = this_.$content.find('input[name=name]').val();
                            let phone  = this_.$content.find('input[name=phone]').val();

                            this_.buttons.submit.disable();

                            $.ajax({
                                url      : '{{ route("insert.branch") }}',
                                dataType : 'json',
                                method   : 'post',
                                data: {
                                    "_token"    : "{{ csrf_token() }}",
                                    name        : name,
                                    phone       : phone,
                                },
                            }).done(function (response) {
                                if (response.status === 200) {
                                    let option = '';
                                    $.each(response.data, function (k, v) {
                                        option += `<option value="${v.id}" ${k === 0 ? 'selected' : ''}>${v.name}</option>`;
                                    });
                                    $('select[name="branch_id"]').html(option).trigger('change');
                                    $(document).find('.close_form').trigger('click');
                                    showSuccessToast(response.message);
                                }
                            }).fail(function (xhr) {
                                alertErrorFormController(xhr);
                                this_.buttons.submit.enable();

                            });
                            return false;
                        }
                    }
                }
            });
        });

        $(document).on('click', '.btn_add_department', function () {
            $.confirm({
                title          : ' {{__('administrator.add')}}' + ' {{__('administrator.department')}}',
                content        : `
                                <div class="form-group col-sm-12 col-xs-12">
                                    <div class="col-sm-4 col-xs-12 ">
                                        <label class="required">{{__('administrator.name_kh')}} </label>
                                    </div>
                                    <div class="col-sm-8">
                                        {!! Form::text('name_kh', null, array('placeholder' => __('administrator.name_kh'),'class' => 'form-control')) !!}
                                    </div>
                                </div>
                                <div class="form-group col-sm-12 col-xs-12">
                                    <div class="col-sm-4 col-xs-12 ">
                                        <label class="required">{{__('administrator.name_en')}}</label>
                                    </div>
                                    <div class="col-sm-8 col-xs-12">
                                        {!! Form::text('name_en', null, array('placeholder' => __('administrator.name_kh'),'class' => 'form-control')) !!}
                                    </div>
                                </div>`
                ,
                theme          : 'modern',
                columnClass    : 'medium',
                type           : 'blue',
                typeAnimated   : true,
                closeAnimation : 'zoom',
                buttons: {
                    cancel: {
                        text     : '{{__('administrator.cancel')}}',
                        btnClass : 'btn-red close_form',
                        keys     : ['esc'],
                        action   : function () {

                        }
                    },
                    submit: {
                        text: '{{__('administrator.submit')}}',
                        btnClass: 'btn-blue',
                        action: function () {
                            let this_  = this;
                            let name_kh  = this_.$content.find('input[name=name_kh]').val();
                            let name_en  = this_.$content.find('input[name=name_en]').val();

                            this_.buttons.submit.disable();

                            $.ajax({
                                url      : '{{ route("hr-department.store") }}',
                                dataType : 'json',
                                method   : 'post',
                                data: {
                                    "_token"    : "{{ csrf_token() }}",
                                    name_kh     : name_kh,
                                    name_en     : name_en,
                                },
                            }).done(function (response) {
                                if (response.status === 200) {
                                    let option = '';
                                    $.each(response.data, function (k, v) {
                                        option += `<option value="${v.id}" ${k === 0 ? 'selected' : ''}>${v.khmer_name}</option>`;
                                    });
                                    $('select[name="department_id"]').html(option).trigger('change');
                                    $(document).find('.close_form').trigger('click');
                                    showSuccessToast(response.message);
                                }
                            }).fail(function (xhr) {
                                alertErrorFormController(xhr);
                                this_.buttons.submit.enable();

                            });
                            return false;
                        }
                    }
                }
            });
        });

        $(document).on('click', '.btn_add_position', function () {
            $.confirm({
                title          : ' {{__('administrator.add')}}' + ' {{__('administrator.position')}}',
                content        : `
                                <div class="form-group col-sm-12 col-xs-12">
                                    <div class="col-sm-4 col-xs-12 ">
                                        <label class="required">{{__('administrator.name_kh')}} </label>
                                    </div>
                                    <div class="col-sm-8">
                                        {!! Form::text('name_kh', null, array('placeholder' => __('administrator.name_kh'),'class' => 'form-control')) !!}
                                    </div>
                                </div>
                                <div class="form-group col-sm-12 col-xs-12">
                                    <div class="col-sm-4 col-xs-12 ">
                                        <label class="required">{{__('administrator.name_en')}}</label>
                                    </div>
                                    <div class="col-sm-8 col-xs-12">
                                        {!! Form::text('name_en', null, array('placeholder' => __('administrator.name_en'),'class' => 'form-control')) !!}
                                    </div>
                                </div>`
                ,
                theme          : 'modern',
                columnClass    : 'medium',
                type           : 'blue',
                typeAnimated   : true,
                closeAnimation : 'zoom',
                buttons: {
                    cancel: {
                        text     : '{{__('administrator.cancel')}}',
                        btnClass : 'btn-red close_form',
                        keys     : ['esc'],
                        action   : function () {

                        }
                    },
                    submit: {
                        text: '{{__('administrator.submit')}}',
                        btnClass: 'btn-blue',
                        action: function () {
                            let this_   = this;
                            let name_kh = this_.$content.find('input[name=name_kh]').val();
                            let name_en = this_.$content.find('input[name=name_en]').val();

                            this_.buttons.submit.disable();

                            $.ajax({
                                url      : '{{ route("hr-position.store") }}',
                                dataType : 'json',
                                method   : 'post',
                                data: {
                                    "_token"    : "{{ csrf_token() }}",
                                    name_kh     : name_kh,
                                    name_en     : name_en,
                                },
                            }).done(function (response) {
                                if (response.status === 200) {
                                    let option = '';
                                    $.each(response.data, function (k, v) {
                                        option += `<option value="${v.id}" ${k === 0 ? 'selected' : ''}>${v.khmer_name}</option>`;
                                    });
                                    $('select[name="position_id"]').html(option).trigger('change');
                                    $(document).find('.close_form').trigger('click');
                                    showSuccessToast(response.message);
                                }
                            }).fail(function (xhr) {
                                alertErrorFormController(xhr);
                                this_.buttons.submit.enable();

                            });
                            return false;
                        }
                    }
                }
            });
        });

        $(document).on('click', '.add_time_policy', function () {
            $.confirm({
                title          : ' {{__('administrator.add')}}' + ' {{__('administrator.time_policy')}}',
                content        : `
                                <div class="form-group">
                                    <label>{{__('administrator.name')}}</label>
                                    <input type="text" name="name" class="form-control border-red" required placeholder="វេនទី 1, 2, 3..." maxlength="50" autocomplete="off">
                                </div>
                                <div class="form-group">
                                    <label>{{__('administrator.note')}}</label>
                                    <textarea name="note" rows="5" maxlength="100" class="no-resize form-control" placeholder="{{__('administrator.note')}}" autocomplete="off"></textarea>
                                </div>`
                ,
                theme          : 'modern',
                columnClass    : 'medium',
                type           : 'blue',
                typeAnimated   : true,
                closeAnimation : 'zoom',
                buttons: {
                    cancel: {
                        text     : '{{__('administrator.cancel')}}',
                        btnClass : 'btn-red close_form',
                        keys     : ['esc'],
                        action   : function () {

                        }
                    },
                    submit: {
                        text: '{{__('administrator.submit')}}',
                        btnClass: 'btn-blue',
                        action: function () {
                            let this_  = this;
                            let name   = this_.$content.find('input[name=name]').val();
                            let note   = this_.$content.find('textarea[name=note]').val();

                            this_.buttons.submit.disable();

                            $.ajax({
                                url      : '{{ route("hr-time-policy.store") }}',
                                dataType : 'json',
                                method   : 'post',
                                data: {
                                    "_token"    : "{{ csrf_token() }}",
                                    name        : name,
                                    note        : note,
                                },
                            }).done(function (response) {
                                if (response.status === 200) {
                                    let option = '';
                                    $.each(response.data, function (k, v) {
                                        option += `<option value="${v.id}" ${k === 0 ? 'selected' : ''}>${v.name}</option>`;
                                    });
                                    $('select[name="time_policy_id"]').html(option).trigger('change');
                                    $(document).find('.close_form').trigger('click');
                                    showSuccessToast(response.message);
                                }
                            }).fail(function (xhr) {
                                alertErrorFormController(xhr);
                                this_.buttons.submit.enable();

                            });
                            return false;
                        }
                    }
                }
            });
        });

    </script>
@endsection


