package rowedto.jockeyedto.sheetedto.meadowedto.naturaledto.idealedto

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.JailedtoBinding
import rowedto.jockeyedto.sheetedto.balsamedto.formaledto.orientationedto.Ambitionedto.inflate
import rowedto.jockeyedto.sheetedto.debutedto.revolutionaryedto.Dynamicedto.BATTERY_INFO
import rowedto.jockeyedto.sheetedto.debutedto.revolutionaryedto.Dynamicedto.JUNK_CLEANER
import rowedto.jockeyedto.sheetedto.debutedto.revolutionaryedto.Dynamicedto.LARGE_FILE
import rowedto.jockeyedto.sheetedto.debutedto.revolutionaryedto.Dynamicedto.PRIVACY_SPACE
import rowedto.jockeyedto.sheetedto.debutedto.revolutionaryedto.Dynamicedto.RECOVERY_AUDIOS
import rowedto.jockeyedto.sheetedto.debutedto.revolutionaryedto.Dynamicedto.RECOVERY_DOCUMENTS
import rowedto.jockeyedto.sheetedto.debutedto.revolutionaryedto.Dynamicedto.RECOVERY_PHOTOS
import rowedto.jockeyedto.sheetedto.debutedto.revolutionaryedto.Dynamicedto.RECOVERY_VIDEOS
import rowedto.jockeyedto.sheetedto.debutedto.revolutionaryedto.Dynamicedto.REPEAT_PHOTOS
import rowedto.jockeyedto.sheetedto.debutedto.revolutionaryedto.Dynamicedto.SCREENSHOT_CLEANER
import rowedto.jockeyedto.sheetedto.debutedto.revolutionaryedto.Dynamicedto.VIDEO_CLEAN
import rowedto.jockeyedto.sheetedto.raceedto.pavementedto.Stewardedto
import java.util.Collections

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

    val list = arrayListOf(
        Fun(JUNK_CLEANER, R.mipmap.admirationedto),
        Fun(RECOVERY_PHOTOS, R.mipmap.bucketedto),
        Fun(RECOVERY_VIDEOS, R.mipmap.realismedto),
        Fun(RECOVERY_DOCUMENTS, R.mipmap.weakedto),
        Fun(RECOVERY_AUDIOS, R.mipmap.architectedto),
        Fun(PRIVACY_SPACE, R.mipmap.graphedto),
        Fun(REPEAT_PHOTOS, R.mipmap.shipedto),
        Fun(SCREENSHOT_CLEANER, R.mipmap.virtueedto),
      //  Fun(WHATSAPP_CLEANER, R.mipmap.deficitedto),
        Fun(LARGE_FILE, R.mipmap.rackedto),
        Fun(VIDEO_CLEAN, R.mipmap.viableedto),
     //   Fun(APP_PROCESS, R.mipmap.econoboxedto),
     //   Fun(APP_MANAGER, R.mipmap.patchedto),

        Fun(BATTERY_INFO, R.mipmap.abuseedto),
    )

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


    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): JJJ {
        return JJJ(R.layout.jailedto.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 = JailedtoBinding.bind(holder.itemView)
        binding.dashedto.setImageDrawable(ContextCompat.getDrawable(context, data.icon))
        binding.spontaneousedto.text = data.name
//        binding.expressionedto.text = data.des
//        binding.necklaceedto.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 = Stewardedto.getInstance().getLong("last_use_junk_cleaner", 0)
        if ((System.currentTimeMillis() - lastUseJunkCleaner) >= 60 * 5 * 1000) {
        } else {
            Collections.rotate(list, list.size - 1)
        }
    }

}