(function ($) {
  "use strict";

  $(document).ready(function ($) {
    // Enhanced dismiss functionality for the new colorful blog promo
    $(".colorful-blog-btn-dismiss, .btnend").on("click", function (e) {
      e.preventDefault();
      
      var $notice = $(this).closest(".mgadin-notice, .colorful-blog-promo");
      
      // Add fade out animation
      $notice.addClass('dismissed');
      
      // Redirect to dismiss the notice
      var url = new URL(location.href);
      url.searchParams.append("xbnotice", 1);
      
      setTimeout(function() {
        location.href = url;
      }, 500);
    });
    
    // Legacy dismiss functionality
    $(".xblog-about-notice .btn-dismiss").on("click", function (e) {
      e.preventDefault();

      var $this = $(this);

      var userid = $(this).data("userid");
      var nonce = $(this).data("nonce");

      $.ajax({
        type: "GET",
        dataType: "json",
        url: ajaxurl,
        data: {
          action: "colorful_blog_dismiss",
          userid: userid,
          _wpnonce: nonce,
        },
        success: function (response) {
          if (true === response.status) {
            $this.parents(".xblog-about-notice").fadeOut("slow");
          }
        },
      });
    });

    $(".eye-notice .notice-dismiss").on("click", function () {
      var url = new URL(location.href);
      url.searchParams.append("hnotice", 1);
      location.href = url;
    });
    
    // Add dismiss animation styles
    $("<style>")
      .text(`
        .colorful-blog-promo.dismissed {
          animation: slideOutUp 0.5s ease-in-out forwards !important;
        }
        @keyframes slideOutUp {
          from {
            opacity: 1;
            transform: translateY(0);
          }
          to {
            opacity: 0;
            transform: translateY(-30px);
          }
        }
      `)
      .appendTo("head");
  });
})(jQuery);
