package com.narutohuo.xindazhou.main.ui

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
import androidx.navigation.ui.setupWithNavController
import com.google.android.material.bottomnavigation.BottomNavigationView
import com.narutohuo.xindazhou.R

/**
 * 主界面Fragment
 * 
 * 包含底部导航栏（TabBar）和各个业务模块的Fragment容器
 * 默认显示"车辆"标签页
 */
class MainFragment : Fragment() {

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

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        val bottomNavView: BottomNavigationView = view.findViewById(R.id.bottomNavView)

        // 获取嵌套的 NavController（main_nav_graph）
        // FragmentContainerView 会自动创建 NavHostFragment
        val childNavHostFragment = childFragmentManager.findFragmentById(R.id.navHostFragment) 
            as? androidx.navigation.fragment.NavHostFragment
        
        // 将底部导航栏与嵌套的 NavController 关联
        childNavHostFragment?.navController?.let { navController ->
            bottomNavView.setupWithNavController(navController)
        }
    }
}

