module Video
  class VideoPage < UniversalPage
    include VideoMetadataForm
    page_url "/"

    div(:loading, class: "LoadingIndicator")
    file_field(:video_upload, id: "browser-upload")
    div(:video_player, class: "VideoPlayer")
    svg(:play, class: "Icons-play")
    span(:elapsed_time, class: "Duration-time")
    text_field(:preview_start_time, class: "PreviewForm-input")
    button(:play_preview, class: "PreviewForm-button")
    button(:cancel_upload, class: "VideoInfoSection-cancel-button")
    button(:delete_video, class: "VideoInfoSection-trash-button")
    button(:confirm_delete_video, class: "Confirm-ContinueBtn")
    div(:active_step, class: "VideoProcessing-status-trail-header-active")
    divs(:completed_step, class: "VideoProcessing-blue-circle-complete")
    div(:validation_errors, class: "ValidatingErrors")
    button(:review_and_submit, class: "VideoProductForm-submit")
    button(:save, class: "VideoProductForm-save")
    button(:save_or_submit, class: "VideoProductForm-submit")
    div(:product_notification, class: "Notification-message-header")

    def upload_video(validity)
      vid_path = if validity == "invalid"
                   "mv-test-assets/invalid_video.mov"
                 else
                   "mv-test-assets/valid_video.mp4"
                 end

      # Create empty file container based off of file name from vid_path
      FileUtils.touch(Support::Paths.uploads + "/#{vid_path.split('/').last}")
      # Download video into temp directory from S3/qa-cucumbers/mv-test-assets/
      Support::S3Client.download_file(
        bucket: "qa-cucumbers",
        key: vid_path,
        destination: Support::Paths.uploads + "/#{vid_path.split('/').last}"
      )
      # Upload video from temp directory
      upload_workaround(
        element: video_upload_element,
        path: Support::Paths.uploads + "/#{vid_path.split('/').last}"
      )
    end
  end
end
