@extends('back-end.master.app')
@section('title', 'Roles')
@section('body')
    <main class="app-content">
        <div class="row">
            <div class="col-md-12">
                <div class="card">

                    <div class="card-body">
                        <div class="row">
                            <div class="col-md-12">
                                <div class="row">
                                    <div class="col-md-9">
                                        <h3 class="">Roles</h3>
                                    </div>
                                    <div class="col-md-3">
                                        <div class="btn-group" style="float: right;" role="group">
                                            <a href="{{ route('roles.create') }}"
                                                class="btn btn-primary btn-primary btn-sm btn-rounded">
                                                <i class="fa fa-plus"></i>New
                                            </a>
                                        </div>
                                    </div>
                                </div>
                                <div class="row mt-4">
                                    <table class="table">
                                        <thead>
                                            <tr>
                                                <th>Name</th>
                                                <th>Action</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            @foreach ($roles as $row)
                                                <tr>
                                                    <td>{{ $row->name }}</td>
                                                    <td>
                                                        <a href="{{ route('roles.edit', $row->id) }}"
                                                            class="btn btn-primary btn-sm">Edit</a>

                                                        <button class="btn btn-danger btn-sm btn-delete"
                                                            data-id='{{ $row->id }}' onclick=""> Delete
                                                        </button>
                                                    </td>
                                                </tr>
                                            @endforeach
                                        </tbody>
                                    </table>


                                    <form id="delete-form" action="" method="POST" style="display: none;">
                                        {{ csrf_field() }}
                                        {{ method_field('DELETE') }}
                                    </form>
                                </div>
                            </div>
                        </div>

                    </div>

                </div>
            </div>
        </div>
    </main>


@endsection


@section('pageJs')
    <script>
        $(".app-menu").removeClass("active");
        $("#nav_account").addClass("active");
        $("#nav_accounti").addClass("is-expanded");
        $("#nab_role").addClass("active");
    </script>
    <script type="text/javascript">
        $(document).on("click", ".btn-delete", function() {
            var id = $(this).attr("data-id");
            swal({
                title: "Are you sure want to delete?",
                text: "...",
                type: "warning",
                showCancelButton: true,
                confirmButtonText: "Yes!",
                cancelButtonText: "No!",
                closeOnConfirm: false,
                closeOnCancel: false
            }, function(isConfirm) {
                if (isConfirm) {
                    $('#delete-form').attr('action', "/roles/delete/" + id);
                    $("#delete-form").submit();
                } else {
                    swal("Cancelled", "Record not deleted", "error");
                    return false;
                }
            });
        });
    </script>
@endsection
