import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:niogu_ecommerce_v1/core/components/bottom_bar_app.dart';

class MainWrapper extends StatelessWidget {
  final StatefulNavigationShell navigationShell;

  const MainWrapper({super.key, required this.navigationShell});

  static final GlobalKey<ScaffoldState> scaffoldKey =
      GlobalKey<ScaffoldState>();

  @override
  Widget build(BuildContext context) {
    return LayoutBuilder(
      builder: (context, constraints) {
        return SafeArea(
          top: false,
          bottom: true,
          right: false,
          left: false,
          child: Stack(
            children: [
              Scaffold(
                key: scaffoldKey,
                extendBody: true,
                resizeToAvoidBottomInset: false,
                body: navigationShell,
                bottomNavigationBar: navigationShell.currentIndex == 2
                    ? null
                    : BottomBarApp(
                        currentIndex: navigationShell.currentIndex,
                        onTap: (index) {
                          navigationShell.goBranch(
                            index,
                            initialLocation:
                                index == navigationShell.currentIndex,
                          );
                        },
                      ),
              ),
            ],
          ),
        );
      },
    );
  }
}
