package com.sdl.selenium.extjs6.form;

import com.sdl.selenium.web.SearchType;
import com.sdl.selenium.web.WebLocator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;

public class TextField extends com.sdl.selenium.web.form.TextField {
    private static final Logger LOGGER = LoggerFactory.getLogger(TextField.class);

    public TextField() {
        setLabelPosition("//following-sibling::*//");
    }

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

    public TextField(WebLocator container, String label) {
        this(container);
        setLabel(label, SearchType.DEEP_CHILD_NODE);
    }

    public static void main(String[] args) {
        TextField textField = new TextField(null, "[review]Choose Source");
        WebLocator iconLocator = new WebLocator(textField).setElPath(textField.getTriggerPath("arrow"));
        LOGGER.debug(iconLocator.getXPath());
    }

    // methods
     public boolean assertSetValue(String value) {
        boolean setted = setValue(value);
        assertThat(setted, is(true));
        return true;
    }

    public String getTriggerPath(String icon) {
        return "/parent::*/parent::*/*[contains(@class,'x-form-" + icon + "-trigger')]";
    }

    public boolean clickIcon(String icon) {
        if (ready()) {
            WebLocator iconLocator = new WebLocator(this).setElPath(getTriggerPath(icon));
            iconLocator.setRenderMillis(500);
            iconLocator.setInfoMessage(this + " -> trigger-" + icon);
            try {
                return iconLocator.click();
            } catch (Exception e) {
                LOGGER.error("Exception on clickIcon: " + e.getMessage());
                return false;
            }
        } else {
            LOGGER.warn("clickIcon : field is not ready for use: " + this);
        }
        return false;
    }

    /**
     * @return true is the element doesn't have attribute readonly
     */
    public boolean isEditable() {
        return !"true".equals(getAttribute("readonly"));
    }

    /**
     * @return true is the element does have attribute disabled
     */
    public boolean isDisabled() {
        return "true".equals(getAttribute("disabled"));
    }

}

@@ -750,287 +750,8 @@
  %7D%0A%0A
-    public static void main(String%5B%5D args) %7B%0A        TextField textField = new TextField(null, %22%5Breview%5DChoose Source%22);%0A        WebLocator iconLocator = new WebLocator(textField).setElPath(textField.getTriggerPath(%22arrow%22));%0A        LOGGER.debug(iconLocator.getXPath());%0A    %7D%0A%0A
     
@@ -2045,10 +2045,292 @@
 %0A    %7D%0A%0A
+    /*public static void main(String%5B%5D args) %7B%0A        TextField textField = new TextField(null, %22%5Breview%5DChoose Source%22);%0A        WebLocator iconLocator = new WebLocator(textField).setElPath(textField.getTriggerPath(%22arrow%22));%0A        LOGGER.debug(iconLocator.getXPath());%0A    %7D*/%0A
 %7D%0A

add extjs6 components