import 'package:flutter/material.dart';

import 'contacts_screen.dart';
import 'conversation_list_screen.dart';
import 'mine_screen.dart';

/// 主页：底部三 Tab —— 消息 / 通讯录 / 我的
class HomeScreen extends StatefulWidget {
  const HomeScreen({super.key});

  @override
  State<HomeScreen> createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
  int _index = 0;

  void switchTab(int index) => setState(() => _index = index);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: IndexedStack(
        index: _index,
        children: [
          ConversationListScreen(onFindContacts: () => switchTab(1)),
          const ContactsScreen(),
          const MineScreen(),
        ],
      ),
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: _index,
        onTap: (i) => setState(() => _index = i),
        items: const [
          BottomNavigationBarItem(icon: Icon(Icons.chat_bubble), label: '消息'),
          BottomNavigationBarItem(icon: Icon(Icons.people), label: '通讯录'),
          BottomNavigationBarItem(icon: Icon(Icons.person), label: '我的'),
        ],
      ),
    );
  }
}
