package com.example.tfat.myapplication.controlbar

import android.content.Context
import android.util.AttributeSet
import android.widget.LinearLayout
import android.view.LayoutInflater
import com.example.tfat.myapplication.R
import kotlinx.android.synthetic.main.control_bar_view.view.*

class ControlBarView : LinearLayout {

    constructor(context : Context) : super(context) {
        initView()
    }

    constructor(context: Context, attrs: AttributeSet): super(context, attrs) {
        initView()
    }

    constructor(context: Context, attrs: AttributeSet, defStyle: Int): super(context, attrs, defStyle) {
        initView()
    }

    private fun initView() {
        val inflater = LayoutInflater.from(context)
        inflater.inflate(R.layout.control_bar_view, this, true)
    }

    fun setBtnSelected(layer : Int) {
        when (layer) {
            6 -> {
                swipe_btn.setBackgroundResource(R.drawable.layer_icon_selected_background)
                layer_background.setBackgroundResource(R.drawable.layer_icon_background)
                layer_4.setBackgroundResource(R.drawable.layer_icon_background)
                layer_3.setBackgroundResource(R.drawable.layer_icon_background)
                layer_2.setBackgroundResource(R.drawable.layer_icon_background)
                layer_1.setBackgroundResource(R.drawable.layer_icon_background)
                layer_1.setImageResource(R.drawable.ic_layer_1_w)
                scene_btn.setBackgroundResource(R.drawable.layer_icon_background)
            }
            0 -> {
                swipe_btn.setBackgroundResource(R.drawable.layer_icon_background)
                layer_background.setBackgroundResource(R.drawable.layer_icon_selected_background)
                layer_4.setBackgroundResource(R.drawable.layer_icon_background)
                layer_3.setBackgroundResource(R.drawable.layer_icon_background)
                layer_2.setBackgroundResource(R.drawable.layer_icon_background)
                layer_1.setBackgroundResource(R.drawable.layer_icon_background)
                layer_1.setImageResource(R.drawable.ic_layer_1_w)
                scene_btn.setBackgroundResource(R.drawable.layer_icon_background)
            }
            4 -> {
                swipe_btn.setBackgroundResource(R.drawable.layer_icon_background)
                layer_background.setBackgroundResource(R.drawable.layer_icon_background)
                layer_4.setBackgroundResource(R.drawable.layer_icon_background)
                layer_3.setBackgroundResource(R.drawable.layer_icon_background)
                layer_2.setBackgroundResource(R.drawable.layer_icon_background)
                layer_1.setBackgroundResource(R.drawable.layer_icon_selected_background)
                layer_1.setImageResource(R.drawable.ic_layer_1_b)
                scene_btn.setBackgroundResource(R.drawable.layer_icon_background)
            }
            3 -> {
                swipe_btn.setBackgroundResource(R.drawable.layer_icon_background)
                layer_background.setBackgroundResource(R.drawable.layer_icon_background)
                layer_4.setBackgroundResource(R.drawable.layer_icon_background)
                layer_3.setBackgroundResource(R.drawable.layer_icon_background)
                layer_2.setBackgroundResource(R.drawable.layer_icon_selected_background)
                layer_1.setBackgroundResource(R.drawable.layer_icon_background)
                layer_1.setImageResource(R.drawable.ic_layer_1_w)
                scene_btn.setBackgroundResource(R.drawable.layer_icon_background)
            }
            2 -> {
                swipe_btn.setBackgroundResource(R.drawable.layer_icon_background)
                layer_background.setBackgroundResource(R.drawable.layer_icon_background)
                layer_4.setBackgroundResource(R.drawable.layer_icon_background)
                layer_3.setBackgroundResource(R.drawable.layer_icon_selected_background)
                layer_2.setBackgroundResource(R.drawable.layer_icon_background)
                layer_1.setBackgroundResource(R.drawable.layer_icon_background)
                layer_1.setImageResource(R.drawable.ic_layer_1_w)
                scene_btn.setBackgroundResource(R.drawable.layer_icon_background)
            }
            1 -> {
                swipe_btn.setBackgroundResource(R.drawable.layer_icon_background)
                layer_background.setBackgroundResource(R.drawable.layer_icon_background)
                layer_4.setBackgroundResource(R.drawable.layer_icon_selected_background)
                layer_3.setBackgroundResource(R.drawable.layer_icon_background)
                layer_2.setBackgroundResource(R.drawable.layer_icon_background)
                layer_1.setBackgroundResource(R.drawable.layer_icon_background)
                layer_1.setImageResource(R.drawable.ic_layer_1_w)
                scene_btn.setBackgroundResource(R.drawable.layer_icon_background)
            }
            5 -> {
                swipe_btn.setBackgroundResource(R.drawable.layer_icon_background)
                layer_background.setBackgroundResource(R.drawable.layer_icon_background)
                layer_4.setBackgroundResource(R.drawable.layer_icon_background)
                layer_3.setBackgroundResource(R.drawable.layer_icon_background)
                layer_2.setBackgroundResource(R.drawable.layer_icon_background)
                layer_1.setBackgroundResource(R.drawable.layer_icon_background)
                layer_1.setImageResource(R.drawable.ic_layer_1_w)
                scene_btn.setBackgroundResource(R.drawable.layer_icon_selected_background)
            }
        }
    }

    fun setonClickSwipeLayerBtn(onClickListener: OnClickListener) {
        swipe_btn.setOnClickListener(onClickListener)
    }

    fun setonClickLayerSceneBtn(onClickListener: OnClickListener) {
        scene_btn.setOnClickListener(onClickListener)
    }

    fun setonClickLayer1Btn(onClickListener: OnClickListener) {
        layer_1.setOnClickListener(onClickListener)
    }
    fun setonClickLayer2Btn(onClickListener: OnClickListener) {
        layer_2.setOnClickListener(onClickListener)
    }
    fun setonClickLayer3Btn(onClickListener: OnClickListener) {
        layer_3.setOnClickListener(onClickListener)
    }
    fun setonClickLayer4Btn(onClickListener: OnClickListener) {
        layer_4.setOnClickListener(onClickListener)
    }
    fun setonClickLayerBackgroundBtn(onClickListener: OnClickListener) {
        layer_background.setOnClickListener(onClickListener)
    }
}