package pages;

import core.BasePage;
import org.openqa.selenium.WebDriver;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class TestProcessPage extends BasePage {

  private static final String PAGE_TITLE_BY_TEXT = "//div[@class='form-group']//*[text()='%s']";
  private static final String BUTTON_BY_NAME = "//button[contains(.,'%s')]";

  public TestProcessPage(WebDriver browser) {
    super(browser, "/#/process/");
  }

  public boolean isPageTitleVisible(String title) {
    return isPresent(getBy(PAGE_TITLE_BY_TEXT, title));
  }

  public String getProcessId() {
    String currentUrl = driver.getCurrentUrl();
    Pattern pattern = Pattern.compile("process\\/(\\d+)");
    Matcher matcher = pattern.matcher(currentUrl);
    matcher.find();
    return matcher.group(1);
  }

  public void clickOnButton(String name) {
    waitForElementToBeClickable(getBy(BUTTON_BY_NAME, name)).click();
  }
}