package com.doverfuelingsolutions.issp.view.fragment

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.StringRes
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.FragmentLoadingBinding
import com.doverfuelingsolutions.issp.utils.StringUtil

class FragmentLoading private constructor(private val msg: String) : Fragment() {

    companion object {

        fun build(@StringRes string: Int): FragmentLoading {
            return FragmentLoading(StringUtil.get(string))
        }
    }

    private lateinit var binding: FragmentLoadingBinding
    private val viewModel: FragmentHolderViewModel by viewModels()

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        if (!this::binding.isInitialized) {
            binding = DataBindingUtil.inflate(inflater, R.layout.fragment_loading, container, false)
            binding.lifecycleOwner = viewLifecycleOwner
            binding.viewModel = viewModel
            viewModel.loadingTip.value = msg
        }
        return binding.root
    }

    class FragmentHolderViewModel(msg: String = StringUtil.get(R.string.in_connect_fusion)) : ViewModel() {
        val loadingTip = MutableLiveData(msg)
    }
}