import { kemonoAPI } from "@wp/api";

export async function initPendingReviewDms(forceReload= false, minutesForRecheck = 30) {
  let HasPendingReviewDms = localStorage.getItem("has_pending_review_dms")  === "true";
  let LastCheckedHasPendingReviewDms = parseInt(localStorage.getItem("last_checked_has_pending_review_dms"));

  if (forceReload || !LastCheckedHasPendingReviewDms || (LastCheckedHasPendingReviewDms < Date.now() - minutesForRecheck * 60 * 1000)) {
    /**
     * @type {string}
     */
    HasPendingReviewDms = await kemonoAPI.dms.retrieveHasPendingDMs();
    localStorage.setItem("has_pending_review_dms", HasPendingReviewDms.toString());
    localStorage.setItem("last_checked_has_pending_review_dms", Date.now().toString());
  }
  if (HasPendingReviewDms)
    document.querySelector(".review_dms > img").src = "/static/menu/red_dm.svg";
  else
    document.querySelector(".review_dms > img").src = "/static/menu/dm.svg";
}
