<script>
    @if(Session::has('notify'))
        @if(!Sartoric\ModularCms\Models\Setting::appsetting('notifandroid'))
        @foreach(Session::get('notify') as $notification)
        title = '';

    @if(array_key_exists('title', $notification)?$notification['title']:false)

        @if($notification['type'] == 'error')
        title  = '<div class="title text-danger"><strong>{{  ($notification['module']) }}'+' '+'{{ __('Errore') }} </strong></div>';
    @endif

        @if($notification['type'] == 'success')
        title  = '<div class="title"><strong>{{  ($notification['module']) }}'+' '+'{{ __('Completato') }} </strong></div>';
    @endif

        @if($notification['type'] == 'info')
        title  = '<div class="title"><strong>{{  ($notification['module']) }}'+' '+'{{ __('Info') }} </strong></div>';
    @endif

    @endif

    var dialog = bootbox.alert({
        message:title + '<div class="message">{!! $notification['message'] !!}</div>',
        closeButton:false,
        size:'small',
        className:'bootbox-md',
        buttons: {
            ok: {
                label: '{{ __('Chiudi') }}',
                className: 'btn btn-no-border btn-outline btn-flat {{ Sartoric\ModularCms\Models\Setting::appsetting('app-main-color') }}'
            }
        }
    });

    @if($notification['type'] != 'error')
    setTimeout(function(){ dialog.modal('hide')}, 3000);
    @endif
    @endforeach
    @else
    // Android MD style
    @foreach(Session::get('notify') as $notification)
    $('body').append("" +
        "<div class='md-error col-md-12'  style='display:none'><div class='md-error-message col-xs-9 col-md-6 text-left'>{{ $notification['message'] }}</div><div class='col-xs-2 col-xs-offset-1 col-md-offset-4 md-error-confirm text-right' style='cursor:pointer;' onclick='$(this).parent(\".md-error\").stop().fadeOut(400)'>{{ __('CHIUDI') }}</div></div>");
    @if($notification['type'] != 'error')
    $('.md-error').stop().fadeIn(400).delay(3000).fadeOut(400); //fade out after 3 seconds
    @else
    $('.md-error').stop().fadeIn(400);
    @endif
    @endforeach
    @endif

    @endif

    function bbConfirmOnSubmit(event)
    {
        var button = $(event.target).find('button[type=submit]');
        var message = button.attr('data-submit-confirm-text');
        var btntext = button.attr('data-submit-confirm-button');

        event.preventDefault();

        bootbox.confirm({
            message:'<div class="message">' + message + '</div>',
            closeButton:false,
            size:'small',
            className:'bootbox-md',
            buttons: {
                confirm: {
                    label: btntext,
                    className: 'btn-no-border btn-outline btn-flat {{ Sartoric\ModularCms\Models\Setting::appsetting('app-main-color') }}'
                },
                cancel: {
                    label: '{{ __("Annulla") }}',
                    className: 'btn-no-border btn-outline btn-flat {{ Sartoric\ModularCms\Models\Setting::appsetting('app-main-color') }}'
                }
            },
            callback: function (result) {
                if(result){
                    event.target.submit();
                }
            }
        });
    }

</script>
