package negligentlyic.wrongic.bottomic

import android.content.Context
import android.view.ViewGroup
import com.easy.clean.R
import com.easy.clean.databinding.BeardicBinding
import heartburnic.Chairic
import negligentlyic.wrongic.bottomic.Timidic.getImgRes
import negligentlyic.wrongic.bottomic.Timidic.mImageStr
import negligentlyic.wrongic.bottomic.Timidic.mVideoStr
import tooic.fatalityic.redic.speckledic.hankeringic.Curableic.toFormatSize
import tooic.fatalityic.redic.speckledic.hankeringic.Resuscitateic.inflate
import com.bumptech.glide.Glide
import com.chad.library.adapter4.BaseQuickAdapter
import java.io.File

class Carnivalic : BaseQuickAdapter<File, Chairic>() {

    var clickAction: ((file: File) -> Unit)? = null

    override fun onBindViewHolder(holder: Chairic, position: Int, item: File?) {
        item ?: return
        val binding = BeardicBinding.bind(holder.itemView)
        val context = holder.itemView.context

        if (mImageStr.contains("." + item.extension) || mVideoStr.contains("." + item.extension)) {
            Glide.with(context).load(item.absoluteFile).into(binding.vialic)
        } else {
            binding.vialic.setImageResource(item.getImgRes())
        }
        binding.consequentic.text = item.name
        binding.prospectic.text = item.length().toFormatSize()
        binding.root.setOnClickListener {
            clickAction?.invoke(item)
        }
    }

    override fun onCreateViewHolder(
        context: Context,
        parent: ViewGroup,
        viewType: Int
    ): Chairic {
        return Chairic(R.layout.beardic.inflate(parent))
    }
}