package rowedto.jockeyedto.sheetedto.atticedto.openedto.postedto

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.TerrifyedtoBinding
import com.google.gson.Gson
import rowedto.jockeyedto.sheetedto.atticedto.Moneyedto
import rowedto.jockeyedto.sheetedto.atticedto.directionedto.noxiousedto.batedto.Negativeedto
import rowedto.jockeyedto.sheetedto.debutedto.revolutionaryedto.Cunningedto
import rowedto.jockeyedto.sheetedto.debutedto.revolutionaryedto.Dynamicedto
import rowedto.jockeyedto.sheetedto.knewedto.economicedto.copyrightedto.Crossingedto
import rowedto.jockeyedto.sheetedto.knewedto.economicedto.copyrightedto.Suitcaseedto.toFormatSize
import rowedto.jockeyedto.sheetedto.meadowedto.naturaledto.idealedto.Compromiseedto
import rowedto.jockeyedto.sheetedto.raceedto.pavementedto.Atedto
import rowedto.jockeyedto.sheetedto.raceedto.pavementedto.Spareedto
import rowedto.jockeyedto.sheetedto.strangeedto.pyramidedto.particlesedto.bounceedto.auditoredto.Crosswalkedto
import rowedto.jockeyedto.sheetedto.strangeedto.pyramidedto.particlesedto.bounceedto.auditoredto.Fatedto
import java.io.File

class Stemedto : Crossingedto<TerrifyedtoBinding>() {

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

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


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

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

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

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

        adapter = Compromiseedto(isList) {
            binding.noveledto.isSelected = it
            binding.dueedto.isEnabled = adapter.getSelectData().isNotEmpty()
            val split = adapter.getSelectDataSize().toFormatSize().split(" ")
            binding.bulletinedto.text = split[0]
            binding.figureedto.text = split[1]
        }
        binding.funeraledto.adapter = adapter
        adapter.setData(pathList)

        Crosswalkedto.showNativeAd(this, binding.breatheedto)
    }

    override fun initListener() {
        binding.concentrateedto.setOnClickListener {
            onBackPressedDispatcher.onBackPressed()
        }
        onBackPressedDispatcher.addCallback {
            Fatedto.showInterstitialAd(this@Stemedto) {
                finishToMain()
            }
        }
        binding.noveledto.setOnClickListener {
            it.isSelected = !it.isSelected
            adapter.toggleSelect(it.isSelected)
            binding.dueedto.isEnabled = it.isSelected
            val split = adapter.getSelectDataSize().toFormatSize().split(" ")
            binding.bulletinedto.text = split[0]
            binding.figureedto.text = split[1]
        }

        binding.dueedto.setOnClickListener {

            Fatedto.showInterstitialAd(this) {
                val list = adapter.getSelectData()
                Atedto.finishAll(Moneyedto::class.java)
                startActivity(
                    Intent(this, Negativeedto::class.java).apply {
                        putExtra("list",list.toTypedArray())
                        putExtra("size", list.map { File(it) }.sumOf { it.length() })
                        putExtra("type", Dynamicedto.WHATSAPP_CLEANER)
                    }
                )
//                runCatching {
//                    list.forEach { File(it).delete() }
//                }
//                startActivity(Intent(this@Stemedto, Softedto::class.java).apply {
//                    putExtra("from", Dynamicedto.WHATSAPP_CLEANER)
//                })
//                finish()
            }
        }
    }


}