$("select").on("select2:close", function (e) {
    $(this).valid();
});

// Error Alert with custom message
function submissionErrorAlertMessage($message) {
    swal.fire({
        "title": "",
        "text": $message,
        "type": "error",
        "icon": "error",
        "confirmButtonClass": "btn btn-secondary",
        "onClose": function (e) {
            console.log('on close event fired!');
        }
    })
}

// Error Alert
function submissionErrorAlert() {
    swal.fire({
        "title": "",
        "text": "There are some errors in your submission, Please fix them.",
        "type": "error",
        "icon": "error",
        "confirmButtonClass": "btn btn-secondary",
        "onClose": function (e) {
            console.log('on close event fired!');
        }
    })
}

// Success Alert
function submissionSuccessAlert($path = null) {
    console.log($path);
    swal.fire({
        "title": "",
        "text": "Saved Successfully",
        "type": "success",
        "icon": "success",
        "buttonsStyling": true,
        "confirmButtonText": "OK",
        "onClose": function (e) {
            if ($path === null) {
                console.log('on close event fired!');
            } else {
                window.location.href = $path;
            }
        }
    })
}

// Success Alert with Redirection
function submissionSuccessRedirect($path = NULL, $message = NULL) {
    console.log($path);
    swal.fire({
        "title": "",
        "text": $message,
        "type": "success",
        "icon": "success",
        "buttonsStyling": true,
        "confirmButtonText": "OK",
        "onClose": function (e) {
            $("#preloader").fadeIn("slow");
            setTimeout(function () {
                window.location.href = $path;
            }, 3000);
        }
    })
}

// Error Alert with Redirection
function submissionErrorRedirect($path = NULL, $message = NULL) {
    console.log($path);
    swal.fire({
        "title": "",
        "text": $message,
        "type": "error",
        "icon": "error",
        "buttonsStyling": true,
        "confirmButtonText": "OK",
        "onClose": function (e) {
            $("#preloader").fadeIn("slow");
            setTimeout(function () {
                window.location.href = $path;
            }, 3000);
        }
    })
}

// Bootstrap Notification
function notificationMessage($type, $title, $message) {
    $.notify({
        title: $title,
        message: $message,
    }, {
        type: $type,
        allow_dismiss: true,
        showProgressbar: false,
        newest_on_top: true,
        animate: {
            enter: 'animate__animated animate__fadeInRight',
            exit: 'animate__animated animate__fadeOutRight'
        },
        placement: {
            from: "bottom",
            align: "right"
        },
        offset: {
            x: 30,
            y: 30
        },
        spacing: 10,
        z_index: 10000,
        delay: 1000,
        timer: 2000,
    });
}

// validate numaric fields
$('.numaric').on('change, keyup', function () {
    var currentInput = $(this).val();
    var fixedInput = currentInput.replace(/[A-Za-z!@#$%^&*()]/g, '');
    $(this).val(fixedInput);
    console.log(fixedInput);
});

// Number Counter
// $('.count').each(function () {
//     $(this).prop('Counter',0).animate({
//         Counter: $(this).text()
//     }, {
//         duration: 4000,
//         easing: 'swing',
//         step: function (now) {
//             $(this).text(Math.ceil(now));
//         }
//     });
// });


