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

import com.codeborne.selenide.SelenideElement;
import com.intland.codebeamer.functionaltest.page.BasePage;
import com.intland.codebeamer.functionaltest.page.trackers.AddTagDialog;
import com.intland.codebeamer.functionaltest.page.wiki.CenterPane;
import com.intland.codebeamer.functionaltest.page.wiki.LeftPane;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.support.ui.ExpectedConditions;

import java.util.concurrent.TimeUnit;

import static com.codeborne.selenide.Selenide.*;

public class MyStartPage extends BasePage {

    public LeftPane leftPane = new LeftPane();
    public CenterPane centerPane = new CenterPane();

    @Override
    public boolean isPageLoaded() throws UnsupportedOperationException {
        try {
            Wait().withTimeout(5, TimeUnit.SECONDS)
                    .ignoring(NoSuchElementException.class)
                    .until(ExpectedConditions.visibilityOf($(By.xpath(".//a[contains(text(), 'Personal Wiki')]"))));
        } catch (Exception e) {
            return false;
        }
        return true;
    }

    public AddTagDialog clickOnTags() {
        $(By.xpath(".//a[text()='Tags:']")).click();
        return page(AddTagDialog.class);
    }

    public SelenideElement getMyStartMenu() {
        return $(By.linkText("My Start"));
    }

    @Override
    public void waitForPageToLoad() {
        leftPane.waitForLeftTreeToLoad();
        centerPane.waitForCenterPaneToLoad();
    }
}
