<div id="nm-list">
  <% APP_DATA[instance.zone.to_sym][:nms].each do |nm| %>
    <% is_popped = instance.pops.filter { |pop| (Time.current - 120.minutes) <= pop.created_at }.any? { |pop| pop.name == nm[:name].parameterize } %>
    <section class="<%= class_names(popped: is_popped, missing_reqs: has_missing_reqs?(nm, forecast)) %>">
      <div>
        <img src="<%= "/#{nm[:element]}.png" %>" alt="<%= nm[:element] %>" width="30" />
      </div>
      <div class="meta">
        <h3 class="nm-info">
          <span class="badge">LV<%= nm[:level].to_s.rjust(2, "0") %></span>
          <%= nm[:name] %>
          <% if nm[:drops] %>
            <span title="<%= nm[:drops] %>" style="font-size: 14px;">✨</span>
          <% end %>
          <% if nm[:weather] %>
            <img src="/weather/<%= nm[:weather] %>.png" title="during <%= nm[:weather] %> only" width="15" />
          <% end %>
        </h3>
        <div class="spawn-info">
          «
          <strong><%= nm[:spawned_by][:name] %></strong>
          <% if nm[:spawned_by][:night_only] %>
            <span title="only at night">🌙</span>
          <% end %>
          <% if nm[:spawned_by][:weather] %>
            <img src="/weather/<%= nm[:spawned_by][:weather] %>.png" title="during <%= nm[:spawned_by][:weather] %> only" width="15" />
          <% end %>
          <small class="badge">LV<%= nm[:spawned_by][:level].to_s.rjust(2, "0") %></small>
        </div>
      </div>
      <div>
        <% if is_popped %>
          <% pop = instance.pops.find { |pop| pop.name == nm[:name].parameterize } %>
          <% mins = ActiveSupport::Duration.build(Time.current - pop.created_at) %>
          » <%= (120.minutes - mins).in_minutes.floor %>m
          <span class="progress-container">
            <span class="progress-bar" style="width: <%= (mins.in_minutes / 120) * 100 %>%"></span>
          </span>
        <% else %>
          <% if nm[:weather] && forecast[0][:curr_weather] != nm[:weather] %>
            <% next_pattern = forecast.find { |f| f[:curr_weather] == nm[:weather] } %>
            <%= Weather.get_weather_name(nm[:weather]) %> in <%= ((next_pattern[:time] - Time.now.utc) / 1.minutes).floor %>m
          <% end %>
          <% if nm[:spawned_by][:weather] && forecast[0][:curr_weather] != nm[:spawned_by][:weather] %>
            <% next_pattern = forecast.find { |f| f[:curr_weather] == nm[:spawned_by][:weather] } %>
            <%= Weather.get_weather_name(nm[:spawned_by][:weather]) %> in <%= ((next_pattern[:time] - Time.now.utc) / 1.minutes).floor %>m
          <% end %>
          <% if (nm[:night_only] || nm[:spawned_by][:night_only]) && is_day? %>
            <div>Night in <%= ((Clock.to_earth_time(Clock.get_current_eorzea_time.change(hour: 18)) - Time.now.utc) / 1.minutes).floor %>m</div>
          <% end %>
        <% end %>
      </div>
      <div class="action needs_pwd">
        <% if is_popped %>
          <button
            class="action reset"
            hx-post="/reset?instance=<%= @instance.public_id %>&nm=<%= nm[:name].parameterize %>"
            hx-target="#nm-list"
            hx-select="#nm-list"
            hx-swap="outerHTML"
          >Reset</button>
        <% else %>
          <button
            class="action"
            hx-post="/pop?instance=<%= @instance.public_id %>&nm=<%= nm[:name].parameterize %>"
            hx-target="#nm-list"
            hx-select="#nm-list"
            hx-swap="outerHTML"
          >Pop</button>
        <% end %>
      </div>
    </section>
  <% end %>
</div>