package com.mobiuz.app.dev

import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import com.mobiuz.app.databinding.ActivityLanguageBinding
import com.mobiuz.app.dev.model.SharedPref
import com.mobiuz.app.dev.ui.auth.AuthActivity
import com.mobiuz.app.dev.ui.global.CONSTANTS
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject

@AndroidEntryPoint
class LanguageActivity : AppCompatActivity() {

    private var _bn: ActivityLanguageBinding? = null
    private val bn get() = _bn ?: throw NullPointerException("cannot inflate")

    @Inject
    lateinit var pref: SharedPref

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        _bn = ActivityLanguageBinding.inflate(layoutInflater)
        setContentView(bn.root)
        window.decorView.systemUiVisibility = window.decorView.systemUiVisibility or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR

        bn.apply {
            uzbekLang.setOnClickListener {
                setLangAndNavigate(CONSTANTS.UZ)
            }
            russianLang.setOnClickListener {
                setLangAndNavigate(CONSTANTS.RU)
            }
            englishLang.setOnClickListener {
                setLangAndNavigate(CONSTANTS.EN)
            }
        }
    }

    private fun setLangAndNavigate(lang: String) {
        pref.language = lang
        startActivity(Intent(this@LanguageActivity, AuthActivity::class.java))
    }

    override fun onDestroy() {
        _bn = null
        super.onDestroy()
    }
}