package com.performics;
import android.content.Intent;
import android.provider.Settings;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.Promise;
import android.app.Activity;
import android.util.Log;




public class OpenDevOptionsModule extends ReactContextBaseJavaModule {
private static ReactApplicationContext reactContext;

    public OpenDevOptionsModule(ReactApplicationContext reactContext) {
        super(reactContext);
        this.reactContext = reactContext;
         Log.d("OpenDevOptionsModule", "init module");
    }

    @Override
    public String getName() {
        return "OpenDevOptions";
    }

    @ReactMethod
    public void open() {
        Log.d("OpenDevOptionsModule", "open");
        Intent intent = new Intent(Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        reactContext.startActivity(intent);
         Log.d("OpenDevOptionsModule", "open1");
    }

    // Check if Developer Options Enabled
    @ReactMethod
    public void isDevOptionsEnabled(Promise promise) {
        try {
             Log.d("OpenDevOptionsModule", "isDevOptionsEnabled");
            int devOptions = Settings.Global.getInt(
                reactContext.getContentResolver(),
                Settings.Global.DEVELOPMENT_SETTINGS_ENABLED,
                0
            );
            promise.resolve(devOptions == 1);
        } catch (Exception e) {
             Log.d("OpenDevOptionsModule", e.toString());
            promise.reject("ERROR", e.toString());
        }
    }
}