package importantedto.appliededto.surgeonedto.promiseedto.wonderedto

import android.content.Intent
import android.graphics.Color
import androidx.activity.addCallback
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import com.base.datarecovery.databinding.HoveredtoBinding
import com.google.gson.Gson
import importantedto.admireedto.sweptedto.testedto.huntedto.storageedto.Leavingedto
import importantedto.admireedto.sweptedto.testedto.huntedto.storageedto.Orbitedto
import importantedto.afteredto.constitutionaledto.Constraintedto.toFormatSize
import importantedto.afteredto.constitutionaledto.Murderedto
import importantedto.appliededto.surgeonedto.promiseedto.Halcyonedto
import importantedto.concreteedto.cameedto.Hateedto
import importantedto.concreteedto.cameedto.Vigorousedto
import importantedto.deserveedto.manufactureredto.viableedto.Workshopedto
import importantedto.gallonedto.Transcendedto
import java.io.File

class Jovialedto : Murderedto<HoveredtoBinding>() {

    private val pathList by lazy {
        val json = intent.extras?.getString("PathList")
        val list = Gson().fromJson(json, Array<String>::class.java)
        list.map { Vigorousedto(it) }
    }
    private lateinit var adapter: Workshopedto

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


    override fun initView() {
        Transcendedto.setStatusBarLightMode(this, true)
        Transcendedto.setStatusBarColor(this, Color.TRANSPARENT)

        val tittle = intent.extras?.getString("Tittle") ?: ""
        binding.assaultedto.text = tittle

        var isList = false
        when (tittle) {
            "Audio Messages" -> {
                binding.questedto.layoutManager = LinearLayoutManager(this)
                isList = true
            }

            else -> {
                binding.questedto.layoutManager = GridLayoutManager(this, 3)
            }
        }

        adapter = Workshopedto(isList) {
            binding.echoedto.isSelected = it
            binding.worldedto.isEnabled = adapter.getSelectData().isNotEmpty()
            val split = adapter.getSelectDataSize().toFormatSize().split(" ")
            binding.ignoranceedto.text = split[0]
            binding.cheatedto.text = split[1]
        }
        binding.questedto.adapter = adapter
        adapter.setData(pathList)

        Orbitedto.showNativeAd(this, binding.agileedto)
    }

    override fun initListener() {
        binding.personaledto.setOnClickListener {
            onBackPressedDispatcher.onBackPressed()
        }
        onBackPressedDispatcher.addCallback {
            Leavingedto.showInterstitialAd(this@Jovialedto) {
                finishToMain()
            }
        }
        binding.echoedto.setOnClickListener {
            it.isSelected = !it.isSelected
            adapter.toggleSelect(it.isSelected)
            binding.worldedto.isEnabled = it.isSelected
            val split = adapter.getSelectDataSize().toFormatSize().split(" ")
            binding.ignoranceedto.text = split[0]
            binding.cheatedto.text = split[1]
        }

        binding.worldedto.setOnClickListener {

            Leavingedto.showInterstitialAd(this) {
                val list = adapter.getSelectData()
                runCatching {
                    list.forEach { File(it).delete() }
                }
                startActivity(Intent(this@Jovialedto, Halcyonedto::class.java).apply {
                    putExtra("from", Hateedto.WHATSAPP_CLEANER)
                })
                finish()
            }
        }
    }


}