import 'package:flutter/material.dart';

/// 字体体系 -- 与 Figma 设计稿对应
///
/// L1 基础常量 — 不含颜色，只定义字号/字重/行高/字距。
/// View 层通过 [AppStyles]（`context.styles`）消费，颜色由主题决定。
/// 特殊场景（固定样式、不跟主题）可直接引用 AppFont。
///
/// ## 数据流位置
///
/// ```
/// AppFont（字体常量）← 你在这里
///   → AppTheme（组装为 TextTheme → ThemeData）
///     → MaterialApp（注入）
///       → context.styles（View 层消费）
/// ```
///
/// ## 使用
///
/// ```dart
/// // 推荐：通过 context.styles 消费（自动响应亮暗主题）
/// final s = context.styles;
/// Text('标题', style: s.headlineMedium);
/// Text('分组', style: s.sectionLabel);   // 预组合：字体 + 主题色
///
/// // 特殊场景：固定样式，不跟主题切换
/// Text('固定', style: AppFont.bodyMedium);
/// ```
class AppFont {
  AppFont._();

  // ── 字体族 ──────────────────────────────────────────────────────────────

  /// 默认字体族（系统字体）
  ///
  /// 接入自定义字体时只需修改此常量 + pubspec.yaml fonts 配置。
  static const String? _fontFamily = null; // null = 系统默认字体

  // ── Display -- 超大展示（启动页、空状态大标题）──────────────────────────

  static const displayLarge = TextStyle(
    fontFamily: _fontFamily,
    fontSize: 57,
    fontWeight: FontWeight.w400,
    letterSpacing: -0.25,
    height: 64 / 57,
  );

  static const displayMedium = TextStyle(
    fontFamily: _fontFamily,
    fontSize: 45,
    fontWeight: FontWeight.w400,
    height: 52 / 45,
  );

  static const displaySmall = TextStyle(
    fontFamily: _fontFamily,
    fontSize: 36,
    fontWeight: FontWeight.w400,
    height: 44 / 36,
  );

  // ── Headline -- 页面标题（导航栏、Section 标题）────────────────────────

  static const headlineLarge = TextStyle(
    fontFamily: _fontFamily,
    fontSize: 32,
    fontWeight: FontWeight.w400,
    height: 40 / 32,
  );

  static const headlineMedium = TextStyle(
    fontFamily: _fontFamily,
    fontSize: 28,
    fontWeight: FontWeight.w400,
    height: 36 / 28,
  );

  static const headlineSmall = TextStyle(
    fontFamily: _fontFamily,
    fontSize: 24,
    fontWeight: FontWeight.w400,
    height: 32 / 24,
  );

  // ── Title -- 卡片 / 列表标题（聊天列表名称、设置项标题）──────────────

  static const titleLarge = TextStyle(
    fontFamily: _fontFamily,
    fontSize: 22,
    fontWeight: FontWeight.w500,
    height: 28 / 22,
  );

  static const titleMedium = TextStyle(
    fontFamily: _fontFamily,
    fontSize: 16,
    fontWeight: FontWeight.w500,
    letterSpacing: 0.15,
    height: 24 / 16,
  );

  static const titleSmall = TextStyle(
    fontFamily: _fontFamily,
    fontSize: 14,
    fontWeight: FontWeight.w500,
    letterSpacing: 0.1,
    height: 20 / 14,
  );

  // ── Body -- 正文内容（聊天气泡、表单输入、描述文字）──────────────────

  static const bodyLarge = TextStyle(
    fontFamily: _fontFamily,
    fontSize: 16,
    fontWeight: FontWeight.w400,
    letterSpacing: 0.5,
    height: 24 / 16,
  );

  static const bodyMedium = TextStyle(
    fontFamily: _fontFamily,
    fontSize: 14,
    fontWeight: FontWeight.w400,
    letterSpacing: 0.25,
    height: 20 / 14,
  );

  static const bodySmall = TextStyle(
    fontFamily: _fontFamily,
    fontSize: 12,
    fontWeight: FontWeight.w400,
    letterSpacing: 0.4,
    height: 16 / 12,
  );

  // ── Label -- 按钮 / 标签 / 辅助文字（按钮文字、Tab、Badge）──────────

  static const labelLarge = TextStyle(
    fontFamily: _fontFamily,
    fontSize: 14,
    fontWeight: FontWeight.w500,
    letterSpacing: 0.1,
    height: 20 / 14,
  );

  static const labelMedium = TextStyle(
    fontFamily: _fontFamily,
    fontSize: 12,
    fontWeight: FontWeight.w500,
    letterSpacing: 0.5,
    height: 16 / 12,
  );

  static const labelSmall = TextStyle(
    fontFamily: _fontFamily,
    fontSize: 11,
    fontWeight: FontWeight.w500,
    letterSpacing: 0.5,
    height: 16 / 11,
  );

  // ── 语义字体（超出 M3 标准级别的产品专属规格）────────────────────────────
  //
  // 这里只定义字号/字重/字距，不含颜色。
  // 颜色由 AppStyles 的预组合样式注入（如 AppStyles.sectionLabel）。

  /// 分组标题：列表 Section、设置分组等（13 / w600 / 0.5 字距）
  static const sectionLabel = TextStyle(
    fontFamily: _fontFamily,
    fontSize: 13,
    fontWeight: FontWeight.w600,
    letterSpacing: 0.5,
  );

  // ── 组装 TextTheme（供 AppTheme 调用）──────────────────────────────────

  /// 根据亮暗模式组装 TextTheme
  ///
  /// 默认亮暗共用同一套字体规格。需要按模式区分时，
  /// 用 copyWith 覆盖个别样式即可，不影响其他级别。
  ///
  /// 示例 -- 暗色模式下 labelLarge 改为 regular：
  /// ```dart
  /// labelLarge: isDark
  ///     ? labelLarge.copyWith(fontWeight: FontWeight.w400)
  ///     : labelLarge,
  /// ```
  ///
  /// AppTheme._build() 中调用：
  /// ```dart
  /// textTheme: AppFont.textTheme(brightness),
  /// ```
  static TextTheme textTheme(Brightness brightness) {
    // final isDark = brightness == Brightness.dark;

    return TextTheme(
      displayLarge: displayLarge,
      displayMedium: displayMedium,
      displaySmall: displaySmall,
      headlineLarge: headlineLarge,
      headlineMedium: headlineMedium,
      headlineSmall: headlineSmall,
      titleLarge: titleLarge,
      titleMedium: titleMedium,
      titleSmall: titleSmall,
      bodyLarge: bodyLarge,
      bodyMedium: bodyMedium,
      bodySmall: bodySmall,
      labelLarge: labelLarge,
      labelMedium: labelMedium,
      labelSmall: labelSmall,
    );
  }
}
