// eslint-disable-next-line import/no-unresolved
import { NativeModules } from 'react-native';
import nativeEventer from '../../common/nativeEventer';

const instance = new nativeEventer('miniAppObserverEvent', NativeModules.MiniAppObserver);
instance.setIntercept({
  resReducer: res => {
    if (instance.isAndroid()) return res;
    const { event, content } = res || {};
    return { name: event, params: content };
  },
});

export default {
  on(eventName, callback) {
    return instance.on(eventName, callback).catch(err => { });
  },

  off(eventName, callback) {
    return instance.off(eventName, callback).catch(err => { });
  }
}
