
document.addEventListener("DOMContentLoaded", function() {
  function applyMobileBreadcrumb() {
    const breadcrumb = document.querySelector('.breadcrumb');
    const items = breadcrumb.querySelectorAll('li');
    let ellipsis = breadcrumb.querySelector('.ellipsis');

    if (items.length > 5) {
      if (!ellipsis) {
        ellipsis = document.createElement('li');
        ellipsis.textContent = '...';
        ellipsis.classList.add('breadcrumb-item', 'ellipsis', 'sm:block');
        breadcrumb.insertBefore(ellipsis, items[4]);

        for (let i = 4; i < items.length - 2; i++) {
          items[i].classList.add('hidden');
        }

        ellipsis.addEventListener('click', function() {
          for (let i = 4; i < items.length - 2; i++) {
            items[i].classList.toggle('hidden');
          }
          ellipsis.classList.toggle('hidden');
        });
        
        // House Icon
        if (items[0]) {
          items[0].innerHTML = '<a href="/"><svg class="w-4 h-4 inline-block" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 9.75L12 3l9 6.75v11.25a2.25 2.25 0 01-2.25 2.25H5.25A2.25 2.25 0 013 20.25V9.75z"></path><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 21v-6h6v6"></path></svg></a>';
          items[0].classList.add('breadcrumb-item');
        }
      }
    }
  }

  function removeMobileBreadcrumb() {
    const breadcrumb = document.querySelector('.breadcrumb');
    const ellipsis = breadcrumb.querySelector('.ellipsis');
    if (ellipsis) {
      ellipsis.remove();
    }

    const items = breadcrumb.querySelectorAll('li');
    for (let i = 0; i < items.length; i++) {
      items[i].classList.remove('hidden');
    }
  }

  function handleResize() {
    if (window.innerWidth <= 1350) {
      applyMobileBreadcrumb();
    } else {
      removeMobileBreadcrumb();
    }
  }
  
  

  
          
          
  var breadcrumbBlackList = {
    '/tuition-financial-aid/': true,
    '/admissions/': true,
    '/life-at-sau/': true,
    '/about-sau/': true,
    '/alumni/': true,
    '/academic-programs/bachelors/': true,
    '/academic-programs/masters/': true,
    '/academic-programs/doctoral/': true,
    '/basic-pages/': true,
    '/about-sau/faculty/faculty-search/faculty/': true,
    '/about-sau/faculty/faculty-search/faculty/biology/': true,
    '/about-sau/faculty/faculty-search/faculty/business/': true,
    '/about-sau/faculty/faculty-search/faculty/criminal-justice/': true,
    '/about-sau/faculty/faculty-search/faculty/education/': true,
    '/about-sau/faculty/faculty-search/faculty/engineering/': true,
    '/about-sau/faculty/faculty-search/faculty/fine-arts/': true,
    '/about-sau/faculty/faculty-search/faculty/health-sciences/': true,
    '/about-sau/faculty/faculty-search/faculty/information-technology/': true,
    '/about-sau/faculty/faculty-search/faculty/liberal-arts/': true,
    '/about-sau/faculty/faculty-search/faculty/nursing/': true,
    '/about-sau/faculty/faculty-search/faculty/psychology/': true,
    '/about-sau/faculty/faculty-search/faculty/social-sciences/': true,
    '/about-sau/faculty/faculty-search/admin-and-staff/': true,
    '/about-sau/news-events/news/2026/': true,
    '/about-sau/news-events/news/2025/': true,
    '/about-sau/news-events/news/2024/': true,
    '/about-sau/news-events/news/2023/': true,
    '/about-sau/news-events/news/2022/': true,
    '/about-sau/news-events/news/2021/': true,
    '/about-sau/news-events/news/2020/': true,
    '/about-sau/news-events/news/2019/': true,
    '/about-sau/news-events/news/2018/': true,
    '/about-sau/news-events/events/2026/': true,
    '/about-sau/news-events/events/2025/': true,
    '/about-sau/news-events/events/2024/': true,
    '/about-sau/news-events/events/2023/': true,
    '/about-sau/news-events/events/2022/': true,
    '/about-sau/news-events/events/2021/': true,
    '/about-sau/news-events/events/2020/': true,
    '/about-sau/news-events/events/2019/': true,
    '/about-sau/news-events/events/2018/': true,
  };


  function parseBreadcrumb(el) {
    if (!el) {
      throw new Error('breadcrumb required');
    }

    const anchors = el.querySelectorAll('a');

    [...anchors].forEach(a => {
      const href = a.getAttribute('href');
      if (breadcrumbBlackList[href]) {
        const next = a.parentNode.nextElementSibling;
        if (next?.textContent.trim() === '/') {
          el.removeChild(next);
        }
        el.removeChild(a.parentNode);
      }
    });

    el.style.visibility = 'visible';
  }

  function init() {
    handleResize();
    parseBreadcrumb(document.querySelector('.breadcrumb'));
  }

  window.addEventListener('resize', handleResize);
  init();
});         






