import 'package:aman_kassa_flutter/core/locator.dart';
import 'package:aman_kassa_flutter/core/route_names.dart';
import 'package:aman_kassa_flutter/core/services/navigator_service.dart';
import 'package:aman_kassa_flutter/redux/actions/calc_actions.dart';
import 'package:aman_kassa_flutter/redux/constants/operation_const.dart';
import 'package:aman_kassa_flutter/redux/constants/setting_const.dart';
import 'package:aman_kassa_flutter/redux/state/calc_state.dart';
import 'package:aman_kassa_flutter/redux/store.dart';
import 'package:aman_kassa_flutter/shared/app_colors.dart';
import 'package:aman_kassa_flutter/shared/shared_styles.dart';
import 'package:aman_kassa_flutter/views/payment/payment_view.dart';
import 'package:aman_kassa_flutter/widgets/components/calculator/calculator.dart';
import 'package:flutter/material.dart';
import 'package:aman_kassa_flutter/widgets/components/calculator/calculator-buttons.dart';
import 'package:aman_kassa_flutter/widgets/components/calculator/number-display.dart';
import 'package:flutter_redux/flutter_redux.dart';

class CalculatorTab extends StatelessWidget {
  final NavigatorService _navigatorService = locator<NavigatorService>();

  final int index;

  CalculatorTab(this.index);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: Column(
      children: <Widget>[
        StoreConnector<AppState, CalcState>(
            converter: (store) => store.state.calcState!,
            builder: (context, vm) {
              return NumberDisplay(
                  value: Calculator.parseItems(vm.calcItems!, vm.isEqual!));
            }),
        CalculatorButtons(onTap: _onPress),
        Row(
          children: <Widget>[
            Expanded(
              child: ElevatedButton(
                  style: ElevatedButton.styleFrom(backgroundColor: redColor, padding: EdgeInsets.all(16.0)),
                  child: Text(
                    "возврат",
                    style: buttonBigTitleTextStyle,
                  ),
                  onPressed: () {
                    _navigatorService.push(PaymentViewRoute,
                        arguments: PaymentModel(
                            mode: SettingModeCalc,
                            operationType: OperationTypeReturn));
                  }),
            ),
            Expanded(
              child: ElevatedButton(
                style: ElevatedButton.styleFrom(backgroundColor: greenColor, padding: EdgeInsets.all(16.0)),
                child: Text(
                  "оплата",
                  style: buttonBigTitleTextStyle,
                ),
                onPressed: () {
                  _navigatorService.push(PaymentViewRoute,
                      arguments: PaymentModel(
                          mode: SettingModeCalc,
                          operationType: OperationTypePay));
                },
              ),
            ),
          ],
        )
      ],
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
    ));
  }

  void _onPress({required String buttonText}) {
    Redux.store!.dispatch(onTapAction(buttonText));
  }
}
