<html lang="en">
<head>
  {{ template "static" }}
  <link 
    href="/static/index.css" 
    rel="stylesheet" 
  >
  
  {{ template "static-meta" }}
</head>

<body>
  <h1 class="display-1 text-center">Welcome to Micrach</h1>
  
  <div class="container">
    {{ template "post-form" }}
    
    <div id="" class="row row-cols-auto gy-4 mb-4">
      {{ range $Post := .Threads }}
      <div class="col col-sm-6 col-md-4 col-lg-3">
        <div class="card">

          {{ $length := len $Post.Files }} 
          {{ if gt $length 0 }}
          {{ $FirstFile := index $Post.Files 0 }}
          <img 
            src="/uploads/{{$Post.ID}}/{{$FirstFile.Name}}" 
            class="card-img-top"
            alt="Uploaded picture"
          >
          {{ end }}

          <div class="card-body">
            {{ if ne $Post.Title "" }}
            <h5 class="card-title">{{$Post.Title}}</h5>
            {{ end }}
            <p class="card-text">{{$Post.Text}}</p>
            <a href="/{{$Post.ID}}" class="btn btn-outline-primary">Open</a>
          </div>
        </div>
      </div>
      {{ end }}
    </div>

    <div class="col col-12">
      <nav aria-label="Page navigation">
        <ul id="pagesList" class="pagination justify-content-center">
          {{ $ActivePage := .Page }}
          {{ range $i := Iterate .PagesCount }}
            <li class="page-item {{ if (eq $i $ActivePage) }} active {{ end }}">
              <a class="page-link" href="/?page={{ $i }}">{{ $i }}</a>
            </li>
          {{ end }}
        </ul>
      </nav>
    </div>
    
  </div>
</body>

</html>