#! python3

from selenium import webdriver
import sys
import time

orders = []


def get_order_info(order_xid):
    browser = webdriver.Firefox()
   
    browser.get(WEBSITE_URL + order_xid)

    email_elem = browser.find_element_by_css_selector('#email')
    email_elem.click()
    email_elem.send_keys(USER_EMAIL)

    password_elem = browser.find_element_by_css_selector('#password')
    password_elem.click()
    password_elem.send_keys(USER_PASSWORD)

    login_submit_elem = browser.find_element_by_css_selector('.buttons > button:nth-child(1)')
    login_submit_elem.click()
    
    time.sleep(3)

    browser.get(WEBSITE_URL + order_xid)

    order_summary = browser.find_element_by_tag_name('body')
    order_summary_png = order_summary.screenshot_as_png
    with open(f"Order Summary - {order_xid}.png", "wb") as order_summary_file: 
        order_summary_file.write(order_summary_png)
    time.sleep(1)
        
    tracking_link = browser.find_element_by_link_text("View Tracking").click()
    time.sleep(3)
    browser.switch_to.window(browser.window_handles[1])
    tracking_page = browser.find_element_by_tag_name('body')
    tracking_png = tracking_page.screenshot_as_png
    with open(f"Shipping Support - {order_xid}.png", "wb") as tracking_support_file:
        tracking_support_file.write(tracking_png)
    time.sleep(1)

    browser.switch_to.window(browser.window_handles[0])
    payment_link = browser.find_element_by_link_text("[details]").click()
    time.sleep(3)
    payment_page = browser.find_element_by_tag_name('body')
    payment_png = payment_page.screenshot_as_png
    with open(f"Payment Support - {order_xid}.png", "wb") as payment_support_file:
        payment_support_file.write(payment_png)
    
    
    browser.quit()

for order_xid in orders:
    get_order_info(order_xid)
    time.sleep(2)
