<!DOCTYPE html>
<html xmlns:th="https://www.thymeleaf.org"
    th:replace="~{modules/layouts/layout :: layout(_head = null,_content = ~{::content},_title = ${title + ' - ' + site.title})}">

<th:block th:fragment="content">

    <div class="page_main uk-width-2-3@m">

        <th:block th:replace="~{modules/header}" />

        <div id="pjax-container" th:with="
            selectedTag = ${#lists.isEmpty(param.tag) ? null : param.tag[0]},
            friendPage = ${friends}
        ">

            <div class="blog_list">
                <div class="blog_list_inner" uk-height-viewport="offset-top: true">

                    <!-- 作者姓名导航栏（参照图库风格新增） -->
                    <div class="friends_cat_nav">
                        <ul id="cat_nav_items">
                            <li>
                                <!-- 全部按钮 -->
                                <a th:attr="data-href=@{/friends}"
                                    th:classappend="${#strings.isEmpty(selectedTag) ? 'active' : ''}" class="cat-link">
                                    全部<span></span>
                                </a>
                            </li>
                            <!-- 遍历所有作者 -->
                            <th:block th:each="authorLink : ${authors}">
                                <li>
                                    <a th:attr="data-href=@{/friends(tag=${authorLink.spec.displayName})}"
                                        th:classappend="${#strings.equals(selectedTag, authorLink.spec.displayName) ? 'active' : ''}"
                                        th:text="${authorLink.spec.displayName}" class="cat-link">
                                        <span></span>
                                    </a>
                                </li>
                            </th:block>
                        </ul>
                    </div>

                    <div id="post_item" class="moment_list">

                        <div th:each="postInfo, iterstat: ${friendPage.items}" th:id="${'post-'+postInfo.metadata.name}"
                            class="loop_content p_item moment_item uk-animation-slide-bottom-small"
                            th:if="${postInfo.spec != null and not #strings.isEmpty(postInfo.spec.description)}"
                            th:with="spec = ${postInfo.spec}">

                            <div class="p_item_inner">

                                <div class="list_user_meta">
                                    <div class="avatar">
                                        <img th:src="@{${spec.logo}}">
                                    </div>

                                    <div class="name">
                                        <div class="avatar_title">
                                            <a target="_blank" th:href="${spec.authorUrl}">
                                                [[${spec.author}]]
                                            </a>
                                        </div>

                                        <time itemprop="datePublished"
                                            th:datetime="${#dates.format(spec.pubDate, 'yyyy-MM-dd HH:mm')}">
                                            <th:block th:replace="~{modules/widgets/time :: time(${spec.pubDate})}">
                                            </th:block>
                                        </time>
                                    </div>
                                </div>

                                <div class="blog_content">
                                    <div class="entry-content">
                                        <div class="p_title moment-collapse-container">
                                            <a target="_blank" th:href="${spec.postLink}">
                                                <div th:utext="${spec.description}"></div>
                                            </a>
                                        </div>
                                        <!-- 图片列表 -->
                                        <div class="img_list img-dynamic-container">
                                            <div class="list_inner"
                                                th:with="imgRaw=${spec.imageFiles},isImgList=${not #strings.isEmpty(imgRaw)}"
                                                th:attr="num=${isImgList ? #arrays.length(imgRaw.split(',')) : 0}">
                                                <!-- 仅使用 imageFiles；字段缺失或为空时不显示图片 -->
                                                <th:block th:if="${isImgList}">
                                                    <th:block th:with="imgArray=${imgRaw.split(',')}">
                                                        <th:block th:each="url : ${imgArray}"
                                                            th:with="cleanUrl=${#strings.trim(url)}">
                                                            <span class="fancybox mo_img"
                                                                th:if="${not #strings.isEmpty(cleanUrl)}"
                                                                th:href="|/upload/image-host/${cleanUrl}|"
                                                                th:data-fancybox="${'post-' + postInfo.metadata.name}">
                                                                <img class="lazy"
                                                                    src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="
                                                                    th:data-src="|/upload/image-host/${cleanUrl}|"
                                                                    alt="">
                                                            </span>
                                                        </th:block>
                                                    </th:block>
                                                </th:block>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <!-- 空数据 -->
                        <th:block th:if="${#lists.isEmpty(friendPage.items)}">
                            <th:block th:replace="~{macro/tpl/content-none}" />
                        </th:block>

                    </div>

                    <!-- 分页：必须保持在 blog_list_inner 里面 -->
                    <th:block th:if="${friendPage.totalPages>1}">
                        <div id="t_pagination">
                            <div class="post-paging">
                                <a th:if="${friendPage.hasNext()}" th:data="${friendPage.nextUrl}"
                                    th:text="${theme.config.base_set.site_page}"></a>
                                <form class="page-jump-form" method="get" action="/friends">
                                    <span class="page-jump-label">转到</span>
                                    <input th:if="${not #strings.isEmpty(selectedTag)}" type="hidden" name="tag"
                                        th:value="${selectedTag}" />
                                    <span class="page-jump-input-wrap">
                                        <button class="page-jump-step page-jump-step-down" type="button"
                                            title="减少页码" aria-label="减少页码"><i class="ri-subtract-line"
                                                aria-hidden="true"></i></button>
                                        <input class="page-jump-input" type="number" name="page" min="1"
                                            th:max="${friendPage.totalPages}" th:value="${friendPage.page}"
                                            inputmode="numeric" aria-label="页码" autocomplete="off" required />
                                        <button class="page-jump-step page-jump-step-up" type="button"
                                            title="增加页码" aria-label="增加页码"><i class="ri-add-line"
                                                aria-hidden="true"></i></button>
                                    </span>
                                    <span class="page-jump-total">/ [[${friendPage.totalPages}]]</span>
                                    <button class="page-jump-submit" type="submit" title="跳转到指定页"
                                        aria-label="跳转到指定页"><i class="ri-arrow-right-line"></i></button>
                                </form>
                            </div>
                        </div>
                    </th:block>

                    <div id="comment_form_reset"></div>

                </div>
            </div>

        </div>

        <th:block th:replace="~{modules/footer-main}" />

    </div>
</th:block>

</html>
