package rallyedto.finishedto

import android.annotation.SuppressLint
import android.content.Intent
import android.graphics.Color
import androidx.activity.addCallback
import androidx.core.view.updatePadding
import com.base.datarecovery.databinding.TriangleedtoBinding
import rallyedto.battleedto.acresedto.Fireplaceedto.toFormatSize
import rallyedto.battleedto.acresedto.Lemonedto
import rallyedto.dumpedto.editionedto.Choiceedto
import rallyedto.finishedto.biggestedto.canedto.greenedto.Snailedto
import rallyedto.finishedto.cableedto.Merchantedto
import rallyedto.finishedto.climateedto.depressionedto.dustedto.Treeedto
import rallyedto.finishedto.exampleedto.Designedto
import rallyedto.finishedto.exampleedto.Thoseedto
import rallyedto.finishedto.hypothesisedto.vegetableedto.breakfastedto.Practicaledto
import rallyedto.finishedto.illnessedto.Sweptedto
import rallyedto.finishedto.pollutionedto.Opaledto
import rallyedto.finishedto.sheepedto.extraterrestrialedto.Pickedto
import rallyedto.policeedto.huntedto.Snuggleedto.BATTERY_INFO
import rallyedto.policeedto.huntedto.Snuggleedto.JUNK_CLEANER
import rallyedto.policeedto.huntedto.Snuggleedto.LARGE_FILE
import rallyedto.policeedto.huntedto.Snuggleedto.PRIVACY_SPACE
import rallyedto.policeedto.huntedto.Snuggleedto.RECOVERY_AUDIOS
import rallyedto.policeedto.huntedto.Snuggleedto.RECOVERY_DOCUMENTS
import rallyedto.policeedto.huntedto.Snuggleedto.RECOVERY_PHOTOS
import rallyedto.policeedto.huntedto.Snuggleedto.RECOVERY_VIDEOS
import rallyedto.policeedto.huntedto.Snuggleedto.REPEAT_PHOTOS
import rallyedto.policeedto.huntedto.Snuggleedto.SCAN_AUDIOS
import rallyedto.policeedto.huntedto.Snuggleedto.SCAN_DOCUMENTS
import rallyedto.policeedto.huntedto.Snuggleedto.SCAN_PHOTOS
import rallyedto.policeedto.huntedto.Snuggleedto.SCAN_VIDEOS
import rallyedto.policeedto.huntedto.Snuggleedto.SCREENSHOT_CLEANER
import rallyedto.policeedto.huntedto.Snuggleedto.VIDEO_CLEAN
import rallyedto.policeedto.huntedto.Snuggleedto.privacyPinPassword
import rallyedto.sunedto.tumouredto.majorityedto.loseedto.Togetheredto
import rallyedto.talledto.blewedto.Islandedto
import rallyedto.talledto.blewedto.Musicaledto
import rallyedto.talledto.blewedto.Pianoedto

class Screamedto : Lemonedto<TriangleedtoBinding>() {
    private val TAG = "ResultActivity"

    override val binding: TriangleedtoBinding by lazy {
        TriangleedtoBinding.inflate(layoutInflater)
    }
    private lateinit var adapter: Choiceedto

    @SuppressLint("SetTextI18n", "NotifyDataSetChanged")
    override fun initView() {
        Islandedto.setStatusBarColor(this, Color.TRANSPARENT)
        binding.massedto.updatePadding(top = Islandedto.getStatusBarHeight())
        adapter = Choiceedto {
            when (it) {

                JUNK_CLEANER -> {
                    startActivity(Intent(this, Practicaledto::class.java))
                }

                REPEAT_PHOTOS -> {
                    startActivity(Intent(this, Opaledto::class.java))
                }

                SCREENSHOT_CLEANER -> {
                    startActivity(Intent(this, Merchantedto::class.java))
                }

                RECOVERY_PHOTOS -> {
                    startActivity(Intent(this, Snailedto::class.java).apply {
                        putExtra("ScanType", SCAN_PHOTOS)
                    })
                }

                RECOVERY_VIDEOS -> {
                    startActivity(Intent(this, Snailedto::class.java).apply {
                        putExtra("ScanType", SCAN_VIDEOS)
                    })
                }

                RECOVERY_DOCUMENTS -> {
                    startActivity(Intent(this, Snailedto::class.java).apply {
                        putExtra("ScanType", SCAN_DOCUMENTS)
                    })
                }

                RECOVERY_AUDIOS -> {
                    startActivity(Intent(this, Snailedto::class.java).apply {
                        putExtra("ScanType", SCAN_AUDIOS)
                    })
                }

                PRIVACY_SPACE -> {
                    if (privacyPinPassword.isNotEmpty()) {
                        startActivity(Intent(this, Designedto::class.java))
                    } else {
                        startActivity(Intent(this, Thoseedto::class.java).apply {

                        })
                    }
                }

//                WHATSAPP_CLEANER -> {
//                    startActivity(Intent(this, WhatsAppCleanerAnimationActivity::class.java))
//                }

                LARGE_FILE -> {
                    startActivity(Intent(this, Sweptedto::class.java))
                }

//                APP_PROCESS -> {
//                    startActivity(Intent(this, AppProcessAnimationActivity::class.java))
//                }

                VIDEO_CLEAN -> {
                    startActivity(Intent(this, Pickedto::class.java))
                }

                BATTERY_INFO -> {
                    startActivity(Intent(this, Treeedto::class.java))
                }

            }
            finish()
        }
        binding.voyageedto.adapter = adapter
        adapter.updateListPosition()
        adapter.notifyDataSetChanged()

        val from = intent.extras?.getString("from")
        Musicaledto.logDebug(TAG, "from=$from")
        when (from) {
            JUNK_CLEANER -> {
                if (intent.getLongExtra("clean_size", 0L) > 0) {
                    val size = intent.getLongExtra("clean_size", 0L).toFormatSize(1)
                    binding.takeedto.text = "Cleaned up $size"
                } else {
                    binding.takeedto.text = "No junk files found."
                }
                Pianoedto.getInstance()
                    .put("last_use_junk_cleaner", System.currentTimeMillis())
            }

            else -> {
                binding.takeedto.text = "Completed!"
            }
        }
        from?.let {
            binding.momentedto.text = it
            adapter.removeItem(it)
        }

        binding.flairedto.setOnClickListener {
            onBackPressedDispatcher.onBackPressed()
        }
        onBackPressedDispatcher.addCallback {
            admobMaxShowInterstitialAd(isShow = Togetheredto.isShowAdResultBackInter()) {
                finishToMain()
            }
        }


        Togetheredto.showNativeAd(this@Screamedto, binding.disappointedto)
    }

    override fun onDestroy() {
        super.onDestroy()
        binding.metaledto.clearAnimation()
    }
}