init {
	screenTemplates := {
		"000": {
			"widgets": {
				"001": {"type": "label", "text": "aid", "state": 0},
				"002": {"type": "textInput", "text": "", "state": 0},
				"003": {"type": "label", "text": "name", "state": 0},
				"004": {"type": "textInput", "text": "", "state": 0},
				"005": {"type": "button", "text": "ok", "state": 0},
				"006": {"type": "button", "text": "search", "state": 0}
				}, 
			"layout": true
		}, 
		"001" :{
			"widgets": {
				"101": {"type": "label", "text": "success!", "state": 0},
				"102": {"type": "button", "text": "back", "state": 0}
			},
			"layout": true
		},
		"002": {
			"widgets": {
				"201": {"type": "textInput", "text": "", "state": 0},
				"202": {"type": "label", "text": "aid", "state": 0},
				"203": {"type": "label", "text": "", "state": 0}
			}
		},
		"409": {
			"widgets": {
				"491": {"type": "label", "text": "conflilct!", "state": 0},
				"492": {"type": "button", "text": "back", "state": 0}
			},
			"layout": true
		}
	}
	sender1 := "002"
	sender2 := "004"
	sender3 := "203"
}

native channel ScreenUpdate {
	in screen(curSc: Json, update(curSc, nextSc)) = nextSc
}

native channel SetLayout {
	in screen.layout(curLayout: Bool, setLayout(nextLayout)) = nextLayout
}

native channel SetVisible(wid: Str) {
	in screen.widgets.{wid}.visible(curVisible: Bool, setVisible(nextVisible)) = nextVisible
}

native channel SetText(wid: Str) {
	in screen.widgets.{wid}.text(curText: Str, setText(nextText)) = nextText
}

native channel SetX(wid: Str) {
	in screen.widgets.{wid}.x(curX: Int, setX(nextX)) = nextX
}

native channel SetY(wid: Str) {
	in screen.widgets.{wid}.y(curY: Int, setY(nextY)) = nextY
}

native channel SetWidth(wid: Str) {
	in screen.widgets.{wid}.width(curWidth: Int, setWidth(nextWidth)) = nextWidth
}

native channel SetHeight(wid: Str) {
	in screen.widgets.{wid}.height(curHeight: Int, setHeight(nextHeight)) = nextHeight
}

native channel MouseEvent(wid: Str) {
	out screen.widgets.{wid}.state(curState: Int, mouseEvent(nextState)) = nextState
}

native channel TextEvent(wid: Str) {
	out screen.widgets.{wid}.text(curText: Str, textEvent(nextText)) = nextText
}

channel addAccount {
	out accounts(accounts, addAccounts(aid: Str, name: Str)) = insert(accounts, aid, name)
}

channel changeName(aid: Str) {
	out accounts.{aid}.name(curName, changeName(nextName)) = nextName
}

channel ChangeCurScreen {
	out curScreen(curScId: Str, changeCurScreen(nextScId)) = nextScId
}

channel ScreenTransition {
	in curScreen(curScId: Str, transScreen(nextScId, screen)) = nextScId
	ref screenTemplates.{nextScId}(screen, transScreen(nextScId, screen))
	out screen(curS, transScreen(nextScId, screen)) = screen
}

channel EventDispatch(wid: Str) {
	in screen.widgets.{wid}.state(curState: Int, dispatchEvent(curScId, wid, nextState)) = nextState
	ref curScreen(curScId: Str, dispatchEvent(curScId, wid, nextState))
	out screenTemplates.{curScId}.widgets.{wid}.state(curState: Int, dispatchEvent(curScId, wid, nextState)) = nextState
}

channel EventDispatch2(wid: Str) {
	in screen.widgets.{wid}.text(curText: Str, dispatchEvent(curScId, wid, nextText)) = nextText
	ref curScreen(curScId: Str, dispatchEvent(curScId, wid, nextText))
	out screenTemplates.{curScId}.widgets.{wid}.text(curText: Str, dispatchEvent(curScId, wid, nextText)) = nextText
}

channel EventHandler2(scId: Str, wid: Str) {
	in screenTemplates.{scId="000"}.widgets.{wid="006"}.state(curState: Str, handleEvent(nextState)) = nextState
	out curScreen(curScId: Str, handleEvent(nextState)) = if(nextState == 0, "002", curScId)
}

channel EventHandler3(scId: Str, wid: Str) {
	in screenTemplates.{scId="000"}.widgets.{wid="005"}.state(curState: Str, handleEvent3(nextState, t1, t2, aid, name, accounts)) = nextState
	ref sender1(t1, handleEvent3(nextState, t1, t2, aid, name, accounts))
	ref sender2(t2, handleEvent3(nextState, t1, t2, aid, name, accounts))
	ref screen.widgets.{t1}.text(aid, handleEvent3(nextState, t1, t2, aid, name, accounts))
	ref screen.widgets.{t2}.text(name, handleEvent3(nextState, t1, t2, aid, name, accounts))
	ref accounts(accounts, handleEvent3(nextState, t1, t2, aid, name, accounts))
	out accounts(accounts, handleEvent3(nextState, t1, t2, aid, name, tmp)) = if(nextState==0, if(contains(accounts, aid), accounts, insert(accounts, aid, {"name": name})), accounts)
	out curScreen(curScId: Str, handleEvent3(nextState, t1, t2, aid, name, accounts)) = if(nextState==0, if(contains(accounts, aid), "409", "001"), curScId)
}

channel EventHandler4(scId: Str, wid: Str) {
	in screenTemplates.{scId="001"}.widgets.{wid="102"}.state(curState: Str, handleEvent4(nextState)) = nextState
	out curScreen(curScId: Str, handleEvent4(nextState)) = if(nextState==0, "000", curScId)
}

channel EventHandler5(scId: Str, wid: Str) {
	in screenTemplates.{scId="002"}.widgets.{wid="201"}.text(curText: Str, handleEvent5(nextText, target, accounts)) = nextText
	ref sender3(target, handleEvent5(nextText, target, accounts))
	ref accounts(accounts, handleEvent5(nextText, target, accounts))
	out screen.widgets.{target}.text(curText, handleEvent5(nextText, target, accounts)) = if(containe(accounts, nextText), lookup(accounts, nextText), curText) 
}

channel EventHandler5(scId: Str, wid: Str) {
	in screenTemplates.{scId="409"}.widgets.{wid="492"}.state(curState: Str, handleEvent5(nextState)) = nextState
	out curScreen(curScId: Str, handleEvent4(nextState)) = if(nextState==0, "000", curScId)
}