package to.etc.domui.component.searchpanel;

import to.etc.domui.component2.form4.FormBuilder;
import to.etc.domui.dom.html.Div;
import to.etc.domui.dom.html.IControl;
import to.etc.domui.dom.html.NodeContainer;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import static java.util.Objects.requireNonNull;

/**
 * @author <a href="mailto:jal@etc.to">Frits Jalvingh</a>
 * Created on 3-2-18.
 */
public class DefaultSearchFormBuilder implements ISearchFormBuilder {
	@Nullable
	private FormBuilder m_builder;

	private Div m_currentTarget;

	private Div m_target;

	@Override public void setTarget(NodeContainer target) throws Exception {
		Div root = m_target = new Div("ui-dfsb-panel");
		target.add(root);
		Div d = m_currentTarget = new Div("ui-dfsb-part");
		root.add(d);
		m_builder = new FormBuilder(d);
	}

	@Override public void append(SearchControlLine<?> it) throws Exception {
		NodeContainer label = it.getLabel();
		if(null != label)
			fb().label(label);
		IControl<?> control = it.getControl();
		fb().control(control);
	}

	public void addBreak() {
		NodeContainer target = requireNonNull(m_target);
		Div d = m_currentTarget = new Div("ui-dfsb-part");
		target.add(d);
		m_builder = new FormBuilder(d);
	}

	@Override public void finish() throws Exception {
		m_builder = null;
	}

	@Nonnull
	public FormBuilder fb() {
		return requireNonNull(m_builder);
	}
}

@@ -529,39 +529,8 @@
 r;%0A%0A
-%09private Div m_currentTarget;%0A%0A
 %09pri
@@ -702,34 +702,16 @@
 %09Div d =
- m_currentTarget =
  new Div
@@ -1096,26 +1096,8 @@
  d =
- m_currentTarget =
  new

Remove unused field.