import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:pharmacy_mobile/blocs/language/functions/bloc_setlanguage.dart';
import 'package:pharmacy_mobile/pages/customer_pages/customer_cart_page.dart';
import 'package:pharmacy_mobile/pages/customer_pages/customer_main_page.dart';
import 'package:pharmacy_mobile/pages/customer_pages/customer_settings_page.dart';
import 'package:pharmacy_mobile/pages/customer_pages/customer_search_page.dart';
import 'package:pharmacy_mobile/widgets/text_widget.dart';
import 'package:animated_notch_bottom_bar/animated_notch_bottom_bar/animated_notch_bottom_bar.dart';

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

  @override
  State<CustomerPage> createState() => _CustomerPageState();
}

class _CustomerPageState extends State<CustomerPage> {
  final _pageController = PageController(initialPage: 0);
  final NotchBottomBarController _notchController = NotchBottomBarController(index: 0);

  Future<void> _setDefault() async {
    final language = await blocSetLanguage(context, 'English');

    if (language) {
      setState(() {});
    }
  }

  void autoRun() async {
    await _setDefault();
  }

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

  @override
  Widget build(BuildContext context) {
    final List<Widget> bottomBarPages = [
      const CustomerMainPage(),
      const CustomerSearchPage(),
      const CustomerCartPage(),
      const CustomerSettingsPage()
    ];

    final Color selectedBarColor = const Color.fromRGBO(241, 255, 255, 0.83);
    final Color unselectedBarColor = const Color.fromRGBO(206, 206, 206, 1);
    final double barFontSize = 8;
    final double barIconInactiveSize = 20;
    final double barIconActiveSize = 20;

    return PopScope(
        canPop: false,
        child: Scaffold(
            resizeToAvoidBottomInset: false,
            body: PageView(
              controller: _pageController,
              physics: const NeverScrollableScrollPhysics(),
              children: List.generate(bottomBarPages.length, (index) => bottomBarPages[index]),
            ),
            extendBody: true,
            bottomNavigationBar: AnimatedNotchBottomBar(
              notchBottomBarController: _notchController,
              showLabel: true,
              textOverflow: TextOverflow.visible,
              maxLine: 1,
              kIconSize: 24,
              kBottomRadius: 20.0,
              color: const Color.fromRGBO(90, 73, 106, 1),
              notchColor: const Color.fromRGBO(182, 143, 210, 1),
              removeMargins: false,
              bottomBarWidth: 500,
              durationInMilliSeconds: 300,
              bottomBarItems: [
                BottomBarItem(
                    inActiveItem: FaIcon(FontAwesomeIcons.house, size: barIconInactiveSize, color: unselectedBarColor),
                    activeItem: FaIcon(
                      FontAwesomeIcons.house,
                      size: barIconActiveSize,
                      color: selectedBarColor,
                    ),
                    itemLabelWidget: TextWidget(
                      text: 'Home',
                      size: barFontSize,
                      bold: true,
                      color: unselectedBarColor,
                    )),
                BottomBarItem(
                  inActiveItem:
                      FaIcon(FontAwesomeIcons.magnifyingGlass, size: barIconInactiveSize, color: unselectedBarColor),
                  activeItem: Icon(FontAwesomeIcons.magnifyingGlass, size: barIconActiveSize, color: selectedBarColor),
                  itemLabelWidget: TextWidget(
                    text: 'Search',
                    size: barFontSize,
                    bold: true,
                    color: unselectedBarColor,
                  ),
                ),
                BottomBarItem(
                  inActiveItem:
                      FaIcon(FontAwesomeIcons.cartShopping, size: barIconInactiveSize, color: unselectedBarColor),
                  activeItem: FaIcon(FontAwesomeIcons.cartShopping, size: barIconActiveSize, color: selectedBarColor),
                  itemLabelWidget: TextWidget(
                    text: 'Cart',
                    size: barFontSize,
                    bold: true,
                    color: unselectedBarColor,
                  ),
                ),
                BottomBarItem(
                  inActiveItem: FaIcon(FontAwesomeIcons.userGear, size: barIconInactiveSize, color: unselectedBarColor),
                  activeItem: FaIcon(FontAwesomeIcons.userGear, size: barIconActiveSize, color: selectedBarColor),
                  itemLabelWidget: TextWidget(
                    text: 'Settings',
                    size: barFontSize,
                    bold: true,
                    color: unselectedBarColor,
                  ),
                ),
              ],
              onTap: (index) {
                _pageController.jumpToPage(index);
              },
            )));
  }
}
