<nav id="quarto-sidebar" class="sidebar collapse sidebar-navigation <%- sidebarStyle || (toc ? "floating" : "") %> overflow-auto">

  <% if (sidebar) { %>
  <% 
    let borderColor = sidebar['border-color'] ? "border-" + sidebar['border-color'] : "";

    let alignCss = ""
    if (sidebar.align === "center") {
      alignCss = "text-center";
    } else if (sidebar.align === "right") {
      alignCss = "text-end";
    } else {
      alignCss = "text-left";
    }

    // Whether there are tools that should be displayed to the user
    let needsTools = !sidebar || !!(sidebar.tools.length > 0 || (sidebar.search && sidebar.search === 'overlay') || sidebar.darkToggle);
    // Where the tools should be added (depending upon what elements are present, the tools)
    // may be displayed in different locations, so this will determine where to display the tools
    // "logo", "title", "search", "fallthrough"

    let toolsLocation;
    // Under the title if that will be displayed
    if (sidebar.title && !navbar) {
      toolsLocation = "title";
    } else if (sidebar.logo) {
      toolsLocation = "logo";
    } else if (sidebar.search && sidebar.search !== "overlay") {
      toolsLocation = "search";
    } else {
      toolsLocation = "fallthrough";
    }
  %>


    
  <% if (sidebar.logo || (sidebar.title && !navbar)) { %>
    <div class="pt-lg-2 mt-2 <%= alignCss %> sidebar-header<%= sidebar.logo && sidebar.title ? ' sidebar-header-stacked' : '' %>">
    <% if (sidebar.logo) { %>
      <a href="/">
      <img src="<%- sidebar.logo %>" alt="" class="sidebar-logo py-0 d-lg-inline d-none"/>
      </a>
    <% } %>
    <% if (needsTools && toolsLocation === "logo") { %>
      <% partial('sidebartools.ejs', { tools: sidebar.tools, className: 'sidebar-tools-main', darkToggle: sidebar.darkToggle, search: sidebar.search, readerToggle: sidebar.readerToggle })%>
    <% } %> 
    
    <% if (!navbar) { %>
    <% if (sidebar.title) { %>
    <div class="sidebar-title mb-0 py-0">
      <% if (!navbar) { %>
      <a href="/">
      <%- sidebar.title %>
      </a> 
      <% } %>  
      <% if (needsTools && toolsLocation === "title") { %>
        <% partial('sidebartools.ejs', { tools: sidebar.tools, className: 'sidebar-tools-main', darkToggle: sidebar.darkToggle, search: sidebar.search, readerToggle: sidebar.readerToggle })%>
      <% } %>  
    </div>
    <% } %>
    <% } %>
      </div>
    <% } %>

    <% if (sidebar.search) { %>
      <div class="<%- sidebar.search === "overlay" ? "d-flex " : "" %>mt-2 flex-shrink-0 align-items-center">
        <% if (sidebar.search !== "overlay") { %>
        <div class="sidebar-search">
        <% partial('navsearch.ejs',  { classes: '' }) %>
        </div>
        <% } %>
        <% if (needsTools && toolsLocation === "search") { %>
        <% partial('sidebartools.ejs', { tools: sidebar.tools, className: 'sidebar-tools-collapse', darkToggle: sidebar.darkToggle, search: sidebar.search, readerToggle: sidebar.readerToggle })%>
        <% } %>  
      </div>
    <% } %>
    <% if (needsTools && toolsLocation === "fallthrough") { %>
        <% partial('sidebartools.ejs', { tools: sidebar.tools, className: 'sidebar-tools-main', darkToggle: sidebar.darkToggle, search: sidebar.search, readerToggle: sidebar.readerToggle })%>
    <% } %>

    <% if (sidebar.contents.length > 0) { %> 
    <div class="sidebar-menu-container"> 
    <ul class="list-unstyled mt-1">
    <% sidebar.contents.forEach(item => { %>
        <% partial('sidebaritem.ejs', { item, depth: 1, collapse: sidebar['collapse-level'], borderColor: borderColor }) %>
    <% }) %>
    </ul>
    </div>
    <% } %>
  <% } %>
   
  <% if (toc) { %>
    <div id="quarto-toc-target"></div>
  <% } %>

</nav>