package cpm.com.gskmtorange.adapter

import android.content.Context
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.imageview.ShapeableImageView
import cpm.com.gskmtorange.R
import cpm.com.gskmtorange.adapter.data.ImageUri
import cpm.com.gskmtorange.constant.CommonUtils.imgPreviewwithError

class SavedImagesAdapter(private val context: Context, private val images: List<ImageUri>) :
    RecyclerView.Adapter<SavedImagesAdapter.SavedImageViewHolder>() {

    class SavedImageViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        val imageView: ShapeableImageView = view.findViewById(R.id.imageView)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SavedImageViewHolder {
        val view = LayoutInflater.from(parent.context)
            .inflate(R.layout.item_image, parent, false)
        return SavedImageViewHolder(view)
    }

    override fun onBindViewHolder(holder: SavedImageViewHolder, position: Int) {
        Log.d("imagedata",images[position].uri)
        imgPreviewwithError(
            context = context,
            url = images[position].uri,
            imgView = holder.imageView,
            R.drawable.pdr
        )
    }

    override fun getItemCount(): Int = images.size

}