$ = jQuery;
$(document).ready(function () {
  $("#bf-festive-new-year").submit(function (e) {
    e.preventDefault();

    var celebration_type = $("#celebration_type").val();
    var decoration_image = $("#decoration_image").val();
    var font_style = $("#font_style").val();
    var pages = $("#pages").val();

    $.ajax({
      type: "POST",
      url: ajax_object.admin_url,
      data: {
        action: "bf_admin_action",
        celebration_type: celebration_type,
        decoration_image: decoration_image,
        font_style: font_style,
        pages: pages,
        _wpnonce: ajax_object.bf_admin_action_nonce, // Include nonce
      },
      success: function (response) {
        if (response.success) {
          // Display the success message
          $("strong").text(response.data); // Use response.data for the message
          $(".bf-alert").css("display", "block");
          setTimeout(function () {
            $(".bf-alert").css("display", "none");
          }, 5000);
        } else {
          // Display the error message
          alert(response.data || "An error occurred.");
        }
      },
      error: function (xhr, status, error) {
        console.error("Error:", error);
        alert("An error occurred. Please try again.");
      },
    });
  });
});
