<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<div th:fragment="side-fragment" class="sidebar-container">
    <section>
        <div class="sidebar-header">
            <span class="widget-title">
                Recent
            </span>
        </div>
        <ul class="widget-list widget-list2 recent">
            <th:block th:with="
            isLogin = ${SessionUtils.isLogin(request)},
            posts = ${@postService.getLatestPosts(@siteConfig.recentSize)}, 
            passCookie = ${CookieUtils.getCookie(request, CookieUtils.PASSWORD_COOKIE)}">
                <th:block th:if="not ${#lists.isEmpty(posts)}">
                    <th:block th:each="newBlog : ${posts}">
                        <th:block th:with="passwordCorrect=${isLogin or #strings.isEmpty(newBlog.password) or (passCookie!=null and CookieUtils.checkPassCookie(passCookie, newBlog, null))}">
                            <li th:class="${!passwordCorrect}?'side-list-item-lock'">
                                <a th:href="@{${newBlog.link}}" 
                                    class="tag tooltipped tooltipped-n">
                                    <th:block th:if="${!passwordCorrect}">
                                        <th:block th:text="${'加密文章 ' + newBlog.postId}"></th:block>
                                        <span style="float: right">🔒</span>
                                    </th:block>
                                    <th:block th:if="${passwordCorrect}" th:text="${newBlog.postTitle}"></th:block>
                                </a>
                            </li>
                        </th:block>
                    </th:block>
                </th:block>
            </th:block>
        </ul>
    </section>
    <section>
        <div class="sidebar-header">
            <span class="widget-title">
                Most Popular
            </span>
        </div>
        <ul class="widget-list widget-list2 recent">
            <th:block th:with="
            isLogin = ${SessionUtils.isLogin(request)},
            posts = ${@postService.getPopularPosts(@siteConfig.popularSize, PostTypeEnum.POST)}, 
            passCookie = ${CookieUtils.getCookie(request, CookieUtils.PASSWORD_COOKIE)}">
                <th:block th:if="not ${#lists.isEmpty(posts)}">
                    <th:block th:each="newBlog : ${posts}">
                        <th:block th:with="passwordCorrect=${isLogin or #strings.isEmpty(newBlog.password) or (passCookie!=null and CookieUtils.checkPassCookie(passCookie, newBlog, null))}">
                            <li th:class="${!passwordCorrect}?'side-list-item-lock'">
                                <a th:href="@{${newBlog.link}}" 
                                    class="tag tooltipped tooltipped-n">
                                    <th:block th:if="${!passwordCorrect}">
                                        <th:block th:text="${'加密文章 ' + newBlog.postId}"></th:block>
                                        <span style="float: right">🔒</span>
                                    </th:block>
                                    <th:block th:if="${passwordCorrect}">
                                        [[${newBlog.postTitle}]]
                                        <span th:title="${newBlog.commentCount + '条评论'}" style="float: right">[[${newBlog.commentCount > 99?'99+':newBlog.commentCount}]]</span>
                                    </th:block>
                                </a>
                            </li>
                        </th:block>
                    </th:block>
                </th:block>
            </th:block>
        </ul>
    </section>
    <section>
        <nav class="nav-menu">
            <ul th:with="uri=${request.requestURI}">
                <li><a href="/"
                       th:classappend="${uri == '/' ? 'current':''}">Home</a></li>
                <li><a href="/archives.html"
                       th:classappend="${uri == '/archives.html' || uri.startsWith('/archives.html/') ? 'current':''}"
                       title="Archives">Archives</a></li>
                <li><a href="/about.html"
                       th:classappend="${uri == '/about.html' || uri.startsWith('/about.html/') ? 'current':''}"
                       title="About">About</a></li>
            </ul>
        </nav>
    </section>
    <section>
        <form method="GET" action="/search" accept-charset="utf-8">
            <input class="search-input" type="text" name="keyword" id="searchbox" autocomplete="off" placeholder="Search...">
        </form>
    </section>
    <section>
        <div class="sidebar-header">
            <span class="widget-title">
                Tags
            </span>
        </div>
        <div class="">
            <ul class="widget-tags">
            <th:block th:with="hotTags=${@metaService.listMetaCount(MetaTypeEnum.TAG, @siteConfig.tagSize, PostTypeEnum.POST)}">
                    <th:block  th:if="${null != hotTags}">
                        <th:block th:each="hotTag : ${hotTags}">
                            <li>
                                <a class="widget-tag" rel="tag" th:href="@{'/tag/' + ${hotTag.urlEncodedFriendlyName}}">
                                    <th:block th:text="${hotTag.name}"></th:block>
                                </a>
                            </li>
                        </th:block>
                    </th:block>
                </th:block>
            </ul>
        </div>
    </section>
</div>
</html>