package aicg.wipf.tzxq

import aicg.wipf.rxxn.Ayhm.inflate
import aicg.wipf.rxxn.Qczw.APP_MANAGER
import aicg.wipf.rxxn.Qczw.JUNK_CLEANER
import aicg.wipf.rxxn.Qczw.LARGE_FILE_CLEANER
import aicg.wipf.rxxn.Qczw.NETWORK_TRAFFIC
import aicg.wipf.rxxn.Qczw.NOTIFICATION_CLEANER
import aicg.wipf.rxxn.Qczw.PHOTO_COMPRESS
import aicg.wipf.rxxn.Qczw.RECENT_APP_USAGE
import aicg.wipf.rxxn.Qczw.SIMILAR_PHOTOS
import aicg.wipf.vzuj.Kmqp.setTrackedOnClickListener
import aicg.wipf.vzuj.Kmqp.string
import aicg.wipf.vzuj.bcxo.Fnpc
import android.app.Activity
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.test.basd.smartjunkcleaner.R
import com.test.basd.smartjunkcleaner.databinding.AzxhnhBinding
import com.test.basd.smartjunkcleaner.databinding.UykpofBinding
import com.test.basd.smartjunkcleaner.databinding.XlrnwjBinding

class Qasn(
    val context: Activity, val itemClick: (kName: String) -> Unit
) : RecyclerView.Adapter<Qasn.VVV>() {

    private val list = listOf(
        ToolsUI(
            tittle = R.string.ތވޞޤޥ_D.string(), tools = listOf(
                ToolUI(JUNK_CLEANER, context.getString(R.string.ޖތޑޝޘ), R.mipmap.rqysvefz), ToolUI(PHOTO_COMPRESS, context.getString(R.string.ޔގޒޛޟ), R.mipmap.mteovrib), ToolUI(SIMILAR_PHOTOS, R.string.ރޕށޟޕ_D.string(), R.mipmap.cyazzdcu), ToolUI(LARGE_FILE_CLEANER, context.getString(R.string.ޗޠޛރތ), R.mipmap.wdwuytyg), ToolUI(APP_MANAGER, context.getString(R.string.ޅތޘޥނ), R.mipmap.rictclof)
            )
        ), ToolsUI(
            tittle = R.string.ޝޅޥޠދ_D.string(), tools = listOf(
                ToolUI(NOTIFICATION_CLEANER, context.getString(R.string.ލޢޙގވ), R.mipmap.vqyaspms), ToolUI(NETWORK_TRAFFIC, context.getString(R.string.ޑޕޅޚށ), R.mipmap.rniwgpnw), ToolUI(RECENT_APP_USAGE, context.getString(R.string.ޢބތމހ), R.mipmap.hpoklqli), )
        ), )

    override fun getItemViewType(position: Int): Int {
        val data = list[position]
        return if (data.isAd) 0 else 1
    }

    inner class VVV(view: View) : ViewHolder(view)

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VVV {
        val viewId = if (viewType == 0) R.layout.xlrnwj else R.layout.uykpof
        return VVV(viewId.inflate(parent))
    }

    override fun getItemCount(): Int {
        return list.size
    }

    override fun onBindViewHolder(holder: VVV, position: Int) {

        val data = list[position]

        if (data.isAd) {
            val binding = XlrnwjBinding.bind(holder.itemView)
            Fnpc.showNativeAd(context, binding.nkqxuhi)
        } else {

            val binding = UykpofBinding.bind(holder.itemView)
            binding.flvcwej.text = data.tittle
            data.tools.forEachIndexed { index, toolUI ->
                val gItem = R.layout.azxhnh.inflate(binding.pbezbpu)
                val toolBinding = AzxhnhBinding.bind(gItem)

                toolBinding.vayqhky.setImageResource(toolUI.drawable)
                toolBinding.vyiqtiu.text = toolUI.fName
                toolBinding.root.setTrackedOnClickListener {
                    itemClick.invoke(toolUI.kName)
                }
                binding.pbezbpu.addView(gItem)
            }
        }

    }

    data class ToolsUI(

        val tittle: String? = null, val tools: List<ToolUI> = listOf(), val isAd: Boolean = false, )

    data class ToolUI(
        val kName: String = R.string.ސފޑނޠ_D.string(), val fName: String = R.string.ސފޑނޠ_D.string(), val drawable: Int = 0
    )
}