package com.atlassian.webdriver.bitbucket.page;

import com.atlassian.pageobjects.elements.ElementBy;
import com.atlassian.webdriver.bitbucket.element.DeleteConfirmationDialog;

public class RepositoryDeleteConfirmationPage extends RepositoryEditSettingsPage {
    @ElementBy(id = "delete-repository-dialog")
    private DeleteConfirmationDialog dialog;

    public RepositoryDeleteConfirmationPage(String projectKey, String slug) {
        super(projectKey, slug);
    }

    public DeleteConfirmationDialog getDialog() {
        return dialog;
    }

    public RepositoryEditSettingsPage clickCancel() {
        dialog.clickCancel();

        return pageBinder.bind(RepositoryEditSettingsPage.class, projectKey, slug);
    }

    public RepositoryEditSettingsPage clickConfirmFail() {
        dialog.clickConfirm();
        return pageBinder.bind(RepositoryEditSettingsPage.class, projectKey, slug);
    }

    public ProjectOverviewPage clickConfirmSuccess() {
        waitForPageLoad(new Runnable() {
            @Override
            public void run() {
                dialog.clickConfirm();
            }
        });

        return pageBinder.bind(ProjectOverviewPage.class, projectKey);
    }

    @Override
    public boolean isHere() {
        return super.isHere() && getDialog().isVisible();
    }
}
