// Copyright (C) 2023 WYATT GROUP
// Please see the AUTHORS file for details.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:wyatt_ui_components/wyatt_ui_components.dart';
import 'package:wyatt_ui_kit/wyatt_ui_kit.dart';
import 'package:wyatt_ui_kit_example/theme/constants.dart';

final Map<String, TextStyle> _styles = {
  'gradient-blue': GradientTextStyle.from(
    GoogleFonts.montserrat(
      fontSize: 20,
      fontWeight: FontWeight.w600,
      color: Constants.blue1,
      height: 1.8,
    ),
    const MultiColor(Constants.blueGradient),
  ),
  'gradient-red': GradientTextStyle.from(
    GoogleFonts.montserrat(
      fontSize: 20,
      fontWeight: FontWeight.w600,
      color: Constants.red1,
      height: 1.8,
    ),
    const MultiColor(Constants.redGradient),
  ),
  'gradient-green': GradientTextStyle.from(
    GoogleFonts.montserrat(
      fontSize: 20,
      fontWeight: FontWeight.w600,
      color: Constants.green1,
      height: 1.8,
    ),
    const MultiColor(Constants.greenGradient),
  ),
  'blue': GoogleFonts.montserrat(
    fontSize: 20,
    fontWeight: FontWeight.w600,
    color: Constants.blue1,
    height: 1.8,
  ),
  'red': GoogleFonts.montserrat(
    fontSize: 20,
    fontWeight: FontWeight.w600,
    color: Constants.red1,
    height: 1.8,
  ),
  'green': GoogleFonts.montserrat(
    fontSize: 20,
    fontWeight: FontWeight.w600,
    color: Constants.green1,
    height: 1.8,
  ),
};

class RichTextBuilderTheme extends RichTextBuilderThemeExtension {
  const RichTextBuilderTheme({
    super.defaultStyle,
    super.styles,
  });

  factory RichTextBuilderTheme.light() => RichTextBuilderTheme(
        defaultStyle: GoogleFonts.montserrat(
          fontSize: 18,
          fontWeight: FontWeight.w500,
          color: Constants.grey3,
          height: 1.8,
        ),
        styles: _styles,
      );

  factory RichTextBuilderTheme.dark() => RichTextBuilderTheme(
        defaultStyle: GoogleFonts.montserrat(
          fontSize: 18,
          fontWeight: FontWeight.w500,
          color: Constants.white,
          height: 1.8,
        ),
        styles: _styles,
      );

  @override
  ThemeExtension<RichTextBuilderThemeExtension> copyWith({
    TextStyle? defaultStyle,
    Map<String, TextStyle>? styles,
  }) =>
      RichTextBuilderTheme(
        defaultStyle: defaultStyle ?? this.defaultStyle,
        styles: styles ?? this.styles,
      );

  @override
  ThemeExtension<RichTextBuilderThemeExtension> lerp(
    covariant ThemeExtension<RichTextBuilderThemeExtension>? other,
    double t,
  ) {
    if (other is! RichTextBuilderTheme) {
      return this;
    }
    return RichTextBuilderTheme(
      defaultStyle: TextStyle.lerp(defaultStyle, other.defaultStyle, t),
      styles: styles,
    );
  }
}
