/** @param {import(".").NS } ns */
const doc = eval('document');

export async function main(ns) {
    // ns.disableLog('ALL');

    // const terminalInput = doc.getElementById("terminal-input");
    // const handler = Object.keys(terminalInput)[1];

    // terminalInput.value = "COMMAND";
    // terminalInput[handler].onChange({ target: terminalInput });
    // terminalInput[handler].onKeyDown({ key: 'Enter', preventDefault: () => null });

    // const terminalButton = doc.querySelector();
    let terminal;
    let city;
    let travel;
    for (const elem of doc.querySelectorAll('div.MuiDrawer-root.MuiDrawer-docked p')) {
        if (elem.textContent == 'Terminal') {
            terminal = elem;
        }
        if (elem.textContent == 'City') {
            city = elem;
        }
        if (elem.textContent == 'Travel') {
            travel = elem;
        }
    }


    travel.click(); await ns.sleep(100);

    for (const aevum of doc.querySelectorAll('div#root span')) {
        if (aevum.textContent == 'A') {
            aevum.click(); await ns.sleep(100);
            break;
        }
    }

    for (const travelConfirm of doc.querySelectorAll('div[role="presentation"] p')) {
        if (travelConfirm.textContent == 'Travel') {
            travelConfirm.click(); await ns.sleep(100);
            break;
        }
    }

    const closeButton = doc.querySelector('div[role="presentation"] button');
    if(!closeButton == undefined) closeButton.click();

    city.click(); await ns.sleep(100);

    for (const uni of doc.querySelectorAll('div#root span')) {
        if (uni.textContent == 'U') {
            uni.click(); await ns.sleep(100);
            break;
        }
    }

    for (const course of doc.querySelectorAll('div#root button')) {
        if (course.textContent == 'Take Algorithms course ($-1.280k / sec)') {
            course.click(); await ns.sleep(100);
            break;
        }
    }

    for (const closeCourse of doc.querySelectorAll('div#root button')) {
        if (closeCourse.textContent == 'Do something else simultaneously') {
            closeCourse.click(); await ns.sleep(100);
            break;
        }
    }
    await ns.sleep(1000);
    console.log(terminal)
    terminal.click(); await ns.sleep(100);
}