package com.keyboard.craft.adapter

import android.content.Context
import android.content.Intent
import android.view.ViewGroup
import android.widget.ImageView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.keyboard.craft.R
import com.keyboard.craft.bean.ItemDataBean
import com.keyboard.craft.activity.DetailsActivity
import com.youth.banner.adapter.BannerAdapter

class HomeBannerImgAdapter(private val context: Context, data: List<ItemDataBean>?) :
    BannerAdapter<ItemDataBean, HomeBannerImgAdapter.BannerViewHolder>(
        data
    ) {

    class BannerViewHolder(var imageView: ImageView) :
        RecyclerView.ViewHolder(imageView)
    
    override fun onBindView(
        holder: BannerViewHolder,
        data: ItemDataBean,
        position: Int,
        size: Int
    ) {
        Glide.with(context)
            .load(data.thumbUrl)
            .error(R.drawable.drw_banner_placeholder)
            .placeholder(R.drawable.drw_banner_placeholder)
            .into(holder.imageView)

        holder.itemView.setOnClickListener {
            val intent = Intent(context, DetailsActivity::class.java)
            intent.putExtra(DetailsActivity.KEY_CRAFT_DETAILS_BEAN, data)
            context.startActivity(intent)
        }
    }
    override fun onCreateHolder(parent: ViewGroup?, viewType: Int): BannerViewHolder {
        val imageView = ImageView(parent!!.context)
        imageView.layoutParams = ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT
        )
        imageView.scaleType = ImageView.ScaleType.CENTER_CROP
        return BannerViewHolder(imageView)
    }

    
}