// ignore_for_file: sized_box_for_whitespace

import 'package:byod/ui/home/new_home2.dart';
import 'package:byod/ui/viewbill/view_bill_new.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import '../../bloc/address_user_bloc.dart';
import '../../bloc/branch_list.dart';
import '../../helper/helper.dart';
import '../../helper/widget/style.dart';
import '../select_branch.dart';

class CustomAppBar extends StatelessWidget {
  const CustomAppBar({
    Key? key,
    required this.titleAppBar,
    required this.isFromSelectBranch,
    required this.isFromMenu,
  }) : super(key: key);

  final String titleAppBar;
  final bool isFromSelectBranch;
  final bool isFromMenu;

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.only(
        top: 15,
        bottom: 19,
        left: paddingLeftRight,
        right: paddingLeftRight,
      ),
      // padding: const EdgeInsets.symmetric(horizontal: paddingLeftRight),
      color: backgroundWhite,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Row(
            children: [
              GestureDetector(
                onTap: () {
                  if (isFromSelectBranch || isFromMenu) {
                    context.read<AddressUser>().getAddressUser(
                          context,
                          isGetBranchList: true,
                          isCallDeliveryCharge: false,
                        );
                    // Navigator.push(
                    //   context,
                    //   MaterialPageRoute(
                    //     builder: (_) => const SelectBranch(
                    //       isFormBill: true,
                    //     ),
                    //   ),
                    // );
                    Navigator.pop(context);
                  }
                  // else if (isFromMenu) {
                  //   context.read<AddressUser>().getAddressUser(
                  //         context,
                  //         isGetBranchList: true,
                  //         isCallDeliveryCharge: false,
                  //       );
                  //   Navigator.push(
                  //     context,
                  //     MaterialPageRoute(
                  //       builder: (_) => const NewHome2(),
                  //     ),
                  //   );
                  // }
                  else {
                    Navigator.pushReplacement(
                      context,
                      MaterialPageRoute(
                        builder: (_) => const ViewBillNew(
                          isRepeatViewBill: true,
                        ),
                      ),
                    );
                  }
                },
                child: Container(
                  width: 24,
                  height: 24,
                  child: Center(
                    child: fontAwesomeNew(
                      arrowBack,
                      arrowBackSize,
                    ),
                  ),
                ),
              ),
              const SizedBox(
                width: 16,
              ),
              Center(
                child: defaultText(
                  context,
                  titleAppBar,
                  maxLines: 1,
                  overFlow: TextOverflow.ellipsis,
                  style: appBarNameViewBill(),
                ),
              ),
            ],
          ),
          // GestureDetector(
          //   onTap: () {
          //     Navigator.pushReplacement(
          //       context,
          //       MaterialPageRoute(
          //         builder: (_) => const ViewBillNew(
          //           isRepeatViewBill: true,
          //         ),
          //       ),
          //     );
          //   },
          //   child: Row(
          //     children: [
          //       defaultText(
          //         context,
          //         'Simpan',
          //         style: appBarNameViewBill(),
          //       ),
          //       const SizedBox(
          //         width: 5,
          //       ),
          //       fontAwesomeNew(
          //         saveIcon,
          //         saveIconSize,
          //       ),
          //     ],
          //   ),
          // ),
        ],
      ),
    );
  }
}
