<% step ||= report_element.step %>
<% step_type_str = step.completed ? 'completed' : 'uncompleted' %>
<% user = step.completed? && step.last_modified_by || step.user %>
<% timestamp = step.completed ? step.completed_on : step.created_at %>
<% assets = step.assets %>
<% export_all = defined?(export_all) && export_all %>
<div class="report-element report-step-element">
  <div class="report-element-body">
    <h5 class="step-name">
      <b><%= t('projects.reports.elements.step.step_pos', pos: (step.position_plus_one)) %></b>&nbsp;<%= step.name %>
      <% unless @settings['exclude_task_metadata'] %>
        <%= step_status_label(step) %>
      <% end %>
    </h5>
    <div class="user-time">
      <% unless @settings['exclude_timestamps'] %>
        <%= t("projects.reports.elements.step.#{step_type_str}.user_time", user: user.full_name , timestamp: l(timestamp, format: :full)) %>
      <% end %>
      <% if !@settings['exclude_task_metadata'] && step.results.size.positive? %>
      | <%= t("projects.reports.elements.step.linked_results") %> <%= step.results.pluck(:name).join('; ') %>
      <% end %>
    </div>
  </div>
  <div class="report-element-children">
    <% step.step_orderable_elements.order(:position).each do |e| %>
      <% if e.orderable_type == 'StepTable' %>
        <% if e.orderable.table.metadata.present? %>
          <% if @settings.dig('task', 'protocol', 'step_well_plates') && e.orderable.table.metadata['plateTemplate'] %>
            <%= render partial: 'reports/elements/step_table_element', locals: { table: e.orderable.table, export_all: export_all, table_type: 'step_well_plates_table' } %>
          <% elsif @settings.dig('task', 'protocol', 'step_tables') && !e.orderable.table.metadata['plateTemplate'] %>
            <%= render partial: 'reports/elements/step_table_element', locals: { table: e.orderable.table, export_all: export_all, table_type: 'step_table' } %>
          <% end %>
        <% elsif @settings.dig('task', 'protocol', 'step_tables') %>
          <%= render partial: 'reports/elements/step_table_element', locals: { table: e.orderable.table, export_all: export_all, table_type: 'step_table' } %>
        <% end %>
      <% end %>
      <% if e.orderable_type == 'Checklist' && @settings.dig('task', 'protocol', 'step_checklists') %>
        <%= render partial: 'reports/elements/step_checklist_element', locals: { checklist: e.orderable, export_all: export_all } %>
      <% end %>
      <% if e.orderable_type == 'StepText' && @settings.dig('task', 'protocol', 'step_texts') %>
        <%= render partial: 'reports/elements/step_text_element', locals: { step_text: e.orderable, export_all: export_all } %>
      <% end %>
      <% if e.orderable_type == 'FormResponse' && @settings.dig('task', 'protocol', 'step_forms') %>
        <%= render partial: 'reports/elements/step_form_element', locals: { form_response: e.orderable } %>
      <% end %>
    <% end %>
    <% if @settings.dig('task', 'protocol', 'step_files') %>
      <% assets.each do |asset| %>
        <%= render partial: 'reports/elements/step_asset_element', locals: { asset: asset, export_all: export_all } %>
      <% end %>
    <% end %>
    <% if @settings.dig('task', 'protocol', 'step_comments') %>
      <%= render partial: 'reports/elements/step_comments_element', locals: { step: step, export_all: export_all } %>
    <% end %>
  </div>
  <% if defined?(children) %>
    <div class="report-element-children">
      <%= children %>
    </div>
  <% end %>
</div>
