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

import android.annotation.SuppressLint
import android.graphics.Color
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.PhotocopyedtoBinding
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.Tiptoeedto
import rowedto.jockeyedto.sheetedto.knewedto.economicedto.copyrightedto.Suitcaseedto.toFormatSize
import rowedto.jockeyedto.sheetedto.raceedto.pavementedto.Autonomyedto.dpToPx

class Highedto(val click: (bean: Tiptoeedto) -> Unit) : RecyclerView.Adapter<Highedto.Whats>() {

    private val beanList = arrayListOf<Tiptoeedto>()

    class Whats(view: View) : ViewHolder(view) {

    }

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

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

    override fun onBindViewHolder(holder: Whats, position: Int) {
        val binding = PhotocopyedtoBinding.bind(holder.itemView)
        val context = holder.itemView.context
        val bean = beanList[position]
        binding.shiftedto.setImageDrawable(ContextCompat.getDrawable(context, bean.icon))
        binding.indirectedto.text = bean.tittle
        if (bean.subFile.isEmpty()) {
            binding.stickedto.visibility = View.GONE
            binding.bulletinedto.setTextColor(Color.parseColor("#999999"))
            binding.marginedto.setImageDrawable(ContextCompat.getDrawable(context, R.mipmap.playedto))
            binding.bandedto.visibility = View.VISIBLE
        } else {
            binding.stickedto.visibility = View.VISIBLE
            runCatching {
                val options = RequestOptions().transform(CenterCrop(), RoundedCorners(context.dpToPx(10)))
                val image1 = bean.subFile[0]
                Glide.with(context).load(image1).apply(options).into(binding.prosperedto)

                val image2 = bean.subFile[1]
                Glide.with(context).load(image2).apply(options).into(binding.furnitureedto)

                val image3 = bean.subFile[2]
                Glide.with(context).load(image3).apply(options).into(binding.fussedto)
            }
            binding.bulletinedto.setTextColor(Color.parseColor("#355BEA"))
            binding.bulletinedto.text = bean.size.toFormatSize()
            binding.marginedto.setImageDrawable(ContextCompat.getDrawable(context, R.mipmap.occuredto))
            binding.bandedto.visibility = View.GONE
        }
        binding.root.setOnClickListener {
            if (bean.subFile.isEmpty()) {
                return@setOnClickListener
            }
            click.invoke(bean)
        }
    }

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


}