package com.abbidot.tracker.ui.activity

import android.content.Intent
import android.view.View
import com.abbidot.baselibrary.constant.EventName
import com.abbidot.baselibrary.constant.MMKVKey
import com.abbidot.baselibrary.eventbus.XEventBus
import com.abbidot.baselibrary.util.AppUtils
import com.abbidot.baselibrary.util.MMKVUtil
import com.abbidot.tracker.R
import com.abbidot.tracker.base.BaseActivity
import com.abbidot.tracker.databinding.ActivitySayHelloBinding
import com.abbidot.tracker.ui.activity.account.CreateAccountV2Activity
import com.abbidot.tracker.ui.activity.account.LoginV2Activity
import com.abbidot.tracker.ui.activity.account.cn.LoginV2CNActivity
import com.abbidot.tracker.ui.activity.account.cn.RegisterCNActivity
import com.abbidot.tracker.util.ThirdPartyUtil

class SayHelloActivity : BaseActivity<ActivitySayHelloBinding>(ActivitySayHelloBinding::inflate) {

    override fun getTopBar() = null

    override fun initData() {
        super.initData()

        mViewBinding.apply {
            root.setBackgroundResource(R.drawable.icon_say_hi_bg)
            if (AppUtils.isChina()) {
                btnSayHelloLoginWechat.visibility = View.VISIBLE
            }
            setOnClickListenerViews(btnSayHelloLogin, btnSayHelloSignup, btnSayHelloLoginWechat)
        }
    }

    override fun liveDataObserve() {
        XEventBus.observe(this, EventName.FinishActivity) {
            finish()
        }
    }

    override fun onClick(v: View?) {
        mViewBinding.apply {
            when (v!!) {
                btnSayHelloLogin -> {
                    if (AppUtils.isChina()) {
                        val intent = Intent(mContext, LoginV2CNActivity::class.java)
                        startActivity(intent)
                    } else {
                        val intent = Intent(mContext, LoginV2Activity::class.java)
                        val email = MMKVUtil.getString(MMKVKey.Email)
                        intent.putExtra(MMKVKey.Email, email)
                        startActivity(intent)
                    }
                }

                btnSayHelloSignup -> {
                    if (AppUtils.isChina()) {
                        startActivity(Intent(mContext, RegisterCNActivity::class.java))
                    } else {
                        startActivity(Intent(mContext, CreateAccountV2Activity::class.java))
                    }
                }

                btnSayHelloLoginWechat -> ThirdPartyUtil.instance.startWXLogin(this@SayHelloActivity)
            }
        }
    }
}