{{define "card"}}
<article class="card" id="card-{{.ID}}"{{if .SelfPoll}} hx-get="/fragments/downloads/{{.ID}}/card" hx-trigger="every {{.PollEvery}}" hx-swap="outerHTML"{{end}}>
  <div class="card-top">
    <div>
      <div class="card-title">{{if eq .MediaType "series"}}<span class="type-ico" title="сериал">📺</span> {{else if eq .MediaType "movie"}}<span class="type-ico" title="фильм">🎬</span> {{end}}<a href="/download/{{.ID}}" style="color:inherit">{{.Title}}</a></div>
      <div class="hash-row">
        <span class="hash-label">ID:</span>
        <span class="hash">{{.ID}}</span>
        <button class="copy-btn" type="button" onclick="copyHash(this,'{{.ID}}')">⧉ копировать</button>
      </div>
    </div>
    {{template "status_badge" .State}}
  </div>

  <div class="card-life">
    <span>{{if .Added}}{{.Added}} <span class="ago">({{.AddedAgo}})</span>{{else}}—{{end}}</span>
    <span class="sep">·</span>
    <span>{{.Size}}</span>
    <span class="sep">·</span>
    <span title="рейтинг раздачи (отдано/скачано)">↑ {{.Ratio}}</span>
  </div>

  {{if .IsDownloading}}{{template "progress" .Progress}}{{end}}

  <div class="card-foot">
    {{if .ActionError}}<span class="card-meta" style="color:var(--st-err)">{{.ActionError}}</span>{{else}}<span class="card-meta">{{if .Note}}{{.Note}}{{else if .Error}}{{.Error}}{{end}}</span>{{end}}
    <div class="card-acts">
      {{if .Reviewable}}<a class="btn btn-primary btn-sm" href="/review/{{.ID}}">Ревью →</a>{{end}}
      {{if .Undoable}}<form method="post" action="/ui/downloads/{{.ID}}/undo" hx-post="/ui/downloads/{{.ID}}/undo" hx-target="#card-{{.ID}}" hx-swap="outerHTML"><input type="hidden" name="surface" value="list"><button class="btn btn-sm btn-danger" type="submit">↩ Откатить</button></form>{{end}}
      {{if .Relinkable}}<form method="post" action="/ui/downloads/{{.ID}}/relink" hx-post="/ui/downloads/{{.ID}}/relink" hx-target="#card-{{.ID}}" hx-swap="outerHTML"><input type="hidden" name="surface" value="list"><button class="btn btn-sm" type="submit">Привязать заново</button></form>{{end}}
      {{if .Retriable}}<form method="post" action="/ui/downloads/{{.ID}}/retry" hx-post="/ui/downloads/{{.ID}}/retry" hx-target="#card-{{.ID}}" hx-swap="outerHTML"><input type="hidden" name="surface" value="list"><button class="btn btn-sm" type="submit">Повторить</button></form>{{end}}
      {{if not .Terminal}}<form method="post" action="/ui/downloads/{{.ID}}/cancel" hx-post="/ui/downloads/{{.ID}}/cancel" hx-target="#card-{{.ID}}" hx-swap="outerHTML"><input type="hidden" name="surface" value="list"><button class="btn btn-sm btn-danger" type="submit">{{if .Reviewable}}Отклонить{{else}}Отменить{{end}}</button></form>{{end}}
    </div>
  </div>
</article>
{{end}}
