<nav class="navbar-default navbar-static-side " role="navigation">
  <div class="sidebar-collapse">
    <ul class="nav metismenu" id="side-menu">
      <li class="nav-header ">
        <div class="dropdown profile-element">
          <%= link_to dashboard_path, :class => 'navbar-link left-layout-link' do %>
            <span>
              <img alt="image" class="" src="<%= image_url '/assets/logos/MissionKontrol-logo-inverted.png' %>" style="width: 110%"/>
            </span>

            <a>
              <span class="clear">
                <span class="block m-t-xs">
                  <% if current_admin_user %>
                    <strong class="font-bold"><%= current_admin_user.full_name %></strong>
                  <% end %>
                </span>

                <% if demo_app %>
                  <span class="text-muted text-xs block">Demo</span>
                <% end %>
              </span>
            </a>
          <% end %>
        </div>

        <div class="logo-element">
          <img src="/assets/logos/kuwinda_thumbnail.png" alt="" class="thumbnail">
        </div>
      </li>

      <li class="<%= active_controller?('dashboard') || active_controller?('show')%>">
        <%= link_to dashboard_path do %>
          <span class="nav-label dashboard-nav-link" data-i18n="nav.layouts">DASHBOARD</span>
        <% end %>
      </li>

      <li class="nav-link-databases <%= active_controller?('tables') && active_action?('show') %>">
        <a href="" id="nav-link-for-databases" class="nav-link-for-databases">
          <span class="nav-label" data-i18n="nav.dashboard">DATA</span> <span class="fa arrow"></span>
        </a>

        <ul class="nav nav-second-level collapse">
          <% if @databases %>
            <% @databases.each do |database| %>
              <li class="<%= 'active' if database.id == current_database_view_id %>">
                <a href="" class="nav-link-databases" data-database-id="<%= database.id %>">
                  <span class="nav-label" data-i18n="nav.layouts">
                    <%= database.friendly_name %>
                  </span><span class="fa arrow"></span>
                </a>
                <ul class="nav nav-second-level nav-databases collapse" id="nav-populate-available-databases-<%= database.id %>">
                  <% database_tables = tables_with_view_permission(database) %>
                  <% database_tables.each do |table| %>
                    <li>
                      <a href="/tables/<%= database.id %>?table=<%= table %>"><%= table %></a>
                    <li>
                  <% end %>
                </ul>
              </li>
            <% end %>
          <% end %>
        </ul>
      </li>

      <li class="<%= active_controller?('task_queues') || active_controller?('layout_builder') || active_controller?('admin_users') || active_controller?('databases') || active_controller?('permissions') %>">
        <a href="" id="nav-link-for-task-queues">
          <span class="nav-label" data-i18n="nav.layouts">TASK QUEUES</span> <span class="fa arrow"></span>
        </a>

        <ul class="nav nav-second-level collapse">
          <% if @databases_with_task_queues %>
            <% @databases_with_task_queues&.each do |database| %>
              <li class="">
                <a href="" id="nav-link-for-database-task-queues">
                  <span class="nav-label"><%= database.friendly_name %></span><span class="fa arrow"></span>
                </a>
                <ul class="nav nav-second-level collapse">
                  <% if @task_queues %>
                    <% @task_queues.select { |task_queue|  task_queue.database_id == database.id }.each do |task_queue| %>
                      <li class="">
                        <%= link_to task_queue_path(task_queue), id: "nav-link-for-task-queues" do %>
                            <%= task_queue.name %>
                        <% end %>
                      </li>
                    <% end%>
                  <% end %>
                </ul>
              </li>
            <% end %>
          <% else %>
            <li>
              <%= link_to task_queues_path, id: "nav-link-for-task-queues" do %>
                No queues created yet. Create one here
              <% end %>
            </li>
          <% end %>
        </ul>
      </li>

      <% if current_admin_user.admin_abilities? %>
        <li class="<%= active_controller?('organisation_settings') || active_controller?('layout_builder') || active_controller?('admin_users') || active_controller?('databases') || active_controller?('permissions') %>">
          <a href="" id="nav-link-for-settings">
            <span class="nav-label" data-i18n="nav.layouts">SETTINGS</span> <span class="fa arrow"></span>
          </a>

          <ul class="nav nav-second-level collapse">
            <li class="">
              <% current_organisation = OrganisationSetting.last %>
              <%= link_to edit_organisation_setting_path(current_organisation), id: "nav-link-for-general-settings" do %>
                <%= image_tag('/assets/images/icons/settings-1.png') %>  General
              <% end %>
            </li>
            <li class="<%= active_controller?('admin_users') %>">
              <%= link_to users_path, id: "nav-link-for-user-settings" do %>
                <%= image_tag('/assets/images/icons/group-3.png') %>  Users
              <% end %>
            </li>
            <li class="<%= active_controller?('permissions') %>">
              <%= link_to permissions_path, id: "nav-link-for-user-settings" do %>
                <%= image_tag('/assets/images/icons/database-1.png') %>  Permissions
              <% end %>
            </li>
            <li class="<%= active_controller?('layout_builder') %>">
              <%= link_to layouts_path do %>
                <%= image_tag('/assets/images/icons/settings-1.png') %> Layouts
              <% end %>
            </li>
            <li class="<%= active_controller?('task_queues') %>">
              <%= link_to task_queues_path, id: "nav-link-for-task-queues" do %>
                <%= image_tag('/assets/images/icons/settings-1.png') %>  Task Queues
              <% end %>
            </li>
            <li class="<%= active_controller?('databases') %>">
              <a href="" id="nav-link-for-available-databases-settings" class="nav-link-for-available-databases">
                <span class="nav-label" data-i18n="nav.layouts">
                  <%= image_tag('/assets/images/icons/database-1.png') %>
                  Databases
                </span> <span class="fa arrow"></span>
              </a>

              <ul id="nav-link-databases-settings" class="nav nav-second-level collapse nav-databases <%= active_controller?('databases') %>">
              </ul>
            </li>
          </ul>
        </li>
      <% end %>
      <% if admin_user_signed_in? %>
        <li>
          <%= link_to "LOGOUT", destroy_admin_user_session_path, method: :delete %>
        </li>
      <% end %>
    </ul>
  </div>
</nav>
