package mg.dot.feufaro.di

import android.content.pm.PackageManager
import android.os.Build
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalContext

@Composable
actual fun rememberAppVersion(): String {
    val context = LocalContext.current

    return remember(context) {
        try {
            val pm = context.packageManager
            val packageName = context.packageName

            val packageInfo = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
                pm.getPackageInfo(packageName, PackageManager.PackageInfoFlags.of(0))
            } else {
                @Suppress("DEPRECATION")
                pm.getPackageInfo(packageName, 0)
            }

            packageInfo.versionName ?: "0.0.0"
        } catch (e: Exception) {
            println("AppVersion Error: ${e.message}")
            e.printStackTrace()
            "0.0.0"
        }
    }
}