'use strict';

jQuery(function ($) {
  $(document).on('click', '.shortpixel.shortpixel-notice .notice-dismiss, .shortpixel.shortpixel-notice .notice-dismiss-action', function (event) {
    event.preventDefault();

    var target = $(event.target).closest('button');
    var parent = target.closest('.shortpixel-notice');
    var isPersistent = parent.data('persistent') === 1 || parent.data('persistent') === '1';

    if (isPersistent && window.SPAATGNoticeConfig) {
      $.post(window.SPAATGNoticeConfig.ajaxUrl, {
        plugin_action: 'dismiss',
        action: parent.data('notice-action'),
        nonce: window.SPAATGNoticeConfig.nonce,
        dismisstype: target.data('dismisstype') || 'dismiss',
        time: target.data('dismiss'),
        id: parent.attr('id')
      });
    }

    parent.fadeTo(100, 0, function () {
      parent.slideUp(100, 0, function () {
        parent.remove();
      });
    });
  });
});
