import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:provider/provider.dart';
import 'package:hmg_patient_app/core/viewModels/project_view_model.dart';

/// Font utility class to manage consistent font selection across the app
class FontUtils {
  /// Get the appropriate font family based on the current language
  static bool getFontFamily(BuildContext context) {
    final projectViewModel = Provider.of<ProjectViewModel>(context, listen: false);
    return projectViewModel.isArabic ? true : false;
  }

  /// Get the appropriate font family for a specific language
  static String getFontFamilyForLanguage(bool isArabic) {
    return isArabic ? 'Cairo' : 'Poppins';
  }
}

extension DynamicTextStyleExtension on BuildContext {
  TextStyle dynamicTextStyle(
      {double? fontSize,
      FontWeight? fontWeight,
      Color? color,
      double? letterSpacing,
      double? wordSpacing,
      double? height,
      List<Shadow>? shadows,
      Color? backgroundColor,
      TextDecoration? decoration,
      Color? decorationColor,
      TextDecorationStyle? decorationStyle,
      double? decorationThickness,
      Locale? locale,
      TextBaseline? textBaseline,
      FontStyle? fontStyle,
      bool isLanguageSwitcher = false}) {
    final family = FontUtils.getFontFamily(this);

    return isLanguageSwitcher
        ? (family
            ? GoogleFonts.poppins(
                fontSize: fontSize,
                fontWeight: fontWeight,
                color: color,
                letterSpacing: letterSpacing,
                wordSpacing: wordSpacing,
                height: height,
                shadows: shadows,
                backgroundColor: backgroundColor,
                decoration: decoration,
                decorationColor: decorationColor,
                decorationStyle: decorationStyle,
                decorationThickness: decorationThickness,
                locale: locale ?? Localizations.localeOf(this),
                textBaseline: textBaseline,
                fontStyle: fontStyle,
              )
            : GoogleFonts.cairo(
                fontSize: fontSize,
                fontWeight: fontWeight,
                color: color,
                letterSpacing: letterSpacing,
                wordSpacing: wordSpacing,
                height: height,
                shadows: shadows,
                backgroundColor: backgroundColor,
                decoration: decoration,
                decorationColor: decorationColor,
                decorationStyle: decorationStyle,
                decorationThickness: decorationThickness,
                locale: locale ?? Localizations.localeOf(this),
                textBaseline: textBaseline,
                fontStyle: fontStyle,
              ))
        : (family
            ? GoogleFonts.cairo(
                fontSize: fontSize,
                fontWeight: fontWeight,
                color: color,
                letterSpacing: letterSpacing,
                wordSpacing: wordSpacing,
                height: height,
                shadows: shadows,
                backgroundColor: backgroundColor,
                decoration: decoration,
                decorationColor: decorationColor,
                decorationStyle: decorationStyle,
                decorationThickness: decorationThickness,
                locale: locale ?? Localizations.localeOf(this),
                textBaseline: textBaseline,
                fontStyle: fontStyle,
              )
            : GoogleFonts.poppins(
                fontSize: fontSize,
                fontWeight: fontWeight,
                color: color,
                letterSpacing: letterSpacing,
                wordSpacing: wordSpacing,
                height: height,
                shadows: shadows,
                backgroundColor: backgroundColor,
                decoration: decoration,
                decorationColor: decorationColor,
                decorationStyle: decorationStyle,
                decorationThickness: decorationThickness,
                locale: locale ?? Localizations.localeOf(this),
                textBaseline: textBaseline,
                fontStyle: fontStyle,
              ));

    // return family
    //     ? GoogleFonts.cairo(
    //   fontSize: fontSize,
    //   fontWeight: fontWeight,
    //   color: color,
    //   letterSpacing: letterSpacing,
    //   wordSpacing: wordSpacing,
    //   height: height,
    //   shadows: shadows,
    //   backgroundColor: backgroundColor,
    //   decoration: decoration,
    //   decorationColor: decorationColor,
    //   decorationStyle: decorationStyle,
    //   decorationThickness: decorationThickness,
    //   locale: locale ?? Localizations.localeOf(this),
    //   textBaseline: textBaseline,
    //   fontStyle: fontStyle,
    // )
    //     : GoogleFonts.poppins(
    //   fontSize: fontSize,
    //   fontWeight: fontWeight,
    //   color: color,
    //   letterSpacing: letterSpacing,
    //   wordSpacing: wordSpacing,
    //   height: height,
    //   shadows: shadows,
    //   backgroundColor: backgroundColor,
    //   decoration: decoration,
    //   decorationColor: decorationColor,
    //   decorationStyle: decorationStyle,
    //   decorationThickness: decorationThickness,
    //   locale: locale ?? Localizations.localeOf(this),
    //   textBaseline: textBaseline,
    //   fontStyle: fontStyle,
    // );
  }
}
