package com.vpn.fastestvpnservice.beans

import android.content.pm.ApplicationInfo
import android.content.pm.PackageManager
import android.graphics.drawable.Drawable
import android.util.Log
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import java.text.Collator

class SelectApplicationEntry : Comparable<SelectApplicationEntry> {

    private var mInfo: ApplicationInfo? = null
    private var mIcon: Drawable? = null
    private var mName: String? = null
    var mSelected: MutableState<Boolean> = mutableStateOf(false)

    constructor(packageManager: PackageManager?, info: ApplicationInfo, state: Boolean) {
        mInfo = info
        val name = info.loadLabel(packageManager!!)
        mName = name.toString()
        mIcon = info.loadIcon(packageManager)
        Log.d("test_splittunnel_data", "$name $state")
    }

    fun setSelected(selected: MutableState<Boolean>) {
        mSelected = selected
    }

    fun isSelected(): MutableState<Boolean> {
        return mSelected
    }

    fun getInfo(): ApplicationInfo? {
        return mInfo
    }

    fun getIcon(): Drawable? {
        return mIcon
    }

    override fun toString(): String {
        return mName!!
    }

    override fun compareTo(another: SelectApplicationEntry): Int {
        return Collator.getInstance().compare(toString(), another.toString())
    }
}

