class StatementsPage < BasePage
  include MathHelper

  page_url "#{ENVied.WORKSTATION_URL}/accounting/statementshistory"

  table(:statement_table, id: "statement-table")

  # Using a bunch of magic numbers here because:
  # 1) PageObject's method for locating row by String is very slow
  # 2) There are several invisible rows in the table. Index 2 is actually the first row of content in the table.
  # 3) Ultimately, the best fix for this is to assign a unique html id for the "latest" period row, and some cells.

  def latest_period
    statement_table_element.when_present[2][0].text
  end

  def latest_period_revenue
    statement_table_element.when_present[2][2].text
  end

  def latest_period_total_payments
    statement_table_element.when_present[2][4].text
  end

  def click_request_report
    statement_table_element.when_present[2].link_element(class: "offline_report").click
  end

  def click_view_breakdown
    statement_table_element.when_present[2].link_element(class: "view-statement").click
  end

  def latest_period_report_status
    statement_table_element.when_present[2].link_element(class: "offline_report").text
  end

  private

  def row_obj_beginning_with(po_table = statement_table_element, str)
    po_table.element.rows.find { |r| r.text.start_with?(str) } # => #<Watir::TableRow:0x...> or nil
  end
end
