<% issue = local_assigns[:issue] || @issue %>
<% assign_to_me_available = RedmineUxToolkit::Services::IssueAssignToMe.available?(issue, User.current) %>
<% assign_to_me_and_start_available = RedmineUxToolkit::Services::IssueAssignToMeAndStart.available?(issue, User.current) %>
<% quick_statuses = RedmineUxToolkit::Services::IssueQuickStatusActions.available_statuses(issue, User.current) %>
<% if assign_to_me_available || assign_to_me_and_start_available || quick_statuses.any? %>
  <div class="ux-toolkit-assign-to-me ux-toolkit-issue-actions"
       role="group"
       aria-label="<%= l(:label_ux_toolkit_issue_quick_actions) %>">
    <span class="ux-toolkit-issue-actions-title"><%= l(:label_ux_toolkit_issue_quick_actions) %></span>
    <div class="ux-toolkit-issue-actions-controls">
      <% if assign_to_me_available %>
        <%= link_to ux_toolkit_sprite_icon('user', l(:button_ux_toolkit_assign_to_me)),
                    ux_toolkit_assign_issue_to_me_path(issue),
                    method: :post,
                    class: 'button-small icon icon-user ux-toolkit-issue-primary-action' %>
      <% end %>
      <% if assign_to_me_and_start_available %>
        <%= link_to ux_toolkit_sprite_icon('time-add', l(:button_ux_toolkit_assign_to_me_and_start)),
                    ux_toolkit_assign_issue_to_me_and_start_path(issue),
                    method: :post,
                    class: 'button-small icon icon-time-add ux-toolkit-issue-primary-action' %>
      <% end %>

      <% if quick_statuses.any? %>
        <div class="ux-toolkit-quick-status-actions">
          <span><%= l(:label_ux_toolkit_set_status) %>:</span>
          <% if quick_statuses.size <= 3 %>
            <% quick_statuses.each do |status| %>
              <%= link_to status.name,
                          ux_toolkit_change_issue_status_path(issue, status_id: status.id),
                          method: :post,
                          class: 'button-small icon icon-edit ux-toolkit-quick-status-action' %>
            <% end %>
          <% else %>
            <%= form_tag ux_toolkit_change_issue_status_path(issue),
                         method: :post,
                         class: 'ux-toolkit-quick-status-form' do %>
              <%= select_tag 'status_id',
                             options_from_collection_for_select(quick_statuses, :id, :name),
                             id: nil,
                             aria: {label: l(:label_ux_toolkit_set_status)} %>
              <%= submit_tag l(:button_apply), class: 'button-small' %>
            <% end %>
          <% end %>
        </div>
      <% end %>
    </div>
  </div>
<% end %>
