package com.doverfuelingsolutions.issp.view.fragment

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import androidx.navigation.fragment.findNavController
import com.doverfuelingsolutions.issp.R
import com.doverfuelingsolutions.issp.utils.log.DFSLog
import com.doverfuelingsolutions.issp.view.MainActivity
import kotlinx.android.synthetic.main.fragment_start.*

class FragmentStart : Fragment() {

    private val globalViewModel: MainActivity.GlobalViewModel by activityViewModels()

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        return inflater.inflate(R.layout.fragment_start, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        val loginResult = findNavController().currentBackStackEntry?.savedStateHandle?.get<Boolean>(FragmentLogin.KEY_LOGIN_RESULT)
        when {
            loginResult == null -> {
                globalViewModel.isLogin.observe(viewLifecycleOwner, {
                })
            }
            loginResult -> {
                initialize()
            }
            else -> {
                // TODO 提示必须登录
                DFSLog.w("先登录OK？")
            }
        }

    }

    private fun initialize() {
        DFSLog.i("action_fragmentStart_to_fragmentMain")
        // TODO: init data and Fusion
    }
}