// 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';

class FlatButtonTheme extends FlatButtonThemeExtension {
  const FlatButtonTheme({
    super.disabledStyle,
    super.focusedStyle,
    super.hoveredStyle,
    super.normalStyle,
    super.tappedStyle,
  });

  factory FlatButtonTheme.light() {
    final style = FlatButtonStyle(
      label: GoogleFonts.montserrat(
        fontSize: 18,
        fontWeight: FontWeight.w600,
      ),
      radius: BorderRadius.circular(15),
      padding: const EdgeInsets.all(10),
      foregroundColors: const MultiColor(Constants.blueGradient),
      backgroundColors: const MultiColor.single(Constants.white),
      borderColors: const MultiColor(Constants.blueGradient),
      stroke: 3,
    );
    return FlatButtonTheme(
      normalStyle: style,
      disabledStyle: style.copyWith(
        label: GoogleFonts.montserrat(
          fontSize: 18,
          fontWeight: FontWeight.w600,
          color: Constants.blue1.withOpacity(0.4),
        ),
        foregroundColors: MultiColor.single(Constants.blue1.withOpacity(0.4)),
        backgroundColors: const MultiColor.single(Constants.white),
        borderColors: MultiColor.single(Constants.blue1.withOpacity(0.4)),
        stroke: 1,
      ),
      hoveredStyle: style.copyWith(
        label: GoogleFonts.montserrat(
          fontSize: 18,
          fontWeight: FontWeight.w600,
          color: Constants.white,
        ),
        foregroundColors: const MultiColor.single(Constants.white),
        backgroundColors: const MultiColor(Constants.blueGradient),
      ),
      focusedStyle: style.copyWith(stroke: 5),
      tappedStyle: style.copyWith(
        label: GoogleFonts.montserrat(
          fontSize: 18,
          fontWeight: FontWeight.w600,
          color: Constants.white,
        ),
        foregroundColors: const MultiColor.single(Constants.white),
        backgroundColors: const MultiColor(Constants.blueDarkGradient),
        borderColors: const MultiColor(Constants.blueDarkGradient),
      ),
    );
  }

  factory FlatButtonTheme.dark() {
    final style = FlatButtonStyle(
      label: GoogleFonts.montserrat(
        fontSize: 18,
        fontWeight: FontWeight.w600,
      ),
      radius: BorderRadius.circular(15),
      padding: const EdgeInsets.all(10),
      foregroundColors: const MultiColor.single(Constants.white),
      backgroundColors: const MultiColor.single(Constants.dark),
      borderColors: const MultiColor(Constants.blueGradient),
      stroke: 3,
    );
    return FlatButtonTheme(
      normalStyle: style,
      disabledStyle: style.copyWith(
        label: GoogleFonts.montserrat(
          fontSize: 18,
          fontWeight: FontWeight.w600,
          color: Constants.grey1,
        ),
        foregroundColors: const MultiColor.single(Constants.grey1),
        backgroundColors: const MultiColor.single(Constants.grey4),
        borderColors: const MultiColor(Constants.greyGradient),
        stroke: 1,
      ),
      hoveredStyle: style.copyWith(
        foregroundColors: const MultiColor.single(Constants.white),
        backgroundColors: const MultiColor(Constants.blueGradient),
      ),
      focusedStyle: style.copyWith(stroke: 5),
      tappedStyle: style.copyWith(
        foregroundColors: const MultiColor.single(Constants.white),
        backgroundColors: const MultiColor(Constants.blueDarkGradient),
        borderColors: const MultiColor(Constants.blueDarkGradient),
      ),
    );
  }

  @override
  ThemeExtension<FlatButtonThemeExtension> copyWith({
    FlatButtonStyle? disabledStyle,
    FlatButtonStyle? focusedStyle,
    FlatButtonStyle? hoveredStyle,
    FlatButtonStyle? normalStyle,
    FlatButtonStyle? tappedStyle,
  }) =>
      FlatButtonTheme(
        disabledStyle: disabledStyle ?? this.disabledStyle,
        focusedStyle: focusedStyle ?? this.focusedStyle,
        hoveredStyle: hoveredStyle ?? this.hoveredStyle,
        normalStyle: normalStyle ?? this.normalStyle,
        tappedStyle: tappedStyle ?? this.tappedStyle,
      );

  @override
  ThemeExtension<FlatButtonThemeExtension> lerp(
    covariant ThemeExtension<FlatButtonThemeExtension>? other,
    double t,
  ) {
    if (other is! FlatButtonTheme) {
      return this;
    }
    return FlatButtonTheme(
      disabledStyle:
          FlatButtonStyle.lerp(disabledStyle, other.disabledStyle, t),
      focusedStyle: FlatButtonStyle.lerp(focusedStyle, other.focusedStyle, t),
      hoveredStyle: FlatButtonStyle.lerp(hoveredStyle, other.hoveredStyle, t),
      normalStyle: FlatButtonStyle.lerp(normalStyle, other.normalStyle, t),
      tappedStyle: FlatButtonStyle.lerp(tappedStyle, other.tappedStyle, t),
    );
  }
}
