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

import android.annotation.SuppressLint
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.base.datarecovery.R
import com.base.datarecovery.databinding.AllowanceedtoBinding
import com.base.datarecovery.databinding.ClinicedtoBinding
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.CenterCrop
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.bumptech.glide.request.RequestOptions
import rowedto.jockeyedto.sheetedto.balsamedto.formaledto.orientationedto.Ambitionedto.inflate
import rowedto.jockeyedto.sheetedto.debutedto.revolutionaryedto.Dynamicedto.SCAN_PHOTOS
import rowedto.jockeyedto.sheetedto.debutedto.revolutionaryedto.Dynamicedto.SCAN_VIDEOS
import rowedto.jockeyedto.sheetedto.debutedto.revolutionaryedto.Numberedto
import rowedto.jockeyedto.sheetedto.raceedto.pavementedto.Autonomyedto.dpToPx
import rowedto.jockeyedto.sheetedto.raceedto.pavementedto.Dishedto

class Nobodyedto(
    private val scanType: Int, private val click: (bean: Numberedto) -> Unit
) : RecyclerView.Adapter<Nobodyedto.FF>() {

    private val TAG = "FileFolderAdapter"
    private val beanList = arrayListOf<Numberedto>()

    class FF(view: View) : ViewHolder(view)

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): FF {
        val layout = when (scanType) {
            SCAN_PHOTOS, SCAN_VIDEOS -> R.layout.clinicedto
            else -> R.layout.allowanceedto
        }
        return FF(layout.inflate(parent))
    }

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

    @SuppressLint("SetTextI18n", "CheckResult")
    override fun onBindViewHolder(holder: FF, position: Int) {

        val bean = beanList[position]
        val context = holder.itemView.context

        when (scanType) {
            SCAN_PHOTOS, SCAN_VIDEOS -> {
                val binding = ClinicedtoBinding.bind(holder.itemView)
                runCatching {
                    val options = RequestOptions().transform(CenterCrop(), RoundedCorners(context.dpToPx(10)))
                    val image1 = bean.recoveryList[0].path
                    val request1 = Glide.with(context).load(image1).apply(options)
                    if (scanType == SCAN_VIDEOS) {
                        request1.error(R.mipmap.yearedto)
                    }
                    request1.into(binding.prosperedto)

                    val image2 = bean.recoveryList[1].path
                    val request2 = Glide.with(context).load(image2).apply(options)
                    if (scanType == SCAN_VIDEOS) {
                        request2.error(R.mipmap.yearedto)
                    }
                    request2.into(binding.furnitureedto)

                    val image3 = bean.recoveryList[2].path
                    val request3 = Glide.with(context).load(image3).apply(options)
                    if (scanType == SCAN_VIDEOS) {
                        request3.error(R.mipmap.yearedto)
                    }
                    request3.into(binding.fussedto)
                }

                binding.bankedto.text = bean.folder
                binding.huntingedto.text = "(${bean.recoveryList.size})"
                binding.root.setOnClickListener {
                    click.invoke(bean)
                }
            }

            else -> {
                Dishedto.logDebug(TAG, "scanType=$scanType")
                val binding = AllowanceedtoBinding.bind(holder.itemView)
                binding.bankedto.text = bean.folder
                binding.sacrificeedto.text = "${bean.recoveryList.size}"
                binding.root.setOnClickListener {
                    click.invoke(bean)
                }
            }
        }


    }

    @SuppressLint("NotifyDataSetChanged")
    fun setData(list: List<Numberedto>) {
        beanList.clear()
        beanList.addAll(list)
        notifyDataSetChanged()
    }
    @SuppressLint("NotifyDataSetChanged")
    fun addData(list: List<Numberedto>) {
        beanList.addAll(list)
        notifyDataSetChanged()
    }
}