<!DOCTYPE html>
<html>
  <head>
    <title><%= content_for?(:title) ? yield(:title) : ENV['PROJECT_NAME_LONG'] %></title>
    <meta name="viewport" content="width=device-width,initial-scale=1">    
    <meta name="turbo-prefetch" content="false">
    <meta name="turbo-cache-control" content="no-cache">

    <%= csrf_meta_tags %>
    <%= csp_meta_tag %>    
    
    <%= stylesheet_link_tag "admin", "lexxy", "tom-select", "popup-menu", "forms", "lists", "assets", "nodes", "attachments" %>    
    <%= javascript_importmap_tags 'admin' %>
  </head>
  <body>
    <nav id="navbar">      
      <div class="navbar-upper">
        <% %i[nodes assets].each do |c| %>
          <%= link_to url_for(controller: c, action: 'index'), 
                      class: (controller_name == c.to_s ? 'navbar-link current' : 'navbar-link'),
                      data: {
                        controller: 'navbar',
                        action: 'click->navbar#set_current',  
                        turbo_frame: 'main',
                        turbo_action: 'advance'
                      } do %>
            <span class="icon"><%= t c, scope: 'icons' %></span>
          <% end %>          
        <% end %>
      </div>      
      
      <%= link_to svg('ikea-foundation-white'), root_url, class: 'logo', target: '_blank'  %>

      <div class="navbar-lower">  
        <% %i[users].each do |c| %>
          <%= link_to url_for(controller: c, action: 'index'), 
                      class: (controller_name == c.to_s ? 'navbar-link current' : 'navbar-link'),
                      data: {
                        controller: 'navbar',
                        action: 'click->navbar#set_current', 
                        turbo_frame: 'main',
                        turbo_action: 'advance'
                      } do %>
            <span class="icon"><%= t c, scope: 'icons' %></span>
          <% end %>          
        <% end if current_user.admin_role? %>
        
        <%= link_to admin_cache_clear_path(locale: nil), 
                    class: 'navbar-link',
                    method: :delete,
                    data: {
                      turbo_method: :delete
                    } do %>
          <span class="icon">bolt</span>
        <% end %> 

        <div data-controller="popup">
          <button class="navbar-link has-popup-menu open--right" data-action="click->popup#toggle">
            <span class="icon">settings</span>
          </button>

          <div class="popup-menu">
            <ul>
              <li><%= tag.div current_user.email %></li>
              <li><%= link_to t('sessions.logout'), admin_logout_path, data: {icon: 'logout', turbo_frame: '_top'} %></li>
            </ul>          
          </div>

        </div>        
      </div>      
    </nav>

    <%= yield %>

    <div id="flash">    
      <%= render 'layouts/flash' %>
    </div>
    
  </body>
</html>