module Project
  class DigitalProductActionRequiredPage < BasePage
    include DigitalProductTrackDetailsForm
    include DigitalProductTrackLocalization
    include ProductSidebar
    include DigitalProductTrackImportForm

    page_url "/project/<%=params[:project_id]%>/product/<%=params[:product_id]%>"

    link(:fix_errors_btn, text: "Fix Errors")
    span(:product_status, class: "Opm-navigation-status-heading")
    img(:artwork, class: "DigitalProductOverviewArtwork-image")

    # rejection section
    button(:see_reasons_button, class: "CollapsableAlert-button")
    div(:rejected_general_comments) do
      div_element(class: "general-comments").div_element(class: "RejectionList-row")
    end
    div(:rejected_release_name_reason) do
      div_element(class: "rejection-release-name").div_element(class: "RejectionList-cell", index: 1)
    end
    div(:rejected_artwork_reason) do
      div_element(class: "rejection-artwork").div_element(class: "RejectionList-cell")
    end
    div(:rejected_track_name_reason) do
      div_element(class: "rejection-track-name").div_element(class: "RejectionList-cell", index: 2)
    end
    div(:rejected_release_date_reason) do
      div_element(class: "rejection-release-date").div_element(class: "RejectionList-cell", index: 1)
    end
    div(:item_product_name, id: "itemProductName")
    div(:item_release_date, id: "itemReleaseDate")
    td(:item_track, class: "DigitalProductOverviewTracks-track-item")
    div(:rejected_artwork, class: "Rejected-artwork")

    def item_has_alert(item)
      item.svg_element(class: "Icons-attention-error").exists?
    end

    def item_has_correction(item)
      wait_until { item.present? }
      item.parent.attribute_value("class").include?("Corrected")
    end
  end
end
