package ru.stqa.pft.appmanager;

import org.openqa.selenium.By;
import org.openqa.selenium.firefox.FirefoxDriver;
import ru.stqa.pft.model.ContactData;

/**
 * Created by Owner on 7/17/2016.
 */
public class ContactHelper extends ContactHelperBase {

  private int contactCount;

  public ContactHelper(FirefoxDriver wd) {
    super(wd);

  }

  public void returnToHomePage() {
    click(By.linkText("home page"));
  }

  public void submitContactForm() {
    click(By.xpath("//div[@id='content']/form/input[21]"));
  }

  public void fillOutContactForm(ContactData contactData) {
    wd.get("http://localhost/addressbook/edit.php");
    type(By.name("firstname"), contactData.getFirstname());
    click(By.cssSelector("label"));
    type(By.name("middlename"), contactData.getMiddlename());
    click(By.name("theform"));
    type(By.name("lastname"), contactData.getLastname());
    type(By.name("nickname"), contactData.getNickname());
    type(By.name("title"), contactData.getTitle());
    type(By.name("company"), contactData.getCompany());
    type(By.name("address"), contactData.getAddress());
    type(By.name("home"), contactData.getHomephone());
    type(By.name("mobile"), contactData.getMobile());
    type(By.name("work"), contactData.getWorkphone());
    type(By.name("email"), contactData.getEmail());
  }

  public void deleteContact() {
    wd.switchTo().alert().accept();
  }

  public void selectContact() {

    if (!wd.findElement(By.name("selected[]")).isSelected()) {
      click(By.name("selected[]"));
    }
    click(By.xpath("//div[@id='content']/form[2]/div[2]/input"));
  }


  public void sumitContactModification() {
    wd.findElement(By.xpath("//div[@id='content']/form[1]/input[22]")).click();
  }


  public void selectContactMofication() {
    wd.findElement(By.xpath("//table[@id='maintable']/tbody/tr[2]/td[8]/a/img")).click();
  }

  public void updateContactForm() {
    wd.findElement(By.name("nickname")).click();
    wd.findElement(By.name("nickname")).clear();
    wd.findElement(By.name("nickname")).sendKeys("Jaifar-Jaifar");
  }

  public void createContact(ContactData contact) {
    fillOutContactForm(contact);
    submitContactForm();
    returnToHomePage();
    logOut();

  }

  private void logOut() {

  }

  public boolean isThereAContact() {
    return isElementPresent(By.name("selected[]"));
  }

  private boolean isElementPresent(By xpath) {
    return false;
  }

  public int getContactCount() {
    return wd.findElements(By.name("selected[]")).size();
  }
}


@@ -248,37 +248,8 @@
  %7B%0A%0A
-  private int contactCount;%0A%0A
   pu
@@ -1564,32 +1564,33 @@
 input%22));%0A  %7D%0A%0A%0A
+%0A
   public void su
@@ -2048,452 +2048,6 @@
   %7D%0A
-%0A  public void createContact(ContactData contact) %7B%0A    fillOutContactForm(contact);%0A    submitContactForm();%0A    returnToHomePage();%0A    logOut();%0A%0A  %7D%0A%0A  private void logOut() %7B%0A%0A  %7D%0A%0A  public boolean isThereAContact() %7B%0A    return isElementPresent(By.name(%22selected%5B%5D%22));%0A  %7D%0A%0A  private boolean isElementPresent(By xpath) %7B%0A    return false;%0A  %7D%0A%0A  public int getContactCount() %7B%0A    return wd.findElements(By.name(%22selected%5B%5D%22)).size();%0A  %7D%0A%7D%0A
+%7D
 %0A

Revert "Count"