<x-app-layout>
    <x-slot name="header">
           @if (session('status'))
            <div class="alert alert-danger" role="alert">
                {{ session('status') }}
            </div>
           @endif
        <div class="row">
            <div class="col-6">
                <h4 class="" title><i class="circular icon fa fa-list"></i> {{ __('Transfers')  }} </h4>
            </div>
         @can('add_transfer')
            <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>
            @endcan
        </div>
    </x-slot>
    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-body">
                    <div class="col-sm-6">
                        
                      <a href="{{ route('installments_export') }}" class="btn btn-primary float-right"> {{ __('Export Excel') }}</a>
                    </div>
                    {{$dataTable->table()}}
                </div>
            </div>
        </div>  
            @include('transfers.form')
    </div>


    <x-slot name="after_script">
        {{$dataTable->scripts()}}
        <script>
                var app = new Vue({
                    el: '#app',
                    mixins: [ FormMixin,DestroyMixin,FetchMixin],
                    data: {
                        action: "{{ route('transfers.store') }}",
                        table: "transfer-table",
                        modal: 'Idmodal',
                        accounts: [],
                        action_update: ''
                    },
                    methods: {
                        create(){
                            this.fields = {...this.fields,status:'pending'}; //Clear input fields.
                            this.action_update = '';
                            if(this.modal) $("#"+this.modal).modal('show');
                        }, 
                        fetchAccounts(search, loading){
                            const vm = this;
                            this.fetchOptions("{{route('accounts.search')}}",search, loading,function(res){
                                vm.accounts = res.data;
                            });
                        },
                        owner(option){
                            if(option.office)return option.office;
                            if(option.user)return option.user;
                            return null;
                        }
                    }
                })
        </script>
        
    </x-slot>
</x-app-layout>
