package com.atlassian.webdriver.bitbucket.page;

import com.atlassian.pageobjects.elements.ElementBy;
import com.atlassian.pageobjects.elements.PageElement;
import com.atlassian.bitbucket.Product;
import com.atlassian.webdriver.bitbucket.util.ElementUtils;
import com.google.common.collect.ImmutableList;
import org.openqa.selenium.By;

import java.util.List;
import java.util.regex.Pattern;

public class AboutPage extends BitbucketPage {

    @ElementBy(cssSelector = ".aui-page-panel-content .copyright")
    private PageElement copyrightStatement;

    @ElementBy(cssSelector = ".aui-page-panel-content .licenses")
    private PageElement licenses;

    @ElementBy(cssSelector = ".aui-page-panel-content .authors")
    private PageElement authors;

    @Override
    public String getUrl() {
        return "/about";
    }

    public boolean hasCopyrightNotice() {
        Pattern copyrightPattern = Pattern.compile("Copyright © " + Product.FIRST_YEAR_OF_RELEASE + "( - \\d{4})? Atlassian Corporation Pty Ltd.");
        return copyrightPattern.matcher(copyrightStatement.getText()).find();
    }

    public List<String> getAuthors() {
        return ImmutableList.copyOf(ElementUtils.getElementTexts(authors.findAll(By.tagName("li"))));
    }

    public List<String> getLibraries() {
        return ImmutableList.copyOf(ElementUtils.getElementTexts(licenses.findAll(By.tagName("li"))));
    }

}
