package importantedto.deserveedto.manufactureredto.viableedto

import android.annotation.SuppressLint
import android.view.View
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.base.datarecovery.R
import com.base.datarecovery.databinding.DiscourageedtoBinding
import importantedto.concreteedto.cameedto.Hateedto.APP_MANAGER
import importantedto.concreteedto.cameedto.Hateedto.APP_PROCESS
import importantedto.concreteedto.cameedto.Hateedto.BATTERY_INFO
import importantedto.concreteedto.cameedto.Hateedto.JUNK_CLEANER
import importantedto.concreteedto.cameedto.Hateedto.LARGE_FILE
import importantedto.concreteedto.cameedto.Hateedto.PRIVACY_SPACE
import importantedto.concreteedto.cameedto.Hateedto.RECOVERY_AUDIOS
import importantedto.concreteedto.cameedto.Hateedto.RECOVERY_DOCUMENTS
import importantedto.concreteedto.cameedto.Hateedto.RECOVERY_PHOTOS
import importantedto.concreteedto.cameedto.Hateedto.RECOVERY_VIDEOS
import importantedto.concreteedto.cameedto.Hateedto.REPEAT_PHOTOS
import importantedto.concreteedto.cameedto.Hateedto.SCREENSHOT_CLEANER
import importantedto.concreteedto.cameedto.Hateedto.WHATSAPP_CLEANER
import importantedto.gallonedto.Waitedto
import importantedto.maidedto.witnessedto.nationalismedto.Gestureedto.inflate
import java.util.Collections

class Policeedto(val click: (name: String) -> Unit) :
    RecyclerView.Adapter<Policeedto.JJJ>() {

    val list = arrayListOf(
        Fun(JUNK_CLEANER, R.mipmap.observeedto),
        Fun(RECOVERY_PHOTOS, R.mipmap.hauntedto),
        Fun(RECOVERY_VIDEOS, R.mipmap.binedto),
        Fun(RECOVERY_DOCUMENTS, R.mipmap.revolutionaryedto),
        Fun(RECOVERY_AUDIOS, R.mipmap.thusedto),
        Fun(PRIVACY_SPACE, R.mipmap.emotionedto),
        Fun(REPEAT_PHOTOS, R.mipmap.liquidedto),
        Fun(SCREENSHOT_CLEANER, R.mipmap.principaledto),
        Fun(WHATSAPP_CLEANER, R.mipmap.corruptionedto),
        Fun(LARGE_FILE, R.mipmap.bookedto),
        Fun(APP_PROCESS, R.mipmap.landscapeedto),
        Fun(APP_MANAGER, R.mipmap.equipedto),
        Fun(BATTERY_INFO, R.mipmap.brandedto),
    )

    class JJJ(view: View) : ViewHolder(view)


    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): JJJ {
        return JJJ(R.layout.discourageedto.inflate(parent))
    }

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

    override fun onBindViewHolder(holder: JJJ, position: Int) {
        val data = list[position]
        val context = holder.itemView.context
        val binding = DiscourageedtoBinding.bind(holder.itemView)
        binding.dueedto.setImageDrawable(ContextCompat.getDrawable(context, data.icon))
        binding.meetingedto.text = data.name
//        binding.neighboredto.text = data.des
//        binding.toyedto.text = data.button
        binding.root.setOnClickListener {
            click.invoke(data.name)
        }
    }


    @SuppressLint("NotifyDataSetChanged")
    fun removeItem(name: String) {
        list.removeIf { it.name == name }
        notifyDataSetChanged()
    }

    data class Fun(
        val name: String = "",
        val icon: Int = 0,
        val des: String = "",
        val button: String = "",
    )

    fun updateListPosition() {
        //本次进入结果页，判断使用垃圾的功能是否超过5分钟
        val lastUseJunkCleaner = Waitedto.getInstance().getLong("last_use_junk_cleaner", 0)
        if ((System.currentTimeMillis() - lastUseJunkCleaner) >= 60 * 5 * 1000) {
        } else {
            Collections.rotate(list, list.size - 1)
        }
    }

}