$(document).ready(function () {
  // Get Current Date
  const getDate = () => {
    const months = [
      "يناير",
      "فبراير",
      "مارس",
      "أبريل",
      "مايو",
      "يونيو",
      "يوليو",
      "أغسطس",
      "سبتمبر",
      "أكتوبر",
      "نوفمبر",
      "ديسمبر",
    ];

    const days = [
      "الأحد",
      "الاثنين",
      "الثلاثاء",
      "الأربعاء",
      "الخميس",
      "الجمعة",
      "السبت",
    ];

    const today = new Date();
    const dayOfWeek = days[today.getDay()];
    const dayOfMonth = today.getDate();
    const month = months[today.getMonth()];
    const year = today.getFullYear();

    const currentDate = `${dayOfWeek} ${dayOfMonth} ${month} ${year}`;
    $(".date-area").html(currentDate);
  };

  const getDateEn = () => {
    const months = [
      "January",
      "February",
      "March",
      "April",
      "May",
      "June",
      "July",
      "August",
      "September",
      "October",
      "November",
      "December",
    ];

    const days = [
      "Sunday",
      "Monday",
      "Tuesday",
      "Wednesday",
      "Thursday",
      "Friday",
      "Saturday",
    ];

    const today = new Date();
    const dayOfWeek = days[today.getDay()];
    const dayOfMonth = today.getDate();
    const month = months[today.getMonth()];
    const year = today.getFullYear();

    const currentDate = `${dayOfWeek} ${dayOfMonth} ${month} ${year}`;
    $(".date-area-en").html(currentDate);
  };

  const Donations = () => {
    // Progress Bar Width
    $(".progress-bar-value").each(function () {
      $(this).css({
        width: $(this).attr("data-width"),
      });
    });
  };

  //   Breaking News Ribbon
  const BreakingNewsRibbon = () => {
    $("#bn1").breakingNews({
      effect: "slide-h",
      autoplay: true,
      timer: 3000,
      color: "red",
    });
    if ($(window).width() > 480) {
      $(".breakingNews>ul").css({
        right: $(".bn-title").width() + 20,
      });
    }
  };

  new WOW().init();

  if ($("body").magnificPopup != undefined) {
    $(".popup").magnificPopup({
      type: "image",
      mainClass: "mfp-with-zoom",
      zoom: {
        enabled: true,
        duration: 300,
        easing: "ease-in-out",
        opener: function (openerElement) {
          return openerElement.is("img")
            ? openerElement
            : openerElement.find("img");
        },
      },
      gallery: {
        enabled: true,
        preload: [0, 2],
        navigateByImgClick: true,
        arrowMarkup:
          '<button title="%title%" type="button" class="mfp-arrow mfp-arrow-%dir%"></button>',
        tPrev: "Previous (Left arrow key)",
        tNext: "Next (Right arrow key)",
        tCounter: '<span class="mfp-counter">%curr% من %total%</span>',
      },
    });

    $(".popup-en").magnificPopup({
      type: "image",
      mainClass: "mfp-with-zoom",
      zoom: {
        enabled: true,
        duration: 300,
        easing: "ease-in-out",
        opener: function (openerElement) {
          return openerElement.is("img")
            ? openerElement
            : openerElement.find("img");
        },
      },
      gallery: {
        enabled: true,
        preload: [0, 2],
        navigateByImgClick: true,
        arrowMarkup:
          '<button title="%title%" type="button" class="mfp-arrow mfp-arrow-%dir%"></button>',
        tPrev: "Previous (Left arrow key)",
        tNext: "Next (Right arrow key)",
        tCounter: '<span class="mfp-counter">%curr% of %total%</span>',
      },
    });
  }

  if ($(".swiper-container").length > 0) {
    var mySwiper = new Swiper(".swiper-container", {
      speed: 600,
      parallax: true,
      spaceBetween: 0,
      pagination: {
        el: ".swiper-pagination",
        clickable: true,
      },
      navigation: {
        nextEl: ".swiper-button-next",
        prevEl: ".swiper-button-prev",
      },
    });

    // Enable parallax on window scroll
    window.addEventListener("scroll", function () {
      mySwiper.update();
    });
  }

  // Function Trigger
  getDate();
  getDateEn();
  Donations();
  BreakingNewsRibbon();
});
