package creditfair_admin_maven_uipages;

import java.util.ArrayList;
import java.util.List;

import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
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;



public class AdminAppprocApprove {
	WebDriver driver;
	Boolean statusnotfound = true;
	String appidpass = null;

	public void AdminAppprocApprove(WebDriver driver) throws Exception {
		this.driver = driver;

	}

	@FindBy(how = How.XPATH, using = "//ul[contains(@class,'dropdown-menu show')]/li/a")
	@CacheLookup
	List<WebElement> statuslist;
	@FindBy(how = How.XPATH, using = "//button[contains(@class,'btn btn-primary status-update-list-negative')]")
	@CacheLookup
	WebElement negativelistbutton;
	@FindBy(how = How.XPATH, using = "//button[contains(@class,'btn btn-primary save_comment_box')]")
	@CacheLookup
	WebElement savestatusbutton;
	@FindBy(how = How.ID, using = "validation_modal_box")
	@CacheLookup
	WebElement validationmodel;
	@FindBy(how = How.XPATH, using = "//div[contains(@id,'validation_modal_box')]/div/div/div[1]/table/tbody/tr/td")
	@CacheLookup
	List<WebElement> clickheredoc;
	@FindBy(how = How.XPATH, using = "//div[contains(@id,'nav-tabContent')]/div[4]/div/div[3]/div[2]/div[12]/select")
	@CacheLookup
	WebElement bureaureport;
	@FindBy(how = How.XPATH, using = "//div[contains(@id,'nav-tabContent')]/div[4]/div/div[3]/div[2]/div[12]/select/option[2]")
	@CacheLookup
	WebElement selectbureaureport;
	@FindBy(how = How.XPATH, using = "//div[contains(@id,'nav-tabContent')]/div[4]/div"
			+ "/descendant::div[contains(@class,'add_more_documents_row row')]/div[2]/div[13]/input")
	@CacheLookup
	WebElement scoreput;
	@FindBy(how = How.XPATH, using = "//div[contains(@id,'nav-tabContent')]/div[4]/div"
			+ "/descendant::div[contains(@class,'add_more_documents_row row')]/div[2]/div[14]/input")
	@CacheLookup
	WebElement creditreportfile;
	@FindBy(how = How.XPATH, using = "//div[contains(@id,'nav-tabContent')]/div[4]/div"
			+ "/descendant::div[contains(@class,'add_more_documents_row row')]/div[3]/div[14]/input")
	@CacheLookup
	WebElement pancardupload;
	@FindBy(how = How.XPATH, using = "//div[contains(@id,'nav-tabContent')]/div[4]/div"
			+ "/descendant::div[contains(@class,'add_more_documents_row row')]/div[4]/div[14]/input")
	@CacheLookup
	WebElement panvalidaupload;

	public void statusSelection(String stauspass) {
		System.out.println("1" + statuslist);
		while (statusnotfound) {
			System.out.println("while" + statuslist);
			for (WebElement statusseelectedlist : statuslist) {
				System.out.println(statusseelectedlist.getText());
				String statusisselectedname = statusseelectedlist.getText();
				if (statusisselectedname.equals(stauspass)) {
					statusseelectedlist.click();
					break;
				}

			}
			statusnotfound = false;
		}

	}

	public void processAppapprove(WebDriver driver) throws Exception {

	try {
//			DbConnection appid = new DbConnection();
//			appidpass = appid.pullId();
//			Thread.sleep(5000);
//			WebElement statuschangebutton = driver
//					.findElement(By.xpath("//tr[contains(@id,'tr_" + appidpass + "')]/td[10]/span[1]"));
//
//			statuschangebutton.click();
//			Thread.sleep(3000);
//			statusSelection("In-process");
//			Alert alertok = driver.switchTo().alert();
//			alertok.accept();
//			Thread.sleep(3000);
//			negativelistbutton.click();
//			Thread.sleep(5000);
//			savestatusbutton.click();
//			Thread.sleep(6000);
//			WebElement statuschangebutton1 = driver
//					.findElement(By.xpath("//tr[contains(@id,'tr_" + appidpass + "')]/td[10]/span[1]"));
//			Thread.sleep(5000);
//			statuschangebutton1.click();
//			Thread.sleep(3000);
//			statusnotfound = true;
//			statusSelection("Waiting For Documents");
//			Alert alertok1 = driver.switchTo().alert();
//			alertok1.accept();
//			Thread.sleep(2000);
//			savestatusbutton.click();
//			Thread.sleep(3000);

//	statuschangebutton.click();
//	Thread.sleep(3000);
//	statusSelection("Waiting For Decision");
//	alertok.accept();
//	Thread.sleep(2000);
//	if (validationmodel.isDisplayed())
//	{
//		clickheredoc.get(1).click();
//	}
//	savestatusbutton.click();
//	ArrayList<String> tabs2 = new ArrayList<String> (driver.getWindowHandles());
//    driver.switchTo().window(tabs2.get(1));
//	Thread.sleep(4000);
//	bureaureport.click();
//	Thread.sleep(1000);
//	selectbureaureport.click();
//	Thread.sleep(2000);
//	scoreput.sendKeys("750");
//	Thread.sleep(1000);
//	System.out.println(creditreportfile);
//	creditreportfile.sendKeys("/Users/pratik/Documents/automation project/automation/creditfair_admin_maven/fileupload/file.png");
//	Thread.sleep(1000);
//	pancardupload.sendKeys("/Users/pratik/Documents/automation project/automation/creditfair_admin_maven/fileupload/file.png");
//	Thread.sleep(1000);
//	panvalidaupload.sendKeys("/Users/pratik/Documents/automation project/automation/creditfair_admin_maven/fileupload/file.png");
//	submitapp.click(); // calling from AdminAddapp class
//	alertok.accept();
//    driver.switchTo().window(tabs2.get(0));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
