package com.rapp;

//import android.widget.LinkSender;

import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.modules.core.DeviceEventManagerModule;
import com.facebook.react.bridge.Arguments;
import javax.annotation.Nullable;
import com.facebook.react.bridge.WritableMap;
import android.support.v4.content.LocalBroadcastManager;
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.Context;
import android.content.IntentFilter;

import java.util.Map;

public class LinkSender extends ReactContextBaseJavaModule {

	  public class LocalBroadcastReceiver extends BroadcastReceiver {
         @Override
         public void onReceive(Context context, Intent intent) {
               String someData = intent.getStringExtra("my-extra-data");
               mReactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
                      .emit("link", someData);
         }
   }

	private ReactContext mReactContext;
	private LocalBroadcastReceiver mLocalBroadcastReceiver;

  public LinkSender(ReactApplicationContext reactContext) {
    super(reactContext);
    this.mReactContext = reactContext;
    this.mLocalBroadcastReceiver = new LocalBroadcastReceiver();
    LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(reactContext);
    localBroadcastManager.registerReceiver(mLocalBroadcastReceiver, new IntentFilter("my-custom-event"));
  }



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

	private void sendEvent(ReactContext reactContext,
                       String eventName,
                       @Nullable WritableMap params) {
	  reactContext
	      .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
	      .emit(eventName, params);
	}
}