package com.awesomeproject3;

import android.content.Context;
import android.util.Log;

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.bridge.ReadableArray;
import com.facebook.react.bridge.WritableArray;
import com.facebook.react.bridge.WritableNativeArray;
import com.facebook.react.modules.core.DeviceEventManagerModule;

public class TplMapsController extends ReactContextBaseJavaModule {
    private static final String MODULE_NAME = "MyModule";


    Context context;


    public TplMapsController(ReactApplicationContext reactContext) {
        super(reactContext);
        Constant.reactApplicationContext = reactContext;
    }

    public TplMapsController(ModuleCallback callback) {
        Constant.moduleCallback = callback;
    }

    @Override
    public String getName() {
        return MODULE_NAME;
    }

    @ReactMethod
    public void myMethod(String param) {
        Constant.moduleCallback.nativeModuleCalled(0,"myMethod");
    }

    @ReactMethod
    public void AddMarker(String lnglat){
        Constant.moduleCallback.nativeModuleCalled(1 , lnglat);
    }

    @ReactMethod
    public void AddCustomMarker(String lnglat){
        Constant.moduleCallback.nativeModuleCalled(3 , lnglat);
    }



    @ReactMethod
    public void AddCustomMarkerWithImage(String lnglat , String longStr){
        Constant.moduleCallback.nativeModuleCalled(5 , lnglat, longStr);
    }

    @ReactMethod
    public void RemoveAllMarkers(){
        Constant.moduleCallback.nativeModuleCalled(4 , "");
    }

    @ReactMethod
    public void RemoveAllPolyLines(){
        Constant.moduleCallback.nativeModuleCalled(5 , "");
    }

    @ReactMethod
    public void SetCameraAnimation(String lnglat , String zoom){
        String lnglatAndZoom = lnglat+";"+zoom;
        Constant.moduleCallback.nativeModuleCalled(2 , lnglatAndZoom);
    }

    @ReactMethod
    public void CameraCallback(String message, Promise promise) {
        Constant.promise  = promise;
    }

    @ReactMethod
    public void passStringArray(ReadableArray array , String color, String width) {

        Constant.PolyLineColor = color;
        Constant.PolyLineWidth = Integer.parseInt(width);
        // Convert the ReadableArray to a WritableArray
        WritableArray writableArray = new WritableNativeArray();
        for (int i = 0; i < array.size(); i++) {
            writableArray.pushString(array.getString(i));
        }

        Constant.moduleCallback.nativeModuleCalled(4 , writableArray);

    }




    public void callbackToRN(String latlng){
//        reactApplicationContext
//                .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
//                .emit("onReady", latlng);
    }

    // Required for rn built in EventEmitter Calls.
    @ReactMethod
    public void addListener(String eventName) {
    }

    @ReactMethod
    public void removeListeners(Integer count) {

    }
}
