<% cache ['board-view', board] do %>
  <% if board.ordered_lists.any? %>
    <ul class="board js-sortable-lists" data-board-id="<%= board.id %>">
      <% board.ordered_lists.each do |list| %>
        <% cache ['board-list', list] do %>

          <li class="list" data-list-id="<%= list.id %>" data-move-url="<%= move_project_board_list_path(current_project, board, list) %>">
            <div class="list-header">
              <h4>
                <%= list.name %>
                <span class="js-list-count badge bg-secondary pull-right"><%= list.cards.count %></span>
              </h4>

              <div class="list-actions">
                <%=
                link_to(
                  "#modal-list-edit-#{list.id}",
                  data: { bs_toggle: 'modal' }
                ) do
              %>
                <i class="fa-solid fa-pencil"></i> Edit
              <% end %>
              <%=
                link_to(
                  [current_project, board, list],
                  class: 'text-error-hover',
                  data: { confirm: "Are you sure?\n\nProceeding will delete this list from the methodology, along with any associated tasks." },
                  method: 'delete'
                ) do %>
                <i class="fa-solid fa-trash"></i> Delete
              <% end %>
            </div>
          </div>

          <ul class="list-cards js-sortable-cards">
            <% list.ordered_cards.each do |card| %>
              <% cache ['board-list-card', card] do %>
                <li class="card" data-card-id="<%= card.id %>" data-move-url="<%= move_project_board_list_card_path(current_project, board, list, card) %>">
                  <%= link_to project_board_list_card_path(current_project, board, list, card) do %>
                    <div class="card-details">
                      <div class="card-title"><%= card.name %></div>
                      <div class="card-badges">
                        <% if card.due_date %>
                          <% case (card.due_date - Date.today).to_i %>
                          <% when -Float::INFINITY..-1 %>
                          <div class="badge bg-danger">
                            <% when 0 %>
                            <div class="badge bg-warning">
                            <% else %>
                              <div class="badge bg-success">
                              <% end %>
                              <span><i class="fa-regular fa-clock"></i></span>
                              <span><%= card.due_date.strftime('%b %-d') %></span>
                            </div>
                          <% end %>
                        </div>
                        <div class="card-members">
                          <% card.assignees.each do |user| %>
                            <%= avatar_image(user, size: 30) %>
                          <% end %>
                        </div>
                      </div>
                    <% end %>
                  </li>
                <% end %> <%# board-list-card cache %>
              <% end %>
            </ul>
            <%= link_to 'Add a task...', new_project_board_list_card_path(current_project, board, list), class: 'card-new' %>
          </li>
        <% end %> <%# board-list cache %>
      <% end %>

      <li class="list list-new">
        <a
          href="#modal-list-new"
          data-bs-toggle="modal"
        >
          Add a list...
        </a>
      </li>
    </ul>
  <% else %>
    <%= render 'shared/empty_state',
      actions_partial: 'boards/board/empty_state_actions',
      name: 'list',
      docs_link: 'https://dradis.com/support/guides/projects/methodologies.html#list',
      text: 'Use lists to organize tasks in the methodology board.'
    %>
  <% end %>
<% end %><%# /board-view cache %>
