package com.atlassian.webdriver.bitbucket.element;

import com.atlassian.pageobjects.elements.PageElement;
import com.atlassian.pageobjects.elements.PageElementFinder;
import com.atlassian.webdriver.bitbucket.util.Locators;
import org.openqa.selenium.By;

import javax.inject.Inject;

public class AUIDropdown2 {

    @Inject
    private PageElementFinder elementFinder;

    private PageElement trigger;
    private PageElement dropdown;

    public AUIDropdown2(PageElement trigger) {
        this.trigger = trigger;
    }

    public AUIDropdown2 open() {
        String menuId = trigger.getAttribute(Locators.ATTR_ARIA_CONTROLS);
        dropdown = elementFinder.find(By.id(menuId));
        trigger.click();
        return this;
    }

    public void clickItem(String itemName) {
        dropdown.find(By.linkText(itemName)).click();
    }
}
