define(["Ti/_/lang"],function(e){function n(e){this._hnd=e,this._listeners={}}var t=window,i={},r=require.sendNativeMessage;return n.prototype._send=function(e,s){var o;return s.hnd=this._hnd,t.handleProxyResponse=function(e){o=e},r("r",e+JSON.stringify(s)),t.handleProxyResponse=void 0,o=JSON.parse(o),o.primitiveValue?o.primitiveValue:o.hnd?i[o.hnd]||(i[o.hnd]=new n(o.hnd)):void 0},n.prototype.invoke=function(e,t,i){return this._send("in",{name:e,argTypes:t,argValues:i.map(function(e){var t=e instanceof n;return{valueHnd:t?e._hnd:void 0,valuePrimitive:t?void 0:e}})})},n.prototype.getProp=function(e,n){return this._send("gp",{name:e,isAttached:n})},n.prototype.setProp=function(e,t,i){var r=t instanceof n;return this._send("sp",{name:e,valueHnd:r?t._hnd:void 0,valuePrimitive:r?void 0:t,isAttached:i})},n.prototype.getAtIndex=function(e,n){return this._send("gi",{name:e,index:n})},n.prototype.setAtIndex=function(e,n,t){return this._send("si",{name:e,value:n,index:t})},n.prototype.getEnum=function(e,n){return this._send("ge",{name:e,value:n})},n.prototype.destory=function(){this._send("de",{})},n.prototype.addEventListener=function(e,n){this._listeners[e]||(this._listeners[e]=[],r("r","ae"+JSON.stringify({hnd:this._hnd,name:e}))),this._listeners[e].push(n)},n.prototype.removeEventListener=function(e,n){var t=this._listeners[e].indexOf(n);this._listeners[e]&&~t&&(this._listeners[e]=this._listeners[e].splice(t,1),this._listeners[e].length||r("r","re"+JSON.stringify({hnd:this._hnd,name:e})))},e.setObject("Ti.MobileWeb.WP8",{createInstance:function(e,s,o){var d;return t.handleProxyResponse=function(e){d=e},r("r","ci"+JSON.stringify({className:e,argTypes:s,argValues:o.map(function(e){var t=e instanceof n;return{valueHnd:t?e._hnd:void 0,valuePrimitive:t?void 0:e}})})),t.handleProxyResponse=void 0,i[d]=new n(d)},getRootGrid:function(){if(i.root)return i.root;var e;return t.handleProxyResponse=function(n){e=n},r("r","gr"),t.handleProxyResponse=void 0,i[e]=new n(e)}})});