package com.dyteMobileSdk;

import android.app.Activity;
import android.util.Log;

import com.dyteMobileSdk.Permissions.RNPermissionsModule;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactRootView;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.modules.core.DeviceEventManagerModule;


public class DyteInstanceManager {
    public static ReactInstanceManager instance;
    public static ReactRootView reactRootView;
    public static RNPermissionsModule permissionsHandler;

    static public Activity getCurrentActivity() {
        ReactContext reactContext
                = instance != null
                ? instance.getCurrentReactContext() : null;
        return reactContext != null ? reactContext.getCurrentActivity() : null;
    }

    static public void sendEvent(String event, WritableMap params){
        ReactContext reactContext
                = instance != null
                ? instance.getCurrentReactContext() : null;
        if(reactContext != null)reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
                .emit(event, params);
    }

    static public void unmountApplication() {
        if (reactRootView != null) {
            reactRootView.unmountReactApplication();
        }
    }
}