import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:design_system/design_system.dart';
import 'ui_colors.dart';

/// Static definitions of typography styles for the Staff Design System.
class UiTypography {
  UiTypography._();

  // ---------------------------------------------------------------------------
  // 0. Base Font Styles
  // ---------------------------------------------------------------------------

  /// The primary font family used throughout the design system.
  static final TextStyle _primaryBase = GoogleFonts.instrumentSans();

  /// The secondary font family used for display or specialized elements.
  static final TextStyle _secondaryBase = GoogleFonts.spaceGrotesk();

  // ---------------------------------------------------------------------------
  // 1. Primary Typography (Instrument Sans)
  // ---------------------------------------------------------------------------

  // --- 1.1 Display ---

  /// Display Large - Font: Instrument Sans, Size: 36, Height: 1.1 (#121826)
  static final TextStyle displayL = _primaryBase.copyWith(
    fontWeight: FontWeight.w400,
    fontSize: 36,
    height: 1.1,
    color: UiColors.textPrimary,
  );

  /// Display medium - Font: Instrument Sans, Size: 32, Height: 1.1 (#121826)
  static final TextStyle displayM = _primaryBase.copyWith(
    fontWeight: FontWeight.w500,
    fontSize: 32,
    height: 1.1,
    color: UiColors.textPrimary,
  );

  /// Display small - Font: Instrument Sans, Size: 32, Height: 1.1 (#121826)
  static final TextStyle displayMb = _primaryBase.copyWith(
    fontWeight: FontWeight.w600,
    fontSize: 32,
    height: 1.1,
    color: UiColors.textPrimary,
  );

  /// Display 1 Medium - Font: Instrument Sans, Size: 26, Height: 1.1 (#121826)
  static final TextStyle display1m = _primaryBase.copyWith(
    fontWeight: FontWeight.w500,
    fontSize: 26,
    height: 1.1,
    color: UiColors.textPrimary,
  );

  /// Display 1 Regular - Font: Instrument Sans, Size: 38, Height: 1.3 (#121826)
  static final TextStyle display1r = _primaryBase.copyWith(
    fontWeight: FontWeight.w400,
    fontSize: 26,
    height: 1.3,
    letterSpacing: -1,
    color: UiColors.textPrimary,
  );

  /// Display 1 Bold - Font: Instrument Sans, Size: 38, Height: 1.3 (#121826)
  static final TextStyle display1b = _primaryBase.copyWith(
    fontWeight: FontWeight.w600,
    fontSize: 26,
    height: 1.3,
    letterSpacing: -1,
    color: UiColors.textPrimary,
  );

  /// Display 2 Medium - Font: Instrument Sans, Size: 16, Height: 1.1 (#121826)
  static final TextStyle display2m = _primaryBase.copyWith(
    fontWeight: FontWeight.w500,
    fontSize: 16,
    height: 1.1,
    color: UiColors.textPrimary,
  );

  /// Display 2 Regular - Font: Instrument Sans, Size: 28, Height: 1.5 (#121826)
  static final TextStyle display2r = _primaryBase.copyWith(
    fontWeight: FontWeight.w400,
    fontSize: 16,
    height: 1.5,
    color: UiColors.textPrimary,
  );

  /// Display 3 Medium - Font: Instrument Sans, Size: 32, Height: 1.1 (#121826)
  static final TextStyle display3m = _primaryBase.copyWith(
    fontWeight: FontWeight.w500,
    fontSize: 14,
    height: 1.1,
    color: UiColors.textPrimary,
  );

  /// Display 3 Regular - Font: Instrument Sans, Size: 32, Height: 1.3 (#121826)
  static final TextStyle display3r = _primaryBase.copyWith(
    fontWeight: FontWeight.w400,
    fontSize: 14,
    height: 1.3,
    color: UiColors.textPrimary,
  );

  /// Display 3 Bold - Font: Instrument Sans, Size: 32, Height: 1.1 (#121826)
  static final TextStyle display3b = _primaryBase.copyWith(
    fontWeight: FontWeight.w600,
    fontSize: 14,
    height: 1.1,
    color: UiColors.textPrimary,
  );

  // --- 1.2 Title ---

  /// Title 1 Medium - Font: Instrument Sans, Size: 18, Height: 1.5 (#121826)
  static final TextStyle title1m = _primaryBase.copyWith(
    fontWeight: FontWeight.w500,
    fontSize: 18,
    height: 1.5,
    color: UiColors.textPrimary,
  );

