package com.autonomy.abc.selenium.page.promotions;

import com.autonomy.abc.selenium.actions.wizard.WizardStep;
import com.autonomy.abc.selenium.element.FormInput;
import com.autonomy.abc.selenium.promotions.DynamicPromotion;
import com.autonomy.abc.selenium.promotions.ResultsNumberStep;
import com.autonomy.abc.selenium.promotions.SearchTriggerStep;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

import java.util.Arrays;
import java.util.List;

public class HSOCreateNewPromotionsPage extends CreateNewPromotionsPage {
    public HSOCreateNewPromotionsPage(WebDriver driver) {
        super(driver);
    }

    private FormInput dataInput(String attribute) {
        return new FormInput(findElement(By.cssSelector("[data-attribute='" + attribute + "']")), getDriver());
    }

    // for dynamic promotions
    public void setDialValue(int value) {
        WebElement dialInput = findElement(By.cssSelector("input.dial"));
        // .clear() does not work properly due to validation
        dialInput.sendKeys("\b\b" + Integer.toString(value));
    }

    @Override
    public List<com.autonomy.abc.selenium.actions.wizard.WizardStep> getDynamicWizardSteps(DynamicPromotion promotion) {
        return Arrays.asList(
            new ResultsNumberStep(this, promotion.getNumberOfResults()),
            new SearchTriggerStep(this, promotion.getTrigger())
        );
    }

    // for static promotions
    public FormInput documentTitle() {
        return dataInput("staticTitle");
    }

    public FormInput documentContent() {
        return dataInput("staticContent");
    }

    @Override
    public void addSpotlightPromotion(final String promotionType, final String searchTrigger) {
        // TODO: move this logic into a "SpotlightPromotion" object
        promotionType("SPOTLIGHT").click();
        continueButton().click();
        addSearchTrigger(searchTrigger);
        finishButton().click();
    }
}

@@ -881,112 +881,134 @@
 lic 
-void setDialValue(int value) %7B%0A        WebElement dialInput = findElement(By.cssSelector(%22input.dial%22));
+WebElement dial() %7B%0A        return findElement(By.cssSelector(%22input.dial%22));%0A    %7D%0A%0A    public void setDialValue(int value) %7B
 %0A   
@@ -1077,21 +1077,18 @@
     dial
-Input
+()
 .sendKey

Add accessor to raw WebElement for test that checks if it is displayed.