package com.sdl.selenium.web.form;

import com.sdl.selenium.web.WebLocator;
import com.sdl.selenium.web.utils.Utils;
import org.openqa.selenium.Keys;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class TextField extends WebLocator implements ITextField {
    private static final Logger LOGGER = LoggerFactory.getLogger(TextField.class);

    public TextField() {
        setClassName("TextField");
        setTag("input");
        setTemplate("placeholder", "@placeholder='%s'");
    }

    public TextField(WebLocator container) {
        this();
        setContainer(container);
    }

    public TextField(String id) {
        this();
        setId(id);
    }

    public <T extends TextField> T setPlaceholder(final String value) {
        String key = "placeholder";
        if(value != null) {
            setElPathSuffix(key, applyTemplate(key, value));
        } else {
            setElPathSuffix(key, null);
        }
        return (T) this;
    }

    public boolean pasteInValue(String value) {
        if (ready()) {
            if (value != null) {
                currentElement.clear();
                Utils.copyToClipboard(value);
                currentElement.sendKeys(Keys.CONTROL, "v");
                LOGGER.info("Set value(" + this + "): " + value + "'");
                return true;
            }
        } else {
            LOGGER.warn("setValue : field is not ready for use: " + toString());
        }
        return false;
    }

    public boolean setValue(String value) {
        return executor.setValue(this, value);
    }

    public String getValue() {
        return executor.getValue(this);
    }
}
@@ -454,66 +454,8 @@
 );%0D%0A
-        setTemplate(%22placeholder%22, %22@placeholder='%25s'%22);%0D%0A
     
@@ -731,196 +731,43 @@
     
-String key = %22placeholder%22;%0D%0A        if(value != null) %7B%0D%0A            setElPathSuffix(key, applyTemplate(key, value));%0D%0A        %7D else %7B%0D%0A            setElPathSuffix(key, null);%0D%0A        %7D
+setAttribute(%22placeholder%22, value);
 %0D%0A  

add setPlaceholder(final String value) for all components which extend com.sdl.selenium.web.form.TextField