  /// Title 1 Regular - Font: Instrument Sans, Size: 16, Height: 1.5 (#121826)
  static final TextStyle title1r = _primaryBase.copyWith(
    fontWeight: FontWeight.w400,
    fontSize: 18,
    height: 1.5,
    color: UiColors.textPrimary,
  );

  /// Title 2 Bold - Font: Instrument Sans, Size: 20, Height: 1.1 (#121826)
  static final TextStyle title2b = _primaryBase.copyWith(
    fontWeight: FontWeight.w600,
    fontSize: 16,
    height: 1.1,
    color: UiColors.textPrimary,
  );

  /// Title 2 Medium - Font: Instrument Sans, Size: 16, Height: 1.5 (#121826)
  static final TextStyle title2m = _primaryBase.copyWith(
    fontWeight: FontWeight.w500,
    fontSize: 16,
    height: 1.5,
    color: UiColors.textPrimary,
  );

  /// Title 2 Regular - Font: Instrument Sans, Size: 16, Height: 1.5 (#121826)
  static final TextStyle title2r = _primaryBase.copyWith(
    fontWeight: FontWeight.w400,
    fontSize: 16,
    height: 1.5,
    color: UiColors.textPrimary,
  );

  // --- 1.3 Headline ---

  /// Headline 1 Medium - Font: Instrument Sans, Size: 26, Height: 1.5 (#121826)
  static final TextStyle headline1m = _primaryBase.copyWith(
    fontWeight: FontWeight.w500,
    fontSize: 26,
    height: 1.5,
    color: UiColors.textPrimary,
  );

  /// Headline 1 Regular - Font: Instrument Sans, Size: 26, Height: 1.5 (#121826)
  static final TextStyle headline1r = _primaryBase.copyWith(
    fontWeight: FontWeight.w400,
    fontSize: 26,
    height: 1.5,
    color: UiColors.textPrimary,
  );

  /// Headline 2 Medium - Font: Instrument Sans, Size: 20, Height: 1.5 (#121826)
  static final TextStyle headline2m = _primaryBase.copyWith(
    fontWeight: FontWeight.w500,
    fontSize: 22,
    height: 1.5,
    color: UiColors.textPrimary,
  );

  /// Headline 2 Regular - Font: Instrument Sans, Size: 20, Height: 1.5 (#121826)
  static final TextStyle headline2r = _primaryBase.copyWith(
    fontWeight: FontWeight.w400,
    fontSize: 22,
    height: 1.5,
    color: UiColors.textPrimary,
  );

  /// Headline 3 Medium - Font: Instrument Sans, Size: 22, Height: 1.5 (#121826)
  static final TextStyle headline3m = _primaryBase.copyWith(
    fontWeight: FontWeight.w500,
    fontSize: 20,
    height: 1.5,
    color: UiColors.textPrimary,
  );

  /// Headline 4 Medium - Font: Instrument Sans, Size: 22, Height: 1.5 (#121826)
  static final TextStyle headline4m = _primaryBase.copyWith(
    fontWeight: FontWeight.w500,
    fontSize: 18,
    height: 1.5,
    color: UiColors.textPrimary,
  );

  /// Headline 4 Regular - Font: Instrument Sans, Size: 20, Height: 1.5 (#121826)
  static final TextStyle headline4r = _primaryBase.copyWith(
    fontWeight: FontWeight.w400,
    fontSize: 18,
    height: 1.5,
    color: UiColors.textPrimary,
  );

  /// Headline 5 Regular - Font: Instrument Sans, Size: 18, Height: 1.5 (#121826)
  static final TextStyle headline5r = _primaryBase.copyWith(
    fontWeight: FontWeight.w400,
    fontSize: 14,
    height: 1.5,
    color: UiColors.textPrimary,
  );

  /// Headline 5 Medium - Font: Instrument Sans, Size: 16, Height: 1.5 (#121826)
  static final TextStyle headline5m = _primaryBase.copyWith(
    fontWeight: FontWeight.w500,
    fontSize: 16,
    height: 1.5,
    color: UiColors.textPrimary,
  );

  // --- 1.4 Title Uppercase ---

  /// Title Uppercase 2 Medium - Font: Instrument Sans, Size: 14, Height: 1.5, Spacing: 0.7 (#121826)
  static final TextStyle titleUppercase2m = _primaryBase.copyWith(
    fontWeight: FontWeight.w500,
    fontSize: 14,
    height: 1.5,
    letterSpacing: 0.4,
    color: UiColors.textPrimary,
  );

