package com.narutohuo.xindazhou

import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.narutohuo.xindazhou.community.ui.CommunityActivity
import com.narutohuo.xindazhou.service.ui.ServiceActivity
import com.narutohuo.xindazhou.shop.ui.ShopActivity
import com.narutohuo.xindazhou.user.ui.UserActivity
import com.narutohuo.xindazhou.vehicle.ui.VehicleActivity
import com.google.android.material.bottomnavigation.BottomNavigationView

/**
 * 主界面 Fragment
 * 
 * 包含底部导航栏，点击跳转到对应的 Activity
 */
class MainFragment : Fragment() {

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        val view = inflater.inflate(R.layout.fragment_main, container, false)
        
        val bottomNavView = view.findViewById<BottomNavigationView>(R.id.bottomNavView)
        bottomNavView.setOnItemSelectedListener { item ->
            when (item.itemId) {
                R.id.vehicleFragment -> {
                    startActivity(Intent(requireContext(), VehicleActivity::class.java))
                    true
                }
                R.id.communityFragment -> {
                    startActivity(Intent(requireContext(), CommunityActivity::class.java))
                    true
                }
                R.id.serviceFragment -> {
                    startActivity(Intent(requireContext(), ServiceActivity::class.java))
                    true
                }
                R.id.shopFragment -> {
                    startActivity(Intent(requireContext(), ShopActivity::class.java))
                    true
                }
                R.id.userFragment -> {
                    startActivity(Intent(requireContext(), UserActivity::class.java))
                    true
                }
                else -> false
            }
        }
        
        // 设置默认选中项
        bottomNavView.selectedItemId = R.id.vehicleFragment
        
        return view
    }
}

