package com.gh.gamecenter.setting.view

import android.os.Bundle
import android.view.View
import com.blankj.utilcode.util.LanguageUtils
import com.gh.gamecenter.common.base.fragment.ToolbarFragment
import com.gh.gamecenter.common.view.DrawableView
import com.gh.gamecenter.setting.databinding.FragmentLanguageSettingBinding
import java.util.*

class LanguageSettingFragment : ToolbarFragment() {

    private lateinit var viewBinding: FragmentLanguageSettingBinding

    override fun getLayoutId(): Int = 0

    override fun getInflatedLayout(): View = FragmentLanguageSettingBinding
        .inflate(layoutInflater)
        .apply { viewBinding = this }.root


    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        viewBinding.icSimplifiedChinese.isChecked = LanguageUtils.isAppliedLanguage(Locale.SIMPLIFIED_CHINESE)
        viewBinding.icSimplifiedChinese.setImageDrawable(DrawableView.getCheckSelectorDrawable(requireContext()))
        viewBinding.rlSimplifiedChinese.setOnClickListener {
            if (!viewBinding.icSimplifiedChinese.isChecked) {
                viewBinding.icTraditionalChinese.isChecked = false
                viewBinding.icSimplifiedChinese.isChecked = true
                LanguageUtils.applyLanguage(Locale.SIMPLIFIED_CHINESE)
            }
        }

        viewBinding.icTraditionalChinese.isChecked = LanguageUtils.isAppliedLanguage(Locale.TRADITIONAL_CHINESE)
        viewBinding.icTraditionalChinese.setImageDrawable(DrawableView.getCheckSelectorDrawable(requireContext()))
        viewBinding.rlTraditionalChinese.setOnClickListener {
            if (!viewBinding.icTraditionalChinese.isChecked) {
                viewBinding.icTraditionalChinese.isChecked = true
                viewBinding.icSimplifiedChinese.isChecked = false
                LanguageUtils.applyLanguage(Locale.TRADITIONAL_CHINESE)
            }
        }
    }

}