import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class KrAppTextStyle extends TextStyle {
  KrAppTextStyle({
    required double fontSize,
    FontWeight fontWeight = FontWeight.w400,
    Color? color,
  }) : super(
          fontSize: fontSize.sp,
          fontFamily: _getFontFamily(fontWeight),
          fontWeight: fontWeight,
          color: color,
          height: 1.4,
        );

  // 提供标题文本样式
  static KrAppTextStyle titleTextStyle({
    required double fontSize,
    Color? color,
  }) {
    return _commonTextStyle(
      fontSize: fontSize,
      fontWeight: FontWeight.w500,
      color: color,
    );
  }

  // 私有方法创建正文文本样式
  static KrAppTextStyle _bodyTextStyle({
    required double fontSize,
    Color? color,
  }) {
    return _commonTextStyle(
      fontSize: fontSize,
      fontWeight: FontWeight.w400,
      color: color,
    );
  }

  // 私有方法创建常规文本样式
  static KrAppTextStyle _commonTextStyle({
    required double fontSize,
    FontWeight fontWeight = FontWeight.w400,
    Color? color,
  }) {
    return KrAppTextStyle(
      fontSize: fontSize,
      fontWeight: fontWeight,
      color: color,
    );
  }

  // 根据字体粗细获取字体家族
  static String _getFontFamily(FontWeight fontWeight) {
    return fontWeight == FontWeight.w500
        ? 'AlibabaPuHuiTi-Medium'
        : 'AlibabaPuHuiTi-Regular';
  }
}