package com.adealink.weparty.joinus.comp

import androidx.lifecycle.LifecycleOwner
import com.adealink.frame.aab.util.getCompatColor
import com.adealink.frame.mvvm.view.ViewComponent
import com.adealink.frame.mvvm.viewmodel.viewModels
import com.adealink.weparty.joinus.R
import com.adealink.weparty.joinus.data.JoinUsStep
import com.adealink.weparty.joinus.databinding.LayoutJoinUsProgressBinding
import com.adealink.weparty.joinus.viewmodel.JoinUsViewModel
import com.adealink.weparty.joinus.viewmodel.JoinUsViewModelFactory
import com.adealink.weparty.R as APP_R

class JoinStepProgressComp(
    lifecycleOwner: LifecycleOwner,
    val binding: LayoutJoinUsProgressBinding
) : ViewComponent(lifecycleOwner) {

    private val viewModel by viewModels<JoinUsViewModel> { JoinUsViewModelFactory() }

    override fun onCreate() {
        super.onCreate()
        initView()
        observeViewModel()
    }

    private fun initView() {

    }

    private fun observeViewModel() {
        viewModel.stepLD.observe(viewLifecycleOwner) { step ->
            updateStep(step)
        }
    }

    private fun updateStep(step: JoinUsStep) {
        when (step) {
            JoinUsStep.STEP_1 -> {
                binding.tvIndex1.setBackgroundResource(R.drawable.join_us_progress_index_selected_bg)
                binding.vLine1To2.setBackgroundColor(getCompatColor(APP_R.color.color_FFC9CDD4))
                binding.tvIndex2.setBackgroundResource(R.drawable.join_us_progress_index_bg)
                binding.vLine2To3.setBackgroundColor(getCompatColor(APP_R.color.color_FFC9CDD4))
                binding.tvIndex3.setBackgroundResource(R.drawable.join_us_progress_index_bg)
            }

            JoinUsStep.STEP_2 -> {
                binding.tvIndex1.setBackgroundResource(R.drawable.join_us_progress_index_selected_bg)
                binding.vLine1To2.setBackgroundColor(getCompatColor(APP_R.color.color_FF15E5E2))
                binding.tvIndex2.setBackgroundResource(R.drawable.join_us_progress_index_selected_bg)
                binding.vLine2To3.setBackgroundColor(getCompatColor(APP_R.color.color_FFC9CDD4))
                binding.tvIndex3.setBackgroundResource(R.drawable.join_us_progress_index_bg)
            }

            JoinUsStep.STEP_3,
            JoinUsStep.UNDER_REVIEW -> {
                binding.tvIndex1.setBackgroundResource(R.drawable.join_us_progress_index_selected_bg)
                binding.vLine1To2.setBackgroundColor(getCompatColor(APP_R.color.color_FF15E5E2))
                binding.tvIndex2.setBackgroundResource(R.drawable.join_us_progress_index_selected_bg)
                binding.vLine2To3.setBackgroundColor(getCompatColor(APP_R.color.color_FF15E5E2))
                binding.tvIndex3.setBackgroundResource(R.drawable.join_us_progress_index_selected_bg)
            }
        }
    }

}