<x-app-layout>
    <x-slot name="header">
        <div class="row">
            <div class="col-6">
                <h4 class="" title><i class="circular icon fa fa-list"></i> {{ __('Roles')  }} </h4>
            </div>
            <div class="col-6">
                <a v-on:click="create()" class="btn btn-primary btn-sm float-right" href="#"><i class="fas fa-plus-circle"></i> {{ __('Create') }}</a>
            </div>
        </div>
    </x-slot>
    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-body">
                    {{$dataTable->table()}}
                </div>
            </div>
        </div>  
            @include('roles.form')
    </div>


    <x-slot name="after_script">
        <script>

        </script>
        {{$dataTable->scripts()}}
        <script>
                var app = new Vue({
                    el: '#app',  
                    mixins: [ FormMixin, DestroyMixin],
                    data: {
                        action_update: '',
                        action: "{{ route('roles.store') }}",
                        table: "roles-table",
                        modal: 'Idmodal',
                        permissions: [],
                        fields: {
                            permissions: []
                        }
                    },
                    mounted: function(){
                            this.loadPermissions();
                    },
                    methods: {
                        create(){
                            this.action_update = '';

                            this.fields = {
                                permissions: []
                            };
                            $("#"+this.modal).modal('show');
                        },
                        edit(href){
                            
                            this.action_update = href;

                            axios.get(href)
                            .then(res=>{
                                this.fields = {name: res.data.name,permissions: res.data.permissions.map(item=>item.id)};
                            });
                        },
                        loadPermissions(){
                            axios.get('api/search/permissions')
                            .then(resp=>{
                                this.permissions=resp.data
                            });
                        }
                    }
                })
        </script>
        
    </x-slot>
</x-app-layout>
