package com.develop.food.base.widgets

import android.content.Context
import android.util.AttributeSet
import android.view.View
import android.widget.RelativeLayout
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.bumptech.glide.request.RequestOptions
import com.develop.base.R
import com.develop.base.databinding.FoodContentViewBinding
import com.develop.base.databinding.WifiContentViewBinding
import com.develop.food.base.data.model.FoodContentModel
import com.develop.food.base.utils.ResDimension

class FoodContentView : RelativeLayout {
    private var binding: FoodContentViewBinding
    private val roundedCorners = RoundedCorners(ResDimension(R.dimen.convert_30px).toInt())
    private val options = RequestOptions.bitmapTransform(roundedCorners)
    constructor(context: Context?) : super(context) {}
    constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) {}
    constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(
        context,
        attrs,
        defStyleAttr
    ) {
    }

    init {
        val root = View.inflate(context, R.layout.food_content_view, this)
        binding = FoodContentViewBinding.bind(root)
    }

    fun setFoodContent(content:FoodContentModel){
        Glide.with(this).load(content.cover).apply(options).into(binding.ivCover)
        binding.tvFoodName.text = content.foodName
        binding.starView.setStarCount(content.starCount)
        binding.tvTimeAndLevel.text = "${content.time}・${content.level}"
    }
}