const pt = require('puppeteer');
const readline = require("readline");

const rl =
  readline.createInterface({
  input: process.stdin,
  output: process.stdout,
})
var userEmail= 'nrasmussen@northpass.com';
var userPassword= 'ecx5pmy!MAN2vgh2knc';
var otp = '056467';
var schoolUUID = '52d19519-103f-45e3-9fa8-d21baa0f8aaa'
var courseUUIDs = [

]

var schoolNameToCloneTo = "Anthology Partner U";

function wait(ms) {
    return new Promise(r => setTimeout(r, ms));
}

pt.launch({ headless: false }).then(async browser => {
    var p = await browser.newPage();
    await p.setViewport({ width: 1000, height: 500 })
    await p.goto('https://app.northpass.com/admin/sign_in')
    await wait(500)
	console.log("First Wait")
    await p.type('#administrator_email', userEmail)
    await p.type('#administrator_password', userPassword)
    await p.click('input.button');
    await wait(500)
	console.log("Second Wait")
    await p.goto('https://app.northpass.com/admin/twofactorauth/edit')
    await wait(500)
    await p.type('#otp_otp_attempt',otp)
    await p.click('input.button');
    await wait(500)
    for (var i = 0; i < courseUUIDs.length;i++) {
        await p.goto('https://app.northpass.com/admin/schools/'+ schoolUUID +'/courses/'+ courseUUIDs[i] +'/clone/new')
				await p.waitForSelector('#react-select-2-input')
        await p.type('#react-select-2-input',schoolNameToCloneTo)
        await p.keyboard.press('Enter');
        await wait(100)
        await p.click('input.button');
			console.log('-- Index: '+i+' -- Cloned course: '+courseUUIDs[i]+' -- ')
        await wait(1000)
      }
    await wait(2000)
    await browser.close()
})
