package creditfair_admin_maven_uipages;

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

import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.CacheLookup;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.How;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import creditfair_admin_maven_locator.AdminAddappLocator;

import java.util.List;

public class AdminAddapp extends AdminAddappLocator {
	WebDriver driver;
	Boolean datenotfound = true;
	String calendermonthcustom = "July 2003";

	public void AdminAddapp(WebDriver driver) {
		this.driver = driver;

	}

	AdminAddappLocator adminlocator = new AdminAddappLocator();

	// date selection function start
	public void dateSelection(WebElement calendermonth, WebElement calenderprevbtton) {
		while (datenotfound) {
			String calendermonthselect = calendermonth.getText();
			if (calendermonthselect.equals(calendermonthcustom)) {
				for (WebElement birthdate : calenderday) {
					String birthdateselect = birthdate.getText();
					if (birthdateselect.equals("27")) {
						birthdate.click();
						break;
					}
				}
				datenotfound = false;
			} else {
				calenderprevbtton.click();
			}
		}

	}
	// date selection function end

	// search application using mobile no start
	public static void searchApplication(WebElement appfilter, WebElement filtermobileno, WebElement searchmobileno,
			WebElement searchbutton, WebElement deleteapp) {

		appfilter.click();
		filtermobileno.click();
		searchmobileno.sendKeys("4342343545");
		searchbutton.click();

	}
// search application using mobile no end

// delete application start 
	public void delteApplication(WebElement deleteapp, WebElement alertmodelok) throws InterruptedException {
		Thread.sleep(5000);
		deleteapp.click();
		alertmodelok.click();
	}
	// delete application end

	// fill application form
	public void appForm(WebDriver driver, WebElement addapplicationbutton, WebElement applicationdetailstab1,
			WebElement applicationdetailstab2, WebElement applicationdetailstab3, WebElement langaugeoption,
			List<WebElement> selectlangauge, WebElement firstname, WebElement middlename, WebElement lastname,
			WebElement fathername, WebElement email, WebElement mobileno, WebElement panno, WebElement alternateno,
			WebElement genderoption, List<WebElement> selectgender, WebElement calenderopen,
			List<WebElement> calenderday, WebElement calendermonth, WebElement calenderprevbtton,
			WebElement monthlyincome, WebElement loanamount, WebElement merchantoption, List<WebElement> selectmerchant,
			WebElement centeroption, List<WebElement> selectcenter, WebElement company, WebElement purposeoption,
			WebElement selectpurpose, WebElement durationyear, WebElement durationmonth, WebElement tenureoption,
			WebElement selecttenure, WebElement maritaloption, WebElement selectmartial, WebElement professionpotion,
			List<WebElement> selectprofession, WebElement permenentaddress, WebElement permenentcity,
			WebElement permenentlandmark, WebElement permenentpincode, WebElement permenentstate,
			WebElement selectpermenentstate, WebElement permenentaddresstaus, WebElement selectPermenentaddressstaus,
			WebElement checkboxaddress, WebElement submitapp) {
		try {
			driver.get("https://test1.creditfair.in/admin/consumer-applications");

//			for(int i=0;i<locatorpath.size();i++)  
//	           {  
//	            System.out.println(locatorpath.get(i));     
//	           }  
			addapplicationbutton.click();
			Thread.sleep(1000);
			applicationdetailstab1.click();
			langaugeoption.click();
			Thread.sleep(1000);
			selectlangauge.get(1).click();
			panno.sendKeys("FFPEV3323F");
			JavascriptExecutor js = (JavascriptExecutor) driver;
			// date selection start
			js.executeScript("window.scrollBy(0,300)", "");
			calenderopen.click();
			Thread.sleep(2000);
			dateSelection(calendermonth, calenderprevbtton);
			// date selection end
			//
			firstname.sendKeys("credit test");
			middlename.sendKeys("middlename");
			lastname.sendKeys("lastname");
			fathername.sendKeys("fathername");
			email.sendKeys("fgghhj@creditfair.in");
			mobileno.sendKeys("4342343545");
			Thread.sleep(2000);
			js.executeScript("window.scrollBy(0,300)", "");
			alternateno.sendKeys("2445345456");
			Thread.sleep(1000);
			genderoption.click();
			selectgender.get(1).click();
			monthlyincome.sendKeys("500000");
			js.executeScript("window.scrollBy(0,300)", "");
			Thread.sleep(2000);
			merchantoption.click();
			selectmerchant.get(1).click();
			Thread.sleep(1000);
			loanamount.sendKeys("100000");
			js.executeScript("window.scrollBy(0,300)", "");
			centeroption.click();
			selectcenter.get(2).click();
			purposeoption.click();
			Thread.sleep(1000);
			selectpurpose.click();
			js.executeScript("window.scrollBy(0,300)", "");
			Thread.sleep(2000);
			durationyear.sendKeys("2");
			durationmonth.sendKeys("2");
			tenureoption.click();
			selecttenure.click();
			maritaloption.click();
			selectmartial.click();
			js.executeScript("window.scrollBy(0,500)", "");
			applicationdetailstab2.click();
			Thread.sleep(1000);
			professionpotion.click();
			selectprofession.get(3).click();
			js.executeScript("window.scrollBy(0,500)", "");
			company.sendKeys("credit fair");
			js.executeScript("window.scrollBy(0,500)", "");
			applicationdetailstab3.click();
			Thread.sleep(1000);
			permenentaddress.sendKeys(
					"Holiday Inn, Sakinaka Junction, Andheri - Kurla Rd, Andheri East, Mumbai, Maharashtra 400072");
			permenentcity.sendKeys("mumbai");
			permenentlandmark.sendKeys("bse");
			permenentpincode.sendKeys("400001");
			permenentstate.click();
			selectpermenentstate.click();
			permenentaddresstaus.click();
			selectPermenentaddressstaus.click();
			checkboxaddress.click();
			js.executeScript("window.scrollBy(0,1000)", "");
			submitapp.click();
			Alert alertok = driver.switchTo().alert();
			alertok.accept();

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
// application form end	

}
