from selenium.webdriver.common.alert import Alert

from pyallied.web.webWaits import customwebDriverwait


class driverAlerts(customwebDriverwait):

    def __init__(self, driver):
        super().__init__(driver)
        self.driver = driver

    # alerts
    # Use this class to interact with alert prompts. 
    # It contains methods for dismissing, accepting, inputting, and getting text from alert prompts.   
    def acceptAlert(self):
        try:
            alertPresence = super().WaitForAlert_is_present()
            if (alertPresence):
                Alert(self.driver).accept()
        except Exception as error:
            raise error

    def dismissAlert(self):
        try:
            alertPresence = super().WaitForAlert_is_present()
            if (alertPresence):
                Alert(self.driver).dismiss()
        except Exception as error:
            raise error

    def getAlertText(self):
        try:
            alertPresence = super().WaitForAlert_is_present()
            if (alertPresence):
                alertText = Alert(self.driver).text
                return alertText
        except Exception as error:
            raise error

    def sendKeystoAlert(self, keysToSend):
        try:
            alertPresence = super().WaitForAlert_is_present()
            alert = self.driver.switch_to.alert
            alert.send_keys(keysToSend)
            # name_prompt = Alert(self.driver)
            # name_prompt.send_keys(keysToSend)
        except Exception as error:
            raise error
            # Special Keys

    # The Keys implementation.
    ''' yet to complete'''
    # Touch Actions
    ''' yet to complete'''
