// ignore_for_file: file_names, sized_box_for_whitespace

import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:tanami_app/core/routes/routes.dart';
import 'package:tanami_app/core/styles/app_color.dart';
import 'package:tanami_app/shared/components/toast_message.dart';

import '../../core/styles/app_images.dart';

class NoInternet extends StatelessWidget {
  const NoInternet({super.key});

  @override
  Widget build(BuildContext context) {
    return WillPopScope(
      onWillPop: () => Future.value(false),
      child: Scaffold(
          backgroundColor: AppColor.plainWhite,
          body: Column(children: [
            Center(
              child: Container(
                margin: const EdgeInsets.only(top: 100),
                height: 180.h,
                width: 1.sw,
                child: Image.asset(AppImages.noInternetImage),
              ),
            ),
            Center(
              child: Padding(
                padding: const EdgeInsets.only(top: 100),
                child: Center(
                  child: Column(
                    children: <Widget>[
                      const SizedBox(
                        height: 15.0,
                      ),
                      Container(
                        margin: const EdgeInsets.symmetric(horizontal: 20),
                        child: Text(
                            "Internet Connection is Down!\n\nEnsure your internet's up and running.",
                            textAlign: TextAlign.center,
                            style: GoogleFonts.dmSans(
                              fontSize: 18.0,
                              fontWeight: FontWeight.w500,
                            )),
                      ),
                      const SizedBox(
                        height: 30.0,
                      ),
                      GestureDetector(
                        onTap: () async {
                          final connectivityResult =
                              await (Connectivity().checkConnectivity());
                          if (connectivityResult[0] ==
                                  ConnectivityResult.wifi ||
                              connectivityResult[0] ==
                                  ConnectivityResult.mobile) {
                            goRouter.pop();
                          } else {
                            errorToastMessage(
                                context, "Internet is still down");
                          }
                        },
                        child: Container(
                          height: 54.h,
                          width: 330.w,
                          decoration: BoxDecoration(
                              borderRadius: BorderRadius.circular(10.h),
                              color: AppColor.primaryColor2),
                          child: Center(
                            child: Text(
                              "Try Again",
                              style: GoogleFonts.dmSans(
                                  color: AppColor.plainWhite, fontSize: 20.sp),
                            ),
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
              ),
            ),
          ])),
    );
  }
}
