package com.atlassian.webdriver.bitbucket.element.activity;

import com.atlassian.pageobjects.elements.PageElement;
import com.atlassian.webdriver.bitbucket.element.Comment;
import org.openqa.selenium.By;

import javax.annotation.Nonnull;

import static com.atlassian.bitbucket.util.Chainable.chain;

public class FileCommentActivity extends CommentActivityItem {

    public FileCommentActivity(@Nonnull PageElement activityContainer) {
        super(activityContainer);
    }

    @Nonnull
    public Comment getComment() {
        return pageBinder.bind(Comment.class, findCommentElement());
    }

    private PageElement findCommentElement() {
        return chain(activityContainer.findAll(By.tagName("li")))
                .filter(element -> element.hasClass("comment"))
                .getFirst();
    }
}
