package kr.co.vividnext.sodalive.live.room.create

import android.annotation.SuppressLint
import android.app.DatePickerDialog
import android.app.TimePickerDialog
import android.content.Intent
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.view.MotionEvent
import android.view.View
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import android.widget.Toast
import androidx.activity.result.contract.ActivityResultContracts
import androidx.core.content.ContextCompat
import androidx.core.content.res.ResourcesCompat
import coil.load
import coil.transform.RoundedCornersTransformation
import com.github.dhaval2404.imagepicker.ImagePicker
import com.jakewharton.rxbinding4.widget.textChanges
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.schedulers.Schedulers
import kr.co.vividnext.sodalive.R
import kr.co.vividnext.sodalive.base.BaseActivity
import kr.co.vividnext.sodalive.common.Constants
import kr.co.vividnext.sodalive.common.LoadingDialog
import kr.co.vividnext.sodalive.common.RealPathUtil
import kr.co.vividnext.sodalive.common.SharedPreferenceManager
import kr.co.vividnext.sodalive.databinding.ActivityLiveRoomCreateBinding
import kr.co.vividnext.sodalive.databinding.ItemLiveTagSelectedBinding
import kr.co.vividnext.sodalive.extensions.convertDateFormat
import kr.co.vividnext.sodalive.extensions.dpToPx
import kr.co.vividnext.sodalive.live.room.LiveRoomType
import kr.co.vividnext.sodalive.live.room.tag.LiveTagFragment
import kr.co.vividnext.sodalive.settings.notification.MemberRole
import org.koin.android.ext.android.inject
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale

