package com.evetensorflowocr;

import androidx.annotation.NonNull;

import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.module.annotations.ReactModule;
import android.app.Activity;
import android.content.Intent;
import com.facebook.react.bridge.Callback;
import android.util.Log;

@ReactModule(name = EveTensorflowOcrModule.NAME)
public class EveTensorflowOcrModule extends ReactContextBaseJavaModule {
  public static final String NAME = "EveTensorflowOcrModule";

  public EveTensorflowOcrModule(ReactApplicationContext reactContext) {
    super(reactContext);
  }

  @Override
  @NonNull
  public String getName() {
    return NAME;
  }

  // Example method
  // See https://reactnative.dev/docs/native-modules-android
  @ReactMethod
  public void multiply(double a, double b, Promise promise) {
    promise.resolve(a * b);
  }

  @ReactMethod
  public void launchBday(String msg, Callback callBack) {

    Activity activity = getCurrentActivity();
    String result = "Hi";
    if (activity == null) {
      Log.v("Love", "No activity");
    } else {
      Log.v("Love", "We have an activity");
    }

    Intent bday = new Intent(activity, MainActivity.class);
    if (bday == null) {
      Log.v("Love", "We do not have an intent for ocr");
      result = "Keep trying";
    } else {
      Log.v("Love", "We do have an intent for ocr");
      result = "You did it!";
    }
    activity.startActivity(bday);
    callBack.invoke(result);
  }

}
