var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: !0 });
import { getClassInstance } from "./lib/unl-utility.js?v=6.1.1";
window.UNL = window.UNL || {};
window.UNL.nav = window.UNL.nav || {};
window.UNL.nav.config = window.UNL.nav.config || {};
let disableDesktopNav = window.UNL.nav.config?.disableDesktopNav ?? !0;
const watchEnabled = window.UNL.nav.config?.watch ?? !1;
let searchDialogClassInstance = null, idmDialogClassInstance = null, currentScreenSize = null, idmDialog = null, searchDialog = null;
watchEnabled ? setUpNavWatch() : (copyNav(), setUpHoverIntent(), setUpUpdateStyles(), initCtaPopups());
window.addEventListener("resize", () => {
  updateStyles();
});
updateStyles();
function setUpNavWatch() {
  const checkList = {
    "nav.dcf-nav-local": !1,
    "nav.dcf-local-copy-dialog": !1,
    "div.dcf-nav": !1,
    "dialog.dcf-nav-dialog": !1,
    "dialog.unl-idm-dialog": !1,
    "dialog.dcf-search-dialog": !1
  }, initializedParts = {
    copyNav: !1,
    setUpHoverIntent: !1,
    setUpUpdateStyles: !1,
    initCtaPopups: !1
  }, updateChecklist = /* @__PURE__ */ __name(() => {
    for (const selector in checkList)
      document.querySelector(selector) !== null && (checkList[selector] = !0);
  }, "updateChecklist"), initIfWeCan = /* @__PURE__ */ __name(() => {
    (!initializedParts.copyNav || !initializedParts.setUpHoverIntent || !initializedParts.setUpUpdateStyles || !initializedParts.initCtaPopups) && updateChecklist(), !initializedParts.copyNav && checkList["nav.dcf-nav-local"] && checkList["nav.dcf-local-copy-dialog"] && (copyNav(), initializedParts.copyNav = !0), !initializedParts.setUpHoverIntent && checkList["div.dcf-nav"] && checkList["dialog.dcf-nav-dialog"] && (setUpHoverIntent(), initializedParts.setUpHoverIntent = !0), !initializedParts.setUpUpdateStyles && checkList["dialog.unl-idm-dialog"] && checkList["dialog.dcf-search-dialog"] && (setUpUpdateStyles(), initializedParts.setUpUpdateStyles = !0), initializedParts.initCtaPopups || (initCtaPopups(), initializedParts.initCtaPopups = !0);
  }, "initIfWeCan");
  initIfWeCan();
  const dcfHeader = document.getElementById("dcf-header"), headerObserver = new MutationObserver((mutationList) => {
    for (const mutationRecord of mutationList)
      for (const nodeAdded of mutationRecord.addedNodes)
        if (nodeAdded instanceof Element && (initIfWeCan(), initializedParts.copyNav && initializedParts.setUpHoverIntent && initializedParts.setUpUpdateStyles)) {
          headerObserver.disconnect();
          return;
        }
  }), observerConfig = {
    subtree: !0,
    childList: !0
  };
  headerObserver.observe(dcfHeader, observerConfig);
}
__name(setUpNavWatch, "setUpNavWatch");
function copyNav() {
  const dcfNavLocal = document.querySelector("nav.dcf-nav-local"), dcfNavLocalCopy = document.querySelector("nav.dcf-local-copy-dialog");
  if (dcfNavLocalCopy.innerHTML = dcfNavLocal.innerHTML, watchEnabled) {
    const navLinksObserver = new MutationObserver(() => {
      dcfNavLocalCopy.innerHTML = dcfNavLocal.innerHTML;
    }), observerConfig = {
      subtree: !0,
      childList: !0
    };
    navLinksObserver.observe(dcfNavLocal, observerConfig);
  }
  const navDialogBackdrop = document.createElement("div");
  navDialogBackdrop.classList.add(
    "dcf-nav-dialog-backdrop",
    "dcf-bg-overlay-light",
    "dcf-d-none@print",
    "dcf-fixed",
    "dcf-top-0",
    "dcf-left-0",
    "dcf-right-0",
    "dcf-bottom-0"
  ), document.body.prepend(navDialogBackdrop);
}
__name(copyNav, "copyNav");
function initCtaPopups() {
  const visitLinks = document.querySelectorAll("#dcf-visit-options li"), applyLinks = document.querySelectorAll("#dcf-apply-options li"), giveLinks = document.querySelectorAll("#dcf-give-options li");
  visitLinks.length > 1 && getClassInstance("unl-visit-popup").then(() => {
    const visitStaticLink = document.getElementById("unl-visit-link"), visitPopup = document.getElementById("unl-visit-popup");
    visitStaticLink.classList.add("dcf-d-none!"), visitPopup.classList.remove("dcf-d-none!");
  }), applyLinks.length > 1 && getClassInstance("unl-apply-popup").then(() => {
    const applyStaticLink = document.getElementById("unl-apply-link"), applyPopup = document.getElementById("unl-apply-popup");
    applyStaticLink.classList.add("dcf-d-none!"), applyPopup.classList.remove("dcf-d-none!");
  }), giveLinks.length > 1 && getClassInstance("unl-give-popup").then(() => {
    const giveStaticLink = document.getElementById("unl-give-link"), givePopup = document.getElementById("unl-give-popup");
    giveStaticLink.classList.add("dcf-d-none!"), givePopup.classList.remove("dcf-d-none!");
  });
}
__name(initCtaPopups, "initCtaPopups");
function setUpHoverIntent() {
  checkForSecondaryNav() === !1 && (disableDesktopNav = !0);
  const dcfNav = document.querySelector("div.dcf-nav"), dcfNavDialog = document.querySelector("dialog.dcf-nav-dialog"), dcfDialogToggleBtn = document.getElementById("dcf-btn-close-desktop-menu");
  let dcfNavDialogClassInstance = null;
  const navDialogContent = document.querySelector("dialog.dcf-nav-dialog .dcf-dialog-content");
  let navOpenTimeout = null, navCloseTimeout = null, isMouseHovering = !1, mouseX = 0, mouseY = 0;
  const navHoverOpenTimeoutDurationMs = 100, navHoverCloseTimeoutDurationMs = 100;
  let navJustClosed = !1, mouseHoverLeaveFlag = !1, mouseHoverEnterFlag = !1;
  disableDesktopNav && dcfNav.querySelector("#dcf-menu-toggle")?.classList.add("dcf-d-none!"), dcfNavDialog.addEventListener("dialogPreOpen", () => {
    const desktopToggleButton = dcfNav.querySelector("#dcf-menu-toggle");
    desktopToggleButton !== null && document.activeElement.isSameNode(desktopToggleButton) && (mouseHoverEnterFlag = !1);
  }), dcfNavDialog.addEventListener("dialogPostOpen", () => {
    dcfNav.querySelector("#dcf-menu-toggle")?.setAttribute("tabindex", "-1"), dcfNav.querySelector("#dcf-menu-toggle")?.setAttribute("aria-hidden", "true"), dcfNav.querySelectorAll("#dcf-navigation a").forEach((singleNavLink) => {
      singleNavLink.setAttribute("tabindex", "-1"), singleNavLink.setAttribute("aria-hidden", "true");
    }), mouseHoverEnterFlag === !1 && dcfNavDialog.querySelector(".dcf-local-copy-dialog a")?.focus(), mouseHoverEnterFlag = !1;
  }), dcfNavDialog.addEventListener("dialogPreClose", (event) => {
    "detail" in event && "type" in event.detail && event.detail.type === "focusout" && (navJustClosed = !0), dcfNavDialog.contains(document.activeElement) && (mouseHoverLeaveFlag = !1);
  }), dcfNavDialog.addEventListener("dialogPostClose", () => {
    dcfNav.querySelector("#dcf-menu-toggle")?.removeAttribute("tabindex"), dcfNav.querySelector("#dcf-menu-toggle")?.removeAttribute("aria-hidden"), dcfNav.querySelectorAll("#dcf-navigation a").forEach((singleNavLink) => {
      singleNavLink.removeAttribute("tabindex", "-1"), singleNavLink.removeAttribute("aria-hidden", "true");
    }), mouseHoverLeaveFlag === !1 && (currentScreenSize === "mobile" ? document.querySelector("button.dcf-btn-nav-mobile").focus() : document.querySelector("button.dcf-btn-nav-desktop").focus()), mouseHoverLeaveFlag = !1;
  }), dcfNavDialog.addEventListener("click", (event) => {
    dcfNavDialogClassInstance !== null && isScreenUnderMediumSize() && !navDialogContent.contains(event.target) && dcfNavDialogClassInstance.close();
  }), dcfNavDialog.addEventListener("dialogReady", (event) => {
    dcfNavDialogClassInstance = event.detail.classInstance;
  }), dcfNav.addEventListener("mouseenter", () => {
    if (navJustClosed === !0) {
      navJustClosed = !1;
      return;
    }
    disableDesktopNav && !isScreenUnderMediumSize() || (navOpenTimeout = setTimeout(() => {
      dcfNavDialogClassInstance !== null && (mouseHoverEnterFlag = !0, dcfNavDialogClassInstance.open());
    }, navHoverOpenTimeoutDurationMs));
  }), dcfNav.addEventListener("mouseleave", () => {
    clearTimeout(navOpenTimeout), navJustClosed = !1;
  }), navDialogContent.addEventListener("mouseleave", () => {
    isMouseHovering = !1;
    const mobileNav = document.getElementById("dcf-nav-toggle-group");
    isScreenUnderMediumSize() && mobileNav.matches(":hover") || (navCloseTimeout = setTimeout(() => {
      dcfNavDialogClassInstance !== null && (mouseHoverLeaveFlag = !0, dcfNavDialogClassInstance.close());
    }, navHoverCloseTimeoutDurationMs));
  }), navDialogContent.addEventListener("mouseenter", () => {
    clearTimeout(navCloseTimeout), isMouseHovering = !0;
  }), navDialogContent.addEventListener("mousemove", (event) => {
    mouseX = event.clientX, mouseY = event.clientY;
  }), window.addEventListener("scroll", () => {
    if (isMouseHovering === !1 || isScreenUnderMediumSize())
      return;
    const rect = navDialogContent.getBoundingClientRect();
    mouseX < rect.left || mouseX > rect.right || mouseY < rect.top || mouseY > rect.bottom ? navCloseTimeout = setTimeout(() => {
      dcfNavDialogClassInstance !== null && (mouseHoverLeaveFlag = !0, dcfNavDialogClassInstance.close());
    }, navHoverCloseTimeoutDurationMs) : clearTimeout(navCloseTimeout);
  }), dcfDialogToggleBtn.addEventListener("click", () => {
    dcfNavDialog.open === !0 && (navJustClosed = !0);
  });
}
__name(setUpHoverIntent, "setUpHoverIntent");
function setUpUpdateStyles() {
  idmDialog = document.querySelector("dialog.unl-idm-dialog"), searchDialog = document.querySelector("dialog.dcf-search-dialog"), idmDialog !== null && (idmDialog.addEventListener("dialogReady", (event) => {
    idmDialogClassInstance = event.detail.classInstance;
  }), idmDialog.addEventListener("dialogPostOpen", () => {
    idmDialog.querySelector(".unl-idm-personal a")?.focus();
  }), idmDialog.addEventListener("dialogPostClose", () => {
    currentScreenSize === "mobile" ? document.querySelector("button.unl-btn-idm-mobile").focus() : document.querySelector("button.unl-btn-idm-desktop").focus();
  })), searchDialog !== null && (searchDialog.addEventListener("dialogReady", (event) => {
    searchDialogClassInstance = event.detail.classInstance;
  }), searchDialog.addEventListener("dialogPostOpen", () => {
    searchDialog.querySelector("#dcf-search_query")?.focus();
  }), searchDialog.addEventListener("dialogPostClose", () => {
    currentScreenSize === "mobile" ? document.querySelector("button.dcf-btn-search-mobile").focus() : document.querySelector("button.dcf-btn-search-desktop").focus();
  }));
}
__name(setUpUpdateStyles, "setUpUpdateStyles");
function updateStyles() {
  isScreenUnderMediumSize() ? (currentScreenSize !== "mobile" && (currentScreenSize = "mobile", idmDialogClassInstance !== null && idmDialogClassInstance.close(), searchDialogClassInstance !== null && searchDialogClassInstance.close()), setMobileStyles()) : (currentScreenSize !== "desktop" && (currentScreenSize = "desktop", idmDialogClassInstance !== null && idmDialogClassInstance.close(), searchDialogClassInstance !== null && searchDialogClassInstance.close()), setDesktopStyles());
}
__name(updateStyles, "updateStyles");
function isScreenUnderMediumSize() {
  return matchMedia("only screen and (max-width: 56.12em)").matches;
}
__name(isScreenUnderMediumSize, "isScreenUnderMediumSize");
function setMobileStyles() {
  searchDialog !== null && searchDialog.classList.add("dcf-dialog-non-modal"), idmDialog !== null && idmDialog.classList.add("dcf-dialog-non-modal");
}
__name(setMobileStyles, "setMobileStyles");
function setDesktopStyles() {
  searchDialog !== null && searchDialog.classList.remove("dcf-dialog-non-modal"), idmDialog !== null && idmDialog.classList.remove("dcf-dialog-non-modal");
}
__name(setDesktopStyles, "setDesktopStyles");
function checkForSecondaryNav() {
  return document.getElementById("dcf-navigation").querySelector("ul").querySelector("ul") !== null;
}
__name(checkForSecondaryNav, "checkForSecondaryNav");
//# sourceMappingURL=nav-container-2.js.map
