package ca.corefacility.bioinformatics.irida.ria.integration.pages.projects;

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import ca.corefacility.bioinformatics.irida.ria.integration.pages.AbstractPage;

/**
 * Created by josh on 2016-10-07.
 */
public class ProjectSampleMetadataImportPage extends AbstractPage {
	private WebDriver driver;

	@FindBy(id = "dz-form") WebElement dzForm;
	@FindBy(id = "sampleId-previous") WebElement sampleIdPrev;
	@FindBy(css = "input[type=radio]") List<WebElement> headerRadios;
	@FindBy(id = "preview-btn") WebElement previewBtn;
	@FindBy(id = "found-pill") WebElement foundPill;
	@FindBy(id = "missing-pill") WebElement missingPill;

	public ProjectSampleMetadataImportPage(WebDriver driver) {
		super(driver);
	}

	public static ProjectSampleMetadataImportPage goToPage(WebDriver driver) {
		this.driver = driver;
		get(driver, "projects/1/sample-metadata");
		return PageFactory.initElements(driver, ProjectSampleMetadataImportPage.class);
	}

	public void uploadMetadataFile(String path) {
		WebDriverWait wait = new WebDriverWait(driver, 10);
		wait.until(ExpectedConditions.visibilityOf(dzForm));
		dzForm.sendKeys(path);
		wait.until(ExpectedConditions.visibilityOf(sampleIdPrev));
	}

	public void selectSampleNameColumn() {
		headerRadios.get(3).click();
		previewBtn.click();
		WebDriverWait wait = new WebDriverWait(driver, 10);
		wait.until(ExpectedConditions.visibilityOf(foundPill));
	}

	public int getFoundCount() {
		return Integer.parseInt(foundPill.findElement(By.className("badge")).getText());
	}
}

@@ -601,36 +601,8 @@
 e %7B%0A
-%09private WebDriver driver;%0A%0A
 %09@Fi
@@ -1086,32 +1086,8 @@
 ) %7B%0A
-%09%09this.driver = driver;%0A
 %09%09ge

Use abstractpage driver