package com.develop.airfryer.ui

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.widget.LinearLayout
import androidx.core.view.children
import com.develop.airfryer.databinding.WaterSprayStatusViewBinding

class WaterSprayStatusView(context: Context, attrs: AttributeSet) : LinearLayout(context, attrs) {

    private val binding: WaterSprayStatusViewBinding

    private var gear = 0;
    private var status = false;

    init {
        binding = WaterSprayStatusViewBinding.inflate(LayoutInflater.from(context), this, true)
        updateSelectedStatus(status)
    }

    fun updateGear(gear:Int){
        this.gear = gear;
        updateSelectedStatus(status)
    }

    fun updateSelectedStatus(status: Boolean) {
        this.status = status;
//        children.forEach { it.visibility = GONE }
        binding.icWaterSpray0Unselected.visibility = View.GONE
        binding.icWaterSpray0Selected.visibility = View.GONE
        binding.icWaterSpray1Selected.visibility = View.GONE
        binding.icWaterSpray1Unselected.visibility = View.GONE
        binding.icWaterSpray2Selected.visibility = View.GONE
        binding.icWaterSpray2Unselected.visibility = View.GONE

        if(gear == 0){
            if(status){
                binding.icWaterSpray0Selected.visibility = View.VISIBLE
            }else{
                binding.icWaterSpray0Unselected.visibility = View.VISIBLE
            }
        }

        if(gear == 1){
            if(status){
                binding.icWaterSpray1Selected.visibility = View.VISIBLE
            }else{
                binding.icWaterSpray1Unselected.visibility = View.VISIBLE
            }
        }

        if(gear == 2){
            if(status){
                binding.icWaterSpray2Selected.visibility = View.VISIBLE
            }else{
                binding.icWaterSpray2Unselected.visibility = View.VISIBLE
            }
        }



    }

}