<%= stylesheet_link_tag "dashboard" %>_
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top">
      <div class="container-fluid">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="/">Pearlception</a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
          <ul class="nav navbar-nav navbar-right">
            <!-- <li><a href="#">Dashboard</a></li> -->
            <!-- <li><a href="#">Settings</a></li>
            <li><a href="#">Profile</a></li>
            <li><a href="#">Help</a></li> -->
            <li>
                <%= link_to(destroy_user_session_path, class: 'logout-link', :method => :delete) do %>
                <i class="fa fa-external-link"></i> Logout
                <% end %>
            </li>
          </ul>
          <!-- <form class="navbar-form navbar-right">
            <input type="text" class="form-control" placeholder="Search...">
          </form> -->
        </div>
      </div>
    </nav>

    <div class="container-fluid">
      <div class="row">
        <div class="col-sm-3 col-md-2 sidebar">
          <ul class="nav nav-sidebar">
            <li class="active"><a href="/">Overview <span class="sr-only">(current)</span></a></li>
            <!-- This will be removed and placed with correct logic in corresponding controller -->
            <% if current_user.admin? %>
                <li><a href="companies#index">Companies</a></li>
            <% else %>
                <li><a href="grades#index">Grades</a></li>
              <!-- <li><a>Reports</a></li>
              <li><a>Analytics</a></li>
              <li><a>Export</a></li> -->
            <% end %>
          </ul>
          <!-- <ul class="nav nav-sidebar">
            <li><a href="">Nav item</a></li>
            <li><a href="">Nav item again</a></li>
            <li><a href="">One more nav</a></li>
            <li><a href="">Another nav item</a></li>
            <li><a href="">More navigation</a></li>
          </ul>
          <ul class="nav nav-sidebar">
            <li><a href="">Nav item again</a></li>
            <li><a href="">One more nav</a></li>
            <li><a href="">Another nav item</a></li>
          </ul> -->
        </div>
        <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
          <h1 class="page-header"><strong><%= current_user.admin? ? "" : Company.find_by(id: current_user.company_id).company_name %></strong> Pearlception Dashboard</h1>

          <!-- <div class="row placeholders">
            <div class="col-xs-6 col-sm-3 placeholder">
              <img src="data:image/gif;base64,R0lGODlhAQABAIAAAHd3dwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" width="200" height="200" class="img-responsive" alt="Generic placeholder thumbnail">
              <h4>Label</h4>
              <span class="text-muted">Something else</span>
            </div>
            <div class="col-xs-6 col-sm-3 placeholder">
              <img src="data:image/gif;base64,R0lGODlhAQABAIAAAHd3dwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" width="200" height="200" class="img-responsive" alt="Generic placeholder thumbnail">
              <h4>Label</h4>
              <span class="text-muted">Something else</span>
            </div>
            <div class="col-xs-6 col-sm-3 placeholder">
              <img src="data:image/gif;base64,R0lGODlhAQABAIAAAHd3dwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" width="200" height="200" class="img-responsive" alt="Generic placeholder thumbnail">
              <h4>Label</h4>
              <span class="text-muted">Something else</span>
            </div>
            <div class="col-xs-6 col-sm-3 placeholder">
              <img src="data:image/gif;base64,R0lGODlhAQABAIAAAHd3dwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" width="200" height="200" class="img-responsive" alt="Generic placeholder thumbnail">
              <h4>Label</h4>
              <span class="text-muted">Something else</span>
            </div>
          </div> -->

          <% if current_user.admin? %>
            <h2 class="sub-header">Recent Results From All Companies</h2>

            <div class="panel-group" id="accordion">
                <span hidden><%= @i = 1 %></span>
                <% ((Company.pluck :company_name) - ["IVA"]).each do |company_name| %>
                    <div class="panel panel-primary">
                      <div class="panel-heading">
                        <h3 class="panel-title text-center">
                          <a data-toggle="collapse" data-parent="#accordion" href="#collapse<%="#{@i}"%>">
                          <%= company_name %> </a>
                        </h3>
                      </div>
                      <div id="collapse<%="#{@i}"%>" class="panel-collapse collapse <%= (@results[company_name.gsub(/'/,'').gsub(/\s/,'')][:active] && @results[company_name.gsub(/'/,'').gsub(/\s/,'')][:name] == company_name.gsub(/'/,'').gsub(/\s/,'') ) ? "in" : ""%>">
                        <div class="panel-body">
                            <div class="table-responsive panel panel-primary">
                              <table class="table table-striped">
                                  <div class="panel-heading">
                                      <thead>
                                        <tr>
                                          <th>Run Date</th>
                                          <th>Location</th>
                                          <th>Harvest Time</th>
                                          <th>Supplier</th>
                                          <th>Distributor</th>
                                          <th>Total Processed</th>
                                          <th>Other</th>
                                          <th>Oyster Info</th>
                                        </tr>
                                      </thead>
                                  </div>
                                  <div class="panel-body">
                                      <span hidden><%= Apartment::Tenant.switch!(company_name.gsub(/'/,'').gsub(/\s/,'')) %></span>
                                      <tbody>
                                          <% @results[company_name.gsub(/'/,'').gsub(/\s/,'')][:results].each_slice(1) do |row| %>
                                            <tr>
                                                <% row.each do |result|
                                                    run = result#Run.find(result.id) %>
                                                    <!-- run date -->
                                                    <td>
                                                        <%= run.runDate %>
                                                    </td>

                                                    <!-- location -->
                                                    <td>
                                                        <%= run.location ? run.location : "" %>
                                                    </td>

                                                    <!-- harvest time -->
                                                    <td>
                                                        <%= "" %>
                                                    </td>

                                                    <!-- supplier -->
                                                    <td>

                                                        <%= run.supplier ? run.supplier : "" %>
                                                    </td>

                                                    <!-- distributor -->
                                                    <td>
                                                        <%= run.distributor ? run.distributor : "" %>
                                                    </td>

                                                    <!-- total processed -->
                                                    <td>
                                                        "result"
                                                    </td>

                                                    <!-- other -->
                                                    <td>
                                                        <%= run.other ? run.other : "" %>
                                                    </td>
                                                    <td>
                                                      <%= link_to "Show", oysters_index_path( :result_id => result.id, :page_num => params[:page]), :class => "btn btn-primary" %>
                                                    </td>
                                                <% end %>
                                            </tr>
                                          <% end %>
                                      </tbody>
                                  </div>
                              </table>
                            </div>

                            <div class="center-block">
                                <div class="col-sm-6 col-sm-offset-3 panel panel-primary" align="center">
                                    <%= paginate @results[company_name.gsub(/'/,'').gsub(/\s/,'')][:results] , params: {company: company_name.gsub(/'/,'').gsub(/\s/,'')} %></br>
                                    <%= page_entries_info @results[company_name.gsub(/'/,'').gsub(/\s/,'')][:results] %>
                                </div>
                            </div>
                        </div>
                      </div>
                    </div>
                    <span hidden><%= @i = @i + 1%></span>
                <% end %>
            </div>
          <% else %>
            <h2 class="sub-header">Recent Results</h2>
            <div class="table-responsive panel panel-primary">
              <table class="table table-striped">
                  <div class="panel-heading">
                      <thead>
                        <tr>
                          <th>Run Date</th>
                          <th>Location</th>
                          <th>Harvest Time</th>
                          <th>Supplier</th>
                          <th>Distributor</th>
                          <th>Total Processed</th>
                          <th>Other</th>
                          <th>Oyster Info</th>
                        </tr>
                      </thead>
                  </div>
                  <div class="panel-body">
                      <tbody>
                          <% @results.each_slice(1) do |row| %>
                            <tr>
                                <% row.each do |result|
                                    run = Run.find(result.id) %>
                                    <!-- run date -->
                                    <td>
                                        <%= run.runDate %>
                                    </td>

                                    <!-- location -->
                                    <td>
                                        <%= run.location ? run.location : "" %>
                                    </td>

                                    <!-- harvest time -->
                                    <td>
                                        <%= "" %>
                                    </td>

                                    <!-- supplier -->
                                    <td>

                                        <%= run.supplier ? run.supplier : "" %>
                                    </td>

                                    <!-- distributor -->
                                    <td>
                                        <%= run.distributor ? run.distributor : "" %>
                                    </td>

                                    <!-- total processed -->
                                    <td>
                                        "result"
                                    </td>

                                    <!-- other -->
                                    <td>
                                        <%= run.other ? run.other : "" %>
                                    </td>
                                    <td>
                                      <%= link_to "Show", oysters_index_path( :result_id => result.id, :page_num => params[:page]), :class => "btn btn-primary" %>
                                    </td>
                                <% end %>
                            </tr>
                          <% end %>
                      </tbody>
                  </div>
              </table>
            </div>
            <div class="center-block">
                <div class="col-sm-6 col-sm-offset-3 panel panel-primary" align="center">
                    <%= paginate @results %></br>
                    <%= page_entries_info @results %>
                </div>
            </div>
          <% end %>

        </div>
      </div>
    </div>
    <%= javascript_include_tag "bootstrap.min" %>_
</body>
