import 'package:aman_kassa_flutter/core/models/calc_model.dart';
import 'package:aman_kassa_flutter/redux/state/calc_state.dart';
import 'package:aman_kassa_flutter/widgets/components/calculator/calculator.dart';
import 'package:meta/meta.dart';
import 'package:redux/redux.dart';
import 'package:redux_thunk/redux_thunk.dart';

import '../store.dart';

@immutable
class SetCalcStateAction {
  final CalcState calcState;
  SetCalcStateAction(this.calcState);
}


Future<void> setEqual(Store<AppState> store) async {
  store.dispatch(SetCalcStateAction(CalcState(isEqual: true)));
}

Future<void> cleanCalcItems(Store<AppState> store) async {
  store.dispatch(SetCalcStateAction(CalcState(calcItems: [])));
}

ThunkAction<AppState> onTapAction(String value) {
  return (Store<AppState> store) async {
    if(value == Calculations.EQUAL){
      return setEqual(store);
    }
    List<CalcModel> calcItems = Calculator.action(value: value, items: store.state.calcState!.calcItems!);
    store.dispatch(SetCalcStateAction(CalcState(calcItems: calcItems, isEqual: false)));
  };
}