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

import 'package:wyatt_ui_components/wyatt_ui_components.dart';
import 'package:wyatt_ui_kit/src/components/buttons/cubit/button_cubit.dart';

class InvalidButtonCubit extends ButtonCubit {
  /// When the button is invalid. The button will add the
  /// [ExtraState.invalid] to its extra states.
  ///
  /// Use [validate] to remove the [ExtraState.invalid] from the extra states.
  ///
  /// Use this method to invalidate the button programmatically.
  FutureOr<void> invalidate() async {
    emit(state.copyWith(extraStates: state.extraStates + [ExtraState.invalid]));
  }

  /// When the button is valid. The button will remove the
  /// [ExtraState.invalid] from its extra states.
  ///
  /// Use [invalidate] to add the [ExtraState.invalid] to the extra states.
  ///
  /// Use this method to validate the button programmatically.
  FutureOr<void> validate() async {
    emit(
      state.copyWith(
        extraStates: state.extraStates
            .where((element) => element != ExtraState.invalid)
            .toList(),
      ),
    );
  }
}
