<header class="container-fluid bg-light border-bottom py-3 sticky-top">
  <div class="row align-items-center">
    <div class="col-4">
      <%= link_to signed_in_root_path, class: "navbar-brand" do %>
        <%= suite_wordmark %>
      <% end %>
    </div>
    <div class="col-4 text-center">
      <h1 class="h4 m-0">
        <% if signed_in? %>
          <% if Current.user.accounts.size > 1 %>
          <div class="dropdown">
            <button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
              <%= Current.account.name %>
            </button>
            <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
              <% Current.user.accounts.each do |account| %>
                <%= link_to(account.name, account_session_path({ account_session: { account_id: account.id } }), class: "dropdown-item", method: :put) %>
              <% end %>
            </div>
          </div>
          <% else %>
            <%= Current.account.name if Current.account %>
          <% end %>
        <% else %>
          <%= yield :page_title %>
        <% end %>
      </h1>
    </div>
    <div class="col-4 text-right">
      <% if signed_in? %>
        <div class="btn-group">
          <%= link_to :profile, class: "text-decoration-none text-reset dropdown-toggle", data: { toggle: "dropdown" } do %>
            <span class="mr-2"><%= get_name_or_email(Current.user) %></span>
            <%= image_or_text_avatar(Current.user) %>
          <% end %>

          <div class="dropdown-menu">
            <% if Current.user.admin? %>
              <%= link_to "BIG Admin", [:admin, :signed_in_root], class: "dropdown-item" %>
            <% end %>

            <%= link_to "Profile Settings", profile_path, class: "dropdown-item" %>

            <% if Current.account && Current.user.account_manager?(Current.account) %>
              <%= link_to "Account Settings", [:account_auths], class: "dropdown-item" %>
            <% end %>

            <%= link_to t(".sign_out"), :session, method: :delete, class: "dropdown-item" %>
          </div>
        </div>
      <% elsif params[:controller] != "sessions" %>
        <span class="navbar-text">Already Have a ME Suite Account?</span>
        <%= link_to "Sign In", [:new, :session], class: "btn btn-sm btn-light border" %>
      <% end %>
    </div>
  </div>
</header>
