import 'dart:convert';
import 'package:connectivity/connectivity.dart';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:crypto/crypto.dart';

class Constants {
  var title;
  var message;
  late AlertDialog alert;
  var color;

  Constants(String title, String message) {
    this.title = title;
    this.message = message;
  }

  Constants1(String color) {
    this.color = color;
  }

  static const TextStyle LoginfontStyle = TextStyle(
      fontFamily: 'Poppins',
      fontSize: 18,
      fontWeight: FontWeight.normal,
      color: Colors.grey);

  static const TextStyle HeaderStyle = TextStyle(
      fontFamily: 'Poppins',
      fontSize: 18,
      fontWeight: FontWeight.w400,
      color: Colors.black);

  static const TextStyle fontStyle = TextStyle(
      fontFamily: 'Poppins',
      fontSize: 18,
      fontWeight: FontWeight.normal,
      color: Colors.white);

  static const TextStyle speeachfontStyle = TextStyle(
      fontFamily: 'Poppins',
      fontSize: 16,
      fontWeight: FontWeight.normal,
      color: Colors.white);

  static const TextStyle LoginbuttonsfontStyle = TextStyle(
    fontFamily: 'Poppins',
    fontSize: 16,
    fontWeight: FontWeight.normal,
    color: Color.fromARGB(255, 12, 18, 22),
  );

  static const TextStyle headerfontStyle = TextStyle(
    fontFamily: 'Poppins',
    fontSize: 16,
    fontWeight: FontWeight.w600,
  );
  static const TextStyle listHeaderfontStyle = TextStyle(
    fontFamily: 'Poppins',
    fontSize: 16,
    fontWeight: FontWeight.w600,
    //6a4d9f
    //color: Color.fromARGB(255, 106, 77, 159),
  );
  static const TextStyle listHeaderoppfontStyle = TextStyle(
    fontFamily: 'Poppins',
    fontSize: 14,
    fontWeight: FontWeight.normal,
    //6a4d9f
    //color: Color.fromARGB(255, 106, 77, 159),
  );
  static const TextStyle listHeadercolorfontStyle = TextStyle(
      fontFamily: 'Poppins',
      fontSize: 16,
      fontWeight: FontWeight.w400,
      color: Colors.red);
  static const TextStyle listHeadercolor1fontStyle = TextStyle(
      fontFamily: 'Poppins',
      fontSize: 16,
      fontWeight: FontWeight.w400,
      color: Colors.green);

  static const TextStyle headerlistitems = TextStyle(
    fontFamily: 'Poppins',
    fontSize: 14,
    fontWeight: FontWeight.normal,
    height: 1.2, // Set the line height as a multiple of the font size
  );
  static const TextStyle headerlistitems1 = TextStyle(
    fontFamily: 'Poppins',
    fontSize: 14,
    fontWeight: FontWeight.bold,
  );
  static const TextStyle open = TextStyle(
      fontFamily: 'Poppins',
      fontSize: 14,
      fontWeight: FontWeight.bold,
      color: Colors.red);
  static const TextStyle close = TextStyle(
      fontFamily: 'Poppins',
      fontSize: 14,
      fontWeight: FontWeight.bold,
      color: Colors.green);
  static const TextStyle listitems = TextStyle(
      fontFamily: 'Poppins',
      fontSize: 12,
      fontWeight: FontWeight.normal,
      color: Colors.black);
  static const TextStyle listheaders = TextStyle(
      fontFamily: 'Poppins',
      fontSize: 14,
      fontWeight: FontWeight.normal,
      color: Color.fromARGB(255, 106, 36, 36));
  static const TextStyle buttonsfontStyle = TextStyle(
    fontFamily: 'Poppins',
    fontSize: 16,
    fontWeight: FontWeight.w600,
    color: Colors.white,
  );
  static const TextStyle whitefontStyle = TextStyle(
    fontFamily: 'Poppins',
    fontSize: 14,
    fontWeight: FontWeight.w400,
    color: Colors.white,
  );
  static const TextStyle footfallheaderfontStyle = TextStyle(
    fontFamily: 'Poppins',
    fontSize: 22,
    fontWeight: FontWeight.bold,
    color: Colors.white,
  );
  static const TextStyle footfallfontStyle = TextStyle(
    fontFamily: 'Poppins',
    fontSize: 12,
    fontWeight: FontWeight.normal,
    color: Colors.white,
  );
  static const TextStyle reviewbuttonsfontStyle = TextStyle(
    fontFamily: 'Poppins',
    fontSize: 14,
    fontWeight: FontWeight.normal,
    color: Colors.black,
  );
  static const TextStyle registerfontStyle = TextStyle(
    fontFamily: 'Poppins',
    fontSize: 14,
    fontWeight: FontWeight.normal,
    color: Colors.green,
  );
  static const TextStyle unregisterfontStyle = TextStyle(
    fontFamily: 'Poppins',
    fontSize: 16,
    fontWeight: FontWeight.normal,
    color: Colors.red,
  );

