import { Page } from 'puppeteer';

export interface GoProperty {
    noc:string
    page:Page
    url:string
    input_box:string
    search_button:string
}

export class Go {
    noc:string
    page:Page
    url:string
    input_box:string
    search_button:string

    constructor(args:GoProperty) {
        this.noc=args.noc
        this.page=args.page
        this.url=args.url
        this.input_box=args.input_box
        this.search_button=args.search_button
    }

    async go() {
        await this.page.goto(this.url)
        await this.page.click(this.input_box,{clickCount:3});
        await this.page.type(this.input_box,this.noc);
        await this.page.waitForTimeout(500);
        await this.page.keyboard.press("ArrowDown");
        const changed=await this.page.waitForFunction((noc, id2) => {
                        const text = document.querySelector(id2).textContent;
                        return text != noc;
                    }, {}, this.noc, this.input_box);

        if(changed) {
            await this.page.keyboard.press("Enter");
            await Promise.all(
            [
                this.page.click(this.search_button),
                this.page.waitForNavigation()
            ]
            )
        }
    }
}


