import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:hmg_patient_app_new/core/dependencies.dart';
import 'package:hmg_patient_app_new/core/utils/size_utils.dart';
import 'package:hmg_patient_app_new/core/utils/utils.dart';
import 'package:hmg_patient_app_new/extensions/string_extensions.dart';
import 'package:hmg_patient_app_new/extensions/widget_extensions.dart';
import 'package:hmg_patient_app_new/features/inpatient_services/inpatient_services_view_model.dart';
import 'package:hmg_patient_app_new/generated/codegen_loader.g.dart';
import 'package:hmg_patient_app_new/theme/colors.dart';
import 'package:hmg_patient_app_new/widgets/appbar/collapsing_list_view.dart';
import 'package:hmg_patient_app_new/widgets/custom_tab_bar.dart';
import 'package:provider/provider.dart';

class InpatientAdvancePaymentPage extends StatelessWidget {
  const InpatientAdvancePaymentPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: AppColors.bgScaffoldColor,
      body: CollapsingListView(
        title: LocaleKeys.advancePayment.tr(),
        child: Consumer<InpatientServicesViewModel>(builder: (context, inpatientServicesVM, child) {
          return Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              SizedBox(height: 16.h),
              CustomTabBar(
                activeTextColor: Color(0xffED1C2B),
                activeBackgroundColor: Color(0xffED1C2B).withValues(alpha: .1),
                initialIndex: 0,
                tabs: [
                  CustomTabBarModel(null, LocaleKeys.requests.tr(context: context)),
                  CustomTabBarModel(null, LocaleKeys.history.tr(context: context)),
                ],
                onTabChange: (index) {
                  inpatientServicesVM.onTabChanged(index);
                },
              ).paddingSymmetrical(24.h, 0.h),
              SizedBox(height: 24.h),
              getSelectedTabView(context).paddingSymmetrical(24.h, 0.h),
            ],
          );
        }),
      ),
    );
  }

  Widget getSelectedTabView(BuildContext context) {
    return getIt.get<InpatientServicesViewModel>().advancePaymentSelectedTabIndex == 0
        ? Container()
        : getIt.get<InpatientServicesViewModel>().isAdvancePaymentHistoryLoading
            ? Container(
                decoration: RoundedRectangleBorder().toSmoothCornerDecoration(
                  color: AppColors.whiteColor,
                  borderRadius: 20.r,
                  hasShadow: false,
                ),
                child: ListView.builder(
                  padding: EdgeInsets.zero,
                  shrinkWrap: true,
                  itemCount: 5,
                  itemBuilder: (context, index) {
                    return Column(
                      children: [
                        "Lorem <i>ipsum dolor sit</i> amet, consectetur <b>adipiscing elit</b>".toText16().toShimmer2(),
                        SizedBox(
                          height: 16.h,
                        ),
                      ],
                    ).paddingSymmetrical(24.h, 16.h);
                  },
                ),
              )
            : getIt.get<InpatientServicesViewModel>().inPatientAdvanceHistoryResponseModel != null
                ? Container()
                : Container(
                    decoration: RoundedRectangleBorder().toSmoothCornerDecoration(
                      color: AppColors.whiteColor,
                      borderRadius: 20.r,
                      hasShadow: false,
                    ),
                    child: Utils.getNoDataWidget(context),
                  );
  }
}
