import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get_rx/src/rx_types/rx_types.dart';
import 'package:injectable/injectable.dart';
import 'package:keyboard/base/base_controller.dart';

import '../../../data/bean/pay_way_info.dart';

@injectable
class DiscountController extends BaseController {
  final RxList<PayWayInfo> payWayList = <PayWayInfo>[].obs;
  final Rxn<PayWayInfo> _selectedPayWay = Rxn<PayWayInfo>();

  PayWayInfo? get selectedPayWay => _selectedPayWay.value;

  @override
  void onInit() {
    super.onInit();
  }

  void clickPayWaySwitch() {
    if (payWayList.isNotEmpty) {
      int currentIndex = payWayList.indexOf(
        _selectedPayWay.value ?? payWayList.first,
      );
      int nextIndex = (currentIndex + 1) % payWayList.length;
      _selectedPayWay.value = payWayList[nextIndex];
    }
  }

  void clickBack() {
    SmartDialog.dismiss(tag: 'discountDialog');
  }

  void clickPayNow() {
    print('clickPayNow');
  }
}
