<% content_for :head do %>
  <%= javascript_include_tag 'dataTable/datatables.min.js' %>
<% end %>

<div class="row wrapper white-bg page-heading m-b">
  <% layout_available = table_has_layout?(@current_table) %>
  <div class="row flex">
    <div class="col-sm-10">
      <h2><%= @database.friendly_name.capitalize %></h2>

      <ol class="breadcrumb">
        <li class="">
          <% if @task_queue %>
            <span>Task Queue</span>
          <% else %>
            <span>Data views</span>
          <% end %>
        </li>

        <li class="">
          <% if @task_queue %>
            <%= @task_queue.name %>
          <% else %>
            <%= link_to @current_table.capitalize, table_path(table: @current_table, id: @current_table.downcase) %>
          <% end %>
        </li>
      </ol>
    </div>

    <div class="col-sm-2 align-self-center">
      <div class="text-right">
        <% if @layout_builder && !@task_queue %>
          <%= link_to('Edit layout', edit_layout_path(@layout_builder.id), html_options = { class: "btn btn-default" }) %>
        <% elsif !@layout_builder %>
          <%= link_to('New layout', new_layout_path(table: @current_table, database_id: @database.id), html_options = { class: "btn btn-default" }) %>
        <% else %>
        <% end %>
      </div>
    </div>
  </div>
</div>

<% if @layout_builder %>
  <div class="m-t">
    <%= render 'single_data_view', layout_builder: @layout_builder %>
  </div>
<% else %>
  <div class="animated">
    <div class="row">
      <div class="col-lg-12">
        <div class="ibox margin-bottom">
          <div class="ibox-content">
            <div class="row">
              <div class="col-xs-12 text-center">
                <h1>This layout is empty. Add fields to view in your layout <%= link_to('here', new_layout_path(table: @current_table, database_id: @database.id), html_options = { class: "underline" }) %></h1>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
<% end %>
