import 'package:aitrainer_app/bloc/menu/menu_bloc.dart';

import 'package:aitrainer_app/widgets/app_bar.dart';
import 'package:aitrainer_app/widgets/bottom_nav.dart';
import 'package:aitrainer_app/widgets/menu_page_widget.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

// ignore: must_be_immutable
class MenuPage extends StatefulWidget {
  int parent;

  MenuPage({required this.parent});

  _MenuPage createState() => _MenuPage();
}

class _MenuPage extends State<MenuPage> {
  // ignore: close_sinks
  late MenuBloc menuBloc;

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    menuBloc = BlocProvider.of<MenuBloc>(context);
    menuBloc.parent = widget.parent;
    return Scaffold(
        appBar: AppBarNav(
          isMenu: true,
        ),
        body: Container(
            decoration: BoxDecoration(
              image: DecorationImage(
                image: AssetImage('asset/image/WT_menu_dark.jpg'),
                fit: BoxFit.fill,
                alignment: Alignment.center,
              ),
            ),
            child: BlocConsumer<MenuBloc, MenuState>(listener: (context, state) {
              if (state is MenuError) {
                ScaffoldMessenger.of(context).showSnackBar(
                    SnackBar(backgroundColor: Colors.orange, content: Text(state.message, style: TextStyle(color: Colors.white))));
              }
            }, builder: (context, state) {
              return MenuPageWidget();
            })),
        bottomNavigationBar: BottomNavigator(bottomNavIndex: 0));
  }
}
