# frozen_string_literal: true

class ApplicationController < ActionController::Base
  include Pagy::Backend

  # allow_browser versions: :modern
  helper_method :sidebar?

  before_action :initialize_navbar

  private

  def initialize_navbar
    return unless request.get?

    @navbar_items = if rodauth.logged_in?
      [
        { label: "Dashboard",                       icon: :speedometer2,   path: :root },
        { label: Report.model_name.human(count: 2), icon: :'journal-text', path: :reports },
        { label: I18n.t("backoffice"),              icon: :gear,         path: :backoffice, active: %w[backoffice checklists checks links link_categories].include?(controller_name) },
        { label: Account.model_name.human,          icon: :person,         path: profile_path }
      ]
    else
      [ { label: "Login", icon: :'door-closed', path: rodauth.login_path, label_class: "text-info" } ]
    end
    @nav_path = controller_name
    @search_url = nil
    @sidebar_items = initialize_sidebar_items
  end

  def sidebar?
    @sidebar_items && @sidebar_items.any?
  end

  def initialize_sidebar_items
    []
  end
end
