import 'package:flutter/material.dart';
import 'package:initial_folder/screens/home/components/notification.dart';
import 'package:initial_folder/screens/login/login_with_email/login_email_screen.dart';
import 'package:initial_folder/screens/search_course/component/filter.dart';
import 'package:initial_folder/size_config.dart';
import 'package:initial_folder/theme.dart';
import 'package:initial_folder/helper/user_info.dart';
import 'package:initial_folder/screens/cart/cart_page.dart';
import 'package:initial_folder/screens/splash/splash_screen_login.dart';
import 'package:initial_folder/widgets/custom_navigator.dart';

class AppBarFilter extends StatelessWidget {
  const AppBarFilter({
    Key? key,
    this.idcourse,
  }) : super(key: key);

  final String? idcourse;

  @override
  Widget build(BuildContext context) {
    Future _showDialogNotLogin(String teks) {
      return showDialog(
        context: context,
        builder: (context) => AlertDialog(
          contentPadding: EdgeInsets.fromLTRB(12, 20, 12, 1),
          content: Text(
            'Mohon login terlebih dahulu sebelum $teks',
            style: primaryTextStyle.copyWith(
                fontSize: getProportionateScreenWidth(12), letterSpacing: 1),
          ),
          actions: [
            GestureDetector(
              onTap: () {
                Navigator.of(context).pop();
              },
              child: Text('Batal',
                  style: primaryTextStyle.copyWith(
                      fontSize: getProportionateScreenWidth(12),
                      letterSpacing: 1,
                      color: primaryColor)),
            ),
            SizedBox(
              width: getProportionateScreenWidth(5),
            ),
            GestureDetector(
              onTap: () {
                Navigator.of(context).pushNamedAndRemoveUntil(
                    LoginEmail.routeName, (Route<dynamic> route) => false);
              },
              child: Text('Login',
                  style: primaryTextStyle.copyWith(
                      fontSize: getProportionateScreenWidth(12),
                      letterSpacing: 1,
                      color: primaryColor)),
            ),
          ],
        ),
      );
    }

    handleNotLoginCart() async {
      var token = await UsersInfo().getToken();
      if (token != null || Condition.loginFirebase == true) {
        Navigator.of(context).push(
          CustomNavigator(
            child: CartPage(),
          ),
        );
      } else {
        String teks = 'dapat mengakses keranjang';
        return _showDialogNotLogin(teks);
      }
    }

    handleNotLoginNotif() async {
      var token = await UsersInfo().getToken();
      if (token != null || Condition.loginFirebase == true) {
        Navigator.push(
          context,
          CustomNavigator(
            child: Notifikasi(),
          ),
        );
      } else {
        String teks = 'dapat mengakses notifikasi';
        return _showDialogNotLogin(teks);
      }
    }

    return Container(
      margin: EdgeInsets.only(left: getProportionateScreenWidth(7)),
      width: SizeConfig.screenWidth,
      height: getProportionateScreenHeight(40),
      child: Row(
        children: [
          IconButton(
            alignment: Alignment.centerLeft,
            icon: Icon(
              Icons.arrow_back,
              size: getProportionateScreenHeight(18),
              color: Theme.of(context).brightness == Brightness.dark
                  ? tenthColor
                  : ninthColor,
            ),
            onPressed: () {
              Navigator.pop(context);
            },
          ),
          Spacer(),
          // IconButton(
          //   padding: EdgeInsets.zero,
          //   onPressed: () => Navigator.of(context, rootNavigator: true).push(
          //     CustomNavigator(
          //       child: const Filter(isNotSearch: true),
          //     ),
          //   ),
          //   icon: Icon(Icons.tune_rounded, color: primaryColor),
          // ),
        ],
      ),
    );
  }
}
