{{define "title"}}{{.Torrent.Name}}{{end}}
{{define "contclass"}}cont-view {{if eq .Torrent.Status 2}}remake{{end}} {{if eq .Torrent.Status 3}}trusted{{end}} {{if eq .Torrent.Status 4}}aplus{{end}}{{end}}
{{ define "make_treeview" }}
{{ range $index, $folder := .Folder.Folders }}
    {{ $folderId := (print $.IdentifierChain "_" $index) }}
    <tr class="tr-filelist tr-folder" style="--nest-level: {{ $.NestLevel }}">
        <td><label for="contents_{{$folderId}}">{{$folder.FolderName}}</label></td>
        <td>{{ fileSize $folder.TotalSize $.T }}</td>
    </tr>
    <tr>
        <td colspan="2">
        <input id="contents_{{$folderId}}" type="checkbox" class="filelist-checkbox">
        <table class="table-filelist">
        {{ template "make_treeview" (makeTreeViewData $folder (inc $.NestLevel) $.T $folderId) }}
        </table>
        </td>
    </tr>
{{ end }}

{{ range .Folder.Files }}
    <tr class="tr-filelist tr-file" style="--nest-level: {{ $.NestLevel }}">
            <td>{{.Filename}}</td>
        <td>{{fileSize .Filesize $.T}}</td>
    </tr>
{{ end }}
{{ end }}

{{define "content"}}
<div style="text-align: left;" class="box">
    {{with .Torrent}}
    {{ range (index $.FormErrors "errors")}}
        <p class="error-text">{{ . }}</p>
    {{end}}
    {{ range (index $.Infos "infos")}}
        <p class="success-text">{{ . }}</p>
    {{end}}
    <div id="torrent-name" class="{{if eq .Status 2}}remake{{end}}
              {{if eq .Status 3}}trusted{{end}}
              {{if eq .Status 4}}aplus{{end}}">
  <p style="text-align: center;" class="torrent-hr">{{.Name}}</p>
   </div>
  <br>
  <table>
      <tr class="torrent-info-row">
      <td class="torrent-info-td torrent-info-label">{{ call $.T "category" }}:</td><td class="torrent-info-td torrent-info-data" style="padding:0"><a href="{{$.URL.Parse (printf "/search?c=%s_%s" .Category .SubCategory) }}">{{ if Sukebei}}{{ call $.T (CategoryName .Category .SubCategory) }}{{else}}{{ call $.T (CategoryName .Category .SubCategory) }}{{end}}</a> <br></td>
      <td class="torrent-info-td torrent-info-label">{{ call $.T "date" }}:</td><td class="torrent-info-td date-full">{{.Date}}</td>
      </tr>
      <tr class="torrent-info-row">
          <td class="torrent-info-td torrent-info-label">{{ call $.T "uploaded_by" }}:</td><td class="torrent-view-td torrent-info-data">{{ genUploaderLink .UploaderID .UploaderName .Hidden }}</td>
          <td class="torrent-info-td torrent-info-label">{{call $.T "seeders"}}:</td><td class="tr-se torrent-info-td">{{if .LastScrape.IsZero}}{{call $.T "unknown"}}{{else}}{{.Seeders}}{{end}}</td>
      </tr>
      <tr class="torrent-info-row">
          <td class="torrent-info-td torrent-info-label">{{ call $.T "website_link" }}:</td><td class="torrent-view-td torrent-info-data">{{if ne .WebsiteLink ""}}<a href="{{.WebsiteLink}}">{{.WebsiteLink}}</a>{{else}}<a href="{{$.Config.WebAddress.Nyaa}}">{{GetHostname $.Config.WebAddress.Nyaa}}{{end}}</td>
          <td class="torrent-info-td torrent-info-label">{{call $.T "leechers"}}:</td><td class="tr-le torrent-info-td">{{if .LastScrape.IsZero}}{{call $.T "unknown"}}{{else}}{{.Leechers}}{{end}}</td>
      </tr>
    <tr class="torrent-info-row">
          <td class="torrent-info-td torrent-info-label">{{call $.T "hash"}}:</td><td style="font-family: monospace;" class="torrent-view-td torrent-info-data">{{.Hash}}</td>
          <td class="torrent-info-td torrent-info-label">{{call $.T "completed"}}:</td><td class="torrent-info-td"><b>{{if .LastScrape.IsZero}}{{call $.T "unknown"}}{{else}}{{.Completed}}{{end}}</b></td>
      </tr>
    <tr class="torrent-info-row">
          <td class="torrent-info-td torrent-info-label">{{call $.T "size"}}:</td><td class="torrent-view-td torrent-info-data">{{ fileSize .Filesize $.T }}</td>
          <td class="torrent-info-td torrent-info-label">{{call $.T "last_scraped"}}</td><td class="torrent-info-td{{if not .LastScrape.IsZero}} date-full">{{formatDateRFC .LastScrape}}{{else}}">{{call $.T "unknown"}}{{end}}</td>
      </tr>
  </table>
