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

/// ThemeExtension — 通过 Theme.of(context) 动态读取当前主题色值
///
/// 使用方式：
/// ```dart
/// final colors = Theme.of(context).extension<AppColorsExtension>()!;
/// Text('xxx', style: TextStyle(color: colors.textPrimary));
/// ```
///
/// 切换深色/浅色主题时自动感知，无需手动判断。
class AppColorsExtension extends ThemeExtension<AppColorsExtension> {
  final Color primary;
  final Color primaryActive;
  final Color primaryLight;
  final Color success;
  final Color successBg;
  final Color warning;
  final Color warningBg;
  final Color danger;
  final Color dangerBg;
  final Color amountPositive;
  final Color amountNegative;
  final Color amountNeutral;
  final Color amountPrimary;
  final Color infoText;
  final Color infoBg;
  final Color infoLightBg;
  final Color infoBorder;
  final Color timelineInactive;
  final Color paidText;
  final Color paidBg;
  final Color unpaidText;
  final Color unpaidBg;
  final Color bgExpired;
  final Color swipeDeleteBg;
  final Color textPrimary;
  final Color textSecondary;
  final Color textPlaceholder;
  final Color textDisabled;
  final Color statusGray;
  final Color bgPage;
  final Color bgCard;
  final Color bgDisabled;
  final Color bgSecondaryContainer;
  final Color border;
  final Color withdrawnText;
  final Color withdrawnBg;
  final Color chart1;
  final Color chart2;
  final Color chart3;
  final Color chart4;
  final Color chart5;
  final Color overlay;
  final Color highlight;
  final Color primary50;
  final Color primary100;
  final Color primary200;
  final Color primary300;
  final Color primary400;
  final Color primary500;
  final Color primary600;
  final Color primary700;
  final Color primary800;
  final Color primary900;

  const AppColorsExtension({
    required this.primary,
    required this.primaryActive,
    required this.primaryLight,
    required this.success,
    required this.successBg,
    required this.warning,
    required this.warningBg,
    required this.danger,
    required this.dangerBg,
    required this.amountPositive,
    required this.amountNegative,
    required this.amountNeutral,
    required this.amountPrimary,
    required this.infoText,
    required this.infoBg,
    required this.infoLightBg,
    required this.infoBorder,
    required this.timelineInactive,
    required this.paidText,
    required this.paidBg,
    required this.unpaidText,
    required this.unpaidBg,
    required this.bgExpired,
    required this.swipeDeleteBg,
    required this.textPrimary,
    required this.textSecondary,
    required this.textPlaceholder,
    required this.textDisabled,
    required this.statusGray,
    required this.bgPage,
    required this.bgCard,
    required this.bgDisabled,
    required this.bgSecondaryContainer,
    required this.border,
    required this.withdrawnText,
    required this.withdrawnBg,
    required this.chart1,
    required this.chart2,
    required this.chart3,
    required this.chart4,
    required this.chart5,
    required this.overlay,
    required this.highlight,
    required this.primary50,
    required this.primary100,
    required this.primary200,
    required this.primary300,
    required this.primary400,
    required this.primary500,
    required this.primary600,
    required this.primary700,
    required this.primary800,
    required this.primary900,
  });

