package com.adealink.weparty.account.login.comp

import androidx.lifecycle.LifecycleOwner
import com.adealink.frame.mvvm.viewmodel.activityViewModels
import com.adealink.frame.util.onClick
import com.adealink.weparty.account.databinding.LayoutAccountLoginOtherWayBinding
import com.adealink.weparty.account.login.data.ThirdType
import com.adealink.weparty.account.login.viewmodel.LoginViewModel
import com.adealink.weparty.account.viewModel.AccountViewModelFactory
import com.adealink.weparty.commonui.BaseViewComponent

class OtherLoginWay(
    lifecycleOwner: LifecycleOwner,
    private val binding: LayoutAccountLoginOtherWayBinding
) : BaseViewComponent(lifecycleOwner) {

    private val loginViewModel by activityViewModels<LoginViewModel> { AccountViewModelFactory() }
    override fun initViews() {
        super.initViews()
        binding.googleLoginBtn.onClick(wait = 1000) {
            login(ThirdType.GOOGLE)
        }
    }

    private fun login(authType: ThirdType) {
        activity?.let { act ->
            showLoading()
            loginViewModel.startAuthLogin(authType, act)
        }
    }

}