module ReactWorkstation
  class ReactCatalogPage < Workstation::BasePage
    include Workstation::CreateRelease

    page_url("/catalog")
    # Search field
    text_field(:search_field, class: "CatalogFilterSearch-section-content-field")

    # Status filters
    div(:filter_by_status_button, id: "CatalogFilterProductStatus")
    li(:delivered_box, id: "product-status-completed")
    li(:submitted_box, id: "product-status-submitted")
    li(:in_progress_box, id: "product-status-in_progress")
    li(:in_correction_box, id: "product-status-error_correction")
    li(:action_required_box, id: "product-status-action_required")
    # Product filters
    div(:filter_by_product_type_button, id: "CatalogFilterProductType")
    li(:digital_box, id: "product-type-digital")
    li(:physical_box, id: "product-type-physical")
    li(:video_box, id: "product-type-video")
    # Date filters
    div(:filter_by_date_button, id: "CatalogFilterDateRange")
    link(:this_month_box, id: "product-date-range-month")
    link(:upcoming_box, id: "product-date-range-upcoming")
    link(:custom_box, id: "product-date-range-custom")

    # clear filters
    div(:clear_all_filters, class: "CatalogTable-clear-link")
    div(:namage_filters, class: "CatalogFilter")
    # Table elements
    div(:no_results_found, class: "CatalogTable-empty-message")
    div(:manage_releases_table, class: "CatalogTable")
    div(:manage_results, class: "CatalogMainContent-content")
    elements(:manage_releases_row, class: "CatalogTable-product-container")

    link(:projects_top_link, text: "Projects")

    def clear_all_filters
      clear_all_filters_element.click if clear_all_filters_element.present?
    end

    def check_filter_and_get_value(filter_by, filter)
      send("filter_by_#{filter_by}_button_element").click
      send("#{filter}_box_element").click
      # 2nd dropdown click is needed for the continuity of the test
      send("filter_by_#{filter_by}_button_element").click
      filter
    end
  end
end