  static const light = AppColorsExtension(
    primary: AppColors.primary,
    primaryActive: AppColors.primaryActive,
    primaryLight: AppColors.primaryLight,
    success: AppColors.success,
    successBg: AppColors.successBg,
    warning: AppColors.warning,
    warningBg: AppColors.warningBg,
    danger: AppColors.danger,
    dangerBg: AppColors.dangerBg,
    amountPositive: AppColors.amountPositive,
    amountNegative: AppColors.amountNegative,
    amountNeutral: AppColors.amountNeutral,
    amountPrimary: AppColors.amountPrimary,
    infoText: AppColors.infoText,
    infoBg: AppColors.infoBg,
    infoLightBg: AppColors.infoLightBg,
    infoBorder: AppColors.infoBorder,
    timelineInactive: AppColors.timelineInactive,
    paidText: AppColors.paidText,
    paidBg: AppColors.paidBg,
    unpaidText: AppColors.unpaidText,
    unpaidBg: AppColors.unpaidBg,
    bgExpired: AppColors.bgExpired,
    swipeDeleteBg: AppColors.swipeDeleteBg,
    textPrimary: AppColors.textPrimary,
    textSecondary: AppColors.textSecondary,
    textPlaceholder: AppColors.textPlaceholder,
    textDisabled: AppColors.textDisabled,
    statusGray: AppColors.statusGray,
    bgPage: AppColors.bgPage,
    bgCard: AppColors.bgCard,
    bgDisabled: AppColors.bgDisabled,
    bgSecondaryContainer: AppColors.bgSecondaryContainer,
    border: AppColors.border,
    withdrawnText: AppColors.withdrawnText,
    withdrawnBg: AppColors.withdrawnBg,
    chart1: AppColors.chart1,
    chart2: AppColors.chart2,
    chart3: AppColors.chart3,
    chart4: AppColors.chart4,
    chart5: AppColors.chart5,
    overlay: AppColors.overlay,
    highlight: AppColors.highlight,
    primary50: AppColors.primary50,
    primary100: AppColors.primary100,
    primary200: AppColors.primary200,
    primary300: AppColors.primary300,
    primary400: AppColors.primary400,
    primary500: AppColors.primary500,
    primary600: AppColors.primary600,
    primary700: AppColors.primary700,
    primary800: AppColors.primary800,
    primary900: AppColors.primary900,
  );

  static const dark = AppColorsExtension(
    primary: AppDarkColors.primary,
    primaryActive: AppDarkColors.primaryActive,
    primaryLight: AppDarkColors.primaryLight,
    success: AppDarkColors.success,
    successBg: AppDarkColors.successBg,
    warning: AppDarkColors.warning,
    warningBg: AppDarkColors.warningBg,
    danger: AppDarkColors.danger,
    dangerBg: AppDarkColors.dangerBg,
    amountPositive: AppDarkColors.amountPositive,
    amountNegative: AppDarkColors.amountNegative,
    amountNeutral: AppDarkColors.amountNeutral,
    amountPrimary: AppDarkColors.amountPrimary,
    infoText: AppDarkColors.infoText,
    infoBg: AppDarkColors.infoBg,
    infoLightBg: AppDarkColors.infoLightBg,
    infoBorder: AppDarkColors.infoBorder,
    timelineInactive: AppDarkColors.timelineInactive,
    paidText: AppDarkColors.paidText,
    paidBg: AppDarkColors.paidBg,
    unpaidText: AppDarkColors.unpaidText,
    unpaidBg: AppDarkColors.unpaidBg,
    bgExpired: AppDarkColors.bgExpired,
    swipeDeleteBg: AppDarkColors.swipeDeleteBg,
    textPrimary: AppDarkColors.textPrimary,
    textSecondary: AppDarkColors.textSecondary,
    textPlaceholder: AppDarkColors.textPlaceholder,
    textDisabled: AppDarkColors.textDisabled,
    statusGray: AppDarkColors.statusGray,
    bgPage: AppDarkColors.bgPage,
    bgCard: AppDarkColors.bgCard,
    bgDisabled: AppDarkColors.bgDisabled,
    bgSecondaryContainer: AppDarkColors.bgSecondaryContainer,
    border: AppDarkColors.border,
    withdrawnText: AppDarkColors.withdrawnText,
    withdrawnBg: AppDarkColors.withdrawnBg,
    chart1: AppDarkColors.chart1,
    chart2: AppDarkColors.chart2,
    chart3: AppDarkColors.chart3,
    chart4: AppDarkColors.chart4,
    chart5: AppDarkColors.chart5,
    overlay: AppDarkColors.overlay,
    highlight: AppDarkColors.highlight,
    primary50: AppDarkColors.primary50,
    primary100: AppDarkColors.primary100,
    primary200: AppDarkColors.primary200,
    primary300: AppDarkColors.primary300,
    primary400: AppDarkColors.primary400,
    primary500: AppDarkColors.primary500,
    primary600: AppDarkColors.primary600,
    primary700: AppDarkColors.primary700,
    primary800: AppDarkColors.primary800,
    primary900: AppDarkColors.primary900,
  );

  @override
  AppColorsExtension copyWith() => this;

