import 'package:flutter/material.dart';
import 'package:initial_folder/models/detail_order_model.dart';
import 'package:initial_folder/providers/payments_provider.dart' as payProv;
import 'package:initial_folder/providers/tab_provider.dart';
import 'package:initial_folder/screens/checkout/components/atm.dart';
import 'package:initial_folder/screens/checkout/components/internet_banking.dart';
import 'package:initial_folder/screens/checkout/components/mobile_banking.dart';
import 'package:initial_folder/size_config.dart';
import 'package:initial_folder/theme.dart';
import 'package:provider/provider.dart';

class TabBarBatasBayar extends StatelessWidget {
  TabBarBatasBayar({
    Key? key,
    this.bank,
  }) : super(key: key);

  final String? bank;

  @override
  Widget build(BuildContext context) {
    print("Apa hayoo ${bank}");
    List<DetailOrderModel> detailOrder =
        Provider.of<payProv.PaymentsProvider>(context).detailOrder;
    String? bankName = detailOrder.isNotEmpty ? detailOrder[0].bankName : null;
    print("Apa hayoo2 ${bankName}");
    TabProvider tab = Provider.of<TabProvider>(context);

    Widget buildContent(int currentIndex) {
      switch (currentIndex) {
        case 0:
          switch (bank ?? bankName) {
            case 'bni':
              return ATMBNI();
            case 'bca':
              return ATMBCA();
            case 'mandiri':
            case 'echannel':
              return AtmMandiri();
            case 'permata':
              return AtmPermata();
            default:
              return SizedBox();
          }
        case 1:
          switch (bank ?? bankName) {
            case 'bni':
              return InternetBankBNI();
            case 'bca':
              return InternetBankBCA();
            case 'mandiri':
            case 'echannel':
              return InternetBankMandiri();
            case 'permata':
              return InternetBankPermata();
            default:
              return SizedBox();
          }
        case 2:
          switch (bank ?? bankName) {
            case 'bni':
              return MobileBankBNI();
            case 'bca':
              return MobileBankBCA();
            case 'mandiri':
            case 'echannel':
              return MobileBankMandiri();
            case 'permata':
              return MobileBankPermata();
            default:
              return SizedBox();
          }
        default:
          return SizedBox();
      }
    }

    return Column(
      children: [
        ExpansionTile(
          title: Text(
            'ATM',
            style: thirdTextStyle.copyWith(
                fontSize: getProportionateScreenWidth(13)),
          ),
          children: [
            buildContent(0),
          ],
        ),
        Container(
          margin:
              EdgeInsets.symmetric(horizontal: getProportionateScreenWidth(8)),
          height: getProportionateScreenHeight(3),
          decoration: BoxDecoration(
            color: secondaryColor.withOpacity(0.1),
            boxShadow: [
              BoxShadow(
                color: secondaryColor.withOpacity(0.1),
                spreadRadius: 1,
                blurRadius: 1,
                offset: Offset(0, 1),
              ),
            ],
          ),
        ),
        ExpansionTile(
          title: Text(
            'Internet Banking',
            style: thirdTextStyle.copyWith(
                fontSize: getProportionateScreenWidth(13)),
          ),
          children: [
            buildContent(1),
          ],
        ),
        Container(
          margin:
              EdgeInsets.symmetric(horizontal: getProportionateScreenWidth(8)),
          height: getProportionateScreenHeight(3),
          decoration: BoxDecoration(
            color: secondaryColor.withOpacity(0.1),
            boxShadow: [
              BoxShadow(
                color: secondaryColor.withOpacity(0.1),
                spreadRadius: 1,
                blurRadius: 1,
                offset: Offset(0, 1),
              ),
            ],
          ),
        ),
        ExpansionTile(
          title: Text(
            'Mobile Banking',
            style: thirdTextStyle.copyWith(
                fontSize: getProportionateScreenWidth(13)),
          ),
          children: [
            buildContent(2),
          ],
        ),
      ],
    );
  }
}