  /// Title Uppercase 3 Medium - Font: Instrument Sans, Size: 12, Height: 1.5, Spacing: 1.5 (#121826)
  static final TextStyle titleUppercase3m = _primaryBase.copyWith(
    fontWeight: FontWeight.w500,
    fontSize: 12,
    height: 1.5,
    letterSpacing: 0.7,
    color: UiColors.textPrimary,
  );

  /// Title Uppercase 4 Medium - Font: Instrument Sans, Size: 11, Height: 1.5, Spacing: 2.2 (#121826)
  static final TextStyle titleUppercase4m = _primaryBase.copyWith(
    fontWeight: FontWeight.w500,
    fontSize: 11,
    height: 1.5,
    letterSpacing: 0.7,
    color: UiColors.textPrimary,
  );

  /// Title Uppercase 4 Bold - Font: Instrument Sans, Size: 11, Height: 1.5, Spacing: 2.2 (#121826)
  static final TextStyle titleUppercase4b = _primaryBase.copyWith(
    fontWeight: FontWeight.w700,
    fontSize: 11,
    height: 1.5,
    letterSpacing: 0.7,
    color: UiColors.textPrimary,
  );

  // --- 1.5 Body ---

  /// Body 1 Bold - Font: Instrument Sans, Size: 16, Height: 1.5 (#121826)
  static final TextStyle body1b = _primaryBase.copyWith(
    fontWeight: FontWeight.w700,
    fontSize: 16,
    height: 1.5,
    color: UiColors.textPrimary,
  );

  /// Body 1 Medium - Font: Instrument Sans, Size: 16, Height: 1.5 (#121826)
  static final TextStyle body1m = _primaryBase.copyWith(
    fontWeight: FontWeight.w500,
    fontSize: 16,
    height: 1.5,
    letterSpacing: -0.025,
    color: UiColors.textPrimary,
  );

  /// Body 1 Regular - Font: Instrument Sans, Size: 16, Height: 1.5 (#121826)
  static final TextStyle body1r = _primaryBase.copyWith(
    fontWeight: FontWeight.w400,
    fontSize: 16,
    height: 1.5,
    letterSpacing: -0.05,
    color: UiColors.textPrimary,
  );

  /// Body 2 Bold - Font: Instrument Sans, Size: 14, Height: 1.5 (#121826)
  static final TextStyle body2b = _primaryBase.copyWith(
    fontWeight: FontWeight.w700,
    fontSize: 14,
    height: 1.5,
    color: UiColors.textPrimary,
  );

  /// Body 2 Medium - Font: Instrument Sans, Size: 14, Height: 1.5 (#121826)
  static final TextStyle body2m = _primaryBase.copyWith(
    fontWeight: FontWeight.w500,
    fontSize: 14,
    height: 1.5,
    color: UiColors.textPrimary,
  );

  /// Body 2 Regular - Font: Instrument Sans, Size: 14, Height: 1.5, Spacing: 0.1 (#121826)
  static final TextStyle body2r = _primaryBase.copyWith(
    fontWeight: FontWeight.w400,
    fontSize: 14,
    height: 1.5,
    letterSpacing: 0.1,
    color: UiColors.textPrimary,
  );

  /// Body 3 Regular - Font: Instrument Sans, Size: 14, Height: 1.5, Spacing: -0.1 (#121826)
  static final TextStyle body3r = _primaryBase.copyWith(
    fontWeight: FontWeight.w400,
    fontSize: 12,
    height: 1.5,
    letterSpacing: -0.1,
    color: UiColors.textPrimary,
  );

  /// Body 3 Medium - Font: Instrument Sans, Size: 14, Height: 1.5, Spacing: -0.1 (#121826)
  static final TextStyle body3m = _primaryBase.copyWith(
    fontWeight: FontWeight.w500,
    fontSize: 12,
    height: 1.5,
    letterSpacing: -0.1,
    color: UiColors.textPrimary,
  );

  /// Body 4 Regular - Font: Instrument Sans, Size: 14, Height: 1.5, Spacing: 0.05 (#121826)
  static final TextStyle body4r = _primaryBase.copyWith(
    fontWeight: FontWeight.w400,
    fontSize: 12,
    height: 1.5,
    letterSpacing: 0.05,
    color: UiColors.textPrimary,
  );

