@extends('admin.layout.index')
@push('css-head')
@endpush
@section('content')
<!-- Page header -->
<div class="page-header page-header-light">
    <div class="breadcrumb-line breadcrumb-line-light header-elements-md-inline">
        <div class="d-flex">
            <div class="breadcrumb">
                <a href="{{url('/admin')}}" class="breadcrumb-item"><i class="icon-home2 mr-2"></i> Dashboard</a>
                <span class="breadcrumb-item active">Permissions</span>
            </div>
        </div>
        <div class="header-elements d-none">
            <div class="breadcrumb justify-content-center">
                <a href="{{ url('admin/permissions/create') }}" class="breadcrumb-elements-item">
                    <i class="icon-plus3 mr-2"></i>
                    Create new
                </a>
            </div>
        </div>
    </div>
</div>
<!-- /page header -->

<!-- Content area -->
<div class="content">
    <div class="card">
        <table class="table datatable-basic">
            <thead>
                <tr>
                    <th style="width: 5%;">#</th>
                    <th>Name</th>
                    <th>Parent</th>
                    <th>Code</th>
                    <th class="text-center">Actions</th>
                </tr>
            </thead>
            <tbody>
                @foreach($permissions as $key => $row)
                <tr>
                    <td>{{ ++$key }}</td>
                    <td>{{ $row->display_name }}</td>
                    <td>{{ $row->parent != 0?$row->parentInfo->display_name:'Parent' }}</td>
                    <td>{{ $row->name }}</td>
                    <td class="text-center">
                        <div class="list-icons">
                            <div class="dropdown">
                                <a href="#" class="list-icons-item" data-toggle="dropdown">
                                    <i class="icon-menu9"></i>
                                </a>

                                <div class="dropdown-menu dropdown-menu-right">
                                    <a href="{{ url('admin/permissions/view') }}/{{ $row->id }}" class="dropdown-item">
                                        <i class="icon-eye"></i> View
                                    </a>
                                    <a href="{{ url('admin/permissions/edit') }}/{{ $row->id }}" class="dropdown-item">
                                        <i class="icon-pencil7"></i> Edit
                                    </a>
                                    {!! Form::model($permissions, ['method' => 'delete', 'url' => ['admin/permissions/delete', $row->id], 'class' =>'dropdown-item form-delete']) !!}
                                    {!! Form::hidden('id', $row->id) !!}
                                        <i class="icon-trash"></i> Delete
                                    {!! Form::close() !!}
                                </div>
                            </div>
                        </div>
                    </td>
                </tr>
                @endforeach
            </tbody>
        </table>
    </div>
</div>
<!-- /content area -->
@endsection

@push('scripts')
    <script src="{{ asset('/assets/global/js/plugins/notifications/sweet_alert.min.js') }}"></script>
    <script src="{{ asset('/assets/global/js/plugins/tables/datatables/datatables.min.js') }}"></script>
    <script src="{{ asset('/assets/global/js/demo_pages/datatables_basic.js') }}"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            $('[data-toggle="tooltip"]').tooltip();
        });
    </script>
    <script type="text/javascript">
        $('.form-delete').click(function(e){
            e.preventDefault();
            $form = $(this);

            swal({
                title: 'Are you sure?',
                text: "You won't be able to revert this!",
                type: 'warning',
                showCancelButton: true,
                confirmButtonColor: '#3085d6',
                cancelButtonColor: '#d33',
                confirmButtonText: 'Yes, delete it!'
            }).then((result) => {
                if (result.value) {
                    $form.submit();
                }
            });
        });
    </script>
@endpush