package com.atlassian.webdriver.bitbucket.page.admin;

import com.atlassian.pageobjects.elements.ElementBy;
import com.atlassian.pageobjects.elements.Options;
import com.atlassian.pageobjects.elements.PageElement;
import com.atlassian.pageobjects.elements.SelectElement;
import com.atlassian.webdriver.bitbucket.page.BitbucketPage;

public class UserDirectoriesPage extends BitbucketPage {

    @ElementBy(cssSelector = ".aui-page-header a[target=_help]")
    private PageElement helpLink;

    @ElementBy(id = "new-directory")
    private PageElement addDirectoryButton;

    @ElementBy(id = "new-directory-type")
    private SelectElement directoryTypeSelector;

    @ElementBy(cssSelector = "#new-directory-form input")
    private PageElement nextButton;

    @Override
    public String getUrl() {
        return "/plugins/servlet/embedded-crowd/directories/list";
    }

    public UserDirectoriesPage popupAddDirectoryDialog() {
        addDirectoryButton.click();
        return pageBinder.bind(UserDirectoriesPage.class);
    }

    public UserDirectoriesPage setDirectoryType(String directoryType) {
        directoryTypeSelector.select(Options.text(directoryType));
        return this;
    }

    public String getHelpLinkTitle() {
        return helpLink.getAttribute("title");
    }

    public String getHelpLinkURL() {
        return helpLink.getAttribute("href");
    }

    public UserDirectorySettingsPage gotoNewDirectorySettingsPage() {
        nextButton.click();
        return pageBinder.bind(UserDirectorySettingsPage.class);
    }

}