  /// Body 4 Medium - Font: Instrument Sans, Size: 14, Height: 1.5, Spacing: 0.05 (#121826)
  static final TextStyle body4m = _primaryBase.copyWith(
    fontWeight: FontWeight.w500,
    fontSize: 12,
    height: 1.5,
    letterSpacing: 0.05,
    color: UiColors.textPrimary,
  );

  // --- 1.6 Footnote ---

  /// Footnote 1 Medium - Font: Instrument Sans, Size: 12, Height: 1.5 (#121826)
  static final TextStyle footnote1m = _primaryBase.copyWith(
    fontWeight: FontWeight.w500,
    fontSize: 12,
    height: 1.5,
    color: UiColors.textPrimary,
  );

  /// Footnote 1 Regular - Font: Instrument Sans, Size: 12, Height: 1.5, Spacing: 0.05 (#121826)
  static final TextStyle footnote1r = _primaryBase.copyWith(
    fontWeight: FontWeight.w400,
    fontSize: 12,
    height: 1.5,
    letterSpacing: 0.05,
    color: UiColors.textPrimary,
  );

  /// Footnote 1 Bold - Font: Instrument Sans, Size: 12, Height: 1.5, Spacing: 0.05 (#121826)
  static final TextStyle footnote1b = _primaryBase.copyWith(
    fontWeight: FontWeight.w700,
    fontSize: 12,
    height: 1.5,
    letterSpacing: 0.05,
    color: UiColors.textPrimary,
  );

  /// Footnote 2 Medium - Font: Instrument Sans, Size: 10, Height: 1.5 (#121826)
  static final TextStyle footnote2m = _primaryBase.copyWith(
    fontWeight: FontWeight.w500,
    fontSize: 10,
    height: 1.5,
    color: UiColors.textPrimary,
  );

  /// Footnote 2 Bold - Font: Instrument Sans, Size: 10, Height: 1.5 (#121826)
  static final TextStyle footnote2b = _primaryBase.copyWith(
    fontWeight: FontWeight.w700,
    fontSize: 10,
    height: 1.5,
    color: UiColors.textPrimary,
  );

  /// Footnote 2 Regular - Font: Instrument Sans, Size: 10, Height: 1.5 (#121826)
  static final TextStyle footnote2r = _primaryBase.copyWith(
    fontWeight: FontWeight.w400,
    fontSize: 10,
    height: 1.5,
    color: UiColors.textPrimary,
  );

  // --- 1.7 Button ---

  /// Button S - Font: Instrument Sans, Size: 10, Height: 1.5 (#121826)
  static final TextStyle buttonS = _primaryBase.copyWith(
    fontWeight: FontWeight.w500,
    fontSize: 10,
    height: 1.5,
    color: UiColors.textPrimary,
  );

  /// Button Medium - Font: Instrument Sans, Size: 12, Height: 1.5 (#121826)
  static final TextStyle buttonM = _primaryBase.copyWith(
    fontWeight: FontWeight.w500,
    fontSize: 12,
    height: 1.5,
    color: UiColors.textPrimary,
  );

  /// Button Large - Font: Instrument Sans, Size: 14, Height: 1.5 (#121826)
  static final TextStyle buttonL = _primaryBase.copyWith(
    fontWeight: FontWeight.w500,
    fontSize: 14,
    height: 1.5,
    color: UiColors.textPrimary,
  );

  /// Button XL - Font: Instrument Sans, Size: 16, Height: 1.5 (#121826)
  static final TextStyle buttonXL = _primaryBase.copyWith(
    fontWeight: FontWeight.w500,
    fontSize: 16,
    height: 1.5,
    color: UiColors.textPrimary,
  );

  // --- 1.8 Link ---

  /// Link 1 Regular - Font: Instrument Sans, Size: 16, Height: 1.5, Underlined (#0A39DF)
  static final TextStyle link1r = _primaryBase.copyWith(
    fontWeight: FontWeight.w400,
    fontSize: 16,
    height: 1.5,
    color: UiColors.textLink,
    decoration: TextDecoration.underline,
    decorationColor: UiColors.textLink,
  );

  /// Link 2 Medium - Font: Instrument Sans, Size: 14, Height: 1.5, Underlined (#0A39DF)
  static final TextStyle link2m = _primaryBase.copyWith(
    fontWeight: FontWeight.w500,
    fontSize: 14,
    height: 1.5,
    color: UiColors.textLink,
    decoration: TextDecoration.underline,
    decorationColor: UiColors.textLink,
  );

