@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="{{route('hr-employee.index')}}">{{__('administrator.employee')}}</a></li>
        </ol>
    </div>
    <div class="page">
        <div class="top-content">
            <div class="row">
                <div class="col-sm-6 col-xs-12">
                    <div class="title-add">
                        <div class="pull-left">
                            <h3>{{__('administrator.employee')}} </h3>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6 col-xs-12">
                    <div class="title-add">
                        <div class="pull-right">
                            @if(Gate::check('Employee Create'))
                                <a href="{{route('hr-employee.create')}}"
                                   class="button_primary">{{__('administrator.add_new')}}</a>
                            @endif
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="box-body">
            <table id="datatable_products" class="table table-striped">
                <thead>
                    <tr>
                        <th>#</th>
                        <th>{{ __('administrator.photo')}}</th>
                        <th>{{ __('administrator.khmer_name')}}</th>
                        <th>{{ __('administrator.english_name')}}</th>
                        <th>{{ __('administrator.code')}}</th>
                        <th>{{ __('administrator.contact')}}</th>
                        <th>{{ __('administrator.joined_date')}}</th>
                        <th>{{ __('administrator.sex')}}</th>
                        <th>{{ __('administrator.branch')}}</th>
                        <th>{{ __('administrator.department')}}</th>
                        <th>{{ __('administrator.role')}}</th>
                        <th>{{ __('administrator.position')}}</th>
                        <th>{{ __('administrator.status')}}</th>
                        <th style="width: 200px;">{{ __('administrator.action')}}</th>
                    </tr>
                </thead>
                <tbody>

                </tbody>
            </table>
        </div>
    </div>
    <div class="modal fade bs-modal-lg" id="myModal" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog modal-dm">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
                    <h3 class="modal-title">{{ __('administrator.are_you_sure')}}</h3>
                </div>
                <br/>
                <form role="form" method="POST" id="form_update">
                    {{csrf_field()}}
                    <div class="row">
                        <div class="col-md-12">
                            <div class="col-md-12">
                                <input type="hidden" name="id" id="id">
                            </div>
                            <div class="form-group col-sm-12 col-xs-12">
                                <label class="required">{{ __('administrator.status')}}</label>
                                <select name="status" class="form-control input-lg select2" required>
                                    <option value="">{{ __('administrator.please_select')}}</option>
                                    <option value="1">{{ __('administrator.activate')}}
                                    </option>
                                    <option value="0">{{ __('administrator.deactivate')}}
                                    </option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" data-dismiss="modal" class="btn btn-danger"><i
                                    class="fa fa-close"></i> {{ __('administrator.close')}}
                        </button>
                        <button type="submit" class="btn btn-success" data-toggle="modal"><i
                                    class="fa fa-save"></i> {{ __('administrator.save')}}
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>
@endsection
@section('js')
    <script type="text/javascript">
        let table = $('#datatable_products');
        $(document).ready(function () {
            getTable();
            $(document).on('click', '.viewPopLink', function () {
                var id = $(this).data('id');
                $('#id').val(id);
                var url = "{{route('hr.employee-change-status')}}";
                $('#form_update').attr('action', url);
                $('#myModal').modal('show');
            });
            table.on('click', '.account-setting', function () {
                getHtmlForm($(this).data('href'),'{{__('administrator.account_setting')}}','500px');
            });


        });
        function getTable() {
            table.DataTable().destroy();
            table.DataTable({
                ordering: false,
                serverSide: true,
                ajax: "{{ route('datatable.hr-get-employee') }}",
                lengthMenu: [20, 30, 50, 100, 200, 500, 1000],
                columns:
                    [
                        {
                            data: 'DT_RowIndex',
                            orderable: false,
                            searchable: false
                        },
                        {
                            "data": "photo",
                            "render": function (data, type, row) {
                                return '<center><img src="' + data + '" border="0" width="35" height="35" class="img-circle" align="center" loading="lazy" /></center>';
                            }
                        },
                        {
                            data: 'name_kh'
                        },
                        {
                            data: 'name'
                        },
                        {
                            data: 'code'
                        },
                        {
                            data: 'phone'
                        },
                        {
                            data: 'joined_date'
                        },
                        {
                            data: 'gender'
                        },
                        {
                            data: 'branch_id'
                        },
                        {
                            data: 'department_id'
                        },
                        {
                            data: 'role_id',
                            searchable: false
                        },
                        {
                            data: 'position_id',
                            searchable: false
                        },
                        {
                            data: 'status'
                        },
                        {
                            data: 'action',
                            searchable: false
                        },
                    ],

                "initComplete": function (settings, json) {

                }

            });
            $.fn.dataTable.ext.errMode = 'throw';
        }
    </script>
@endsection
