from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
from baseWeb import baseWeb
import time

class ostinWeb(baseWeb):
    def openSite(self):
        self.driver.get("http://www.ostin.com")
        element = self.driver.find_element_by_css_selector(".o-city-confirm__accept.button.button-red.button-small")
        element.click()

    def clickFavorite(self):
        element = self.driver.find_element_by_class_name("navigation__button-favorite-icon")
        element.click()

    def login(self, email, password):
        element = self.driver.find_element_by_name("o-auth-log-email")
        element.send_keys(email)
        actions = ActionChains(self.driver)
        actions.send_keys(Keys.TAB)
        actions.send_keys(password)
        actions.perform()
        element = self.driver.find_element_by_class_name("show-it")
        element.click()
        element = self.driver.find_element_by_css_selector(".button-small.text-center.o-auth-modal__login-btn.button-red")
        element.click()
        time.sleep(5)

    def addToFavorite(self):
        element = self.driver.find_element_by_css_selector(".button.button-grey.o-product__favorite-button-icon")
        element.click()

    def chosseRandomProduct(self):
        element = self.driver.find_elements_by_class_name("product-card__image-container")[0]
        element.click()