<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <link rel="icon" type="image/png" href="/favicon.png" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="stylesheet" href="/style.css" />
    <title>Levels</title>

    <style>
      .level {
        width: 100%;
        height: 4em;
        background-color: var(--background-color-2);
        border-radius: 2em;
        padding: 1em;
        display: flex;
        flex-direction: row;
        align-items: stretch;
        gap: 0.5em;
      }
      .line {
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
      }
      .name {
        flex: 1 1 0px;
        min-width: 0;
        font-size: 1.2em;
      }
      .id {
        flex: 0 0 auto;
      }
      .level-img {
        flex: 0 0 auto;
      }
      .level-right {
        flex: 1 1 0px;
        min-width: 0;
      }
      .pagination {
        display: flex;
        flex-direction: row;
        gap: 1em;
      }
      img {
        width: auto;
        height: 100%;
      }
      .levels {
        width: 600px;
        max-width: 90vw;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 1em;
      }
      .level a {
        text-decoration: none;
      }
    </style>
  </head>
  <body style="display: flex; flex-direction: column; align-items: center; gap: 1em">
    <div class="levels">
    <%- levels.each do |id, name, username, difficulty_community, difficulty_set, demon_difficulty_int, featured, epic| -%>
      <div class="level">
        <%=
          difficulty = (difficulty_set || difficulty_community).try { |n| LevelDifficulty.new(n) }
          demon_difficulty = demon_difficulty_int.try { |n| DemonDifficulty.new(n) }
          "<img src='#{Templates.get_difficulty_icon(difficulty, featured, epic, demon_difficulty)}' class='level-img'>"
        %>
        <div class="level-right">
          <span class="line"><span class="name"><a href="/levels/<%= id %>"><%= name %></a></span><span class="id dim">#<%= id %></span></span>
          <small>by <a href="/user/<%= username %>"><%= username %></a></small><br>
        </div>
      </div>
    <%- end -%>
    </div>
    <div class="pagination">
      <%- if page > 0 -%>
        <a href="?page=<%= page - 1 %>"><</a>
      <%- end -%>
      <%- if total_levels > ((page + 1) * levels_per_page) -%>
        <a href="?page=<%= page + 1 %>">></a>
      <%- end -%>
    </div>
  </body>
</html>
