package com.atlassian.webdriver.bitbucket.element;

import com.atlassian.pageobjects.elements.PageElement;
import com.atlassian.pageobjects.elements.PageElementFinder;
import com.atlassian.pageobjects.elements.query.TimedCondition;
import org.openqa.selenium.By;

import javax.annotation.Nonnull;
import javax.inject.Inject;

public class AppSwitcherDropdown extends AbstractElementPageObject {

    @Inject
    PageElementFinder elementFinder;

    public AppSwitcherDropdown(@Nonnull PageElement container) {
        super(container);
    }

    /**
     * Checks if the app switcher is on the current page.
     *
     * @return A condition checking if the app switcher is present.
     */
    public TimedCondition isPresent() {
        return container.timed().isPresent();
    }

    /**
     * Click the app switcher trigger.
     *
     * @return The page object representing the dropdown.
     */
    public AppSwitcherDropdownItems clickTrigger() {
        container.click();
        return pageBinder.bind(AppSwitcherDropdownItems.class, elementFinder.find(By.id("app-switcher")));
    }
}
