<ul>
  <% if @can[:edit] %>
    <% if @time_entry %>
      <li><%= context_menu_link l(:button_edit), bulk_time_entries_path(time_entry_id: @time_entry, back_url: @back), class: 'icon icon-edit' %></li>
    <% else %>
      <li><%= context_menu_link l(:button_edit), time_entries_bulk_edit_path(ids: @ids), class: 'icon icon-edit' %></li>
    <% end %>
  <% end %>

  <%= call_hook(:view_time_entries_context_menu_start, { time_entries: @time_entries, can: @can, back: @back, time_entry: @time_entry }) %>

  <% if @activities.present? && @can[:edit] %>
    <li class="folder">
      <a href="#" class="submenu"><%= l(:field_activity) %></a>
      <ul>
        <% @activities.each do |activity| %>
          <li><%= context_menu_link activity.name, bulk_update_time_entries_path(ids: @ids, time_entry: { activity_id: activity }, back_url: @back), method: :post, selected: (@time_entry && activity == @time_entry.activity) %></li>
        <% end %>
        <li><%= context_menu_link l(:label_none), bulk_update_time_entries_path(ids: @ids, time_entry: { activity_id: 'none' }, back_url: @back), method: :post, selected: (@time_entry && @time_entry.activity.nil?) %></li>
      </ul>
    </li>
  <% end %>

  <% if @issues.present? && @can[:edit] %>
    <li class="folder">
      <a href="#" class="submenu"><%= l(:field_issue) %></a>
      <ul>
        <% @issues.each do |issue| %>
          <li><%= context_menu_link truncate(issue.subject, length: 50), bulk_update_time_entries_path(ids: @ids, time_entry: { issue_id: issue }, back_url: @back), method: :post, selected: (@time_entry && issue == @time_entry.issue) %></li>
        <% end %>
        <li><%= context_menu_link l(:label_none), bulk_update_time_entries_path(ids: @ids, time_entry: { issue_id: 'none' }, back_url: @back), method: :post, selected: (@time_entry && @time_entry.issue.nil?) %></li>
      </ul>
    </li>
  <% end %>

  <% @options_by_custom_field.each do |field, options| %>
    <li class="folder cf_<%= field.id %>">
      <a href="#" class="submenu"><%= field.name %></a>
      <ul>
        <% options.each do |text, value| %>
          <li><%= bulk_update_time_entry_custom_field_context_menu_link(field, text, value || text) %></li>
        <% end %>
        <% unless field.is_required? %>
          <li><%= bulk_update_time_entry_custom_field_context_menu_link(field, l(:label_none), '__none__') %></li>
        <% end %>
      </ul>
    </li>
  <% end %>

  <% if @can[:edit] && TimeEntry.easy_locking_enabled? %>
    <% locking_url = { controller: 'timelog', action: 'resolve_easy_lock', ids: @ids, back_url: @back } %>
    <% if (@time_entry.nil? || (@time_entry && !@time_entry.easy_locked?)) && @can[:easy_locking] %>
      <li>
        <%= context_menu_link(l(:button_timelog_easy_lock), locking_url.merge({ locked: 'true' }), method: 'post', class: 'icon icon-lock') %>
      </li>
    <% end %>
    <% if (@time_entry.nil? || (@time_entry && @time_entry.easy_locked?)) && @can[:easy_unlocking] %>
      <li>
        <%= context_menu_link(l(:button_timelog_easy_unlock), locking_url.merge({ locked: 'false' }), method: 'post', class: 'icon icon-unlock') %>
      </li>
    <% end %>
  <% end %>

  <% if @can[:edit] %>
    <li>
      <%= context_menu_link l(:button_delete), time_entries_destroy_path(ids: @ids, back_url: @back), method: :delete, data: { confirm: l(:text_time_entries_destroy_confirmation) }, class: 'icon icon-del' %>
    </li>
  <% end %>

  <%= call_hook(:view_time_entries_context_menu_end, { time_entry: @time_entry, time_entries: @time_entries, can: @can, back: @back }) %>
</ul>
