import 'package:car_provider_app/theme/colors.dart';
import 'package:flutter/cupertino.dart';
import 'package:intl/intl.dart';

extension EmailValidator on String {
  Widget get toWidget => Text(this);

  Widget toText10({Color? color, bool isBold = false}) => Text(
        this,
        style: TextStyle(fontSize: 10, fontWeight: isBold ? FontWeight.bold : FontWeight.w600, color: color ?? headingColor, letterSpacing: -0.4),
      );

  Widget toText11({Color? color, bool isUnderLine = false, bool isBold = false}) => Text(
        this,
        style: TextStyle(
            fontSize: 11,
            fontWeight: isBold ? FontWeight.bold : FontWeight.w600,
            color: color ?? headingColor,
            letterSpacing: -0.33,
            decoration: isUnderLine ? TextDecoration.underline : null),
      );

  Widget toText12({Color? color, bool isUnderLine = false, bool isBold = false, bool isCenter = false, int maxLine = 0}) => Text(
        this,
        textAlign: isCenter ? TextAlign.center : null,
        maxLines: (maxLine > 0) ? maxLine : null,
        style: TextStyle(
            fontSize: 12,
            fontWeight: isBold ? FontWeight.bold : FontWeight.w600,
            color: color ?? headingColor,
            letterSpacing: -0.72,
            decoration: isUnderLine ? TextDecoration.underline : null),
      );

  Widget toText13({Color? color, bool isUnderLine = false}) => Text(
        this,
        style: TextStyle(fontSize: 13, fontWeight: FontWeight.w600, color: color ?? headingColor, letterSpacing: -0.52, decoration: isUnderLine ? TextDecoration.underline : null),
      );

  Widget toText14({Color? color, bool isBold = false}) => Text(
        this,
        style: TextStyle(color: color ?? headingColor, fontSize: 14, letterSpacing: -0.48, fontWeight: isBold ? FontWeight.bold : FontWeight.w600),
      );

  Widget toText16({Color? color, bool isBold = false}) => Text(
        this,
        style: TextStyle(color: color ?? headingColor, fontSize: 16, letterSpacing: -0.64, fontWeight: isBold ? FontWeight.bold : FontWeight.w600),
      );

  Widget toText17({Color? color, bool isBold = false}) => Text(
        this,
        style: TextStyle(color: color ?? headingColor, fontSize: 17, letterSpacing: -0.68, fontWeight: isBold ? FontWeight.bold : FontWeight.w600),
      );

  Widget toText22({Color? color, bool isBold = false}) => Text(
        this,
        style: TextStyle(height: 1, color: color ?? headingColor, fontSize: 22, letterSpacing: -1.44, fontWeight: isBold ? FontWeight.bold : FontWeight.w600),
      );

  Widget toText24({Color? color, bool isBold = false}) => Text(
        this,
        style: TextStyle(height: 23 / 24, color: color ?? headingColor, fontSize: 24, letterSpacing: -1.44, fontWeight: isBold ? FontWeight.bold : FontWeight.w600),
      );

  Widget toText32({Color? color, bool isBold = false}) => Text(
        this,
        style: TextStyle(height: 32 / 32, color: color ?? headingColor, fontSize: 32, letterSpacing: -1.92, fontWeight: isBold ? FontWeight.bold : FontWeight.w600),
      );

  bool isValidEmail() {
    return RegExp(r'^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$').hasMatch(this);
  }

  String toFormattedDate() {
    String date = this.split("T")[0];
    String time = this.split("T")[1];
    var dates = date.split("-");
    return "${dates[2]} ${getMonth(int.parse(dates[1]))} ${dates[0]} ${DateFormat('hh:mm a').format(DateFormat('hh:mm:ss').parse(time))}";
  }

  getMonth(int month) {
    switch (month) {
      case 1:
        return "January";
      case 2:
        return "February";
      case 3:
        return "March";
      case 4:
        return "April";
      case 5:
        return "May";
      case 6:
        return "June";
      case 7:
        return "July";
      case 8:
        return "August";
      case 9:
        return "September";
      case 10:
        return "October";
      case 11:
        return "November";
      case 12:
        return "December";
    }
  }
}
