package com.base.pdfviewerscannerwhite.ui.result

import android.annotation.SuppressLint
import android.content.Intent
import android.graphics.Color
import androidx.activity.addCallback
import com.base.pdfviewerscannerwhite.R
import com.base.pdfviewerscannerwhite.ads.admob.AdmobNativeUtils
import com.base.pdfviewerscannerwhite.bean.ConstObject.FUNCTION_APP_PROCESS
import com.base.pdfviewerscannerwhite.bean.ConstObject.FUNCTION_SCAM_JUNK
import com.base.pdfviewerscannerwhite.databinding.ActivityResultBinding
import com.base.pdfviewerscannerwhite.helper.BaseActivity
import com.base.pdfviewerscannerwhite.ui.appprocess.AppProcessLoadingActivity
import com.base.pdfviewerscannerwhite.ui.cleanjunk.ScanJunkActivity
import com.base.pdfviewerscannerwhite.utils.BarUtils
import com.base.pdfviewerscannerwhite.utils.KotlinExt.toFormatSize

class ResultActivity : BaseActivity<ActivityResultBinding>() {

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

    var from = ""

    @SuppressLint("SetTextI18n")
    override fun initView() {
        BarUtils.setStatusBarLightMode(this, true)
        BarUtils.setStatusBarColor(this, Color.parseColor("#00B7DD"))
//        binding.root.updatePadding(top = BarUtils.getStatusBarHeight())
        AdmobNativeUtils.showNativeAd(this, binding.flAd, R.layout.layout_admob_app_exit)

        from = intent.extras?.getString("from") ?: ""


        when (from) {
            FUNCTION_SCAM_JUNK -> {
                binding.ivFunction.setImageResource(R.mipmap.process)
                binding.tvFunctionDesc.text = getString(R.string.manage_processes_run_in_the_background)
                binding.tvFunctionBtn.text = getString(R.string.scan_now)

                binding.tvFunctionBtn.setOnClickListener {
                    startActivity(Intent(this, AppProcessLoadingActivity::class.java))
                    finish()
                }
            }

            FUNCTION_APP_PROCESS -> {
                binding.ivFunction.setImageResource(R.mipmap.clean)
                binding.tvFunctionDesc.text = getString(R.string.clean_up_your_phone_storage)
                binding.tvFunctionBtn.text = getString(R.string.clean_now)
                binding.tvFunctionBtn.setOnClickListener {
                    startActivity(Intent(this, ScanJunkActivity::class.java))
                    finish()
                }
                val s = intent.extras?.getString("clean_size")?.toLong() ?: 0
                if (s != 0L) {
                    binding.tvSize.text = "Cleaned up ${s.toFormatSize(1)}"
                }
            }
        }


    }

    override fun initListener() {
        super.initListener()
        onBackPressedDispatcher.addCallback {
            finishToMain()
        }
    }


}