package com.intland.codebeamer.functionaltest.page.projects;

import com.codeborne.selenide.Condition;
import com.intland.codebeamer.functionaltest.page.BasePage;
import com.intland.codebeamer.functionaltest.page.CreateProjectPage;
import com.intland.codebeamer.functionaltest.page.wiki.ProjectWikiPage;
import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;

import static com.codeborne.selenide.Selectors.byText;
import static com.codeborne.selenide.Selenide.$;
import static com.codeborne.selenide.Selenide.page;

public class ProjectsPage extends BasePage {

    public void changeProjectLarge(String projectName) {
        $(By.linkText(projectName)).hover().parent().$(By.className("menuArrowDown")).click();
        $(byText("Large")).click();
    }

    public void changeProjectSmall(String projectName) {
        $(By.linkText(projectName)).hover().parent().$(By.className("menuArrowDown")).click();
        $(byText("Small")).click();
    }

    public void waitForSave() {
        $(byText("Your changes have been successfully saved!")).shouldBe(Condition.visible);
        $(byText("Your changes have been successfully saved!")).shouldBe(Condition.hidden);
    }

    public Dimension getBoxSize(String projectName) {
        return $(By.linkText(projectName)).getSize();
    }

    public CreateProjectPage clickOnNewProject() {
        $(By.linkText("New Project")).click();
        return page(CreateProjectPage.class);
    }

    public void clickOnCompactList() {
        $(byText("Compact List")).click();
    }

    public ProjectWikiPage clickOnProject(String projectName) {
        $(By.partialLinkText(projectName)).click();
        return page(ProjectWikiPage.class);
    }

}
