package tech.alexontest.poftutor.pages;

import com.google.inject.Inject;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.CacheLookup;
import org.openqa.selenium.support.FindBy;
import tech.alexontest.poftutor.pageblocks.PostSummaryBlock;
import tech.alexontest.poftutor.pageblocks.PostSummaryBlockDesktop;
import tech.alexontest.poftutor.pageblocks.TagCloudWidgetBlock;
import tech.alexontest.poftutor.pageblocks.TagCloudWidgetBlockDesktop;

import java.util.List;
import java.util.stream.Collectors;

public final class HomePageDesktop extends AbstractPage implements HomePage {

    @FindBy(css = ".site-title")
    @CacheLookup
    private WebElement title;

    @FindBy(css = ".widget")
    @CacheLookup
    private List<WebElement> widgets;

    @FindBy(css = ".post-content")
    @CacheLookup
    private List<WebElement> articles;

    @FindBy(css = ".site-info")
    private WebElement footerText;

    @FindBy(css = ".site-info a")
    private List<WebElement> footerLinks;

    private final TagCloudWidgetBlockDesktop tagCloudWidgetBlockDesktop;

    @Inject
    public HomePageDesktop(final WebDriver webDriver, final TagCloudWidgetBlockDesktop tagCloudWidgetBlockDesktop) {
        super(webDriver);
        this.tagCloudWidgetBlockDesktop = tagCloudWidgetBlockDesktop;
    }

    @Override
    public String getBrowserTabPageTitle() {
        return "Alexander on Testing – Adventures in Software Testing";
    }

    @Override
    public String getURL() {
        return "https://alexanderontesting.com/";
    }

    @Override
    public String getTitle() {
        return title.getText();
    }

    @Override
    public int getWidgetCount() {
        return widgets.size();
    }

    @Override
    public List<PostSummaryBlock> getArticles() {
        return articles.stream()
                .map(PostSummaryBlockDesktop::new)
                .collect(Collectors.toList());
    }

    @Override
    public TagCloudWidgetBlock getTagCloudWidgetBlock() {
        return tagCloudWidgetBlockDesktop;
    }

    @Override
    public String getFooterText() {
        return footerText.getText();
    }

    @Override
    public List<String> getFooterLinks() {
        return footerLinks.stream()
                .map(we -> we.getAttribute("href"))
                .collect(Collectors.toList());
    }
}

@@ -431,79 +431,8 @@
 ock;
-%0Aimport tech.alexontest.poftutor.pageblocks.TagCloudWidgetBlockDesktop;
 %0A%0Aim
@@ -1000,39 +1000,32 @@
 CloudWidgetBlock
-Desktop
  tagCloudWidgetB
@@ -1028,23 +1028,16 @@
 getBlock
-Desktop
 ;%0A%0A    @
@@ -1122,23 +1122,16 @@
 getBlock
-Desktop
  tagClou
@@ -1142,23 +1142,16 @@
 getBlock
-Desktop
 ) %7B%0A    
@@ -1204,23 +1204,16 @@
 getBlock
-Desktop
  = tagCl
@@ -1218,39 +1218,32 @@
 CloudWidgetBlock
-Desktop
 ;%0A    %7D%0A%0A    @Ov
@@ -1951,23 +1951,16 @@
 getBlock
-Desktop
 ;%0A    %7D%0A

Use the Interface in the HomePage field