<script>
$('.select2').select2();    
</script>

{{-- Set User Login Token to use in the APIs --}}
@if (Session::has('token'))
    @php
        $token = Session::get('token');
        $app_url = Session::get('app_url');
        $applocale = Str::lower(Session::get('applocale'));
    @endphp
    <script>
        $(function(){
            "use strict";
            localStorage.setItem('token', "{{ $token }}");
            localStorage.setItem('applocale', "{{$applocale}}");
            localStorage.setItem('app_url', "{{$app_url}}");
        });
    </script>
@endif

{{-- Enable Anchor links in the bootstrap tabs for urls sent by the controllers --}}
<script>
    // Javascript to enable link to tab
    var hash = location.hash.replace(/^#/, '');  // ^ means starting, meaning only match the first hash
    if (hash) {
        $('.nav-tabs a[href="#' + hash + '"]').tab('show');
    } 

    // Change hash for page-reload
    $('.nav-tabs a').on('shown.bs.tab', function (e) {
        window.location.hash = e.target.hash;
    })
</script>

@if(Session::has('message'))
<script>
    
    $(function(){
        "use strict";
        toastr.options = {
            "closeButton": false,
            "debug": false,
            "newestOnTop": true,
            "progressBar": true,
            "positionClass": "toast-top-right",
            "preventDuplicates": false,
            "onclick": null,
            "showDuration": "300",
            "hideDuration": "300",
            "timeOut": "2000",
        }
        
        var type = "{{ Session::get('alert-type', 'info') }}";
        switch(type){
            case 'info':
                toastr.info("{{ Session::get('message') }}");
                break;

            case 'warning':
                toastr.warning("{{ Session::get('message') }}");
                break;

            case 'success':
                toastr.success("{{ Session::get('message') }}");
                break;

            case 'error':
                toastr.error("{{ Session::get('message') }}");
                break;
        }
    })
</script>
@endif



