import { getComponentEventActionCallbacks } from './componentEventActionEmitter';

export function emitComponentEvent({ data: { actionName }, target }) {
  const callbacks = getComponentEventActionCallbacks(target.key, actionName);
  if (callbacks) {
    callbacks.forEach(callback => callback());
  }
}

export const emitComponentEventAction = {
  id: Number.MAX_SAFE_INTEGER,
  projId: Number.MAX_SAFE_INTEGER,
  projKey: '__impage__inject_materials',
  name: 'emitComponentEventAction',
  info: { name: 'emitComponentEventAction', author: 'elliothu' },
  isComponentAction: true,
  action: emitComponentEvent,
};
