module Workstation
  class LoginPage < UniversalPage
    include Workstation::Auth0Login
    page_url "/login/v2"

    # initial login form
    main(:login_form, class: "login")
    text_field(:username, name: "username")
    text_field(:password, name: "password")
    button(:submit, type: "submit", visible: true)
    div(:alert_text, class: "alert-danger")
    div(:alert_success, class: "alert-success")
    button(:forgot_password, id: "btn-forgot")
    div(:loading_indicator, class: "LoadingIndicator-dots")
    div(:auth0_spinner, class: "auth0-loading")

    def login_with_user_data(user)
      # 2018-12-05: Goes to old workstation login page on prod
      # Get rid of this goto line when auth0 is fully implemented
      @browser.goto "workstation.theorchard.com" if URI(@browser.url).host.include? "workstation.auth0.com"
      login_with(user[:username], user[:password])
    end

    def login_with(user, pass)
      self.username = user
      self.password = pass
      @browser.send_keys :enter
    end
  end
end
