// ignore_for_file: public_member_api_docs, sort_constructors_first
// 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/>.

part of 'button_cubit.dart';

class ButtonState extends Equatable {
  const ButtonState({required this.state, required this.extraStates});

  const ButtonState.initial(this.state) : extraStates = const [];

  /// The control state of the button
  final ControlState state;

  /// Not in control state, because a button state can be
  /// a control state + extra state
  /// e.g :
  /// - ControlState.hover + [ExtraState.invalid]
  /// - ControlState.tapped + [ExtraState.invalid + ExtraState.freezed]
  final List<ExtraState> extraStates;

  bool get isDisabled => state.isDisabled();
  bool get isEnabled => state.isEnabled();
  bool get isFocused => state.isFocused();
  bool get isHovered => state.isHovered();
  bool get isTapped => state.isTapped();
  bool get isSelected => extraStates.contains(ExtraState.selected);
  bool get isInvalid => extraStates.contains(ExtraState.invalid);
  bool get isFreezed => extraStates.contains(ExtraState.freezed);

  @override
  List<Object?> get props => [state, extraStates];

  @override
  bool? get stringify => true;

  ButtonState copyWith({
    ControlState? state,
    List<ExtraState>? extraStates,
  }) =>
      ButtonState(
        state: state ?? this.state,
        extraStates: extraStates ?? this.extraStates,
      );
}
