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

class TextInputStyle extends ThemeStyle<TextInputStyle> {
  TextInputStyle({
    this.labelStyle,
    this.hintStyle,
    this.backgroundColors,
    this.borderColors,
    this.boxShadow,
    this.radius,
    this.inputStyle,
    this.iconColor,
    this.prefixStyle,
    this.prefixIconColor,
    this.suffixStyle,
    this.suffixIconColor,
  });

  final TextStyle? labelStyle;
  final TextStyle? hintStyle;

  final Color? iconColor;
  final TextStyle? prefixStyle;
  final Color? prefixIconColor;
  final TextStyle? suffixStyle;
  final Color? suffixIconColor;

  final MultiColor? backgroundColors;
  final Color? borderColors;
  final BoxShadow? boxShadow;
  final BorderRadiusGeometry? radius;
  final TextStyle? inputStyle;

  static TextInputStyle? merge(TextInputStyle? a, TextInputStyle? b) {
    if (b == null) {
      return a?.copyWith();
    }
    if (a == null) {
      return b.copyWith();
    }
    return a.copyWith(
      labelStyle: b.labelStyle,
      hintStyle: b.hintStyle,
      backgroundColors: b.backgroundColors,
      borderColors: b.borderColors,
      boxShadow: b.boxShadow,
      radius: b.radius,
      inputStyle: b.inputStyle,
      iconColor: b.iconColor,
      prefixStyle: b.prefixStyle,
      prefixIconColor: b.prefixIconColor,
      suffixIconColor: b.suffixIconColor,
      suffixStyle: b.suffixStyle,
    );
  }

  static TextInputStyle? lerp(
    TextInputStyle? a,
    TextInputStyle? b,
    double t,
  ) {
    if (a == null || b == null) {
      return null;
    }

    return b.copyWith(
      labelStyle: TextStyle.lerp(a.labelStyle, b.labelStyle, t),
      hintStyle: TextStyle.lerp(a.hintStyle, b.hintStyle, t),
      backgroundColors:
          MultiColor.lerp(a.backgroundColors, b.backgroundColors, t),
      radius: BorderRadiusGeometry.lerp(a.radius, b.radius, t),
      borderColors: Color.lerp(a.borderColors, b.borderColors, t),
      boxShadow: BoxShadow.lerp(a.boxShadow, b.boxShadow, t),
      inputStyle: TextStyle.lerp(a.inputStyle, b.inputStyle, t),
      prefixStyle: TextStyle.lerp(a.prefixStyle, b.prefixStyle, t),
      suffixStyle: TextStyle.lerp(a.suffixStyle, b.suffixStyle, t),
      prefixIconColor: Color.lerp(a.prefixIconColor, b.prefixIconColor, t),
      suffixIconColor: Color.lerp(a.suffixIconColor, b.suffixIconColor, t),
      iconColor: Color.lerp(a.iconColor, b.iconColor, t),
    );
  }

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

  @override
  TextInputStyle copyWith({
    TextStyle? labelStyle,
    TextStyle? hintStyle,
    MultiColor? backgroundColors,
    Color? borderColors,
    BoxShadow? boxShadow,
    BorderRadiusGeometry? radius,
    TextStyle? inputStyle,
    Color? iconColor,
    TextStyle? prefixStyle,
    Color? prefixIconColor,
    TextStyle? suffixStyle,
    Color? suffixIconColor,
  }) =>
      TextInputStyle(
        labelStyle: labelStyle ?? this.labelStyle,
        hintStyle: hintStyle ?? this.hintStyle,
        backgroundColors: backgroundColors ?? this.backgroundColors,
        radius: radius ?? this.radius,
        borderColors: borderColors ?? this.borderColors,
        boxShadow: boxShadow ?? this.boxShadow,
        inputStyle: inputStyle ?? this.inputStyle,
        prefixStyle: prefixStyle ?? this.prefixStyle,
        suffixStyle: suffixStyle ?? this.suffixStyle,
        prefixIconColor: prefixIconColor ?? this.prefixIconColor,
        suffixIconColor: suffixIconColor ?? this.suffixIconColor,
        iconColor: iconColor ?? this.iconColor,
      );
}
