module Accounting
  class StatementAttachmentsPage < UniversalPage
    page_url "accounting/statementshistory/period/<%=params[:report_period]%>/
                        <%=params[:period]%>/<%=params[:period]%>/statement_attachment"
    h2(:page_header) { div_element(class: "statement-attachments-list-form").h2_element }
    table(:attachments_table, class: %w[table table-striped])
    div(:statements_link, id: "bread")
    rows(:file_row, class: "statement_attachment")

    def file_details(file_name)
      row = row_by_file_name(file_name)
      return unless row
      row_values = row.tds.map(&:text)
      Hash[table_header.zip(row_values)].symbolize_keys
    end

    def row_by_file_name(file_name)
      attachments_table_element.trs.find { |row| row.text.split(" ").include?(file_name) }
    end

    def table_header
      %w[upload_date file_name file_type status]
    end
  end
end
