package ui.pages;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.CacheLookup;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.ExpectedConditions;
import ui.BasePageObject;

/**
 * Created with IntelliJ IDEA.
 * User: BrayanRosas
 * Date: 11/10/15
 * Time: 6:09 PM
 * To change this template use File | Settings | File Templates.
 */
public class ResourcePage extends BasePageObject{

    boolean exitsResource=false;
    Actions action = new Actions(driver);

    @FindBy(xpath= "//button[@id='btnRemove']/preceding-sibling::button")
    WebElement buttonAddResource;

    @FindBy(id= "btnRemove")
    WebElement buttonRemoveResource;

    @FindBy(xpath= "//input[@ng-model='resourceNameFilter']")
    WebElement inputFilterResource;

    @FindBy(xpath= "//div[@class='ngCell centeredColumn col1 colt1']")
    WebElement columnIconResource;

    @FindBy(xpath= "//div[@class='ngCell centeredColumn col2 colt2']")
    WebElement columnNameResource;

    @FindBy(xpath= "//div[@class='ngCell centeredColumn col3 colt3']")
    WebElement columnCustomNameResource;

    public ResourcePage() {
        PageFactory.initElements(driver, this);
        waitUntilPageObjectIsLoaded();
    }

    @Override
    public void waitUntilPageObjectIsLoaded() {
        wait.until(ExpectedConditions.visibilityOf(buttonAddResource));
    }

    public boolean existInColumnName(String resourceName){

        if(isPresent(By.xpath("//div[@class='ngCell centeredColumn col2 colt2']//span[text()='"+resourceName+"']"))) {
            exitsResource=true;

        }
        else {
          exitsResource=false;
        }
        return exitsResource;
    }

    public boolean existInColumnCustomName(String resourceCustomName){

        if(isPresent(By.xpath("//div[@class='ngCell centeredColumn col3 colt3']//span[text()='"+resourceCustomName+"']"))) {
            exitsResource=true;

        }
        else {
            exitsResource=false;
        }
        return exitsResource;
    }

    public ResourceInfoPage goToPropertyResource(String resourceName){

        action.moveToElement(columnCustomNameResource.findElement(By.xpath("//span[text()='"+resourceName+"']"))).doubleClick().build().perform();
        columnCustomNameResource.findElement(By.xpath("//span[text()='"+resourceName+"']")).click();
        return new ResourceInfoPage();
    }
}


@@ -359,17 +359,16 @@
 t;%0A%0A/**%0A
- 
 * Create
@@ -389,17 +389,16 @@
 J IDEA.%0A
- 
 * User: 
@@ -409,17 +409,16 @@
 anRosas%0A
- 
 * Date: 
@@ -426,17 +426,16 @@
 1/10/15%0A
- 
 * Time: 
@@ -442,17 +442,16 @@
 6:09 PM%0A
- 
 * To cha
@@ -506,17 +506,16 @@
 plates.%0A
- 
 */%0Apubli
@@ -559,21 +559,28 @@
 Object%7B%0A
-%0A
     
+private 
 boolean 
@@ -604,16 +604,24 @@
 se;%0A    
+private 
 Actions 
@@ -1719,33 +1719,32 @@
 sResource=true;%0A
-%0A
         %7D%0A      
@@ -1897,25 +1897,24 @@
 ustomName)%7B%0A
-%0A
         if(i
@@ -2058,17 +2058,16 @@
 e=true;%0A
-%0A
         
@@ -2226,33 +2226,32 @@
  resourceName)%7B%0A
-%0A
         action.m
@@ -2527,11 +2527,9 @@
 ;%0A    %7D%0A
+
 %7D
-%0A%0A

Fix the encapsulation attributes