;(function ($) {
  function bafStoreNoticeInfo($key) {
    return $.ajax({
      type: "POST",
      url: BafAdminData.ajaxurl,
      data: {
        action: "baf_set_notice_status", // this is the name of our WP AJAX function that we'll set up next
        noticeKey: $key,
      },
      dataType: "JSON",
    })
  }

  if ($(".baf_remove_notice").length > 0) {
    $(".baf_remove_notice").each(function () {
      let $this = $(this)
      let $noticeStatusKey = $this.data("key")

      // Click Event.

      $this.on("click", function () {
        $(this)
          .closest(".notice")
          .slideUp("slow", function () {
            // call the ajax request here to store the setting to DB.
            $.when(bafStoreNoticeInfo($noticeStatusKey)).done(function (response_data) {
              // console.log(response_data)
            })
          })
      })
    })
  }
})(jQuery)
