package com.intland.codebeamer.functionaltest.page;

import com.intland.codebeamer.functionaltest.page.mystart.MyStartPage;
import org.openqa.selenium.By;

import com.codeborne.selenide.Condition;

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

public class ProjectAdminSettingsPage extends BasePage {

    public void clickOnRemoveProject() {
        $(By.name("REMOVE")).click();
        $(By.className("ui-dialog-buttonset")).shouldBe(Condition.visible);
    }

    public void confirmRemoveProject() {
        $(By.className("ui-dialog-buttonset")).$(byText("Yes")).click();
        $(byAttribute("value", "Delete Project...")).shouldBe(Condition.visible);
    }

    public void clickOnDeleteProject() {
        $(byAttribute("value", "Delete Project...")).click();
        $(By.className("ui-dialog-buttonset")).shouldBe(Condition.visible);
    }

    public MyStartPage confirmDeleteProject() {
        $(By.className("ui-dialog-buttonset")).$(byText("Yes")).click();
        $(By.linkText("Continue")).shouldBe(Condition.visible);
        $(By.linkText("Continue")).click();
        $(By.linkText("New Child Page")).shouldBe(Condition.visible);
        return page(MyStartPage.class);
    }

    public void tickAvailableAsTemplate(boolean isSelected) {
        $("#templateCheckbox").setSelected(isSelected);
    }

    public void clickOnSave() {
        $("#saveButton").click();
    }

    public void checkIfApprovalWorkflowsTab(Condition condition) {
        $("#project-admin-approvals-tab").shouldBe(condition);
    }

    public void checkIfCalendarTab(Condition condition) {
        $("#project-calendar-tab").shouldBe(condition);
    }
}
