jQuery(document).ready(function( $ ){
    var ajaxUrl = blogPostXNoticeOject.ajaxUrl, _wpnonce = blogPostXNoticeOject._wpnonce
    var welcomeOption = blogPostXNoticeOject.welcomeOption

    var noticeContainer = $('.blog-postx-admin-notice')
    if( noticeContainer.length > 0 ) {
        // dismiss notice
        noticeContainer.on('click', '.alert-dismiss, .action-button.review-never, .action-button.already-reviewed', function(){
            var _this = $(this), notice
            if( _this.parents('.blog-postx-admin-notice').hasClass( 'blog-postx-welcome-notice' ) ) notice = welcomeOption
            $.ajax({
                url: ajaxUrl,
                method: "POST",
                data: {
                    "action": 'blog_postx_admin_notice_ajax_call',
                    "_wpnonce": _wpnonce,
                    "dismiss_option": notice
                },
                beforeSend: function(){
                    _this.text( 'Dismissing...' )
                },
                success: function( result ) {
                    var parsedResult = JSON.parse( result )
                    if( parsedResult.status ) _this.parents( '.blog-postx-admin-notice' ).fadeOut()
                },
                complete: function() {
                    _this.text( 'Dismissed' )
                }
            })
        })
    }
})