// 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 'dart:ui';

import 'package:flutter/widgets.dart';
import 'package:wyatt_ui_components/src/core/utils/multi_color.dart';
import 'package:wyatt_ui_components/src/domain/entities/buttons/button_style.dart';

class FileSelectionButtonStyle extends ButtonStyle<FileSelectionButtonStyle> {
  const FileSelectionButtonStyle({
    this.title,
    this.subTitle,
    super.radius,
    super.padding,
    super.foregroundColors,
    super.backgroundColors,
    super.borderColors,
    super.stroke,
    super.shadow,
  });

  /// Merges non-null `b` attributes in `a`
  static FileSelectionButtonStyle? merge(
    FileSelectionButtonStyle? a,
    FileSelectionButtonStyle? b,
  ) {
    if (b == null) {
      return a?.copyWith();
    }
    if (a == null) {
      return b.copyWith();
    }

    return a.copyWith(
      title: b.title,
      subTitle: b.subTitle,
      radius: b.radius,
      padding: b.padding,
      foregroundColors: b.foregroundColors,
      backgroundColors: b.backgroundColors,
      borderColors: b.borderColors,
      stroke: b.stroke,
      shadow: b.shadow,
    );
  }

  /// Used for interpolation.
  static FileSelectionButtonStyle? lerp(
    FileSelectionButtonStyle? a,
    FileSelectionButtonStyle? b,
    double t,
  ) {
    if (a == null || b == null) {
      return null;
    }
    // b.copyWith to return b attributes even if they are not lerped
    return b.copyWith(
      title: TextStyle.lerp(a.title, b.title, t),
      subTitle: TextStyle.lerp(a.title, b.title, t),
      foregroundColors: MultiColor.lerp(
        a.foregroundColors,
        b.foregroundColors,
        t,
      ),
      backgroundColors: MultiColor.lerp(
        a.backgroundColors,
        b.backgroundColors,
        t,
      ),
      borderColors: MultiColor.lerp(
        a.borderColors,
        b.borderColors,
        t,
      ),
      radius: BorderRadiusGeometry.lerp(a.radius, b.radius, t),
      padding: EdgeInsetsGeometry.lerp(a.padding, b.padding, t),
      stroke: lerpDouble(a.stroke, b.stroke, t),
      shadow: BoxShadow.lerp(a.shadow, b.shadow, t),
    );
  }

  /// Title text style
  ///
  /// Default to `TextTheme.labelLarge`
  final TextStyle? title;

  /// Sub title text style
  ///
  /// Default to `TextTheme.labelSmall`
  final TextStyle? subTitle;

  @override
  FileSelectionButtonStyle? mergeWith(FileSelectionButtonStyle? other) =>
      FileSelectionButtonStyle.merge(this, other);

  @override
  FileSelectionButtonStyle? copyWith({
    TextStyle? title,
    TextStyle? subTitle,
    BorderRadiusGeometry? radius,
    EdgeInsetsGeometry? padding,
    MultiColor? foregroundColors,
    MultiColor? backgroundColors,
    MultiColor? borderColors,
    double? stroke,
    BoxShadow? shadow,
  }) =>
      FileSelectionButtonStyle(
        title: title ?? this.title,
        subTitle: subTitle ?? this.subTitle,
        radius: radius ?? this.radius,
        padding: padding ?? this.padding,
        foregroundColors: foregroundColors ?? this.foregroundColors,
        backgroundColors: backgroundColors ?? this.backgroundColors,
        borderColors: borderColors ?? this.borderColors,
        stroke: stroke ?? this.stroke,
        shadow: shadow ?? this.shadow,
      );
}
