import java.util.*;

public class Widget {
	private String type;
	private String text;
	private boolean visible;
	private int x;
	private int y;
	private int width;
	private int height;
	private int state;
	private Map<String, Map<String, Object>> data;
	private List<String> columns;
	private String primaryKeyName;
	private Widget1 widget;
	private CurScreen curScreen;
	private ScreenTemplates screenTemplates;
	private SwingPresenter presenter;
    public Widget(String type, String text, boolean visible, int x, int y, int width, int height, int state, Map<String, Map<String, Object>> data, List<String> columns, String primaryKeyName, ScreenTemplates screenTemplates, SwingPresenter presenter) {
        this.type = type;
        this.text = text;
        this.visible = visible;
        this.x = x;
        this.y = y;
        this.width = width;
        this.height = height;
        this.state = state;
        this.data = data;
        this.columns = columns;
        this.primaryKeyName = primaryKeyName;
        this.screenTemplates = screenTemplates;
        this.presenter = presenter;
    }
	public Map<String, Object> getValue() {
		Map temp_nil3 = new HashMap<>();
		temp_nil3.put("type",this.getType());
		temp_nil3.put("text",this.getText());
		temp_nil3.put("visible",this.getVisible());
		temp_nil3.put("x",this.getX());
		temp_nil3.put("y",this.getY());
		temp_nil3.put("width",this.getWidth());
		temp_nil3.put("height",this.getHeight());
		temp_nil3.put("state",this.getState());
        if (this.getType().equals("table")) {
            temp_nil3.put("data",this.getData());
            temp_nil3.put("columns",this.getColumns());
            temp_nil3.put("primaryKeyName",this.getPrimaryKeyName());
        }
		return temp_nil3;
	}
	public String getType() {
		return this.type;
	}
	public String getText() {
		return this.text;
	}
	public boolean getVisible() {
		return this.visible;
	}
	public int getX() {
		return this.x;
	}
	public int getY() {
		return this.y;
	}
	public int getWidth() {
		return this.width;
	}
	public int getHeight() {
		return this.height;
	}
	public int getState() {
		return this.state;
	}
	public Map<String, Map<String, Object>> getData() {
		return this.data;
	}
    public List<String> getColumns() {
        return this.columns;
    }
    public String getPrimaryKeyName() {
        return this.primaryKeyName;
    }
	public void changeX(String wid, int x) {
		this.x = x;
		this.presenter.setX(wid, x);
	}
	public void changeY(String wid, int y) {
		this.y = y;
		this.presenter.setY(wid, y);
	}
	public void changeVisible(String wid, boolean visible) {
		this.visible = visible;
		this.presenter.setVisible(wid, visible);
	}
    public void changeText(String text) {
        this.text = text;
    }
//	public void updateFromWidget(String self, String scId, String wid, Map<String, Object> widget, String curScreen) {
//		this.value = widget;
//	}
	public void updateDataFromState(String screenId, String widId, int state, String search1, String search2, String search3, String search5, String search6, String result, String address1_, String address2_, String businessdescription1_, String businessdescription2_, String companyoverview_, Map<String, Map<String, Object>> businessCardManagement) {
		Map<String, Map<String, Object>> temp_if0;
		if ((state==0)) {
			Map<String, Object> temp_json92 = new HashMap<>();
			temp_json92.put("住所１", search5);
			temp_json92.put("住所２", search6);
			temp_json92.put("事業内容１", search1);
			temp_json92.put("事業内容２", search2);
			temp_json92.put("会社概要", search3);
			Map<String, Map<String, Object>> temp_search0 = new HashMap<>();
			for (String key: businessCardManagement.keySet()) {
				boolean isMatch = true;
				for (String qKey: temp_json92.keySet()) {
					Map<String, Object> value = businessCardManagement.get(key);
					for (String valKey: value.keySet()) {
						if (temp_json92.get(qKey) != null && !temp_json92.get(qKey).equals("") && valKey.equals(qKey)) {
							if (!((String) value.get(valKey)).contains((String) temp_json92.get(qKey))) {
								isMatch = false;
							}
							break;
						}
					}
					if (!isMatch) break;
				}
				if (isMatch) {
					temp_search0.put(key, businessCardManagement.get(key));
				}
			}
			temp_if0 = temp_search0;
		} else {
			temp_if0 = this.data;
		}
		this.data = temp_if0;
		this.presenter.setTable(screenId, widId, temp_if0);
	}
	public void textEvent(String wid, String nextText) {
		this.text = nextText;
	}
	public void mouseEvent(String wid, int nextState) {
		this.state = nextState;
		this.widget = screenTemplates.getScreenTemplate(curScreen.getValue()).getWidgets1().getWidget1(wid);
		this.widget.updateStateFromState(wid, wid, wid, this.state, curScreen.getValue());
	}
	public void setCurScreen(CurScreen curScreen) {
		this.curScreen = curScreen;
	}
}