module ReactWorkstation
  class ReactHomePage < Workstation::HomePage
    include Workstation::CreateRelease

    page_url("/index2")

    div(:label_name_dropdown, id: "HeaderAccountDetails")

    # Accounting Snapshot section
    div(:revenue, class: "RecentRevenueList")
    links(:accounting_period_link, class: "RecentRevenueList-link")
    headers(:accounting_period_name, class: "RecentRevenueList-interval")
    div(:react_loader, class: "LoaderWrapper-image")
    # top nav section - header
    nav(:react_top_nav) { div_element(class: "Header").nav_element }
    link(:top_nav_analytics_link) { react_top_nav_element.link_element(text: "Analytics") }

    div(:header_left, class: "navbar-header")
    ul(:header_center, class: "nav navbar-nav")
    div(:header_right, class: "Header-right")
    div(:header_loader, class: "HeaderDropdownLoader-line-bottom")
    # User menu section
    link(:react_user_menu, class: "dropdown-toggle")
    div(:react_user_header, class: "auth0-dropdown-menu")
    link(:react_admin_link, href: "/account/admin")
    link(:react_myaccount_link, href: "/account/myprofile")
    # top tracks section
    spans(:top_ten_item, class: ["TopTracksItem-text-top",
                                 "!TopTracksItem-text-alignRight"])
    div(:top_ten_loader, class: "LoaderWrapper-image")
    div(:top_ten_loader_line, class: "TopTracksLoader-line")
    div(:top_ten_title, class: "TopTracks-title")

    # global search seaction
    divs(:search_results, class: "GlobalSearchResults-option")
    text_field(:global_search_releases_input_box) do
      div_element(class: "GlobalSearchResults").text_field_element
    end
    svg(:global_search_releases_button) do
      div_element(class: "GlobalSearchResults").svg_element(class: "Icons-search")
    end
    # top tracks section
    div(:top_sound_recordings, class: "TopSoundRecordings")
    div(:top_sound_recordings_icon, class: "TopSoundRecordingsItem-icon")
    div(:top_sound_recordings_text, class: "TopSoundRecordingsItem-text")
    spans(:top_sound_recordings_text_bottom, class: "TopSoundRecordingsItem-text-bottom")

    # footer
    div(:footer, class: "Footer")

    # the react homepage does not have the various modals so always counts as fresh
    # this method is needed to provide feature parity with home_page.rb
    def on_fresh_page?
      div_element(id: "HeaderAccountDetails").exists?
    end

    def top_nav_to(name, _)
      react_top_nav_element.link_element(text: name).click
    end

    def go_to_admin_page
      react_user_menu
      react_myaccount_link
      wait_until { react_admin_link.present? }
    end

    # this method is added to avoid select top ten category in home page
    # since the new react home page only supports top ten tracks
    def select_top_ten(_selection)
      puts "new react home page supports only tracks"
    end
  end
end
