package pages;

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

public class ProcessesPage extends BasePage {

  private static final String SELECTED_TAB = "//div[@class='radio-content'][@title='%s']";
  private static final String TEXT_ON_PAGE = "//text//div[contains(.,'%s')]";
  private static final String TAB_INPUT_BY_NAME = "//label[.//span[contains(.,'%s')]]//input";
  private static final String BUTTON_BY_NAME = "//button[contains(.,'%s')]";
  private static final String LINK_BY_NAME = "//a[@class='nav-link'][contains(.,'%s')]";
  private static final String MODAL_TITLE_BY_NAME = "//*[@class='modal-title'][contains(.,'%s')]";
  private static final String PROCESS_IN_GRID_BY_ID = "//static-column-grid//div[@row-id='%s']";

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

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

  public void clickOnLink(String name) {
    waitForElementToBeClickable(getBy(LINK_BY_NAME, name)).click();
  }

  public void clickOnTab(String name) {
    waitForElementToBeClickable(getBy(TAB_INPUT_BY_NAME, name)).click();
  }

  public boolean isTabSelected(String name) {
    return isPresent(getBy(SELECTED_TAB, name));
  }

  public boolean isTitleVisible(String title) {
    return isPresent(getBy(TEXT_ON_PAGE, title));
  }

  public boolean isProcessVisibleInGrid(String processId) {
    return isPresent(getBy(PROCESS_IN_GRID_BY_ID, processId));
  }

  public void clickOnProcessInGrid(String processId) {
    waitForElementToBeClickable(getBy(PROCESS_IN_GRID_BY_ID, processId)).click();
  }

  public boolean isDialogOpened(String title) {
    return isPresent(getBy(MODAL_TITLE_BY_NAME, title));
  }
}
