<x-app-layout>
    <x-slot name="after_style">
        <link href="/bower_components/admin-lte/plugins/select2/css/select2.min.css" rel="stylesheet">
        <link href="/bower_components/admin-lte/plugins/select2-bootstrap4-theme/select2-bootstrap4.min.css" rel="stylesheet">
    </x-slot>
    <x-slot name="header">
        <div class="row">
            <div class="col-6">
                <h4 class="" title><i class="circular icon fa fa-list"></i> {{ __('Services')  }} </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('services.form')
    </div>


    <x-slot name="after_script">
        <script src="/bower_components/admin-lte/plugins/select2/js/select2.min.js"></script>
        <script src="/bower_components/admin-lte/plugins/bootstrap-switch/js/bootstrap-switch.min.js"></script>

        {{$dataTable->scripts()}}
        <script>
                var app = new Vue({
                    el: '#app',
                    mixins: [ FormMixin,DestroyMixin, FetchMixin],
                    data: {
                        subject_type: 'room-type',
                        action: "{{ route('services.store') }}",
                        table: "service-table",
                        modal: 'Idmodal',
                        ships: [],
                        destination_ports: [],
                        origin_ports: [],
                        room_types: [],
                        cars: [],
                        articles: []
                    },
                    mounted:function(){
                        const vm = this; 
                        $(document).on('draw.dt',function(e){
                            $("input[data-bootstrap-switch]").each(function() {
                                $(this).bootstrapSwitch('state', $(this).prop('checked'));
                                $(this).on('switchChange.bootstrapSwitch', function() {
                                    var id = $(this).data('id');
                                    axios.put("/services/" + id)
                                        .then(res => {
                                            vm.reload();
                                        });
                                });
                            });
                        });
                    },
                    methods: {
                        fetchShips(search, loading){
                            const vm = this;
                            this.fetchOptions("{{route('ships.search')}}",search, loading,function(res){
                                vm.ships = res.data;
                            });
                        },
                        fetchOriginPorts(search, loading){
                            const vm = this;
                            this.fetchOptions("{{route('ports.origin.search')}}",search, loading,function(res){
                                vm.origin_ports = res.data;
                            });
                        },
                        fetchDestinationPorts(search, loading){
                            const vm = this;
                            this.fetchOptions("{{route('ports.destination.search')}}",search, loading,function(res){
                                vm.destination_ports = res.data;
                            });
                        },
                        fetchRoomTypes(search, loading){
                            const vm = this;
                            this.fetchOptions("{{route('room-types.search')}}",search, loading,function(res){
                                vm.room_types = res.data;
                            });
                        },
                        fetchCars(search, loading){
                            const vm = this;
                            this.fetchOptions("{{route('cars.search')}}",search, loading,function(res){
                                vm.cars = res.data;
                            });
                        },
                        fetchArticles(search, loading){
                            const vm = this;
                            this.fetchOptions("{{route('articles.search')}}",search, loading,function(res){
                                vm.articles = res.data;
                            });
                        },
                    }
                })
        </script>
        
    </x-slot>
</x-app-layout>
