package com.doverfuelingsolutions.issp.view.fragment

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.doverfuelingsolutions.issp.R
import com.doverfuelingsolutions.issp.databinding.FragmentInitBinding
import com.doverfuelingsolutions.issp.utils.StringUtil

class FragmentInit : Fragment() {

    private lateinit var binding: FragmentInitBinding
    private val initViewModel: FragmentInitViewModel by viewModels()

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        binding = DataBindingUtil.inflate(inflater, R.layout.fragment_init, container, false)
        binding.lifecycleOwner = viewLifecycleOwner
        binding.viewModel = initViewModel
        return binding.root
    }

    fun fail(msg: String) {
        initViewModel.isLoading.value = false
        initViewModel.failTip.value = StringUtil.get(R.string.tip_connect_fail_reason_config, msg)
    }

    class FragmentInitViewModel : ViewModel() {
        val isLoading = MutableLiveData(true)
        val loadingTip = MutableLiveData(StringUtil.get(R.string.in_connect_fusion))
        val failTip = MutableLiveData(StringUtil.get(R.string.connect_timeout))
    }
}