package gwt.react.preact_sanity_test.client;


import gwt.interop.utils.client.plainobjects.JsPlainObj;
import gwt.react.client.components.Component;
import gwt.react.client.components.ComponentConstructorFn;
import gwt.react.client.components.ComponentUtils;
import gwt.react.client.elements.ReactElement;
import gwt.react.client.proptypes.BaseProps;
import gwt.react.client.proptypes.html.InputProps;
import gwt.react.client.proptypes.html.LabelProps;
import gwt.react.client.proptypes.html.attributeTypes.InputType;
import jsinterop.annotations.JsPackage;
import jsinterop.annotations.JsType;

import static gwt.interop.utils.client.plainobjects.JsPlainObj.$;
import static gwt.react.client.api.React.DOM.*;

/**
 * This example shows a stateful component where we have renamed the JsType and added it to the global scope
 */
@JsType(name = "RenamedStatefulExample2", namespace = JsPackage.GLOBAL)
public class StatefulExample2 extends Component<BaseProps, StatefulExample2.State>{

	@JsType(isNative = true, namespace = JsPackage.GLOBAL, name="Object")
	static class State extends JsPlainObj {
		public boolean checked;
	}

	public StatefulExample2(BaseProps props) {
		super(props);
	}

	@Override
	protected ReactElement<?, ?> render() {
		return
			div(null,
				label(new LabelProps()
						.HtmlFor("checkField"),
						"Click me "
				),
				input(new InputProps()
						.id("checkField")
						.type(InputType.checkbox)
						.checked(state.checked)
						.onClick(e -> setState($(new State(), "checked", !state.checked)))
			)
		);
	}

	//You cannot pass the Class directly to React.createElement if you have renamed the JsType or
	//disabled class meta data using (-XdisableClassMetadata) . In this case you need to use ComponentUtils.getCtorFn
	//to get the constructor function
	public static ComponentConstructorFn<BaseProps> component() {
		return ComponentUtils.getCtorFn("RenamedStatefulExample2");
	}
}

@@ -230,33 +230,29 @@
 ent.
-components.ComponentUtils
+elements.ReactElement
 ;%0Aim
@@ -274,33 +274,29 @@
 client.e
-lem
+v
 ents.
-ReactElem
+MouseEv
 ent;%0Aimp
@@ -695,16 +695,84 @@
 t.DOM.*;
+%0Aimport static gwt.react.client.components.ComponentUtils.getCtorFn;
 %0A%0A/**%0A *
@@ -1245,16 +1245,315 @@
 s);%0A%09%7D%0A%0A
+%09void onClicked(MouseEvent e) %7B%0A%09%09//React recommends using the setState function if you are setting the new state based on the old state.%0A%09%09//possibly set state calls could be batched up and updated asynchronously%0A%09%09setState((prevState, props) -%3E $(new State(), %22checked%22, !prevState.checked));%0A%09%7D%0A%0A
 %09@Overri
@@ -1832,65 +1832,24 @@
 ick(
-e -%3E setState($(new State(), %22checked%22, !state.che
+this::onCli
 cked)
-))
 %0A%09%09%09
@@ -2163,24 +2163,24 @@
 mponent() %7B%0A
+
 %09%09return Com
@@ -2176,31 +2176,16 @@
 %09return 
-ComponentUtils.
 getCtorF

Update to support ES6 Style components