package com.plugin.openbrowser;

import com.getcapacitor.JSObject;
import com.getcapacitor.Plugin;
import com.getcapacitor.PluginCall;
import com.getcapacitor.PluginMethod;
import com.getcapacitor.annotation.CapacitorPlugin;

@CapacitorPlugin(name = "OpenBrowser")
public class OpenBrowserPlugin extends Plugin {

    private OpenBrowser implementation = new OpenBrowser();

    @PluginMethod
    public void echo(PluginCall call) {
        String value = call.getString("value");

        JSObject ret = new JSObject();
        ret.put("value", implementation.echo(value));
        call.resolve(ret);
    }

    @PluginMethod
    public void open(PluginCall call) {
        String url = call.getString("url");
        boolean isExternal = call.getBoolean("ext");
        if(implementation == null) {
            implementation = new OpenBrowser();
        }
        implementation.open(getActivity(), url, isExternal);
    }
}