  @override
  AppColorsExtension lerp(ThemeExtension<AppColorsExtension>? other, double t) {
    if (other is! AppColorsExtension) return this;
    return AppColorsExtension(
      primary: Color.lerp(primary, other.primary, t)!,
      primaryActive: Color.lerp(primaryActive, other.primaryActive, t)!,
      primaryLight: Color.lerp(primaryLight, other.primaryLight, t)!,
      success: Color.lerp(success, other.success, t)!,
      successBg: Color.lerp(successBg, other.successBg, t)!,
      warning: Color.lerp(warning, other.warning, t)!,
      warningBg: Color.lerp(warningBg, other.warningBg, t)!,
      danger: Color.lerp(danger, other.danger, t)!,
      dangerBg: Color.lerp(dangerBg, other.dangerBg, t)!,
      amountPositive: Color.lerp(amountPositive, other.amountPositive, t)!,
      amountNegative: Color.lerp(amountNegative, other.amountNegative, t)!,
      amountNeutral: Color.lerp(amountNeutral, other.amountNeutral, t)!,
      amountPrimary: Color.lerp(amountPrimary, other.amountPrimary, t)!,
      infoText: Color.lerp(infoText, other.infoText, t)!,
      infoBg: Color.lerp(infoBg, other.infoBg, t)!,
      infoLightBg: Color.lerp(infoLightBg, other.infoLightBg, t)!,
      infoBorder: Color.lerp(infoBorder, other.infoBorder, t)!,
      timelineInactive: Color.lerp(
        timelineInactive,
        other.timelineInactive,
        t,
      )!,
      paidText: Color.lerp(paidText, other.paidText, t)!,
      paidBg: Color.lerp(paidBg, other.paidBg, t)!,
      unpaidText: Color.lerp(unpaidText, other.unpaidText, t)!,
      unpaidBg: Color.lerp(unpaidBg, other.unpaidBg, t)!,
      bgExpired: Color.lerp(bgExpired, other.bgExpired, t)!,
      swipeDeleteBg: Color.lerp(swipeDeleteBg, other.swipeDeleteBg, t)!,
      textPrimary: Color.lerp(textPrimary, other.textPrimary, t)!,
      textSecondary: Color.lerp(textSecondary, other.textSecondary, t)!,
      textPlaceholder: Color.lerp(textPlaceholder, other.textPlaceholder, t)!,
      textDisabled: Color.lerp(textDisabled, other.textDisabled, t)!,
      statusGray: Color.lerp(statusGray, other.statusGray, t)!,
      bgPage: Color.lerp(bgPage, other.bgPage, t)!,
      bgCard: Color.lerp(bgCard, other.bgCard, t)!,
      bgDisabled: Color.lerp(bgDisabled, other.bgDisabled, t)!,
      bgSecondaryContainer: Color.lerp(
        bgSecondaryContainer,
        other.bgSecondaryContainer,
        t,
      )!,
      border: Color.lerp(border, other.border, t)!,
      withdrawnText: Color.lerp(withdrawnText, other.withdrawnText, t)!,
      withdrawnBg: Color.lerp(withdrawnBg, other.withdrawnBg, t)!,
      chart1: Color.lerp(chart1, other.chart1, t)!,
      chart2: Color.lerp(chart2, other.chart2, t)!,
      chart3: Color.lerp(chart3, other.chart3, t)!,
      chart4: Color.lerp(chart4, other.chart4, t)!,
      chart5: Color.lerp(chart5, other.chart5, t)!,
      overlay: Color.lerp(overlay, other.overlay, t)!,
      highlight: Color.lerp(highlight, other.highlight, t)!,
      primary50: Color.lerp(primary50, other.primary50, t)!,
      primary100: Color.lerp(primary100, other.primary100, t)!,
      primary200: Color.lerp(primary200, other.primary200, t)!,
      primary300: Color.lerp(primary300, other.primary300, t)!,
      primary400: Color.lerp(primary400, other.primary400, t)!,
      primary500: Color.lerp(primary500, other.primary500, t)!,
      primary600: Color.lerp(primary600, other.primary600, t)!,
      primary700: Color.lerp(primary700, other.primary700, t)!,
      primary800: Color.lerp(primary800, other.primary800, t)!,
      primary900: Color.lerp(primary900, other.primary900, t)!,
    );
  }
}
