{{define "post/body"}}
<article class="j13-post" data-post-id="{{.PostID}}" data-csrf="{{.CSRF}}" data-logged-in="{{if .LoggedIn}}1{{else}}0{{end}}">
  <header class="j13-post__header">
    <h1 class="j13-post__title">{{.PostTitle}}</h1>
    <div class="j13-post__meta">
      {{if .Pinned}}<span class="j13-tag j13-tag--pin">置顶</span>{{end}}
      {{if .Featured}}<span class="j13-tag j13-tag--feat">精华</span>{{end}}
      {{if .EditLocked}}<span class="j13-tag">禁编</span>{{end}}
      {{if .CommentsLocked}}<span class="j13-tag">已结贴</span>{{end}}
      {{if .PostTypeLabel}}<span class="j13-tag">{{.PostTypeLabel}}</span>{{end}}
      {{if .BoardName}}<a class="j13-tag" href="/board/{{.BoardID}}">{{.BoardName}}</a>{{end}}
      {{if .AuthorID}}<a href="/user/{{.AuthorID}}">{{.AuthorName}}</a>{{else}}<span>{{.AuthorName}}</span>{{end}}
      <span>{{.CreatedLabel}}</span>
      <span>{{.ViewCount}} 阅读</span>
    </div>
    {{if .LoggedIn}}
    <div class="j13-post__actions">
      <form method="post" action="/post/{{.PostID}}/like" class="j13-inline-form">
        <input type="hidden" name="_csrf" value="{{.CSRF}}"/>
        <button type="submit">{{if .Liked}}取消赞{{else}}赞{{end}} ({{.LikeCount}})</button>
      </form>
      <form method="post" action="/post/{{.PostID}}/favorite" class="j13-inline-form">
        <input type="hidden" name="_csrf" value="{{.CSRF}}"/>
        <button type="submit">{{if .Favorited}}取消收藏{{else}}收藏{{end}}</button>
      </form>
      {{if .CanEdit}}<a class="j13-linkbtn" href="/post/{{.PostID}}/edit">编辑</a>{{end}}
      {{if .CanReportPost}}
      <details class="j13-report">
        <summary class="j13-linkbtn">举报</summary>
        <form method="post" action="/post/{{.PostID}}/report" class="j13-report__form">
          <input type="hidden" name="_csrf" value="{{.CSRF}}"/>
          <label>原因
            <select name="reason" required>
              <option value="">请选择</option>
              <option value="spam">垃圾广告</option>
              <option value="abuse">人身攻击 / 辱骂</option>
              <option value="illegal">违法违规</option>
              <option value="irrelevant">内容无关 / 灌水</option>
              <option value="other">其他</option>
            </select>
          </label>
          <label>补充说明（可选）
            <input name="detail" maxlength="500" placeholder="可选"/>
          </label>
          <button type="submit" class="j13-btn j13-btn--sm">提交举报</button>
        </form>
      </details>
      {{end}}
    </div>
    {{end}}
    {{if .IsAdmin}}
    <div class="j13-post__admin" role="group" aria-label="管理操作">
      <form method="post" action="/post/{{.PostID}}/admin/pin" class="j13-inline-form">
        <input type="hidden" name="_csrf" value="{{.CSRF}}"/>
        <input type="hidden" name="enable" value="{{if .GlobalPinned}}0{{else}}1{{end}}"/>
        <button type="submit" class="j13-linkbtn">{{if .GlobalPinned}}取消全局置顶{{else}}全局置顶{{end}}</button>
      </form>
      <form method="post" action="/post/{{.PostID}}/admin/board-pin" class="j13-inline-form">
        <input type="hidden" name="_csrf" value="{{.CSRF}}"/>
        <input type="hidden" name="enable" value="{{if .BoardPinned}}0{{else}}1{{end}}"/>
        <button type="submit" class="j13-linkbtn">{{if .BoardPinned}}取消版内置顶{{else}}版内置顶{{end}}</button>
      </form>
      <form method="post" action="/post/{{.PostID}}/admin/feature" class="j13-inline-form">
        <input type="hidden" name="_csrf" value="{{.CSRF}}"/>
        <input type="hidden" name="enable" value="{{if .Featured}}0{{else}}1{{end}}"/>
        <button type="submit" class="j13-linkbtn">{{if .Featured}}取消精华{{else}}设为精华{{end}}</button>
      </form>
      <form method="post" action="/post/{{.PostID}}/admin/edit-lock" class="j13-inline-form">
        <input type="hidden" name="_csrf" value="{{.CSRF}}"/>
        <input type="hidden" name="enable" value="{{if .EditLocked}}0{{else}}1{{end}}"/>
        <button type="submit" class="j13-linkbtn">{{if .EditLocked}}允许编辑{{else}}禁止编辑{{end}}</button>
      </form>
      <form method="post" action="/post/{{.PostID}}/admin/comments-lock" class="j13-inline-form">
        <input type="hidden" name="_csrf" value="{{.CSRF}}"/>
        <input type="hidden" name="enable" value="{{if .CommentsLocked}}0{{else}}1{{end}}"/>
        <button type="submit" class="j13-linkbtn">{{if .CommentsLocked}}解锁评论{{else}}锁定评论{{end}}</button>
      </form>
      <form method="post" action="/post/{{.PostID}}/admin/delete" class="j13-inline-form" onsubmit="return confirm('确认移入回收站？');">
        <input type="hidden" name="_csrf" value="{{.CSRF}}"/>
        <button type="submit" class="j13-linkbtn">移入回收站</button>
      </form>
    </div>
    {{end}}
  </header>
  <div class="j13-post__content post-detail-content">{{safeHTML .BodyHTML}}</div>
