<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<th:block th:fragment="renderRecentComment(comment)">
    <th:block th:with="
        passwordCorrect=${PostPassJar.validFromSession(request.session, comment)},
        title=${passwordCorrect ? comment.postTitle : ('加密文章' + comment.postId)}">
        <li th:if="${passwordCorrect}" class="comment">
            <div class="comment-item">
                <div class="detail">
                    <div class="title">
                        <a th:title="${'查看 ' + comment.author + ' 在 ' + title + ' 中的完整评论'}"
                           th:href="@{${'/comments/go/' + comment.id}}">
                           
                            <img 
                                class="avatar" 
                                referrerpolicy="same-origin"
                                loading="lazy"
                                width="20" height="20"
                                th:attr="alt=${comment.author},title=${comment.author}"
                                th:src="${comment.avatarUrl}">
                            [[${' @ ' + title}]]
                        </a>
                        <span th:title="${#temporals.format(comment.createTime, 'yyyy-MM-dd HH:mm:ss')}">[[${AgoUtils.ago(comment.createTime)}]]</span>
                    </div>
                    <span class="comment-content" th:text="${@markdownService.getCommentContentText(comment)}"></span>
                </div>
            </div>
            <div class="comment-children" th:if="${not #lists.isEmpty(comment.subComments)}">
                <th:block th:each="sub,index:${comment.subComments}">
                    <ol class="comment-list" th:insert="~{this::renderRecentComment(${sub})}"></ol>
                </th:block>
            </div>
        </li>
    </th:block>
</th:block>
<div th:fragment="side-fragment(type)" class="sidebar-container" th:with="
isLogin = ${SessionUtils.isLogin(request)}
">
    <section>
        <div class="git-like">
            <div class="stat">
                <div class="stat-item">
                    <h3 th:text="
                    ${@statisticsService.daysSince(2015, 04, 01)}">0</h3>
                    <span>DAYS</span>
                </div>
                <div class="stat-item">
                    <h3 th:text="
                    ${@statisticsService.totalReleasedPostsCount()}">0</h3>
                    <span>POSTS</span>
                </div>
                <div class="stat-item">
                    <h3 th:text="${@statisticsService.totalCommentsCount(
                        CommentStatusEnum.RELEASED)}">0</h3>
                    <span>REPLIES</span>
                </div>
            </div>
            <div class="graph"
            th:utext="${@apiControllerV1.gitLikeStatisticsSvg(15, 5)}"></div>
        </div>
    </section>
    
    <th:block th:with="
    posts = ${@postService.getPopularPosts(@siteConfig.popularSize, PostTypeEnum.POST)}">
        <section th:if="${posts != null and posts.size() > 0}">
            <div class="sidebar-header">
                <div class="widget-title extra">
                    <span class="extra posts">Popular</span>
                    <span class="origin posts">Posts</span>
                </div>
            </div>
            <ul class="widget-list popular">
                <th:block th:if="not ${#lists.isEmpty(posts)}">
                    <th:block th:each="post : ${posts}">
                        <th:block th:with="
                            passwordCorrect=${PostPassJar.validFromSession(request.session, post)},
                            title=${passwordCorrect ? post.postTitle : ('加密文章' + post.postId)}">
                            <li th:class="${!passwordCorrect}?'side-list-item-lock'">
                                <a th:href="@{${post.link}}" th:attr="title=${title}"
                                    class="tag">
                                    <th:block th:if="${!passwordCorrect}">
                                        <span th:text="${title}"></span>
                                        <span class="comment-count" style="float: right">🔒</span>
                                    </th:block>
                                    <th:block th:if="${passwordCorrect}">
                                        <span>[[${title}]]</span>
                                        <span class="comment-count" th:title="${post.commentCount + '条评论'}" style="float: right">[[${post.commentCount}]]</span>
                                    </th:block>
                                </a>
                            </li>
                        </th:block>
                    </th:block>
                </th:block>
            </ul>
        </section>
    </th:block>
    
    <section class="search-section">
        <form method="GET" th:attr="action=@{${type == 'TWEET'?'/tweet/search':'/search'}}" accept-charset="utf-8">
            <input class="search-input" type="text" name="keyword" id="searchbox" autocomplete="off" placeholder="Search...">
        </form>
    </section>
    
    <th:block th:with="hotTags=${@metaService.listMetaCount(MetaTypeEnum.TAG, @siteConfig.tagSize, PostTypeEnum.POST)}">
        <section th:if="${hotTags != null && hotTags.size() > 0}">
	        <div class="sidebar-header">
	            <span class="widget-title extra">
	                <span class="extra tags">Common</span>
	                <span class="origin tags">Tags</span>
	            </span>
	        </div>
	        <ul class="widget-tags">
	            <th:block th:each="hotTag, i : ${hotTags}">
	                <li>
	                    <a
                        th:classappend="'macaron-tag-' + ${i.index % 8}"
	                    class="widget-tag" rel="tag" th:href="@{'/tag/' + ${hotTag.urlEncodedFriendlyName}}">
	                        <th:block th:text="${hotTag.name}"></th:block>
	                    </a>
	                </li>
	            </th:block>
	        </ul>
	    </section>
    </th:block>
    
    <th:block th:with="
            comments = ${@commentService.getLatestComments(@siteConfig.recentCommentSize, PostTypeEnum.POST, PostTypeEnum.PAGE, PostTypeEnum.TWEET)}">
        <section th:if="${comments != null and comments.size() > 0}">
            <div class="sidebar-header">
                <span class="widget-title extra">
                    <span class="extra replies">Recent</span>
                    <span class="origin replies">Replies</span>
                </span>
            </div>
            <ul class="widget-list comments">
                <th:block th:if="not ${#lists.isEmpty(comments)}">
                    <th:block th:each="comment : ${comments}">
                        <th:block th:insert="~{this::renderRecentComment(${comment})}"></th:block>
                    </th:block>
                </th:block>
            </ul>
        </section>
    </th:block>
</div>
</html>