package com.atlassian.webdriver.bitbucket.page;

import com.atlassian.pageobjects.elements.ElementBy;
import com.atlassian.pageobjects.elements.PageElement;
import com.atlassian.webdriver.bitbucket.element.DiffSelectionDropdown;
import com.atlassian.webdriver.bitbucket.element.SideBySideDiffFileContent;

public class ChangesetSideBySideDiffPage extends CommitPage<ChangesetSideBySideDiffPage, SideBySideDiffFileContent> {

    @ElementBy(id = "diff-options-dropdown-trigger")
    protected PageElement dropdown;

    @ElementBy(className ="file-content", pageElementClass = SideBySideDiffFileContent.class)
    protected SideBySideDiffFileContent fileContent;

    public ChangesetSideBySideDiffPage(String projectKey, String repoSlug, String commitId) {
        this(projectKey, repoSlug, commitId, null, null);
    }

    public ChangesetSideBySideDiffPage(String projectKey, String repoSlug, String commitId, String parentId) {
        this(projectKey, repoSlug, commitId, parentId, null);
    }

    public ChangesetSideBySideDiffPage(String projectKey, String repoSlug, String commitId, String parentId, String changePath) {
        super(projectKey, repoSlug, commitId, parentId, changePath, ChangesetSideBySideDiffPage.class);
    }

    @Override
    public SideBySideDiffFileContent getFileContent() {
        return fileContent;
    }

    public ChangesetUnifiedDiffPage switchToUnified() {
        pageBinder.bind(DiffSelectionDropdown.class, dropdown).open().selectSideBySide();
        ChangesetUnifiedDiffPage page = pageBinder.bind(ChangesetUnifiedDiffPage.class, projectKey, repoSlug, commitId, parentId, changePath);
        page.getFileContent().waitUntilFileContentLoaded();
        return page;
    }
}
