$(document).ready(function () {
    $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });
    $('.form-global-handle').submit(function (event) {
        event.preventDefault();
        // var title = global_locale == 'en' ? 'Are you sure?' : 'Apakah anda yakin?';
        // var mes = global_locale == 'en' ? 'Are you sure untuk melanjutkannya?' : 'Apakah anda yakin untuk melanjutkan?';
        var title = 'Apakah anda yakin ?'
        var mes = 'Apakah anda yakin untuk melanjutkannya ?'
        Swal.fire({
            title: title,
            text: mes,
            icon: "warning",
            showCancelButton: true,
            confirmButtonColor: '#DD6B55',
            confirmButtonText: 'Yes',
        }).then((result) => {
            $('body').css('padding', '0');
            if (result.value) {
                $.blockUI();

                $(this).off('submit').submit();
            }
        });
    });

    $('.cek_email').change(function (e) {
        var email = $(this).val();
        var route = $(this).data('route');
        var id = $(this).data('id') == 'undefined' ? '' : $(this).data('id');
        console.log(id);
        e.preventDefault();
        $.ajax({
            type: "POST",
            url: route,
            data: {
                'email': email,
                'id': id,
            },
            dataType: "json",
            success: function (response) {
                if (response.status == true) {
                    $('.cek_email').addClass('border-danger');
                    var html = '<small class="text-danger">' + response.message + '</small>';
                    $('.email-notification').html(html);

                } else {
                    $('.cek_email').removeClass('border-danger');
                    $('.email-notification').html('');
                }
            }
        });
    });
});