</article>

<section class="j13-comments" id="comments">
  <h2>评论 ({{.CommentCount}})</h2>
  {{if not .Comments}}
  <p class="j13-empty">暂无评论。</p>
  {{else}}
  <ul class="j13-comment-list">
    {{range .Comments}}
    <li class="j13-comment" id="floor-{{.Floor}}" data-comment-id="{{.ID}}" data-floor="{{.Floor}}" data-author="{{.AuthorName}}">
      <div class="j13-comment__meta">
        <span class="j13-comment__floor">#{{.Floor}}</span>
        {{if .AuthorID}}<a href="/user/{{.AuthorID}}">{{.AuthorName}}</a>{{else}}<span>{{.AuthorName}}</span>{{end}}
        <span>{{.CreatedLabel}}</span>
        {{if .IsPrivate}}<span class="j13-tag">私密</span>{{end}}
        {{if .ReplyToFloor}}
        <span class="j13-comment__reply-to">回复 <a href="#floor-{{.ReplyToFloor}}">#{{.ReplyToFloor}}</a>{{if .ReplyToAuthor}} {{.ReplyToAuthor}}{{end}}</span>
        {{end}}
      </div>
      {{if .ContentHidden}}
      <p class="j13-muted">（私密评论不可见）</p>
      {{else}}
      <div class="j13-comment__body">{{safeHTML .Content}}</div>
      {{end}}
      {{if $.LoggedIn}}
      <div class="j13-comment__actions">
        <form method="post" action="/post/{{$.PostID}}/comments/{{.ID}}/like" class="j13-inline-form">
          <input type="hidden" name="_csrf" value="{{$.CSRF}}"/>
          <button type="submit" class="j13-linkbtn">{{if .Liked}}取消赞{{else}}赞{{end}} ({{.LikeCount}})</button>
        </form>
        {{if not $.CommentsLocked}}
        <button type="button" class="j13-linkbtn j13-comment__reply-btn" data-reply-to="{{.ID}}" data-reply-floor="{{.Floor}}" data-reply-author="{{.AuthorName}}">回复</button>
        {{end}}
        {{if .CanReport}}
        <details class="j13-report">
          <summary class="j13-linkbtn">举报</summary>
          <form method="post" action="/post/{{$.PostID}}/comments/{{.ID}}/report" class="j13-report__form">
            <input type="hidden" name="_csrf" value="{{$.CSRF}}"/>
            <label>原因
              <select name="reason" required>
                <option value="">请选择</option>
                <option value="spam">垃圾广告</option>
                <option value="abuse">人身攻击 / 辱骂</option>
                <option value="illegal">违法违规</option>
                <option value="irrelevant">内容无关 / 灌水</option>
                <option value="other">其他</option>
              </select>
            </label>
            <label>补充说明（可选）
              <input name="detail" maxlength="500" placeholder="可选"/>
            </label>
            <button type="submit" class="j13-btn j13-btn--sm">提交举报</button>
          </form>
        </details>
        {{end}}
      </div>
      {{end}}
    </li>
    {{end}}
  </ul>
  {{end}}

  {{if .LoggedIn}}
  {{if .CommentsLocked}}
  <p class="j13-muted">评论已锁定。</p>
  {{else}}
  <form class="j13-comment-form" method="post" action="/post/{{.PostID}}/comments" id="comment-form">
    <input type="hidden" name="_csrf" value="{{.CSRF}}"/>
    <input type="hidden" name="reply_to" id="comment-reply-to" value=""/>
    <p class="j13-muted j13-comment-reply-hint" id="comment-reply-hint" hidden></p>
    <label for="comment-content">发表评论</label>
    <textarea id="comment-content" name="content" rows="4" required maxlength="8000"></textarea>
    <label class="j13-check">
      <input type="checkbox" name="is_private" value="1"/>
      私密评论（仅相关可见）
    </label>
    <div class="j13-form__row">
      <button type="submit">提交</button>
      <button type="button" class="j13-btn-secondary" id="comment-reply-clear" hidden>取消回复</button>
    </div>
  </form>
  {{end}}
  {{else}}
  <p><a href="/login?redirect={{.PostPath}}">登录</a> 后回复。</p>
  {{end}}
</section>
{{end}}
