"use strict";exports.__esModule=!0,exports.defineUnityEvent=defineUnityEvent;var _eventEmitter=require("../common/event-emitter"),_modelApi=require("./model-api"),_constant=require("../common/constant");function getEventName(a,b){if(b===_modelApi.MOUSE_CLICK_TYPE.right)return _constant.ModelMouseEvent.ContextMenu;if(b===_modelApi.MOUSE_CLICK_TYPE.left){if(a===_modelApi.MOUSE_EVENT_TYPE.MouseClick)return _constant.ModelMouseEvent.Click;if(a===_modelApi.MOUSE_EVENT_TYPE.MouseEnter)return _constant.ModelMouseEvent.Hover;if(a===_modelApi.MOUSE_EVENT_TYPE.MouseLeave)return _constant.ModelMouseEvent.Blur;if(a===_modelApi.MOUSE_EVENT_TYPE.MouseDoubleClick)return _constant.ModelMouseEvent.DBlclick}return""}function defineUnityEvent(a,b){return c=>d=>{let e=!1,f=d.unity;const g=f.addNotificationListener(_modelApi.NOTIFICATION_TYPE.ObjectMouseEventRaised,f=>{if(e)return;let g,{ObjectId:h,Position:i,WorldPosition:j,EventType:k,Button:l}=f,m=getEventName(k,l);if(a===m)if(h&&d.global&&(h===d.global.modelId||h===d.global.id?g=d.global:g=d.global.get(h,!1)),m===_constant.ModelMouseEvent.Click){let e=new _eventEmitter.DTEvent(a,{event:void 0,object:g?g.model:void 0,uv:{x:i.X,y:i.Y},point:{x:j.X,y:j.Y,z:j.Z},component:g,modelId:h});b.call(null,d,e,c)}else if(m===_constant.ModelMouseEvent.DBlclick){let e=new _eventEmitter.DTEvent(a,{event:void 0,object:g?g.model:void 0,uv:{x:i.X,y:i.Y},point:{x:j.X,y:j.Y,z:j.Z},component:g,modelId:h});b.call(null,d,e,c)}});return{name:a,type:"event",disable:()=>{e=!0},enable:()=>{e=!1},remove:()=>{g()}}}}