// 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 SymbolButtonTheme extends SymbolButtonThemeExtension {
  const SymbolButtonTheme({
    super.disabledStyle,
    super.focusedStyle,
    super.hoveredStyle,
    super.normalStyle,
    super.tappedStyle,
    super.selectedStyle,
  });

  factory SymbolButtonTheme.light() {
    final style = SymbolButtonStyle(
      label: GoogleFonts.montserrat(
        fontSize: 14,
        fontWeight: FontWeight.w400,
      ),
      dimension: 60,
      radius: BorderRadius.circular(12),
      padding: const EdgeInsets.all(10),
      foregroundColors: const MultiColor.single(Constants.grey2),
      backgroundColors: MultiColor.single(Constants.white.withOpacity(0.04)),
      borderColors: const MultiColor(Constants.greyGradient),
      stroke: 2,
    );
    return SymbolButtonTheme(
      normalStyle: style,
      disabledStyle: style.copyWith(
        label: GoogleFonts.montserrat(
          fontSize: 14,
          fontWeight: FontWeight.w400,
          color: Constants.grey1,
        ),
        foregroundColors: MultiColor.single(Constants.grey1.withOpacity(0.4)),
        backgroundColors: const MultiColor.single(Constants.white),
        borderColors: MultiColor.single(Constants.grey1.withOpacity(0.4)),
      ),
      hoveredStyle: style.copyWith(
        backgroundColors: MultiColor.single(Constants.grey1.withOpacity(0.4)),
      ),
      focusedStyle: style.copyWith(stroke: 4),
      tappedStyle: style.copyWith(
        backgroundColors: MultiColor.single(Constants.grey1.withOpacity(0.4)),
      ),
      selectedStyle: style.copyWith(
        label: GoogleFonts.montserrat(
          fontSize: 14,
          fontWeight: FontWeight.w600,
        ),
        foregroundColors: const MultiColor.single(Constants.grey2),
        borderColors: const MultiColor(Constants.greenGradient),
      ),
    );
  }

  factory SymbolButtonTheme.dark() {
    final style = SymbolButtonStyle(
      label: GoogleFonts.montserrat(
        fontSize: 14,
        fontWeight: FontWeight.w400,
      ),
      dimension: 60,
      radius: BorderRadius.circular(12),
      padding: const EdgeInsets.all(10),
      foregroundColors: const MultiColor.single(Constants.white),
      backgroundColors: MultiColor.single(Constants.white.withOpacity(0.04)),
      borderColors: const MultiColor(Constants.greyGradient),
      stroke: 2,
    );
    return SymbolButtonTheme(
      normalStyle: style,
      disabledStyle: style.copyWith(
        label: GoogleFonts.montserrat(
          fontSize: 14,
          fontWeight: FontWeight.w400,
          color: Constants.grey1,
        ),
        foregroundColors: const MultiColor.single(Constants.grey1),
        backgroundColors: const MultiColor.single(Constants.grey4),
      ),
      hoveredStyle: style.copyWith(
        backgroundColors: const MultiColor(Constants.greyDarkGradient),
      ),
      focusedStyle: style.copyWith(stroke: 4),
      tappedStyle: style.copyWith(
        backgroundColors: const MultiColor(Constants.greyDarkGradient),
      ),
      selectedStyle: style.copyWith(
        label: GoogleFonts.montserrat(
          fontSize: 14,
          fontWeight: FontWeight.w600,
        ),
        foregroundColors: const MultiColor.single(Constants.white),
        borderColors: const MultiColor(Constants.greenGradient),
      ),
    );
  }

  @override
  ThemeExtension<SymbolButtonThemeExtension> copyWith({
    SymbolButtonStyle? disabledStyle,
    SymbolButtonStyle? focusedStyle,
    SymbolButtonStyle? hoveredStyle,
    SymbolButtonStyle? normalStyle,
    SymbolButtonStyle? tappedStyle,
    SymbolButtonStyle? selectedStyle,
  }) =>
      SymbolButtonTheme(
        disabledStyle: disabledStyle ?? this.disabledStyle,
        focusedStyle: focusedStyle ?? this.focusedStyle,
        hoveredStyle: hoveredStyle ?? this.hoveredStyle,
        normalStyle: normalStyle ?? this.normalStyle,
        tappedStyle: tappedStyle ?? this.tappedStyle,
        selectedStyle: selectedStyle ?? this.selectedStyle,
      );

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