@extends('layouts.admin')

@section('title')Administratori @endsection
@section('header')Administratori @endsection
@section('header_desc') @endsection
@section('breadcumbs') @endsection

@section('content')
    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
                <div class="box">
                    <div class="box-header">
                        <h3 class="box-title">Pregled administratora</h3>
                    </div>
                    @if (session('result'))
                        <div class="alert alert-success alert-dismissible">
                            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                            <i class="icon fa fa-check"></i> <strong>Info: </strong> &nbsp;  &nbsp;
                            {{ session('result') }}
                        </div>
                    @endif
                    @if (session('error'))
                        <div class="alert alert-danger alert-dismissible">
                            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                            <i class="icon fa fa-exclamation-triangle"></i> <strong>Info: </strong> &nbsp;  &nbsp;
                            {{ session('error') }}
                        </div>
                    @endif
                <!-- /.box-header -->
                    @can('create', $admin)
                        <div class="text-right">
                            <a class="btn btn-outline-success" href="{{ route('admin.admin.create') }}"><i class="ionicons ion-ios-plus-outline"> Dodajte novog administratora</i></a>
                            <hr>
                        </div>
                    @endcan
                    <div class="box-body">
                        <table id="data-table" class="table table-hover">
                            <thead>
                            <tr>
                                <th>ID</th>
                                <th>Ime i prezime</th>
                                <th>Sektor</th>
                                <th>Telefon</th>
                                <th>Super admin</th>
                                <th align="right">Status</th>
                                <th style="text-align: right;">&nbsp;</th>
                                <th style="text-align: right;">&nbsp;</th>
                            </tr>
                            </thead>
                            <tbody>

                            @foreach($admins as $admin)
                                <tr>
                                    <td>{{$admin->id}}</td>
                                    <td>{{ucwords($admin->full_name)}}</td>
                                    <td> {{$admin->department->dep_name}}</td>
                                    <td> {{$admin->phone}}</td>
                                    <td> {{$admin->is_super_admin ? 'Da' : 'Ne'}} </td>
                                    <td> {{$admin->status ? 'Aktivan' : 'Neaktivan'}}</td>
                                    <td style="text-align: right;">
                                        @can('update', $admin)
                                            <a class="btn btn-outline-success btn-xsm" href="{{ route('admin.admin.edit', ['admin' => $admin->id ]) }}">
                                                <i class="fa fa-pencil-square-o"></i> Izmeni
                                            </a>
                                        @else
                                            &nbsp;
                                        @endcan
                                    </td>
                                    <td style="text-align: right;">
                                        @can('delete', $admin)
                                            {{ Form::open(array('route' => array('admin.admin.destroy', $admin->id), 'method' => 'DELETE', 'class'=>'form-inline', 'onsubmit' => 'return submitDeleteForm(this);')) }}
                                            {{ Form::hidden('admin', $admin->id) }}
                                            <button type="submit" class="btn btn-outline-danger btn-xsm delete"><i class="fa fa-times-circle-o"></i> Obriši</button>
                                            {{ Form::close() }}
                                        @else
                                            &nbsp;
                                        @endcan
                                    </td>
                                </tr>
                            @endforeach
                            </tbody>
                        </table>
                    </div>
                    <!-- /.box-body -->
                </div>
                <!-- /.box -->
            </div>
            <!-- /.col -->
        </div>
        <!-- /.row -->

    </section>
@endsection


@push('css')
<link rel="stylesheet" href="{{asset('assets/components/datatables.net-bs/css/dataTables.bootstrap.min.css')}}">
@endpush

@push('primscripts')
<script src="{{asset('assets/components/datatables.net/js/jquery.dataTables.min.js')}}"></script>
<script src="{{asset('assets/components/datatables.net-bs/js/dataTables.bootstrap.js')}}"></script>
@endpush
@push('scripts')
<script>
    $(function () {
        $('#data-table').DataTable({
            'paging'      : true,
            'lengthChange': false,
            'searching'   : true,
            'ordering'    : true,
            'info'        : true,
            'autoWidth'   : false,
            "bStateSave"  : true,
            "language": {
                "sProcessing":   "{{__('adminforms.data_tables.sProcessing')}}",
                "sLengthMenu":   "{{__('adminforms.data_tables.sLengthMenu')}}",
                "sZeroRecords":  "{{__('adminforms.data_tables.sZeroRecords')}}",
                "sInfo":         "{{__('adminforms.data_tables.sInfo')}}",
                "sInfoEmpty":    "{{__('adminforms.data_tables.sInfoEmpty')}}",
                "sInfoFiltered": "{{__('adminforms.data_tables.sInfoFiltered')}}",
                "sInfoPostFix":  "{{__('adminforms.data_tables.sInfoPostFix')}}",
                "sSearch":       "{{__('adminforms.data_tables.sSearch')}}",
                "sUrl":          "{{__('adminforms.data_tables.sUrl')}}",
                "oPaginate": {
                    "sFirst":    "{{__('adminforms.data_tables.sFirst')}}",
                    "sPrevious": "{{__('adminforms.data_tables.sPrevious')}}",
                    "sNext":     "{{__('adminforms.data_tables.sNext')}}",
                    "sLast":     "{{__('adminforms.data_tables.sLast')}}",
                }
            }
        })
    })
</script>
@endpush