package pxds.czbe.twvj

import android.content.Intent
import android.os.Environment
import android.os.StatFs
import android.util.Log
import android.widget.ScrollView
import androidx.core.view.updatePadding
import com.blankj.utilcode.util.BarUtils
import com.test.basd.supercleanermax.R
import com.test.basd.supercleanermax.databinding.JgzjqwBinding
import fsir.tqqe.Ausa
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.launch
import pxds.apch.ldfl.lijc.Xxkn
import pxds.etmo.Ffhe
import pxds.etmo.Jmut
import pxds.etmo.Jmyh
import pxds.etmo.Ngma
import pxds.etmo.Ozev
import pxds.etmo.Uknt
import pxds.etmo.Vryl
import pxds.lmmd.zmwf.Khko.setTrackedOnClickListener
import pxds.lmmd.zmwf.Khko.string
import pxds.lmmd.zmwf.Khko.toFormatSize
import pxds.lmmd.zmwf.Qwcj
import pxds.lmmd.zmwf.Wecj

class Xteh : Wecj<JgzjqwBinding>() {

    override val binding: JgzjqwBinding by lazy {
        JgzjqwBinding.inflate(layoutInflater)
    }

    var totalsize = 0L

    fun b(): Long {
        try {
            val statFs = StatFs(Environment.getExternalStorageDirectory().path)
            val statFs2 = StatFs(Environment.getRootDirectory().path)
            val blackSize = statFs2.blockSizeLong * statFs2.availableBlocksLong + statFs.blockSizeLong * statFs.availableBlocksLong
            return a(blackSize)
        } catch (e10: Exception) {
            return 0L
        }
    }

    override fun setListener() {
        binding.zkpmnns.setTrackedOnClickListener {
            binding.pqzeyix.fullScroll(ScrollView.FOCUS_DOWN)
        }
        listOf(binding.ezvaglx, binding.cqvsciw, binding.rijmixk).setTrackedOnClickListener {
            startActivity(Intent(requireContext(), Vryl::class.java))
        }
        binding.lcpcrpe.setTrackedOnClickListener {
            startActivity(Intent(requireActivity(), Ausa::class.java))
        }
        binding.tfbhkkc.setTrackedOnClickListener {
            startActivity(Intent(requireContext(), Jmyh::class.java))
        }
        binding.pwiupla.setTrackedOnClickListener {
            startActivity(Intent(requireContext(), Ozev::class.java))
        }

        binding.dzrnpqx.setTrackedOnClickListener {
            startActivity(Intent(requireContext(), Jmut::class.java))
        }

        binding.pkqhbkw.setTrackedOnClickListener {
            startActivity(Intent(requireActivity(), Xxkn::class.java))
        }

        binding.ntygxdm.setTrackedOnClickListener {
            startActivity(Intent(requireActivity(), Ngma::class.java))
        }
        binding.qxniklo.setTrackedOnClickListener {
            startActivity(Intent(requireActivity(), Ffhe::class.java))
        }

        binding.wcfqbac.setTrackedOnClickListener {
            startActivity(Intent(requireActivity(), Uknt::class.java))
        }

        MainScope().launch(Dispatchers.IO) {
            Qwcj.startMoritor()
        }
    }

    fun f(): Long {
        return if (totalsize > 0) {
            totalsize
        } else try {
            val statFs = StatFs(Environment.getExternalStorageDirectory().path)
            val statFs2 = StatFs(Environment.getRootDirectory().path)
            Log.i(
                R.string.ޣފޤޜފ_D.string(), R.string.ޜގއޘޡ_D.string() + statFs2.blockSizeLong * statFs2.blockCountLong + R.string.ޖނބޕގ_D.string() + statFs.blockSizeLong * statFs.blockCountLong
            )
            var blockSizeLong = statFs2.blockSizeLong * statFs2.blockCountLong + statFs.blockSizeLong * statFs.blockCountLong

            blockSizeLong = getClosestPowerOfTwo(blockSizeLong)
            totalsize = blockSizeLong
            blockSizeLong

        } catch (e10: java.lang.Exception) {
            0L
        }
    }

    fun getClosestPowerOfTwo(size: Long): Long {
        var powerOfTwo: Long = 1
        while (powerOfTwo < size) {
            powerOfTwo *= 2
        }
        return powerOfTwo
    }

    private fun initStorage() {
        val stat = StatFs(Environment.getExternalStorageDirectory().path)
        val totalSize = f()
        val availableSize = b()
        val usedSize = totalSize - availableSize
        val usedPercentage = usedSize.toFloat() / totalSize * 100
        binding.fksjtnj.progress = usedPercentage
        binding.vtlszlg.text = R.string.ތޑދޥޒ_D.string((usedSize.toFormatSize()).toString(), (totalSize.toFormatSize()).toString())
    }

    override fun setView() {
        binding.root.updatePadding(top = BarUtils.getStatusBarHeight())
        initStorage()
    }

    fun a(j10: Long): Long {
        var j10 = j10
        var i7 = 0
        while (true) {
            val j11: Long = 1000
            if (j10 < j11) {
                break
            }
            j10 /= j11
            i7++
        }
        for (i10 in 0 until i7) {
            j10 *= 1024
        }
        return j10
    }
}