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

  factory FileSelectionButtonTheme.light() {
    final style = FileSelectionButtonStyle(
      title: GoogleFonts.montserrat(
        fontSize: 16,
        fontWeight: FontWeight.w400,
      ),
      subTitle: GoogleFonts.montserrat(
        fontSize: 11,
        fontWeight: FontWeight.w400,
      ),
      radius: BorderRadius.circular(12),
      padding: const EdgeInsets.all(13),
      foregroundColors: const MultiColor.single(Constants.grey2),
      backgroundColors: MultiColor.single(Constants.white.withOpacity(0.04)),
      borderColors: const MultiColor(Constants.greyGradient),
      stroke: 2,
    );
    return FileSelectionButtonTheme(
      normalStyle: style,
      disabledStyle: style.copyWith(
        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)),
      ),
      invalidStyle: style.copyWith(
        subTitle: GoogleFonts.montserrat(
          fontSize: 11,
          fontWeight: FontWeight.w400,
          color: Constants.red1,
        ),
        borderColors: const MultiColor(Constants.redGradient),
      ),
      // Unused
      selectedStyle: style.copyWith(
        foregroundColors: const MultiColor.single(Constants.grey2),
        borderColors: const MultiColor(Constants.greenGradient),
      ),
    );
  }

  factory FileSelectionButtonTheme.dark() {
    final style = FileSelectionButtonStyle(
      title: GoogleFonts.montserrat(
        fontSize: 16,
        fontWeight: FontWeight.w400,
      ),
      subTitle: GoogleFonts.montserrat(
        fontSize: 11,
        fontWeight: FontWeight.w400,
      ),
      radius: BorderRadius.circular(12),
      padding: const EdgeInsets.all(13),
      foregroundColors: const MultiColor.single(Constants.white),
      backgroundColors: MultiColor.single(Constants.white.withOpacity(0.04)),
      borderColors: const MultiColor(Constants.greyGradient),
      stroke: 1,
    );
    return FileSelectionButtonTheme(
      normalStyle: style,
      disabledStyle: style.copyWith(
        foregroundColors: const MultiColor.single(Constants.grey1),
        backgroundColors: const MultiColor.single(Constants.grey4),
      ),
      hoveredStyle: style.copyWith(
        borderColors: const MultiColor.single(Constants.white),
      ),
      focusedStyle: style.copyWith(stroke: 3),
      tappedStyle: style.copyWith(
        backgroundColors: const MultiColor(Constants.greyDarkGradient),
      ),
      invalidStyle: style.copyWith(
        subTitle: GoogleFonts.montserrat(
          fontSize: 11,
          fontWeight: FontWeight.w400,
          color: Constants.red1,
        ),
        borderColors: const MultiColor(Constants.redGradient),
      ),
      // Unused
      selectedStyle: style.copyWith(
        foregroundColors: const MultiColor.single(Constants.white),
        borderColors: const MultiColor(Constants.greenGradient),
      ),
    );
  }

  @override
  ThemeExtension<FileSelectionButtonThemeExtension> copyWith({
    FileSelectionButtonStyle? disabledStyle,
    FileSelectionButtonStyle? focusedStyle,
    FileSelectionButtonStyle? hoveredStyle,
    FileSelectionButtonStyle? normalStyle,
    FileSelectionButtonStyle? tappedStyle,
    FileSelectionButtonStyle? selectedStyle,
    FileSelectionButtonStyle? invalidStyle,
  }) =>
      FileSelectionButtonTheme(
        disabledStyle: disabledStyle ?? this.disabledStyle,
        focusedStyle: focusedStyle ?? this.focusedStyle,
        hoveredStyle: hoveredStyle ?? this.hoveredStyle,
        normalStyle: normalStyle ?? this.normalStyle,
        tappedStyle: tappedStyle ?? this.tappedStyle,
        selectedStyle: selectedStyle ?? this.selectedStyle,
        invalidStyle: invalidStyle ?? this.invalidStyle,
      );

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