module TopNav
  include PageObject

  link(:my_page_tab_link, text: "My Page")
  link(:relationships_tab_link, text: "Relationships")
  link(:communication_tab_link, text: "Communication")
  link(:reports_tab_link, text: "Reports")
  link(:marketing_tab_link, text: "Marketing")
  link(:accounting_tab_link, text: "Accounting")
  link(:warehouse_tab_link, text: "Warehouse")
  link(:technology_tab_link, text: "Technology")
  link(:users_tab_link, text: "Users")
  link(:search_tab_link, text: "Search")
  h5(:user_full_name) { div_element(id: "accountInfo").h5_element }
  link(:logout_link) { div_element(id: "accountInfo").link_element(class: "icon_logout") }
  link(:parent_breadcrumb_link) { p(class: "breadcrumb").link_element } # first link only
  links(:breadcrumb_link) { p(class: "breadcrumb").link_elements }
  list_item(:current_tab, class: "current")

  # Public: Switches to a different tab if not on the selected one. Compares
  # tab_text with the text of the currently selected tab. If the text doesn't
  # match, the correct tab is then clicked.
  #
  # tab_text - The String of the tab the user wants to be on
  #
  # Examples
  #
  #   If CURRENTLY on Relationships tab:
  #   switch_to_tab_if_not_current('Relationships')
  #   # => "Relationships is the right tab"
  #   switch_to_tab_if_not_current('Communication')
  #   # => "Switched to Communication"
  #
  # Returns String
  def switch_to_tab_if_not_current(tab_text)
    if current_tab == tab_text
      "#{current_tab} is the right tab"
    else
      send "#{tab_text.to_snake_case}_tab_link"
      "Switched to #{tab_text}"
    end
  end
end
