package com.vpn.fastestvpnservice.utils

import android.content.Context
import android.graphics.drawable.Drawable
import android.util.Log
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
import androidx.lifecycle.LifecycleOwner
import java.util.*

class Utils {

    companion object {

        fun getDrawable(context: Context, name: String?): Int {
            val iso = name?.toLowerCase().toString()
            Log.d("image_logo", "iso => $iso")
            return context.resources.getIdentifier(iso, "drawable", context.packageName)
        }

        fun getDrawableGray(context: Context, name: String?): Int {
            val iso = name?.toLowerCase().toString()
            val iso_gray = "gray_$iso"
            return context.resources.getIdentifier(iso_gray, "drawable", context.packageName)
        }

//        @Composable
//        fun OnLifecycleEvent(onEvent: (
//            owner: LifecycleOwner,
//            event: Lifecycle.Event
//        ) -> Unit) {
//            val eventHandler = rememberUpdatedState(onEvent)
//            val lifecycleOwner = rememberUpdatedState(LocalLifecycleOwner.current)
//
//            DisposableEffect(lifecycleOwner.value) {
//                val lifecycle = lifecycleOwner.value.lifecycle
//                val observer = LifecycleEventObserver { owner, event ->
//                    eventHandler.value(owner, event)
//                }
//
//                lifecycle.addObserver(observer)
//                onDispose {
//                    lifecycle.removeObserver(observer)
//                }
//            }
//        }

        /*  fun openWebActivity(contexts: Activity, url: String, title: String) {
              val intent = Intent(contexts, WebViwActivity::class.java)
              intent.putExtra(WebViwActivity.PARAM_WEB_VIEW_URL, url)
              intent.putExtra("title", title)
              contexts.startActivity(intent)
              contexts.overridePendingTransition(R.anim.open_next, R.anim.close_main)
          }*/

//        fun getCountryFlag(context: Context, countryCode: String): Drawable? {
//            try{
//                return AppCompatResources.getDrawable(
//                    context, context.resources.getIdentifier(
//                        context.packageName + ":drawable/" + countryCode.toLowerCase(Locale.getDefault()),
//                        null,
//                        null
//                    )
//                )
//            }catch (e:java.lang.Exception){
//
//            }
//            return null
//        }
//
//        fun getCountryFlagImage(context: Context, countryCode: String): Drawable? {
//            try{
//                return AppCompatResources.getDrawable(
//                    context, context.resources.getIdentifier(
//                        context.packageName + ":drawable/" + countryCode.toLowerCase(Locale.getDefault()),
//                        null,
//                        null
//                    )
//                )
//            }catch (e:java.lang.Exception){
//
//            }
//            return null
//        }
//
//        fun getCountryFlagGray(context: Context, countryCode: String): Drawable? {
//            val grayStr = "gray_"
//            try{
//                return AppCompatResources.getDrawable(
//                    context, context.resources.getIdentifier(
//                        context.packageName + ":drawable/" + grayStr + countryCode.toLowerCase(Locale.getDefault()),
//                        null,
//                        null
//                    )
//                )
//            }catch (e:java.lang.Exception){
//
//            }
//            return null
//        }

    }
}