  static const TextStyle LoginuseridStyle = TextStyle(
    fontFamily: 'Poppins',
    fontSize: 16,
    fontWeight: FontWeight.normal,
    color: Color.fromARGB(255, 228, 240, 255),
  );

  static Future<void> showAlertDialog1(BuildContext context) async {
    AlertDialog alert = const AlertDialog(
      content: Row(
        children: [
          CircularProgressIndicator(),
        ],
      ),
    );

    showDialog(
      barrierDismissible: false,
      context: context,
      builder: (BuildContext context) {
        return alert;
      },
    );
  }

  static showLoader(BuildContext ctx) {
    showDialog(
        context: ctx,
        builder: (context) {
          return const Center(child: CircularProgressIndicator());
        });
  }

  static Future<void> dismissAlertDialog1(BuildContext context) async {
    Navigator.pop(context);
  }

  static Future<bool> checkInternetConnectivity() async {
    var connectivityResult = await (Connectivity().checkConnectivity());
    if (connectivityResult == ConnectivityResult.none) {
      return false;
    } else {
      return true;
    }
  }

  static LinearGradient getReturn() {
    const LinearGradient gradient = LinearGradient(
      colors: [
        //#6e87d6
        //#48c5ef
        //4da2dd
        //Color(0xFF4da2dd),
        Color(0xFFaa39e6),
        //Color(0xFFC2185B),
        Color(0xFF7b32fe),
      ],
      begin: Alignment.bottomLeft,
      end: Alignment.bottomRight,
    );
    return gradient;
  }

  static Future<void> saveLoginCredentials(
      String username,
      String empid,
      String storeslist,
      String storeName,
      String accessLevel,
      bool validate) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    prefs.setString('userId', username);
    prefs.setString('empId', empid);
    prefs.setString('stores_list', storeslist);
    prefs.setString('storeName', storeName);
    prefs.setString('access', accessLevel);
    prefs.setBool('islogged', validate);
  }

  Future<bool?> getLoggedIn() async {
    SharedPreferences preferences = await SharedPreferences.getInstance();
    bool? validate = preferences.getBool('islogged');
    return validate;
  }

  Future<String?> getStoreId() async {
    SharedPreferences preferences = await SharedPreferences.getInstance();
    return preferences.getString('store_Id');
  }

  static String hashPassword(String password) {
    var bytes = utf8.encode(password);
    var digest = sha256.convert(bytes);
    return digest.toString();
  }

  static String capitalizeFirstLetter(String text) {
    if (text.isEmpty) {
      return text;
    }
    return text[0].toUpperCase() + text.substring(1);
  }

  static dialogMessage(BuildContext context, String title, String message) {
    Widget okButton = TextButton(
        child: const Text("Cancel"),
        onPressed: () {
          Navigator.of(context).pop();
        });
    AlertDialog alert = AlertDialog(
      title: Text(title),
      content: Text(message),
      actions: [
        okButton,
      ],
    );
    showDialog(
      context: context,
      builder: (BuildContext context) {
        return alert;
      },
    );
  }

  static double getDropdownItemHeight(BuildContext context) {
    double deviceHeight = MediaQuery.of(context).size.height;
    double dropdownItemHeight = deviceHeight / 1.6;
    return dropdownItemHeight;
  }

  showAlertDialog(BuildContext context, bool val) {
    Widget okButton = TextButton(
        child: const Text("Ok"),
        onPressed: () {
          if (val) {
            Navigator.popUntil(context, (route) => route.isFirst);
          } else {
            Navigator.of(context).pop();
          }
        });
    AlertDialog alert = AlertDialog(
      title: Text(title),
      content: Text(message),
      actions: [
        okButton,
      ],
    );
    showDialog(
      context: context,
      builder: (BuildContext context) {
        return alert;
      },
    );
  }
}
