package com.intland.codebeamer.functionaltest.page;

import com.codeborne.selenide.Selenide;
import com.codeborne.selenide.WebDriverRunner;
import com.intland.codebeamer.functionaltest.page.wiki.ProjectWikiPage;
import org.openqa.selenium.By;

import java.util.concurrent.TimeUnit;

import static com.codeborne.selenide.Condition.visible;
import static com.codeborne.selenide.Selenide.$;
import static com.codeborne.selenide.Selenide.page;

/**
 * Copyright by Intland Software
 * <p>
 * All rights reserved.
 * <p>
 * This software is the confidential and proprietary information
 * of Intland Software. ("Confidential Information"). You
 * shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement
 * you entered into with Intland.
 */
public class ProjectTemplatePage extends BasePage {

    public ProjectWikiPage clickOnFinish() {
        WebDriverRunner.getWebDriver().manage().timeouts().pageLoadTimeout(120, TimeUnit.SECONDS);
        $("#finishButton").click();
        $(By.linkText("Wiki")).waitUntil(visible, 120000);
        WebDriverRunner.getWebDriver().manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
        return page(ProjectWikiPage.class);
    }

    public void checkIncludeAllWorkItems(boolean isSelected) {
        $("#importAllAssets1").shouldBe(visible).setSelected(isSelected);
    }

    public void checkIncludeWikiPages(boolean isSelected) {
        $("#generateWikiPages1").setSelected(isSelected);
    }

    public String getName() {
        return $("#name").getValue();
    }

    public void fillName(String name){
        $("#name").clear();
        $("#name").sendKeys(name);
    }

    public void setCategory(String category) {
        $("#categoryOther").setValue(category);
    }

    public boolean isProjectAlreadyExists(){
        return !Selenide.getElements(By.xpath(".//span[@id=\"name.errors\"]")).isEmpty();
    }
}
