<!DOCTYPE html>
<html xmlns:th="https://www.thymeleaf.org">

<th:block th:fragment="icon(href, item)"
          th:with="bs=${theme.config.basic}, ni=${theme.config.basic != null ? theme.config.basic.navIcons : null}, ac=${#annotations.getOrDefault(item, 'icon_code', '')}">

  <!-- 归档 -->
  <th:block th:if="${#strings.contains(href, '/archives')}">
    <i th:if="${(ni != null and ni.iconArchives != null and !#strings.isEmpty(ni.iconArchives)) or !#strings.isEmpty(ac)}"
       th:classappend="${(ni != null and ni.iconArchives != null and !#strings.isEmpty(ni.iconArchives)) ? ni.iconArchives : ac}" class="nav-custom-icon"></i>
    <svg th:if="${(ni == null or ni.iconArchives == null or #strings.isEmpty(ni.iconArchives)) and #strings.isEmpty(ac)}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
      <path d="M21 8v13H3V8"/><path d="M1 3h22v5H1z"/><path d="M10 12h4"/>
    </svg>
  </th:block>

  <!-- 标签 -->
  <th:block th:if="${#strings.contains(href, '/tags')}">
    <i th:if="${(ni != null and ni.iconTags != null and !#strings.isEmpty(ni.iconTags)) or !#strings.isEmpty(ac)}"
       th:classappend="${(ni != null and ni.iconTags != null and !#strings.isEmpty(ni.iconTags)) ? ni.iconTags : ac}" class="nav-custom-icon"></i>
    <svg th:if="${(ni == null or ni.iconTags == null or #strings.isEmpty(ni.iconTags)) and #strings.isEmpty(ac)}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
      <path d="M20.59 13.41l-7.17 7.17a2 2 0 0 1-2.83 0L2 12V2h10l8.59 8.59a2 2 0 0 1 0 2.82z"/><line x1="7" y1="7" x2="7.01" y2="7"/>
    </svg>
  </th:block>

  <!-- 分类 -->
  <th:block th:if="${#strings.contains(href, '/categories')}">
    <i th:if="${(ni != null and ni.iconCategories != null and !#strings.isEmpty(ni.iconCategories)) or !#strings.isEmpty(ac)}"
       th:classappend="${(ni != null and ni.iconCategories != null and !#strings.isEmpty(ni.iconCategories)) ? ni.iconCategories : ac}" class="nav-custom-icon"></i>
    <svg th:if="${(ni == null or ni.iconCategories == null or #strings.isEmpty(ni.iconCategories)) and #strings.isEmpty(ac)}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
      <path d="M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"/>
    </svg>
  </th:block>

  <!-- 关于我 -->
  <th:block th:if="${#strings.contains(href, '/about')}">
    <i th:if="${(ni != null and ni.iconAbout != null and !#strings.isEmpty(ni.iconAbout)) or !#strings.isEmpty(ac)}"
       th:classappend="${(ni != null and ni.iconAbout != null and !#strings.isEmpty(ni.iconAbout)) ? ni.iconAbout : ac}" class="nav-custom-icon"></i>
    <svg th:if="${(ni == null or ni.iconAbout == null or #strings.isEmpty(ni.iconAbout)) and #strings.isEmpty(ac)}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
      <path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"/><circle cx="12" cy="7" r="4"/>
    </svg>
  </th:block>

  <!-- 碎碎念 -->
  <th:block th:if="${#strings.contains(href, '/moments')}">
    <i th:if="${(ni != null and ni.iconMoments != null and !#strings.isEmpty(ni.iconMoments)) or !#strings.isEmpty(ac)}"
       th:classappend="${(ni != null and ni.iconMoments != null and !#strings.isEmpty(ni.iconMoments)) ? ni.iconMoments : ac}" class="nav-custom-icon"></i>
    <svg th:if="${(ni == null or ni.iconMoments == null or #strings.isEmpty(ni.iconMoments)) and #strings.isEmpty(ac)}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
      <path d="M4 19.5A2.5 2.5 0 0 1 6.5 17H20"/><path d="M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z"/>
    </svg>
  </th:block>

  <!-- 朋友们 -->
  <th:block th:if="${#strings.contains(href, '/links')}">
    <i th:if="${(ni != null and ni.iconLinks != null and !#strings.isEmpty(ni.iconLinks)) or !#strings.isEmpty(ac)}"
       th:classappend="${(ni != null and ni.iconLinks != null and !#strings.isEmpty(ni.iconLinks)) ? ni.iconLinks : ac}" class="nav-custom-icon"></i>
    <svg th:if="${(ni == null or ni.iconLinks == null or #strings.isEmpty(ni.iconLinks)) and #strings.isEmpty(ac)}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
      <path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"/>
    </svg>
  </th:block>

  <!-- 留言板 -->
  <th:block th:if="${#strings.contains(href, '/guestbook')}">
    <i th:if="${(ni != null and ni.iconGuestbook != null and !#strings.isEmpty(ni.iconGuestbook)) or !#strings.isEmpty(ac)}"
       th:classappend="${(ni != null and ni.iconGuestbook != null and !#strings.isEmpty(ni.iconGuestbook)) ? ni.iconGuestbook : ac}" class="nav-custom-icon"></i>
    <svg th:if="${(ni == null or ni.iconGuestbook == null or #strings.isEmpty(ni.iconGuestbook)) and #strings.isEmpty(ac)}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
      <path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/>
    </svg>
  </th:block>

  <!-- 项目集 -->
  <th:block th:if="${#strings.contains(href, '/projects')}">
    <i th:if="${(ni != null and ni.iconProjects != null and !#strings.isEmpty(ni.iconProjects)) or !#strings.isEmpty(ac)}"
       th:classappend="${(ni != null and ni.iconProjects != null and !#strings.isEmpty(ni.iconProjects)) ? ni.iconProjects : ac}" class="nav-custom-icon"></i>
    <svg th:if="${(ni == null or ni.iconProjects == null or #strings.isEmpty(ni.iconProjects)) and #strings.isEmpty(ac)}" viewBox="0 0 24 24" fill="currentColor">
      <path d="M12 0C5.37 0 0 5.37 0 12c0 5.31 3.435 9.795 8.205 11.385.6.105.825-.255.825-.57 0-.285-.015-1.23-.015-2.235-3.015.555-3.795-.735-4.035-1.41-.135-.345-.72-1.41-1.23-1.695-.42-.225-1.02-.78-.015-.795.945-.015 1.62.87 1.845 1.23 1.08 1.815 2.805 1.305 3.495.99.105-.78.42-1.305.765-1.605-2.67-.3-5.46-1.335-5.46-5.925 0-1.305.465-2.385 1.23-3.225-.12-.3-.54-1.53.12-3.18 0 0 1.005-.315 3.3 1.23.96-.27 1.98-.405 3-.405s2.04.135 3 .405c2.295-1.56 3.3-1.23 3.3-1.23.66 1.65.24 2.88.12 3.18.765.84 1.23 1.905 1.23 3.225 0 4.605-2.805 5.625-5.475 5.925.435.375.81 1.095.81 2.22 0 1.605-.015 2.895-.015 3.3 0 .315.225.69.825.57A12.02 12.02 0 0024 12c0-6.63-5.37-12-12-12z"/>
    </svg>
  </th:block>

  <!-- 图库 -->
  <th:block th:if="${#strings.contains(href, '/photos')}">
    <i th:if="${(ni != null and ni.iconPhotos != null and !#strings.isEmpty(ni.iconPhotos)) or !#strings.isEmpty(ac)}"
       th:classappend="${(ni != null and ni.iconPhotos != null and !#strings.isEmpty(ni.iconPhotos)) ? ni.iconPhotos : ac}" class="nav-custom-icon"></i>
    <svg th:if="${(ni == null or ni.iconPhotos == null or #strings.isEmpty(ni.iconPhotos)) and #strings.isEmpty(ac)}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
      <rect x="3" y="3" width="18" height="18" rx="2" ry="2"/><circle cx="8.5" cy="8.5" r="1.5"/><polyline points="21 15 16 10 5 21"/>
    </svg>
  </th:block>

  <!-- 朋友圈 -->
  <th:block th:if="${#strings.contains(href, '/friends-circle')}">
    <i th:if="${(ni != null and ni.iconFriendsCircle != null and !#strings.isEmpty(ni.iconFriendsCircle)) or !#strings.isEmpty(ac)}"
       th:classappend="${(ni != null and ni.iconFriendsCircle != null and !#strings.isEmpty(ni.iconFriendsCircle)) ? ni.iconFriendsCircle : ac}" class="nav-custom-icon"></i>
    <svg th:if="${(ni == null or ni.iconFriendsCircle == null or #strings.isEmpty(ni.iconFriendsCircle)) and #strings.isEmpty(ac)}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
      <path d="M23 19a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h4l2-3h6l2 3h4a2 2 0 0 1 2 2z"/><circle cx="12" cy="13" r="4"/>
    </svg>
  </th:block>

  <!-- 便签墙 -->
  <th:block th:if="${#strings.contains(href, '/wishes')}">
    <i th:if="${(ni != null and ni.iconWishes != null and !#strings.isEmpty(ni.iconWishes)) or !#strings.isEmpty(ac)}"
       th:classappend="${(ni != null and ni.iconWishes != null and !#strings.isEmpty(ni.iconWishes)) ? ni.iconWishes : ac}" class="nav-custom-icon"></i>
    <svg th:if="${(ni == null or ni.iconWishes == null or #strings.isEmpty(ni.iconWishes)) and #strings.isEmpty(ac)}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
      <path d="M15.5 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V8.5L15.5 3Z"/><path d="M14 3v4a2 2 0 0 0 2 2h4"/><path d="M8 13h8"/><path d="M8 17h8"/>
    </svg>
  </th:block>

  <!-- 装备 -->
  <th:block th:if="${#strings.contains(href, '/equipments')}">
    <i th:if="${(ni != null and ni.iconEquipments != null and !#strings.isEmpty(ni.iconEquipments)) or !#strings.isEmpty(ac)}"
       th:classappend="${(ni != null and ni.iconEquipments != null and !#strings.isEmpty(ni.iconEquipments)) ? ni.iconEquipments : ac}" class="nav-custom-icon"></i>
    <svg th:if="${(ni == null or ni.iconEquipments == null or #strings.isEmpty(ni.iconEquipments)) and #strings.isEmpty(ac)}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
      <rect x="2" y="7" width="20" height="14" rx="2" ry="2"/><polyline points="16 7 16 2 8 2 8 7"/>
    </svg>
  </th:block>

  <!-- 未匹配已知路径：先查自定义页面图标列表，再 annotation fallback -->
  <th:block th:if="${!#strings.contains(href, '/archives') and !#strings.contains(href, '/tags') and !#strings.contains(href, '/categories') and !#strings.contains(href, '/about') and !#strings.contains(href, '/moments') and !#strings.contains(href, '/links') and !#strings.contains(href, '/guestbook') and !#strings.contains(href, '/projects') and !#strings.contains(href, '/photos') and !#strings.contains(href, '/friends-circle') and !#strings.contains(href, '/wishes') and !#strings.contains(href, '/equipments')}"
            th:with="customIcons=${theme.config.basic != null ? theme.config.basic.customNavIcons : null}">
    <!--/* 遍历自定义页面图标列表匹配 */-->
    <th:block th:if="${customIcons != null}" th:each="ci : ${customIcons}">
      <i th:if="${ci.slug != null and !#strings.isEmpty(ci.slug) and #strings.contains(href, '/' + ci.slug) and ci.icon != null and !#strings.isEmpty(ci.icon)}"
         th:classappend="${ci.icon}" class="nav-custom-icon"></i>
    </th:block>
    <!--/* annotation fallback（自定义列表未匹配时） */-->
    <i th:if="${!#strings.isEmpty(ac)}" th:classappend="${ac}" class="nav-custom-icon"></i>
    <!--/* 最终默认图标（无自定义匹配且无 annotation 时） */-->
    <svg th:if="${#strings.isEmpty(ac) and (customIcons == null or #lists.isEmpty(customIcons))}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
      <circle cx="12" cy="12" r="10"/><path d="M12 16v-4M12 8h.01"/>
    </svg>
  </th:block>

</th:block>
</html>
