package com.develop.food.base.widgets

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View

import androidx.constraintlayout.widget.ConstraintLayout
import com.develop.base.databinding.SteamFireBinding
import com.develop.food.base.utils.ResDimension
import com.develop.food.base.utils.isNightTheme


class SteamFire @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null,
    defStyleAttr: Int = 0
) : ConstraintLayout(context, attrs, defStyleAttr) {

    private val binding: SteamFireBinding =
        SteamFireBinding.inflate(LayoutInflater.from(context), this, true)

    init {

        if (isNightTheme()) {
            val param = binding.fire1.layoutParams
            param.width = dp84
            param.height = dp121
            binding.fire1.layoutParams = param
            binding.fire2.layoutParams = param
            binding.fire3.layoutParams = param
        }
    }

    fun configNum(temp: Int) {

        var num = 3;
        if (temp <= 105) {
            num = 1
        } else if (temp <= 115) {
            num = 2
        } else {
            num = 3
        }



        binding.fire1.visibility = if (num >= 1) View.VISIBLE else View.GONE
        binding.fire2.visibility = if (num >= 2) View.VISIBLE else View.GONE
        binding.fire3.visibility = if (num >= 3) View.VISIBLE else View.GONE
    }

    companion object {
        val dp84 = ResDimension(com.develop.base.R.dimen.convert_84px).toInt()
        val dp121 = ResDimension(com.develop.base.R.dimen.convert_121px).toInt()
    }

}