class LiveRoomCreateActivity : BaseActivity<ActivityLiveRoomCreateBinding>(
    ActivityLiveRoomCreateBinding::inflate
) {

    private val viewModel: LiveRoomCreateViewModel by inject()

    private lateinit var loadingDialog: LoadingDialog

    private val handler = Handler(Looper.getMainLooper())

    private val datePickerDialogListener =
        DatePickerDialog.OnDateSetListener { _, year, monthOfYear, dayOfMonth ->
            viewModel.beginDate = String.format("%d-%02d-%02d", year, monthOfYear + 1, dayOfMonth)
            viewModel.setReservationDate(
                String.format(
                    "%d.%02d.%02d",
                    year,
                    monthOfYear + 1,
                    dayOfMonth
                )
            )
        }

    private val timePickerDialogListener =
        TimePickerDialog.OnTimeSetListener { _, hourOfDay, minute ->
            val timeString = String.format("%02d:%02d", hourOfDay, minute)
            viewModel.beginTime = timeString
            viewModel.setReservationTime(timeString.convertDateFormat("HH:mm", "a hh:mm"))
        }

    private val tagFragment: LiveTagFragment by lazy {
        LiveTagFragment(viewModel.tags) { tag, isChecked ->
            when {
                isChecked && viewModel.tags.size < 3 -> {
                    viewModel.addTag(tag)
                    return@LiveTagFragment true
                }

                !isChecked -> {
                    viewModel.removeTag(tag)
                    return@LiveTagFragment true
                }

                else -> {
                    Toast.makeText(
                        this,
                        "최대 3개까지 선택 가능합니다.",
                        Toast.LENGTH_SHORT
                    ).show()
                    return@LiveTagFragment false
                }
            }
        }
    }

    private val imageResult =
        registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
            val resultCode = result.resultCode
            val data = result.data

            if (resultCode == RESULT_OK) {
                // Image Uri will not be null for RESULT_OK
                val fileUri = data?.data!!
                binding.ivCover.background = null
                binding.ivCover.load(fileUri) {
                    crossfade(true)
                    placeholder(R.drawable.ic_place_holder)
                    transformations(RoundedCornersTransformation(13.3f.dpToPx()))
                }
                viewModel.coverImageUri = fileUri
                viewModel.coverImagePath = null
            } else if (resultCode == ImagePicker.RESULT_ERROR) {
                Toast.makeText(this, ImagePicker.getError(data), Toast.LENGTH_SHORT).show()
            }
        }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        viewModel.getRealPathFromURI = {
            RealPathUtil.getRealPath(applicationContext, it)
        }

        bindData()

        viewModel.setTimeNow(
            intent.getBooleanExtra(Constants.EXTRA_LIVE_TIME_NOW, true)
        )

        viewModel.getAllMenuPreset()
    }

    @SuppressLint("SetTextI18n", "ClickableViewAccessibility")
    override fun setupView() {
        loadingDialog = LoadingDialog(this, layoutInflater)


        binding.tvBack.setOnClickListener { finish() }
        binding.ivPhotoPicker.setOnClickListener {
            ImagePicker.with(this)
                .crop()
                .galleryOnly()
                .galleryMimeTypes( // Exclude gif images
                    mimeTypes = arrayOf(
                        "image/png",
                        "image/jpg",
                        "image/jpeg"
                    )
                )
                .createIntent { imageResult.launch(it) }
        }

        binding.llOpen.setOnClickListener {
            viewModel.setRoomType(LiveRoomType.OPEN)
            binding.llConfigTime.visibility = View.VISIBLE
            binding.tvConfigTime.visibility = View.VISIBLE
        }
        binding.llPrivate.setOnClickListener {
            viewModel.setRoomType(LiveRoomType.PRIVATE)
            binding.llConfigTime.visibility = View.VISIBLE
            binding.tvConfigTime.visibility = View.VISIBLE
        }

        binding.llTimeNow.setOnClickListener { viewModel.setTimeNow(true) }
        binding.llTimeReservation.setOnClickListener { viewModel.setTimeNow(false) }

        binding.tvReservationDate.setOnClickListener {
            val reservationDate = viewModel.beginDate.split("-")
            val datePicker: DatePickerDialog

            if (reservationDate.isNotEmpty() && reservationDate.size == 3) {
                datePicker = DatePickerDialog(
                    this,
                    R.style.DatePickerStyle,
                    datePickerDialogListener,
                    reservationDate[0].toInt(),
                    reservationDate[1].toInt() - 1,
                    reservationDate[2].toInt()
                )
            } else {
                val dateString = SimpleDateFormat(
                    "yyyy.MM.dd",
                    Locale.getDefault()
                ).format(Date()).split(".")

                datePicker = DatePickerDialog(
                    this,
                    R.style.DatePickerStyle,
                    datePickerDialogListener,
                    dateString[0].toInt(),
                    dateString[1].toInt() - 1,
                    dateString[2].toInt()
                )
            }

            datePicker.show()
        }

        binding.tvReservationTime.setOnClickListener {
            val reservationTime = viewModel.beginTime.split(":")
            val timePicker: TimePickerDialog

            if (reservationTime.isNotEmpty() && reservationTime.size == 2) {
                timePicker = TimePickerDialog(
                    this,
                    R.style.TimePickerStyle,
                    timePickerDialogListener,
                    reservationTime[0].toInt(),
                    reservationTime[1].toInt(),
                    false
                )
            } else {
                val timeString = SimpleDateFormat(
                    "HH:mm",
                    Locale.getDefault()
                ).format(Date()).split(":")

                timePicker = TimePickerDialog(
                    this,
                    R.style.TimePickerStyle,
                    timePickerDialogListener,
                    timeString[0].toInt(),
                    timeString[1].toInt(),
                    false
                )
            }

            timePicker.show()
        }

        binding.tvSelectTag.setOnClickListener {
            if (tagFragment.isAdded) return@setOnClickListener

            tagFragment.show(supportFragmentManager, tagFragment.tag)
        }

        binding.tvMakeRoom.setOnClickListener {
            binding.tvMakeRoom.isEnabled = false
            viewModel.createLiveRoom {
                val intent = Intent()
                if (it.id != null) {
                    intent.putExtra(Constants.EXTRA_ROOM_ID, it.id)
                }

                if (it.channelName != null) {
                    intent.putExtra(Constants.EXTRA_ROOM_CHANNEL_NAME, it.channelName)
                }
                setResult(RESULT_OK, intent)
                finish()
            }

            handler.postDelayed(
                { binding.tvMakeRoom.isEnabled = true },
                3000
            )
        }

        if (SharedPreferenceManager.isAuth) {
            binding.llSetAdult.visibility = View.VISIBLE
        } else {
            binding.llSetAdult.visibility = View.GONE
        }

        if (SharedPreferenceManager.role == MemberRole.CREATOR.name) {
            binding.llPrice.visibility = View.VISIBLE
            binding.tvPriceFree.setOnClickListener { binding.etPrice.setText("0") }
            binding.tvPrice100.setOnClickListener { binding.etPrice.setText("100") }
            binding.tvPrice300.setOnClickListener { binding.etPrice.setText("300") }
            binding.tvPrice500.setOnClickListener { binding.etPrice.setText("500") }
            binding.tvPrice1000.setOnClickListener { binding.etPrice.setText("1000") }
            binding.tvPrice2000.setOnClickListener { binding.etPrice.setText("2000") }
        } else {
            binding.llPrice.visibility = View.GONE
        }

        binding.tvGetRecentInfo.setOnClickListener {
            viewModel.getRecentInfo {
                binding.tvGetRecentInfo.visibility = View.GONE

                binding.etTitle.setText(it.title)
                binding.etNotice.setText(it.notice)
                binding.etNumberOfPeople.setText(it.numberOfPeople.toString())
                binding.ivCover.background = null
                binding.ivCover.load(it.coverImageUrl) {
                    crossfade(true)
                    placeholder(R.drawable.ic_place_holder)
                    transformations(RoundedCornersTransformation(13.3f.dpToPx()))
                }
            }
        }

        binding.etNotice.setOnTouchListener { view, motionEvent ->
            view.parent.parent.requestDisallowInterceptTouchEvent(true)
            if ((motionEvent.action and MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) {
                view.parent.parent.requestDisallowInterceptTouchEvent(false)
            }
            false
        }

        binding.etMenu.setOnTouchListener { view, motionEvent ->
            view.parent.parent.requestDisallowInterceptTouchEvent(true)
            if ((motionEvent.action and MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) {
                view.parent.parent.requestDisallowInterceptTouchEvent(false)
            }
            false
        }

        binding.ivSwitch.setOnClickListener {
            viewModel.toggleIsActivateMenu()
        }

        binding.llSelectMenu1.setOnClickListener {
            viewModel.selectMenuPreset(LiveRoomCreateViewModel.SelectedMenu.MENU_1)
        }

        binding.llSelectMenu2.setOnClickListener {
            viewModel.selectMenuPreset(LiveRoomCreateViewModel.SelectedMenu.MENU_2)
        }

        binding.llSelectMenu3.setOnClickListener {
            viewModel.selectMenuPreset(LiveRoomCreateViewModel.SelectedMenu.MENU_3)
        }

        binding.llAvailableJoinCreatorY.setOnClickListener {
            viewModel.setAvailableJoinCreator(true)
        }

        binding.llAvailableJoinCreatorN.setOnClickListener {
            viewModel.setAvailableJoinCreator(false)
        }
    }

    @SuppressLint("SetTextI18n")
    private fun bindData() {
        compositeDisposable.add(
            binding.etTitle.textChanges().skip(1)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe {
                    viewModel.title = it.toString()
                }
        )

        compositeDisposable.add(
            binding.etNotice.textChanges().skip(1)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe {
                    binding.tvNumberOfCharacters.text = "${it.length}자"
                    viewModel.content = it.toString()
                }
        )

        compositeDisposable.add(
            binding.etNumberOfPeople.textChanges().skip(1)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe {
                    if (it.isEmpty()) {
                        viewModel.numberOfPeople = 0
                    } else {
                        viewModel.numberOfPeople = it.toString().toInt()
                    }
                }
        )

        compositeDisposable.add(
            binding.etRoomPassword.textChanges().skip(1)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe {
                    if (it.isEmpty()) {
                        viewModel.password = null
                    } else {
                        try {
                            viewModel.password = it.toString()
                        } catch (e: NumberFormatException) {
                            binding.etRoomPassword.setText(it.substring(0, it.length - 1))
                        }
                    }
                }
        )

        compositeDisposable.add(
            binding.etMenu.textChanges().skip(1)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe {
                    viewModel.menu = it.toString()
                }
        )

        viewModel.toastLiveData.observe(this) {
            it?.let { Toast.makeText(applicationContext, it, Toast.LENGTH_LONG).show() }
        }

        viewModel.isLoading.observe(this) {
            if (it) {
                loadingDialog.show(screenWidth, "라이브를 생성하는 중입니다.")
            } else {
                loadingDialog.dismiss()
            }
        }

        viewModel.timeNowLiveData.observe(this) {
            if (it) {
                binding.llReservationDatetime.visibility = View.GONE
                binding.ivTimeReservation.visibility = View.GONE
                binding.ivTimeNow.visibility = View.VISIBLE
                binding.llTimeNow.setBackgroundResource(R.drawable.bg_round_corner_6_7_3bb9f1)
                binding.llTimeReservation.setBackgroundResource(
                    R.drawable.bg_round_corner_6_7_13181b
                )
                binding.tvTimeNow.setTextColor(
                    ContextCompat.getColor(
                        applicationContext,
                        R.color.color_eeeeee
                    )
                )

                binding.tvTimeReservation.setTextColor(
                    ContextCompat.getColor(
                        applicationContext,
                        R.color.color_3bb9f1
                    )
                )
            } else {
                binding.llReservationDatetime.visibility = View.VISIBLE
                binding.ivTimeReservation.visibility = View.VISIBLE
                binding.ivTimeNow.visibility = View.GONE
                binding.llTimeNow.setBackgroundResource(R.drawable.bg_round_corner_6_7_13181b)
                binding.llTimeReservation.setBackgroundResource(
                    R.drawable.bg_round_corner_6_7_3bb9f1
                )

                binding.tvTimeNow.setTextColor(
                    ContextCompat.getColor(
                        applicationContext,
                        R.color.color_3bb9f1
                    )
                )

                binding.tvTimeReservation.setTextColor(
                    ContextCompat.getColor(
                        applicationContext,
                        R.color.color_eeeeee
                    )
                )
            }
        }

        viewModel.roomTypeLiveData.observe(this) {
            when (it) {
                LiveRoomType.PRIVATE -> {
                    binding.ivPrivate.visibility = View.VISIBLE
                    binding.ivOpen.visibility = View.GONE

                    binding.llPrivate.setBackgroundResource(R.drawable.bg_round_corner_6_7_3bb9f1)
                    binding.llOpen.setBackgroundResource(R.drawable.bg_round_corner_6_7_13181b)

                    binding.tvPrivate.setTextColor(
                        ContextCompat.getColor(
                            applicationContext,
                            R.color.color_eeeeee
                        )
                    )

                    binding.tvOpen.setTextColor(
                        ContextCompat.getColor(
                            applicationContext,
                            R.color.color_3bb9f1
                        )
                    )

                    binding.llRoomPassword.visibility = View.VISIBLE
                }

                else -> {
                    binding.ivOpen.visibility = View.VISIBLE
                    binding.ivPrivate.visibility = View.GONE

                    binding.llOpen.setBackgroundResource(R.drawable.bg_round_corner_6_7_3bb9f1)
                    binding.llPrivate.setBackgroundResource(R.drawable.bg_round_corner_6_7_13181b)

                    binding.tvPrivate.setTextColor(
                        ContextCompat.getColor(
                            applicationContext,
                            R.color.color_3bb9f1
                        )
                    )

                    binding.tvOpen.setTextColor(
                        ContextCompat.getColor(
                            applicationContext,
                            R.color.color_eeeeee
                        )
                    )

                    binding.llRoomPassword.visibility = View.GONE
                }
            }
        }

        viewModel.reservationDateLiveData.observe(this) {
            binding.tvReservationDate.text = it
        }

        viewModel.reservationTimeLiveData.observe(this) {
            binding.tvReservationTime.text = it
        }

        viewModel.selectedLiveData.observe(this) {
            binding.llSelectTags.removeAllViews()
            for (index in it.indices) {
                val tag = it[index]
                val itemView = ItemLiveTagSelectedBinding.inflate(layoutInflater)
                itemView.tvTag.text = tag
                itemView.ivRemove.setOnClickListener {
                    viewModel.removeTag(tag)
                }
                binding.llSelectTags.addView(itemView.root)

                if (index > 0) {
                    val layoutParams = itemView.root.layoutParams as LinearLayout.LayoutParams
                    layoutParams.marginStart = 10.dpToPx().toInt()
                    itemView.root.layoutParams = layoutParams
                }
            }
        }

        if (SharedPreferenceManager.role == MemberRole.CREATOR.name ||
            SharedPreferenceManager.isAuth
        ) {

            binding.llAgeAll.setOnClickListener {
                viewModel.setAdult(false)
            }

            binding.llAge19.setOnClickListener {
                viewModel.setAdult(true)
            }

            viewModel.isAdultLiveData.observe(this) {
                if (it) {
                    binding.ivAgeAll.visibility = View.GONE
                    binding.llAgeAll.setBackgroundResource(R.drawable.bg_round_corner_6_7_13181b)
                    binding.tvAgeAll.setTextColor(
                        ContextCompat.getColor(
                            applicationContext,
                            R.color.color_3bb9f1
                        )
                    )

                    binding.ivAge19.visibility = View.VISIBLE
                    binding.llAge19.setBackgroundResource(R.drawable.bg_round_corner_6_7_3bb9f1)
                    binding.tvAge19.setTextColor(
                        ContextCompat.getColor(
                            applicationContext,
                            R.color.color_eeeeee
                        )
                    )
                } else {
                    binding.ivAge19.visibility = View.GONE
                    binding.llAge19.setBackgroundResource(R.drawable.bg_round_corner_6_7_13181b)
                    binding.tvAge19.setTextColor(
                        ContextCompat.getColor(
                            applicationContext,
                            R.color.color_3bb9f1
                        )
                    )

                    binding.ivAgeAll.visibility = View.VISIBLE
                    binding.llAgeAll.setBackgroundResource(R.drawable.bg_round_corner_6_7_3bb9f1)
                    binding.tvAgeAll.setTextColor(
                        ContextCompat.getColor(
                            applicationContext,
                            R.color.color_eeeeee
                        )
                    )
                }
            }
        }

        if (SharedPreferenceManager.role == MemberRole.CREATOR.name) {
            compositeDisposable.add(
                binding.etPrice.textChanges()
                    .skip(1)
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe {
                        if (it.isNotEmpty()) {
                            val price = it.toString().toUIntOrNull()
                            if (price != null) {
                                viewModel.setPrice(price.toInt())
                            } else {
                                binding.etPrice.setText(it.substring(0, it.length - 1))
                                binding.etPrice.setSelection(it.length - 1)
                            }
                        } else {
                            viewModel.setPrice(0)
                        }
                    }
            )

            viewModel.priceLiveData.observe(this) {
                allPriceSelectFalse()

                when (it) {
                    0 -> priceSelect(binding.tvPriceFree)
                    100 -> priceSelect(binding.tvPrice100)
                    300 -> priceSelect(binding.tvPrice300)
                    500 -> priceSelect(binding.tvPrice500)
                    1000 -> priceSelect(binding.tvPrice1000)
                    2000 -> priceSelect(binding.tvPrice2000)
                    else -> binding.rlPrice.isSelected = true
                }
            }

            viewModel.isActivateMenuLiveData.observe(this) {
                if (it) {
                    binding.llEditMenu.visibility = View.VISIBLE
                    binding.ivSwitch.setImageResource(R.drawable.btn_toggle_on_big)
                } else {
                    binding.llEditMenu.visibility = View.GONE
                    binding.ivSwitch.setImageResource(R.drawable.btn_toggle_off_big)
                }
            }

            viewModel.selectedMenuLiveData.observe(this) {
                deselectAllMenuPreset()

                when(it) {
                    LiveRoomCreateViewModel.SelectedMenu.MENU_2 -> selectMenuPresetButton(
                        binding.ivSelectMenu2,
                        binding.llSelectMenu2,
                        binding.tvSelectMenu2
                    )

                    LiveRoomCreateViewModel.SelectedMenu.MENU_3 -> selectMenuPresetButton(
                        binding.ivSelectMenu3,
                        binding.llSelectMenu3,
                        binding.tvSelectMenu3
                    )

                    else -> selectMenuPresetButton(
                        binding.ivSelectMenu1,
                        binding.llSelectMenu1,
                        binding.tvSelectMenu1
                    )
                }
            }

            viewModel.menuLiveData.observe(this) {
                binding.etMenu.setText(it)
            }

            viewModel.isAvailableJoinCreatorLiveData.observe(this) {
                if (it) {
                    binding.ivAvailableJoinCreatorN.visibility = View.GONE
                    binding.llAvailableJoinCreatorN.setBackgroundResource(R.drawable.bg_round_corner_6_7_13181b)
                    binding.tvAvailableJoinCreatorN.setTextColor(
                        ContextCompat.getColor(
                            applicationContext,
                            R.color.color_3bb9f1
                        )
                    )

                    binding.ivAvailableJoinCreatorY.visibility = View.VISIBLE
                    binding.llAvailableJoinCreatorY.setBackgroundResource(R.drawable.bg_round_corner_6_7_3bb9f1)
                    binding.tvAvailableJoinCreatorY.setTextColor(
                        ContextCompat.getColor(
                            applicationContext,
                            R.color.color_eeeeee
                        )
                    )
                } else {
                    binding.ivAvailableJoinCreatorY.visibility = View.GONE
                    binding.llAvailableJoinCreatorY.setBackgroundResource(R.drawable.bg_round_corner_6_7_13181b)
                    binding.tvAvailableJoinCreatorY.setTextColor(
                        ContextCompat.getColor(
                            applicationContext,
                            R.color.color_3bb9f1
                        )
                    )

                    binding.ivAvailableJoinCreatorN.visibility = View.VISIBLE
                    binding.llAvailableJoinCreatorN.setBackgroundResource(R.drawable.bg_round_corner_6_7_3bb9f1)
                    binding.tvAvailableJoinCreatorN.setTextColor(
                        ContextCompat.getColor(
                            applicationContext,
                            R.color.color_eeeeee
                        )
                    )
                }
            }
        }
    }

    private fun allPriceSelectFalse() {
        binding.rlPrice.isSelected = false
        priceSelectFalse(binding.tvPriceFree)
        priceSelectFalse(binding.tvPrice100)
        priceSelectFalse(binding.tvPrice300)
        priceSelectFalse(binding.tvPrice500)
        priceSelectFalse(binding.tvPrice1000)
        priceSelectFalse(binding.tvPrice2000)
    }

    private fun priceSelectFalse(priceView: TextView) {
        priceView.isSelected = false
        priceView.setTextColor(
            ContextCompat.getColor(
                applicationContext,
                R.color.color_eeeeee
            )
        )
        priceView.typeface = ResourcesCompat.getFont(
            applicationContext,
            R.font.gmarket_sans_medium
        )
    }

    private fun priceSelect(priceView: TextView) {
        priceView.isSelected = true
        priceView.setTextColor(
            ContextCompat.getColor(
                applicationContext,
                R.color.color_3bb9f1
            )
        )
        priceView.typeface = ResourcesCompat.getFont(
            applicationContext,
            R.font.gmarket_sans_bold
        )
    }

    private fun deselectAllMenuPreset() {
        binding.ivSelectMenu1.visibility = View.GONE
        binding.ivSelectMenu2.visibility = View.GONE
        binding.ivSelectMenu3.visibility = View.GONE

        binding.llSelectMenu1.setBackgroundResource(R.drawable.bg_round_corner_6_7_13181b)
        binding.tvSelectMenu1.setTextColor(
            ContextCompat.getColor(
                applicationContext,
                R.color.color_3bb9f1
            )
        )

        if (viewModel.menuList.size > 0) {
            binding.llSelectMenu2.setBackgroundResource(R.drawable.bg_round_corner_6_7_13181b)
            binding.tvSelectMenu2.setTextColor(
                ContextCompat.getColor(
                    applicationContext,
                    R.color.color_3bb9f1
                )
            )
        } else {
            binding.llSelectMenu2.setBackgroundResource(R.drawable.bg_round_corner_6_7_777777)
            binding.tvSelectMenu2.setTextColor(
                ContextCompat.getColor(
                    applicationContext,
                    R.color.color_555555
                )
            )
        }

        if (viewModel.menuList.size > 1) {
            binding.llSelectMenu3.setBackgroundResource(R.drawable.bg_round_corner_6_7_13181b)
            binding.tvSelectMenu3.setTextColor(
                ContextCompat.getColor(
                    applicationContext,
                    R.color.color_3bb9f1
                )
            )
        } else {
            binding.llSelectMenu3.setBackgroundResource(R.drawable.bg_round_corner_6_7_777777)
            binding.tvSelectMenu3.setTextColor(
                ContextCompat.getColor(
                    applicationContext,
                    R.color.color_555555
                )
            )
        }
    }

    private fun selectMenuPresetButton(
        ivSelectMenuPreset: ImageView,
        llSelectMenuPreset: LinearLayout,
        tvSelectMenuPreset: TextView
    ) {
        ivSelectMenuPreset.visibility = View.VISIBLE
        llSelectMenuPreset.setBackgroundResource(R.drawable.bg_round_corner_6_7_3bb9f1)
        tvSelectMenuPreset.setTextColor(
            ContextCompat.getColor(
                applicationContext,
                R.color.color_eeeeee
            )
        )
    }
}
