<div class="row wrapper border-bottom white-bg page-heading">
  <div class="col-sm-6">
    <h1>Available Layouts</h1>
    <ol class="breadcrumb">
      <li class="breadcrumb-item">
        <%= link_to 'Home', dashboard_path %>
      </li>

      <li class="breadcrumb-item">
        <%= link_to 'Layouts', layouts_path %>
      </li>
    </ol>
  </div>
</div>

<div class="wrapper wrapper-content animated ">
  <div class="row">
    <div class="col-sm-12">
      <% @databases.each do |database| %>
        <button class="accordion"><%= database.friendly_name %><span class="float-right"><img src="/assets/images/icons/plus-thick.png"></span></button>
        <div class="panel">
          <div class="col-sm-2 pull-right margin-top-nav">
            <%= link_to('Add new', new_layout_path(database_id: database.id), html_options = { class: "btn btn-purple" }) %>
          </div>
          <table id="table-layouts-<%= database.id %>" class="table" data-database-id="<%= database.id %>">
            <thead class="thead-light">
              <tr>
                <th>Single Data View name</th>
                <th>Table</th>
                <th></th>
              </tr>
            </thead>
            <tbody class="table-borderless table-hover">
              <% @view_builders.select { |view_builder| view_builder.database_id == database.id }.each do |view_builder| %>
                <tr>
                  <td><%= view_builder.view_name %></td>
                  <td><%= view_builder.table_name.humanize %></td>
                  <td>
                    <%= link_to('Edit', edit_layout_path(view_builder.id), html_options = { class: "btn btn-primary btn-wide" }) %>
                  </td>
                </tr>
              <% end if @view_builders %>
            </tbody>
          </table>
          <br />
        </div>
      <% end %>
    </div>
  </div>
  <% if false %>
    <div class="row">
      <div class="col-sm-12">
        <div class="ibox margin-bottom">
          <div class="ibox-content">
            <table class="table table-hover">
              <thead>
                <tr>
                  <th>Layout name</th>
                  <th>Layout table</th>
                  <th></th>
                </tr>
              </thead>
              <tbody>
                <% @view_builders.each do |view_builder| %>
                  <tr>
                    <td><%= view_builder.view_name %></td>
                    <td><%= view_builder.table_name %></td>
                    <td>
                      <%= link_to('Settings', edit_layout_path(view_builder.id), html_options = { class: "btn btn-info" }) %>
                    </td>
                  </tr>
                <% end if @view_builders %>
              </tbody>
            </table>
          </div>
        </div>
      </div>
    </div>
  <% end %>
</div>
