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

  factory SimpleIconButtonTheme.light() {
    final style = SimpleIconButtonStyle(
      dimension: 30,
      radius: BorderRadius.circular(5),
      padding: const EdgeInsets.all(5),
      foregroundColors: const MultiColor.single(Constants.dark),
      backgroundColors: MultiColor.single(Constants.grey1.withOpacity(0.2)),
    );
    return SimpleIconButtonTheme(
      normalStyle: style,
      disabledStyle: style.copyWith(
        foregroundColors: MultiColor.single(Constants.dark.withOpacity(0.4)),
      ),
      hoveredStyle: style.copyWith(
        backgroundColors: MultiColor.single(Constants.grey1.withOpacity(0.4)),
      ),
      focusedStyle: style,
      tappedStyle: style.copyWith(
        backgroundColors: MultiColor.single(Constants.grey1.withOpacity(0.5)),
      ),
    );
  }

  factory SimpleIconButtonTheme.dark() {
    final style = SimpleIconButtonStyle(
      dimension: 30,
      radius: BorderRadius.circular(5),
      padding: const EdgeInsets.all(5),
      foregroundColors: const MultiColor.single(Constants.white),
      backgroundColors: MultiColor.single(Constants.grey3.withOpacity(0.2)),
    );
    return SimpleIconButtonTheme(
      normalStyle: style,
      disabledStyle: style.copyWith(
        foregroundColors: MultiColor.single(Constants.white.withOpacity(0.4)),
      ),
      hoveredStyle: style.copyWith(
        backgroundColors: MultiColor.single(Constants.grey3.withOpacity(0.4)),
      ),
      focusedStyle: style,
      tappedStyle: style.copyWith(
        backgroundColors: MultiColor.single(Constants.grey3.withOpacity(0.5)),
      ),
    );
  }

  @override
  ThemeExtension<SimpleIconButtonThemeExtension> copyWith({
    SimpleIconButtonStyle? disabledStyle,
    SimpleIconButtonStyle? focusedStyle,
    SimpleIconButtonStyle? hoveredStyle,
    SimpleIconButtonStyle? normalStyle,
    SimpleIconButtonStyle? tappedStyle,
  }) =>
      SimpleIconButtonTheme(
        disabledStyle: disabledStyle ?? this.disabledStyle,
        focusedStyle: focusedStyle ?? this.focusedStyle,
        hoveredStyle: hoveredStyle ?? this.hoveredStyle,
        normalStyle: normalStyle ?? this.normalStyle,
        tappedStyle: tappedStyle ?? this.tappedStyle,
      );

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