package com.ejada.hmg.utils

import io.flutter.plugin.common.MethodChannel
import io.flutter.plugin.common.MethodChannel.Result

class FlutterText{

    companion object{
        fun with(key:String, completion:(String)->Unit){
            HMGUtils.getPlatformChannel().invokeMethod("localizedValue",key, object:MethodChannel.Result{
                override fun success(result: Any?) {
                    val localized  = result as String?
                    if (localized != null){
                        completion(localized)
                    }else{
                        completion(key)
                    }
                }

                override fun error(errorCode: String, errorMessage: String?, errorDetails: Any?) {
                    completion(key)
                    require(false){
                        "'localizedValue' $errorMessage"
                    }
                }

                override fun notImplemented() {
                    require(false){
                        "'localizedValue' method not implemented at flutter"
                    }
                }

            })
        }
    }
}