package com.cloud.hmg_patient_app

import com.ejada.hmg.MainActivity
import android.os.Build
import android.util.Log
import androidx.annotation.RequiresApi
import com.cloud.hmg_patient_app.penguin.PenguinView
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel

class PenguinInPlatformBridge(
    private var flutterEngine: FlutterEngine,
    private var mainActivity: MainActivity
) {

    private lateinit var channel: MethodChannel

    companion object {
        private const val CHANNEL = "launch_penguin_ui"
    }

    @RequiresApi(Build.VERSION_CODES.O)
    fun create() {
//        openTok = OpenTok(mainActivity, flutterEngine)
        channel = MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL)
        channel.setMethodCallHandler { call: MethodCall, result: MethodChannel.Result ->
            when (call.method) {
                "launchPenguin" -> {
                    print("the platform channel is being called")
                    val args = call.arguments as Map<String, Any>?
                    Log.d("TAG", "configureFlutterEngine: $args")
                    println("args")
                    args?.let {
                        PenguinView(
                            mainActivity,
                            100,
                            args,
                            flutterEngine.dartExecutor.binaryMessenger,
                            activity = mainActivity,
                            channel
                        )
                    }
                }

                else -> {
                    result.notImplemented()
                }
            }
        }
    }

}
