package pxds.hpls.xkxo

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.supercleanermax.R
import com.test.basd.supercleanermax.databinding.BdaadpBinding
import com.test.basd.supercleanermax.databinding.GbefwrBinding
import com.test.basd.supercleanermax.databinding.SyuuflBinding
import pxds.dlpf.buoz.fico.Dsce.APP_MANAGER
import pxds.dlpf.buoz.fico.Dsce.JUNK_CLEANER
import pxds.dlpf.buoz.fico.Dsce.LARGE_FILE_CLEANER
import pxds.dlpf.buoz.fico.Dsce.NETWORK_TRAFFIC
import pxds.dlpf.buoz.fico.Dsce.NOTIFICATION_CLEANER
import pxds.dlpf.buoz.fico.Dsce.PHOTO_COMPRESS
import pxds.dlpf.buoz.fico.Dsce.RECENT_APP_USAGE
import pxds.dlpf.buoz.fico.Dsce.SIMILAR_PHOTOS
import pxds.dlpf.buoz.fico.Ipnk.inflate
import pxds.lmmd.zmwf.Khko.setTrackedOnClickListener
import pxds.lmmd.zmwf.Khko.string
import pxds.lmmd.zmwf.jyyf.hwbn.wzxb.Utdc

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

    private val list = listOf(
        ToolsUI(
            tittle = R.string.ޚޣށޡގ_D.string(), tools = listOf(
                ToolUI(JUNK_CLEANER, context.getString(R.string.ޏޜޙކޑ), R.mipmap.jfntrtrt), ToolUI(PHOTO_COMPRESS, context.getString(R.string.ޝރށޒޡ), R.mipmap.qkrgpvzn), ToolUI(SIMILAR_PHOTOS, R.string.ޚއޞޝޕ_D.string(), R.mipmap.onnpagee), ToolUI(LARGE_FILE_CLEANER, context.getString(R.string.ނޒބފރ), R.mipmap.qkrgpvzn), ToolUI(APP_MANAGER, context.getString(R.string.ރސރރޘ), R.mipmap.aokjzubh), )
        ), ToolsUI(
            tittle = R.string.ޟބވޏޤ_D.string(), tools = listOf(
                ToolUI(NOTIFICATION_CLEANER, context.getString(R.string.ޢސޣޥވ), R.mipmap.hxdylsvj), ToolUI(NETWORK_TRAFFIC, context.getString(R.string.ކފނލއ), R.mipmap.vowqbazu), ToolUI(RECENT_APP_USAGE, context.getString(R.string.ޅނޗޥޘ), R.mipmap.qdurhfnw), )
        ), )

    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.bdaadp else R.layout.syuufl
        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 = BdaadpBinding.bind(holder.itemView)
            Utdc.showNativeAd(context, binding.plgnakm)
        } else {

            val binding = SyuuflBinding.bind(holder.itemView)
            binding.ljhubwr.text = data.tittle
            data.tools.forEachIndexed { index, toolUI ->
                val gItem = R.layout.gbefwr.inflate(binding.okitpff)
                val toolBinding = GbefwrBinding.bind(gItem)

                toolBinding.klpobam.setImageResource(toolUI.drawable)
                toolBinding.ivrxehl.text = toolUI.fName
                toolBinding.root.setTrackedOnClickListener {
                    itemClick.invoke(toolUI.kName)
                }
                binding.okitpff.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
    )
}