<% html_title l(:label_ux_toolkit_log_files) %>

<div class="contextual">
  <% if @selected_log_file %>
    <%= link_to l(:label_ux_toolkit_refresh_log),
                ux_toolkit_log_files_path(file: @selected_log_file.name, lines: @line_count),
                class: 'icon icon-reload' %>
    <%= link_to ux_toolkit_sprite_icon('clear-query', l(:label_ux_toolkit_flush_log_file)),
                flush_ux_toolkit_log_file_path(file: @selected_log_file.name, lines: @line_count),
                method: :post,
                data: {confirm: l(:text_ux_toolkit_confirm_flush_log_file)},
                class: 'icon ux-toolkit-log-flush-action' %>
  <% end %>
</div>

<h2><%= l(:label_ux_toolkit_log_files) %></h2>

<% if @log_files.blank? %>
  <p class="nodata"><%= l(:text_ux_toolkit_no_log_files) %></p>
<% else %>
  <%= form_tag ux_toolkit_log_files_path, method: :get, class: 'ux-toolkit-log-viewer-form' do %>
    <p>
      <%= label_tag 'file', l(:label_ux_toolkit_log_file) %>
      <%= select_tag 'file',
                     options_for_select(@log_files.map {|file| [file.name, file.name] },
                                        @selected_log_file&.name),
                     onchange: 'this.form.submit();' %>

      <%= label_tag 'lines', l(:label_ux_toolkit_log_lines) %>
      <%= select_tag 'lines',
                     options_for_select(@line_counts.map {|count| [count, count] }, @line_count) %>

      <%= submit_tag l(:label_ux_toolkit_refresh_log), name: nil %>
    </p>
  <% end %>

  <% if @selected_log_file %>
    <p class="ux-toolkit-log-file-meta">
      <strong><%= h(@selected_log_file.name) %></strong>
      <span>
        <%= l(:label_ux_toolkit_log_file_size) %>:
        <%= number_to_human_size(@selected_log_file.size) %>
      </span>
      <span>
        <%= l(:label_ux_toolkit_log_file_modified) %>:
        <%= format_time(@selected_log_file.modified_at) %>
      </span>
    </p>
  <% end %>

  <% if @log_error.present? %>
    <p class="nodata"><%= h(@log_error) %></p>
  <% elsif @log_content.blank? %>
    <p class="nodata"><%= l(:text_ux_toolkit_empty_log_file) %></p>
  <% else %>
    <pre class="ux-toolkit-log-output"><%= h(@log_content) %></pre>
  <% end %>
<% end %>
