package com.base.scanqrclear.luma
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import com.base.scanqrclear.R
import com.base.scanqrclear.databinding.ActivityCleanResultBinding

class CleanResultActivity : BaseActivity2() {

    companion object {
        var total = 0L
        var titleName = ""
        fun start(context: Context, total: Long, titleName: String) {
            Companion.total = total
            Companion.titleName = titleName
            val intent = Intent(context, CleanResultActivity::class.java)
            context.startActivity(intent)
        }
    }

    private val binding by lazy(LazyThreadSafetyMode.NONE) {
        ActivityCleanResultBinding.inflate(layoutInflater)
    }

    private lateinit var adapter: CleanResultAdapter

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(binding.root)
        initView()
    }

    //todo
//    override fun handleBackPressed() {
//        showAdInterstitial(AdmobHelps.isShowAdResultBackInter()) { finishOrToMain() }
//    }

    private fun initView() {
        adapter = CleanResultAdapter(getData())
        adapter.callback = object : BaseAdapter.OnClickCallback<FunctionBean> {
            override fun onClicked(view: View, position: Int, item: FunctionBean) {
                ActivityJumpHelps.start(this@CleanResultActivity, launcher, item.name)
                finish()
            }
        }
        binding.rvResult.adapter = adapter
        binding.rvResult.layoutManager = LinearLayoutManager(this)

        if (titleName.isNotEmpty()) binding.tvTitle.text = titleName
        binding.tvCleanedUp.text = "${getString(R.string.cleaned_up)} ${Utils.getSize(total)}"
        binding.flBack.setOnClickListener {
            onBackPressedDispatcher.onBackPressed()
        }
    }

    private fun getData(): List<FunctionBean> {
        val list = mutableListOf<FunctionBean>().apply {
            add(FunctionBean(R.mipmap.icon_junk_scan, R.string.junk_scan, R.string.result_clean_junk, text = R.string.clean_now))
           // add(FunctionBean(R.mipmap.icon_battery_1, R.string.battery_info, R.string.result_battery_info, text = R.string.view))
            add(FunctionBean(R.mipmap.icon_app_t, R.string.app_process, R.string.result_app_processes, text = R.string.view))
          //  add(FunctionBean(R.mipmap.icon_large_1, R.string.large_files, R.string.result_large_file, text = R.string.clean_now))
           // add(FunctionBean(R.mipmap.icon_image, R.string.image_compressor, R.string.result_photo_compression, text = R.string.compress))
            add(FunctionBean(R.mipmap.icon_screenshot_1, R.string.screenshot_clean, R.string.result_screenshot_clean, text = R.string.clean_now))
            add(FunctionBean(R.mipmap.icon_similar, R.string.similar_photos, R.string.result_similar_photos, text = R.string.clean_now))
          //  add(FunctionBean(R.mipmap.icon_app_1, R.string.app_manager, R.string.result_app_manager, text = R.string.view))
            add(FunctionBean(R.mipmap.icon_whatsapp_clean_t, R.string.whatsapp_clean, R.string.result_whatsapp_clean, text = R.string.clean_now))
        }

        val filteredList = list.filter { getString(it.name) != titleName }
        val randomIndices = filteredList.indices.shuffled().take(4).toList()
        val data = randomIndices.map { filteredList[it] }
        return data
    }
}