module Royalties
  class AccountingPeriodsPage < RoyaltiesPage
    page_url "/accounting-periods"

    button(:add_new_period, text: "+ Add New Accounting Period")
    table(:periods_table, class: %w[AccountingPeriodList table])
    spans(:accounting_periods, class: "TableWithEmbeddedForm-clickable")
    element(:open_period) do
      wait_until { add_new_period_element.exist? }
      unless accounting_periods_elements.size.nil?
        span(text: accounting_periods_elements[0].text).parent.parent.parent
      end
    end
    text_field(:period_name, id: "accountingPeriodName")
    button(:save_period, id: "saveNewPeriodBtn")

    svg(:edit_period_id) do
      button_element(name: "editBtn-").svg_element(class: %w[Glyph Edit])
    end
    text_field(:period_id_value, id: "oaAccountingPeriodId")
    button(:save_period_id, id: "saveNewPeriodBtn")
  end
end
