import{DTEvent}from"../common/event-emitter";import{MOUSE_CLICK_TYPE,MOUSE_EVENT_TYPE,NOTIFICATION_TYPE}from"./model-api";import{ModelMouseEvent}from"../common/constant";function getEventName(a,b){if(b===MOUSE_CLICK_TYPE.right)return ModelMouseEvent.ContextMenu;if(b===MOUSE_CLICK_TYPE.left){if(a===MOUSE_EVENT_TYPE.MouseClick)return ModelMouseEvent.Click;if(a===MOUSE_EVENT_TYPE.MouseEnter)return ModelMouseEvent.Hover;if(a===MOUSE_EVENT_TYPE.MouseLeave)return ModelMouseEvent.Blur;if(a===MOUSE_EVENT_TYPE.MouseDoubleClick)return ModelMouseEvent.DBlclick}return""}export function defineUnityEvent(a,b){return c=>d=>{let e=!1,f=d.unity;const g=f.addNotificationListener(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===ModelMouseEvent.Click){let e=new 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===ModelMouseEvent.DBlclick){let e=new 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()}}}}