/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.guis.bnds; import gplx.*; import gplx.xowa.*; import gplx.xowa.guis.*;
import gplx.gfui.ipts.*; import gplx.xowa.guis.cmds.*;
interface Xog_bnd_wkr {
	void Bind_ipt_to_box(String box, String ipt);
}
class Xog_bnd_wkr__null implements Xog_bnd_wkr {
	public void Bind_ipt_to_box(String box, String ipt) {}
}
class Xog_bnd_temp implements Gfo_invk {
	private Xoae_app app;
	private final    Ordered_hash regy = Ordered_hash_.New();
	private final    Xog_bnd_wkr bnd_wkr = new Xog_bnd_wkr__null();
	private Xog_bnd_box[] boxs = Xog_bnd_box_.Ary();
	public void Init_by_app(Xoae_app app) {
		this.app = app;
		Init_itm(Xog_cmd_itm_.Key_gui_browser_tabs_new_dflt__at_dflt__focus_y	, Xog_bnd_box_.Tid_browser				, "mod.c+key.t");
	}
	private void Init_itm(String cmd, int box, String... ipts) {
		int ipts_len = ipts.length;
		for (int i = 0; i < ipts_len; i++) {
			String ipt_str = ipts[i];
			Init_itm(cmd, i, box, IptArg_.parse_or_none_(ipt_str));
		}
	}
	// private void Init_itm(String cmd, int idx, int box, String ipt) {Init_itm(cmd, idx, box, IptArg_.parse_or_none_(ipt));}
	private void Init_itm(String cmd, int idx, int box, IptArg ipt) {
		String key = cmd + "-" + Int_.To_str(idx + List_adp_.Base1);		// EX: xowa.widgets.url.focus-1 xowa.widgets.url.focus-2
		Xog_bnd_itm itm = new Xog_bnd_itm(key, Bool_.Y, cmd, box, ipt);
		boxs[box].Add(itm);
		regy.Add(itm.Key(), itm);
		app.Cfg().Bind_many_app(this, cmd);
	}
	public Object Invk(GfsCtx ctx, int ikey, String k, GfoMsg m) {
		Xog_bnd_cfg_itm itm = Xog_bnd_cfg_itm.Parse(m.ReadStr("v"));
		bnd_wkr.Bind_ipt_to_box(itm.Box(), itm.Ipt());
		return this;
	}
}
class Xog_bnd_cfg_itm {
	public Xog_bnd_cfg_itm(String box, String ipt) {
		this.box = box;
		this.ipt = ipt;
	}
	public String Box() {return box;} private final    String box;
	public String Ipt() {return ipt;} private final    String ipt;
	public static Xog_bnd_cfg_itm Parse(String s) {
		String[] parts = String_.Split(s, "|");
		return new Xog_bnd_cfg_itm(parts[0], parts[1]);
	}
}
