<% status = my_module.my_module_status %>
<div class="status-label">
  <%= t('my_module_statuses.dropdown.status_label') %>
</div>
<div class="dropdown sci-dropdown status-flow-dropdown"
     data-status-changing="<%= my_module.status_changing %>"
     data-status-check-url="<%= status_state_my_module_path(my_module) %>">
  <button class="btn btn-secondary dropdown-toggle <%= 'disabled' if my_module.status_changing || my_module.archived_branch? %>"
          type="button"
          data-toggle="dropdown"
          aria-haspopup="true"
          aria-expanded="true"
          style="<%= "background-color: #{status.color}" %>;">
    <span>
      <% if my_module.status_changing %>
        <i class="fas fa-spinner fa-spin"></i>
        <span><%= t('my_module_statuses.dropdown.status_transitioning_label') %></span>
      <% end %>
      <%= status.name %>
    </span>
    <span class="caret pull-right"></span>
  </button>
  <ul class="dropdown-menu" aria-labelledby="dropdownTaskFlow" id="dropdownTaskFlowList" data-link-url="<%= update_state_my_module_url(my_module) %>">
    <% if can_change_my_module_flow_status?(@my_module) %>
      <% unless status.initial_status? %>
        <% previous_s = status.previous_status %>
        <% previous_s_errors = previous_s.conditions_errors(my_module) %>
        <li data-state-id="<%= previous_s.id %>" id="previousStatusSelector" class="<%= 'disabled' if previous_s_errors.any? %>">
          <span><%= t('my_module_statuses.dropdown.return_label') %></span>
          <i class="fas fa-long-arrow-alt-right"></i>
          <div class=" status-container">
            <div class="status-name" style="<%= "background-color: #{previous_s.color}" %>"><%= previous_s.name %></div>
          </div>
        </li>
        <span class="error-message"><% previous_s_errors.each do |error| %>
            <%= error %><br>
          <% end %></span>
      <% end %>

      <% unless status.final_status? %>
        <% next_s = status.next_status %>
        <% next_s_errors = next_s.conditions_errors(my_module) %>
        <li data-state-id="<%= next_s.id %>" id="nextStatusSelector" class="<%= 'disabled' if next_s_errors.any? %>">
          <span><%= t('my_module_statuses.dropdown.move_label') %></span>
          <i class="fas fa-long-arrow-alt-right"></i>
          <div class="status-container">
            <div class="status-name" style="<%= "background-color: #{next_s.color}" %>"><%= next_s.name %></div>
          </div>
        </li>
        <span class="error-message" data-errors-for="next-status"><% next_s_errors.each do |error| %>
            <%= error %><br>
          <% end %></span>
      <% end %>
    <% else %>
      <span class="error-message permission-error"><%= t('my_module_statuses.dropdown.no_permission_label') %></span>
    <% end %>
    <li id="viewTaskFlow">
      <%= t('my_module_statuses.dropdown.view_flow_label') %>
    </li>
  </ul>
</div>
