package rallyedto.dumpedto.editionedto

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.CenteredtoBinding
import rallyedto.farewelledto.Strategicedto.inflate
import rallyedto.policeedto.huntedto.Snuggleedto.BATTERY_INFO
import rallyedto.policeedto.huntedto.Snuggleedto.JUNK_CLEANER
import rallyedto.policeedto.huntedto.Snuggleedto.LARGE_FILE
import rallyedto.policeedto.huntedto.Snuggleedto.PRIVACY_SPACE
import rallyedto.policeedto.huntedto.Snuggleedto.RECOVERY_AUDIOS
import rallyedto.policeedto.huntedto.Snuggleedto.RECOVERY_DOCUMENTS
import rallyedto.policeedto.huntedto.Snuggleedto.RECOVERY_PHOTOS
import rallyedto.policeedto.huntedto.Snuggleedto.RECOVERY_VIDEOS
import rallyedto.policeedto.huntedto.Snuggleedto.REPEAT_PHOTOS
import rallyedto.policeedto.huntedto.Snuggleedto.SCREENSHOT_CLEANER
import rallyedto.policeedto.huntedto.Snuggleedto.VIDEO_CLEAN
import rallyedto.talledto.blewedto.Pianoedto
import java.util.Collections

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

    val list = arrayListOf(
        Fun(JUNK_CLEANER, R.mipmap.dayedto),
        Fun(RECOVERY_PHOTOS, R.mipmap.traceedto),
        Fun(RECOVERY_VIDEOS, R.mipmap.disagreeedto),
        Fun(RECOVERY_DOCUMENTS, R.mipmap.planetedto),
        Fun(RECOVERY_AUDIOS, R.mipmap.reliefedto),
        Fun(PRIVACY_SPACE, R.mipmap.consideredto),
        Fun(REPEAT_PHOTOS, R.mipmap.antennaedto),
        Fun(SCREENSHOT_CLEANER, R.mipmap.beneficiaryedto),
      //  Fun(WHATSAPP_CLEANER, R.mipmap.perceptionedto),
        Fun(LARGE_FILE, R.mipmap.flexibleedto),
        Fun(VIDEO_CLEAN, R.mipmap.paralyzededto),
     //   Fun(APP_PROCESS, R.mipmap.audienceedto),
     //   Fun(APP_MANAGER, R.mipmap.resortedto),

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

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


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

}