window.addEventListener("DOMContentLoaded", (event) => {
  var url = new URL(window.location.href);
  var params = new URLSearchParams(url.search);
  if (params.has("contact")) $("#modal-contact").modal("show");
  if (params.has("connexion")) $("#modal-login").modal("show");
  if (window.location.href.split("?")[1]) {
    history.replaceState({}, "", location.protocol + "//" + location.host + location.pathname.replace("index.awp", "") + window.location.hash.split("?")[0]);
  }

  $(window).on("load resize", function () {
    $(".article").each(function (index) {
      $(this).find(".card-subtitle").height("auto");
      $(this).find(".card-price").height("auto");
    });
    let maxHeight = 0;
    $(".article").each(function () {
      maxHeight = maxHeight > $(this).outerHeight() ? maxHeight : $(this).outerHeight();
    });
    const maxSubtitleHeight = Math.max.apply(
      null,
      $(".article .card-subtitle")
        .map(function () {
          return $(this).height();
        })
        .get()
    );
    const maxPriceHeight = Math.max.apply(
      null,
      $(".article .card-price")
        .map(function () {
          return $(this).height();
        })
        .get()
    );
    for (let index = 0; index < 2; index++) {
      $(".article").each(function (index) {
        if ($(this).outerHeight() < maxHeight) {
          if ($(this).find(".card-subtitle").outerHeight() < maxSubtitleHeight) $(this).find(".card-subtitle").outerHeight(maxSubtitleHeight);
          else if ($(this).find(".card-price").outerHeight() < maxPriceHeight) $(this).find(".card-price").outerHeight(maxPriceHeight);
        }
      });
    }
  });
  $(".carousel-control-prev").on("click", function () {
    $("." + $(this).data("bs-target").substring(1)).carousel("prev");
  });
  $(".carousel-control-next").on("click", function () {
    $("." + $(this).data("bs-target").substring(1)).carousel("next");
  });
});
