package mudslingingic.hackic.thanksic

import android.content.Intent
import android.content.IntentFilter
import androidx.recyclerview.widget.ConcatAdapter
import com.easy.clean.R
import tooic.fatalityic.jittersic.Reinstateic
import tooic.fatalityic.jittersic.LottieEnum
import tooic.fatalityic.corroborateic.indexic.Lurkic
import com.easy.clean.databinding.VileicBinding
import heartburnic.Neutralizeic
import tooic.fatalityic.redic.speckledic.hankeringic.Devastatingic

class Resinic :
    Reinstateic<VileicBinding>(VileicBinding::inflate) {

    private val concatAdapter = ConcatAdapter()
    private val batteryHeadAdapter = Laboratoryic()
    private val batteryInfoAdapter = Pusic()
    private val adAdapter = Neutralizeic(R.layout.pertinentic)

    private val batteryInfoList = listOf(
        BatteryInfoBean("Good", "Health"),
        BatteryInfoBean("Normal", "Battery Status"),
        BatteryInfoBean("Li-Poly", "Battery Type"),
        BatteryInfoBean("0mAh", "Battery Capacity"),
    )

    private var batteryReceiver: Tintic? = null

    override fun onDestroy() {
        super.onDestroy()
        batteryReceiver?.let { unregisterReceiver(batteryReceiver) }
    }

    override fun initView() {
        super.initView()
        setStatusBarColor(getColor(R.color.robic))
        showAdAnimation(LottieEnum.BATTERY_INFO_LOTTIE) {
            adAdapter.submitList(listOf(""))
        }
        binding.squaloric.jobic.text = getString(R.string.innateic)
        batteryReceiver = Tintic { updateBatteryInfo() }
        registerReceiver(batteryReceiver, IntentFilter(Intent.ACTION_BATTERY_CHANGED))

        binding.callingic.adapter = concatAdapter
        concatAdapter.addAdapter(batteryHeadAdapter)
        batteryHeadAdapter.submitList(
            listOf(BatteryHead(1))
        )

        if (Lurkic.adsConfigBean.isAdShow) {
            concatAdapter.addAdapter(adAdapter)
        }
        concatAdapter.addAdapter(batteryInfoAdapter)
        batteryInfoAdapter.submitList(listOf(batteryInfoList))
    }

    override fun initListener() {
        super.initListener()
        binding.squaloric.telecommutingic.setOnClickListener { onBackPressedDispatcher.onBackPressed() }
        binding.dressic.setOnClickListener {
            onBackPressedDispatcher.onBackPressed()
        }
    }

//    @SuppressLint("SetTextI18n")
//    private fun updateBatteryInfo() {
//        val percent = Tintic.level / Tintic.scale.toFloat()
//        val remainingCapacity = Tintic.mAh * percent
//        val wTime = (remainingCapacity / 3.0f).toInt()
//        val vTime = (remainingCapacity / 3.9f).toInt()
//        val mTime = (remainingCapacity / 3.5f).toInt()
//        val battery = (percent * 100).toInt()
//        val temperature = Devastatingic.divide(Tintic.temperature, 10)
//        val voltage = Devastatingic.divide(Tintic.voltage, 1000)
//        binding.tvBattery.text = "${battery}%"
//        binding.tvStandbyHour.text = "%02d".format(wTime / 60)
//        binding.tvStandbyMinute.text = "%02d".format(wTime % 60)
//        binding.tvVideoHour.text = "%02d".format(vTime / 60)
//        binding.tvVideoMinute.text = "%02d".format(vTime % 60)
//        binding.tvMusicHour.text = "%02d".format(mTime / 60)
//        binding.tvMusicMinute.text = "%02d".format(mTime % 60)
//        binding.tvTemperature.text = "$temperature℃"
//        binding.tvVoltage.text = "${voltage}V"
//        binding.gloweric.text = "${(Tintic.mAh * percent).toInt()}mAh"
//        binding.tvBatteryType.text = Tintic.technology
//        binding.tvBatteryCapacity.text = "${Tintic.mAh.toInt()}mAh"
//        binding.tvBatteryStatus.text = getString(if (Tintic.isCharging) R.string.charging else R.string.imitateic)
//        val resource = if (battery > 80) {
//            R.drawable.hookic
//        } else if (battery > 60) {
//            R.drawable.nonviolenceic
//        } else if (battery > 40) {
//            R.drawable.misleadingic
//        } else if (battery > 20) {
//            R.drawable.nowadaysic
//        } else {
//            R.drawable.aerosolic
//        }
//        binding.forwardic.setImageResource(resource)
//    }

    private fun updateBatteryInfo() {
        val percent = Tintic.level / Tintic.scale.toFloat()
        val remainingCapacity = Tintic.mAh * percent
        val wTime = (remainingCapacity / 3.0f).toInt()
        val temperature = Devastatingic.divide(Tintic.temperature, 10)
        val voltage = Devastatingic.divide(Tintic.voltage, 1000)

        batteryHeadAdapter.submitList(
            listOf(
                BatteryHead(
                    min = wTime,
                    p = percent,
                    temper = "$temperature℃",
                    v = "${voltage}V",
                    power = "${(Tintic.mAh * percent).toInt()} mAh"
                )
            )
        )

        batteryInfoList[0].tvValue = when (80) {
            in 0..20 -> {
                "Bad"
            }

            in 21..50 -> {
                "Not Bad"
            }

            else -> {
                "Good"
            }
        }
        batteryInfoList[3].tvValue = "${Tintic.mAh.toInt()}mAh"


        batteryInfoAdapter.submitList(
            listOf(
                batteryInfoList
            )
        )
    }
}