package com.mob5.smarthousew

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.mob5.smarthousew.R
import com.mob5.smarthouse.common.Rooms

class RoomsAdapter(val context: Context, val list: Rooms): RecyclerView.Adapter<RoomsAdapter.VH>() {
    class VH(views: View): RecyclerView.ViewHolder(views){
        val image: ImageView = views.findViewById(R.id.room_icon)
        val name: TextView = views.findViewById(R.id.room_name)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VH {
        return VH(LayoutInflater.from(context).inflate(R.layout.rec_rooms, parent, false))
    }

    override fun onBindViewHolder(holder: VH, position: Int) {
        when (list.items[position].type){
            "Kitchen" -> Glide.with(context).load(R.drawable.ic_kitchen_red).into(holder.image)
            "Bathroom" -> Glide.with(context).load(R.drawable.ic_bathroom_red).into(holder.image)
            "Bedroom" -> Glide.with(context).load(R.drawable.ic_bedroom_red).into(holder.image)
            "Garage" -> Glide.with(context).load(R.drawable.ic_garage_red).into(holder.image)
            "Kids" -> Glide.with(context).load(R.drawable.ic_kids_red).into(holder.image)
            "Office" -> Glide.with(context).load(R.drawable.ic_office_red).into(holder.image)
            "Toilet" -> Glide.with(context).load(R.drawable.ic_toilet_red).into(holder.image)
            "TV" -> Glide.with(context).load(R.drawable.ic_tv_red).into(holder.image)
        }
        holder.name.text = list.items[position].name
    }

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