<% cache [current_user, experiment] do %>
  <div class="dropdown experiment-actions-menu">
    <button class="btn btn-light dropdown-toggle icon-btn" type="button" id="experimentActionsDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
      <i class="fas fa-ellipsis-h"></i>
    </button>
    <ul class="dropdown-menu dropdown-menu-right" aria-labelledby="experimentActionsDropdown">
      <!-- Edit experiment -->
      <% if experiment.active? && can_manage_experiment?(experiment) %>
        <li>
          <%= link_to edit_experiment_url(experiment),
                      remote: true,
                      class: 'edit-experiment experiment-action-link' do %>
            <i class="fas fa-pen"></i>
            <span><%= t('experiments.index.edit_option') %></span>
          <% end %>
        </li>
      <% end %>
      <!-- Duplicate experiment -->
      <% if can_clone_experiment?(experiment) %>
        <li>
          <%= link_to clone_modal_experiment_url(experiment),
                      remote: true, type: 'button',
                      class: 'clone-experiment experiment-action-link' do %>
            <i class="fas fa-copy"></i>
            <span><%= t('experiments.index.clone_option') %></span>
          <% end %>
        </li>
      <% end %>
      <!-- Move experiment -->
      <% if can_move_experiment?(experiment) %>
        <li>
          <%= link_to move_modal_experiment_url(experiment),
                      remote: true,
                      class: 'move-experiment experiment-action-link' do %>
            <i class="fas fa-arrow-right"></i>
            <span><%= t('experiments.index.move_option') %></span>
          <% end %>
        </li>
      <% end %>
      <!-- Archive/restore experiment -->
      <% if experiment.active? && can_archive_experiment?(experiment) %>
        <li class="form-dropdown-item">
          <%= button_to(archive_experiment_path(experiment),
                        method: :post,
                        remote: true,
                        class: 'btn btn-light',
                        form_class: 'experiment-action-form',
                        data: { confirm: t('experiments.index.archive_confirm') } ) do %>
            <i class="fas fa-archive"></i>
            <span><%= t('experiments.index.archive_option') %></span>
        <% end %>
        </li>
      <% elsif experiment.archived? && can_restore_experiment?(experiment) %>
        <li class="form-dropdown-item">
          <%= button_to(experiment_path(experiment, format: :json),
                        method: :put,
                        remote: true,
                        class: 'btn btn-light',
                        form_class: 'experiment-action-form',
                        params: { experiment: { archived: false } }) do %>
            <i class="fas fa-undo"></i>
            <span><%= t('experiments.index.restore_option') %></span>
          <% end %>
        </li>
      <% end %>
      <li class="form-dropdown-break">
        <hr>
      </li>
      <li class="form-dropdown-item">
        <div class="form-dropdown-item-info">
          <small><%= t('experiments.experiment_id') %>: <strong><%= experiment.code %></strong></small>
        </div>
      </li>
    </ul>
  </div>
<% end %>