  /// Link 2 Regular - Font: Instrument Sans, Size: 14, Height: 1.5, Underlined (#0A39DF)
  static final TextStyle link2r = _primaryBase.copyWith(
    fontWeight: FontWeight.w400,
    fontSize: 14,
    height: 1.5,
    color: UiColors.textLink,
    decoration: TextDecoration.underline,
    decorationColor: UiColors.textLink,
  );

  // ---------------------------------------------------------------------------
  // 2. Secondary Typography (Space Grotesk)
  // ---------------------------------------------------------------------------

  // --- 2.1 Display ---

  /// Display 1 Bold (Secondary) - Font: Space Grotesk, Size: 50, Height: 1.1 (#121826)
  static final TextStyle secondaryDisplay1b = _secondaryBase.copyWith(
    fontWeight: FontWeight.w400,
    fontSize: 50,
    height: 1.1,
    color: UiColors.textPrimary,
  );

  /// Display 1 Regular (Secondary) - Font: Space Grotesk, Size: 50, Height: 1.1 (#121826)
  static final TextStyle secondaryDisplay1r = _secondaryBase.copyWith(
    fontWeight: FontWeight.w400,
    fontSize: 50,
    height: 1.1,
    color: UiColors.textPrimary,
  );

  /// Display 2 Bold (Secondary) - Font: Space Grotesk, Size: 40, Height: 1.1 (#121826)
  static final TextStyle secondaryDisplay2b = _secondaryBase.copyWith(
    fontWeight: FontWeight.w700,
    fontSize: 40,
    height: 1.1,
    color: UiColors.textPrimary,
  );

  /// Display 2 Regular (Secondary) - Font: Space Grotesk, Size: 40, Height: 1.1 (#121826)
  static final TextStyle secondaryDisplay2r = _secondaryBase.copyWith(
    fontWeight: FontWeight.w400,
    fontSize: 40,
    height: 1.1,
    color: UiColors.textPrimary,
  );

  // ---------------------------------------------------------------------------
  // 3. TextTheme Mapping
  // ---------------------------------------------------------------------------

  /// Primary TextTheme
  static TextTheme get textTheme => TextTheme(
    displayLarge: display1r,
    displayMedium: displayL,
    displaySmall: display3m,
    headlineLarge: headline1m,
    headlineMedium: headline3m,
    headlineSmall: headline2m,
    titleLarge: title1m,
    titleMedium: title2m,
    titleSmall: body2m,
    bodyLarge: body1r,
    bodyMedium: body2r,
    bodySmall: footnote1r,
    labelLarge: buttonL,
    labelMedium: buttonM,
    labelSmall: footnote2r,
  );
}

/// Extension to easily color text styles using the Staff Design System color palette.
extension TypographyColors on TextStyle {
  /// Primary text color (#121826)
  TextStyle get textPrimary => copyWith(color: UiColors.textPrimary);

  /// Secondary text color (#6A7382)
  TextStyle get textSecondary => copyWith(color: UiColors.textSecondary);

  /// Inactive text color (#9CA3AF)
  TextStyle get textInactive => copyWith(color: UiColors.textInactive);

  /// Tertiary text color (#9CA3AF)
  TextStyle get textTertiary => copyWith(color: UiColors.textInactive);

  /// Placeholder text color (#9CA3AF)
  TextStyle get textPlaceholder => copyWith(color: UiColors.textPlaceholder);

  /// Description text color (#6A7382)
  TextStyle get textDescription => copyWith(color: UiColors.textDescription);

  /// Success text color (#10B981)
  TextStyle get textSuccess => copyWith(color: UiColors.textSuccess);

  /// Error text color (#F04444)
  TextStyle get textError => copyWith(color: UiColors.textError);

  /// Warning text color (#D97706)
  TextStyle get textWarning => copyWith(color: UiColors.textWarning);

  /// Link text color (#0A39DF)
  TextStyle get textLink => copyWith(color: UiColors.textLink);

  /// White text color (#FFFFFF)
  TextStyle get white => copyWith(color: UiColors.white);

  /// Black text color (#000000)
  TextStyle get black => copyWith(color: UiColors.black);

  /// Underline decoration
  TextStyle get underline => copyWith(decoration: TextDecoration.underline);

  /// Active content color
  TextStyle get activeContentColor => copyWith(color: UiColors.textPrimary);
}
