
<th:block
  xmlns:th="http://www.thymeleaf.org"
  xmlns:sec="http://www.thymeleaf.org/extras/spring-security"
  th:fragment="menu(showIcon)"
>
  <ul>
    <li class="icon" th:if="${showIcon}">
      <a
        href="#"
        onclick="event.preventDefault()"
        aria-expanded="false"
        role="button"
        th:aria-label="#{fragment.menu.toggle-button.aria-label}"
      >
        <span class="iconify-huge iconify material-symbols--menu"></span>
      </a>
    </li>
    <th:block th:insert="~{:: base-menu}"></th:block>
    <th:block th:each="item : ${theme.config?.styles?.extra_menu_items}">
      <th:block th:if="${item?.type == 'random'}">
        <th:block th:with="posts = ${postFinder.random(1)}">
          <li th:each="post : ${posts}">
            <a
              href="/"
              th:href="${post.status.permalink}"
              th:aria-label="#{fragment.menu.random-button.aria-label}"
              th:text="#{fragment.menu.random}"
            ></a>
          </li>
        </th:block>
      </th:block>
      <li th:if="${item?.type == 'user'}">
        <a
          sec:authorize="isAnonymous()"
          href="/login"
          onclick="this.href = '/login?redirect_uri=' + encodeURIComponent(window.location.href)"
          th:text="#{fragment.menu.login}"
        >
        </a>
        <a
          sec:authorize="isAuthenticated()"
          th:with="loggedInUser = ${contributorFinder.getContributor(#authentication.name)}"
          th:text="${loggedInUser.displayName}"
          href="/uc"
        >
        </a>
      </li>
      <li
        th:if="${item?.type == 'search'
                 and pluginFinder.available('PluginSearchWidget')}"
      >
        <a
          href="javascript:SearchWidget.open();"
          th:aria-label="#{fragment.menu.search-button.aria-label}"
          th:text="#{fragment.menu.search}"
        ></a>
      </li>
    </th:block>
  </ul>
</th:block>
<th:block th:fragment="base-menu" th:with="menuItems = ${menuFinder.getPrimary().menuItems}">
  <th:block th:unless="${theme.config?.global?.is_i18n_menu_show}">
    <th:block th:each="menuItem : ${menuItems}">
      <th:block th:insert="~{:: menu-item(${menuItem})}"></th:block>
    </th:block>
  </th:block>
  <th:block
    th:if="${theme.config?.global?.is_i18n_menu_show
             and !theme.config?.global?.is_i18n_prefix_match_mode}"
  >
    <th:block th:each="menuItem : ${menuItems}">
      <th:block th:if="${#strings.equals(menuItem.status.displayName, page_language)}">
        <th:block th:each="menuItemChildren : ${menuItem?.children}">
          <th:block th:insert="~{:: menu-item(${menuItemChildren})}"></th:block>
        </th:block>
      </th:block>
    </th:block>
  </th:block>
  <th:block
    th:if="${theme.config?.global?.is_i18n_menu_show
             and theme.config?.global?.is_i18n_prefix_match_mode}"
  >
    <th:block th:each="menuItem : ${menuItems}">
      <th:block
        th:if="${page_language != null
                 and menuItem.status.displayName != null
                 and #strings.startsWith(page_language, menuItem.status.displayName)}"
      >
        <th:block th:each="menuItemChildren : ${menuItem?.children}">
          <th:block th:insert="~{:: menu-item(${menuItemChildren})}"></th:block>
        </th:block>
      </th:block>
    </th:block>
  </th:block>
  <th:block th:if="${theme.config?.global?.is_i18n_menu_show}">
    <th:block th:each="menuItem : ${menuItems}">
      <th:block th:if="${#strings.equals(menuItem.status.displayName, theme.config?.global?.default_page_language)}">
        <th:block th:each="menuItemChildren : ${menuItem.children}">
          <li
            style="display: none"
            class="default-menu"
            th:classappend="${#lists.isEmpty(menuItemChildren?.children) ? '' : 'has-submenu'}"
          >
            <th:block th:replace="~{:: menu-item-content(${menuItemChildren})}"></th:block>
          </li>
        </th:block>
      </th:block>
    </th:block>
  </th:block>
</th:block>
<th:block th:fragment="menu-item(item)">
  <li class="matched-menu" th:classappend="${#lists.isEmpty(item?.children) ? '' : 'has-submenu'}">
    <th:block th:replace="~{:: menu-item-content(${item})}"></th:block>
  </li>
</th:block>
<th:block th:fragment="menu-item-content(item)">
  <th:block th:if="${#lists.isEmpty(item?.children)}">
    <a
      th:href="@{${item?.status?.href}}"
      th:target="${item?.spec?.target?.value}"
      th:aria-label="#{fragment.menu.menuItem.aria-label(${item.status?.displayName})}"
      th:text="${item?.status?.displayName}"
      >目录项填充位置</a
    >
  </th:block>
  <th:block th:unless="${#lists.isEmpty(item?.children)}">
    <span class="submenu-container">
      <button
        class="submenu-toggle v-cursor-pointer tw-ae tw-oa tw-p tw-be tw-c"
        th:aria-label="#{fragment.menu.submenu-toggle.aria-label}"
        type="button"
      >
        <span class="iconify-large-middle tw-hd iconify material-symbols--keyboard-arrow-down"></span></button
      ><a
        class="submenu-link"
        th:href="@{${item?.status?.href}}"
        th:target="${item?.spec?.target?.value}"
        th:aria-label="#{fragment.menu.menuItem.aria-label(${item.status?.displayName})}"
        th:text="${item?.status?.displayName}"
        th:attr="data-parent-href=${item?.status?.href},
                data-parent-target=${item?.spec?.target?.value},
                data-parent-label=${item?.status?.displayName},
                data-submenu-hrefs=${#strings.arrayJoin(item.children.![status.href].toArray(), '|||')},
                data-submenu-targets=${#strings.arrayJoin(item.children.![spec.target.value].toArray(), '|||')},
                data-submenu-labels=${#strings.arrayJoin(item.children.![status.displayName].toArray(), '|||')},
                data-submenu-index='0',
                data-submenu-count=${#lists.size(item.children) + 1}"
        >菜单项填充位置</a
      >
    </span>
  </th:block>
</th:block>
<button
  th:fragment="theme-toggle-button"
  th:if="${theme.config?.styles?.is_show_color_scheme_toggle_button}"
  id="theme-toggle-button"
  accesskey="t"
  title="(Alt + T)"
  type="button"
  class="tw-zb tw-p tw-ca"
>
  <span
    id="theme-toggle-button-icon"
    style="display: none"
    class="icon iconify-large iconify tw-j tw-k"
  ></span>
  <style>#theme-toggle-button .icon:hover{color:var(--color-accent)}</style>
</button>
