module SideSearch
  include PageObject

  div(:quicksearch_module, id: "quickSearch")
  text_field(:quicksearch_input, id: "smartSearch")
  button(:quicksearch_search_button, name: "srchSubmit")
  label(:label_quicksearch, for: "label")
  label(:artist_quicksearch, for: "artist")
  label(:release_quicksearch, for: "release")
  label(:track_quicksearch, for: "track")
  label(:subaccount_quicksearch, for: "subaccount")
  link(:more_options_link) { quicksearch_module_element.link_element(text: "More Options") }

  # Public: Waits for the quick search module to appear on the page
  #
  # Returns nothing
  def wait_for_side_search
    quicksearch_module_element.element.wait_until(&:present?)
  end

  # Public: Clicks the label corresponding to the type of search desired.
  # Enters search_parameter into the search field and clicks the search button.
  #
  # search_option - The String corresponding to the desired type of search.
  # search_parameter - The String or Integer the user is searching for.
  #
  # Examples
  #
  #   search_with_option('Release',888608968850)
  #
  # Returns nothing
  def search_with_option(search_option, search_parameter)
    wait_for_side_search
    "#{search_option.downcase}_quicksearch_element.element.click".split(".").inject(self, :send)
    self.quicksearch_input = search_parameter.to_s
    quicksearch_search_button
  end
end
