from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By

from .find_elements import *
from .invoke_api import *
from .get_driver import *

import os

download_dir = "C:\\TMPIMGGI\\LAST_IMG\\"
download_kit = "C:\\TMPIMGKIT\\"
download_ggi = "C:\\TMPIMGGI\\"
driver = None

class lib:
    def __init__(self):
        self.last_element = None


    def create_dirs():
        global download_dir, download_kit, download_ggi
        for directory in [download_dir, download_kit, download_ggi]:

            if not os.path.exists(directory):
                os.makedirs(directory)
                print(f" - Diretório criado: {directory}")

    def initialize_driver():
        global driver
        if driver is None:
            driver = get_driver.backcode__dont_use__launch_browser(download_dir)
            return driver

    def get(link):
        global driver
        if driver != None:
            get_driver.backcode__dont_use__get(driver, link)

    def find_element_with_wait(by, value, timeout=10, parent=None):
        global driver
        if driver != None:
            self.last_element = find_elements.find_element_with_wait_backcode(driver, by.lower(), value, timeout, parent)
            return self.last_element

        else: raise ValueError("Error: Driver is None")

    def find_elements_with_wait(by, value, timeout=10, parent=None):
        global driver
        if driver != None:
            self.last_element = find_elements.find_elements_with_wait_backcode(driver, by.lower(), value, timeout, parent)
            return self.last_element

        else: raise ValueError("Error: Driver is None")

    def click(self):
        self.last_element.click()

    def send_keys(self, text):
        self.last_element.send_keys


