import 'package:carrotapp/pages/a_page.dart';
import 'package:carrotapp/pages/b_page.dart';
import 'package:carrotapp/pages/c_page.dart';
import 'package:carrotapp/pages/d_page.dart';
import 'package:carrotapp/pages/e_page.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: HomePage(),
    );
  }
}

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {

  // 상태
  int selectedIndex = 0;
  var loadPages = [0];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: IndexedStack(
        index: selectedIndex,
        children: [
          loadPages.contains(0) ? const APage() : Container(),
          loadPages.contains(1) ? const BPage() : Container(),
          loadPages.contains(2) ? const CPage() : Container(),
          loadPages.contains(3) ? const DPage() : Container(),
          loadPages.contains(4) ? const EPage() : Container(),
        ],
      ),
      bottomNavigationBar: BottomNavigationBar(
        onTap: (index){
          var pages = [...loadPages];

          if(!pages.contains(index)){
            pages.add(index);
          }

          loadPages = pages;
          selectedIndex = index;
          setState(() {});
        },
        type: BottomNavigationBarType.fixed,
        showSelectedLabels: false,
        showUnselectedLabels: false,
        currentIndex: selectedIndex,
        selectedItemColor: Colors.orange,
        unselectedItemColor: Colors.black54,
        items: [
          BottomNavigationBarItem(icon: Icon(CupertinoIcons.home), label: ""),
          BottomNavigationBarItem(icon: Icon(CupertinoIcons.home), label: ""),
          BottomNavigationBarItem(icon: Icon(CupertinoIcons.home), label: ""),
          BottomNavigationBarItem(icon: Icon(CupertinoIcons.home), label: ""),
          BottomNavigationBarItem(icon: Icon(CupertinoIcons.home), label: ""),
        ],
      ),
    );
  }
}