package pwa_creditfair;

import java.util.List;
import java.util.Scanner;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class pwa_sixthform extends pwa_config{
	public void dateemi_selection() throws InterruptedException {
		Actions actions = new Actions(driver);
		WebDriverWait wait = new WebDriverWait(driver, 5000);
		Scanner console = new Scanner(System.in);
		Boolean datenotfound = true;
		driver.manage().timeouts().implicitlyWait(2000, TimeUnit.SECONDS);
		driver.findElement(By.xpath("//*[@id=\"app\"]/div/div[1]/div[1]/main/div[3]/div/div[1]/span/div/div")).click();
		Thread.sleep(2000);
		while (datenotfound) {

			List<WebElement> enableDate = driver.findElements(By.xpath(
					".//div[contains(@class,'rc-calendar-picker rc-calendar-picker-placement-bottomLeft')]/descendant::div[contains(@class,'rc-calendar')]"
					+ "/descendant::div[contains(@class,'rc-calendar-panel')]/descendant::div[contains(@class,'rc-calendar-date-panel')]"
					+ "/descendant::div[contains(@aria-disabled,'true')]"));

			// If date match with input then goes to this loop.
			if (enableDate.size()!=42)
         
			{
				driver.findElement(By.xpath(
						".//div[contains(@class,'rc-calendar-picker rc-calendar-picker-placement-bottomLeft')]/descendant::div[contains(@class,'rc-calendar')]"
						+ "/descendant::div[contains(@class,'rc-calendar-panel')]/descendant::div[contains(@class,'rc-calendar-date-panel')]"
						+ "/descendant::div[contains(@aria-disabled,'false')]")).click();
				driver.manage().timeouts().implicitlyWait(2000, TimeUnit.SECONDS);
                driver.findElement(By.xpath("//*[@id=\"app\"]/div/div[1]/div[1]/main/div[3]/div/div[3]/button")).click();
				datenotfound = false;
				System.out.println("Application successfully login and auto approved");
			}
//			// If date not match with input then goes to this loop.
			else {
				driver.findElement(By.xpath(
						".//div[contains(@class,'rc-calendar-picker rc-calendar-picker-placement-bottomLeft')]/descendant::div[contains(@class,'rc-calendar')]/descendant::div[contains(@class,'rc-calendar-panel')]/descendant::div[contains(@class,'rc-calendar-date-panel')]/descendant::div[contains(@class,'rc-calendar-header')]/descendant::a[contains(@class,'rc-calendar-next-month-btn')]"))
						.click();

			}

		}
		driver.get("https://testpwa.creditfair.in");
	}
}