import { EventProxy } from '../utils/eventProxy';

const componentEvents = new EventProxy();

export function onComponent(eventType, callback) {
  componentEvents.on(eventType, callback);
}

export function emitComponent(eventType, instance, meta, global) {
  // eslint-disable-next-line
  const params = getComponentEventListenerCallbackParams(instance, global, meta);
  componentEvents.emit(eventType, params);
}

function getComponentEventListenerCallbackParams(
  { key, component: { id, info, name, projKey, projId } },
  global,
  meta
) {
  return {
    global,
    meta,
    component: {
      key,
      id,
      info,
      name,
      projId,
      projKey,
    },
  };
}