<div class="torrent-buttons">
  <a href="{{.Magnet}}" class="form-input btn-green"><div class="magnet-icon"></div> {{call $.T "magnet_link"}}</a>
  {{ if ne .TorrentLink ""}}
  <a href="{{.TorrentLink}}" class="form-input"><div class="download-icon"></div> {{call $.T "torrent_file"}}</a>
  {{end}}
  {{ if gt $.User.ID 0}}
  <a id="reportPopup" href="#" class="form-input">{{ call $.T "report_btn" }}</a>
    {{ if HasAdmin $.User}}
    <a href="{{ genRoute "mod_tdelete" }}?id={{ .ID }}" class="form-input btn-red" onclick="if (!confirm('{{ call $.T "are_you_sure" }}')) return false;">{{ call $.T "delete" }}</a>
    <a href="{{ genRoute "mod_tedit" }}?id={{ .ID }}" class="form-input btn-orange">{{ call $.T "edit" }}</a>
    {{ else if CurrentUserIdentical $.User .UploaderID }}
    <a href="{{ genRoute "user_torrent_delete" }}?id={{ .ID }}" class="form-input btn-red" onclick="if (!confirm('{{ call $.T "are_you_sure" }}')) return false;">{{ call $.T "delete" }}</a>
    <a href="{{ genRoute "user_torrent_edit" }}?id={{ .ID }}" class="form-input btn-orange">{{ call $.T "edit" }}</a>
    {{end}}
{{end}}
  </div>
  <p class="torrent-hr">{{call $.T "description"}}</p>
  {{ if ne .Description ""}}
  <div id="description-box" class="torrent-info-box">{{.Description}}</div>
  {{else}}
  <p>{{ call $.T "no_description" }}</p>
  {{end}}
  <input type="checkbox" id="show-filelist">
  <label class="torrent-hr filelist-control" for="show-filelist">{{call $.T "files"}}</label>
  <div class="torrent-info-box" id="filelist">
    {{ if gt (len .FileList) 0 }}
    {{/* how do i concat lol */}}
    <table class="table-filelist">
      <thead>
        <th style="width: 80%">{{call $.T "file_name"}}</th>
        <th>{{call $.T "size"}}</th>
      </thead>
      <tbody>
        {{ template "make_treeview" (makeTreeViewData $.RootFolder 0 $.T "root") }}
      </tbody>
    </table>
    {{ else }}
      <p>{{ call $.T "no_files" }}</p>
    {{ end }}
  </div>

  <p class="torrent-hr">{{call $.T "comments"}}</p>
  {{range $index, $element := .Comments}}
  <div class="torrent-info-box comment-box">
 <span class="comment-index"><a href="#comment_{{inc $index}}">#{{inc $index}}</a><small style="padding-left: 4px;" class="date-short">{{formatDateRFC .Date}}</small></span>
  <p>{{.Username}}</p>
  <p>{{.Content}}</p>
  </div>
  {{end}}
  {{end}}
  <div style="margin-top: 10px" class="torrent-info-box">
    <form method="post">
                {{ block "csrf_field" $ }}{{end}}
                <div class="comment-form">
                    <div class="comment-text">
                    <h3>{{ if gt .User.ID 0}} {{call $.T "submit_a_comment_as_username" .User.Username}} {{else}} {{call $.T "submit_a_comment_as_anonymous"}} {{end}}</h3>
                    <textarea style="height: 10rem;" placeholder="サンキュー" name="comment" class="form-input up-input"></textarea>
                    </div>
                    <div class="comment-captcha">
                {{block "captcha" (makeCaptchaData .CaptchaID $.T)}}{{end}}
                <button type="submit" class="form-input up-btn">{{call $.T "submit" }}</button>
                    </div>
                </div>
  </form>
  </div>
 </div>
 {{ if gt $.User.ID 0 }}
     <!-- Modal -->
    <div id="modal_mod_tools" class="modal">
        <!-- Modal content -->
        <div class="modal-content">
            <form method="post" action="/report/{{$.Torrent.ID}}">
                <div class="modal-header">
                    <span class="close">&times;</span>
                    <h2>{{ call $.T "report_torrent_number" (print $.Torrent.ID) }}</h2>
                </div>
                <div class="modal-body">
                    <h4>{{ call $.T "report_type" }}</h4>
                        {{ template "csrf_field" $ }}
                        <input type="radio" name="report_type" value="illegal_content" id="illegal" required> <label for="illegal">{{ call $.T "illegal_content" }}</label><br />
                        <input type="radio" name="report_type" value="spam_garbage" id="spam" required> <label for="spam">{{ call $.T "spam_garbage" }}</label><br />
                        <input type="radio" name="report_type" value="wrong_category" id="wrongcat" required> <label for="wrongcat">{{ call $.T "wrong_category" }}</label><br />
                        <input type="radio" name="report_type" value="duplicate_deprecated" id="dup" required> <label for="dup">{{ call $.T "duplicate_deprecated" }}</label><br />
                        {{template "captcha" (makeCaptchaData $.CaptchaID $.T)}}
                </div>
                <div class="modal-footer">
                    <span><button id="confirm_changes" type="submit">{{ call $.T "yes"}}</button>
                    <button class="close" onclick="Modal.CloseActive();">{{ call $.T "no"}}</button></span>
                    <h3>{{ call $.T "are_you_sure" }} </h3>
                </div>
            </form>
        </div>
    </div>
 {{end}}
{{end}}
{{ define "footer_js"}}
<script type="text/javascript" src="{{ $.URL.Parse "/js/modal.js" }}"></script>
<script type="text/javascript">
    // Modal initialization
    Modal.Init({
        elements: document.getElementsByClassName("modal"),
        button: "#reportPopup"
    });
</script>
{{end}}
