import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:hmg_patient_app_new/core/utils/date_util.dart';
import 'package:hmg_patient_app_new/core/utils/size_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/presentation/inpatient_services/inpatient_services_homepage.dart';
import 'package:hmg_patient_app_new/theme/colors.dart';
import 'package:hmg_patient_app_new/widgets/buttons/custom_button.dart';
import 'package:hmg_patient_app_new/widgets/chip/app_custom_chip_widget.dart';
import 'package:hmg_patient_app_new/widgets/routes/custom_page_route.dart';
import 'package:provider/provider.dart';

import '../../../generated/locale_keys.g.dart';

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

  @override
  Widget build(BuildContext context) {
    return Consumer<InpatientServicesViewModel>(builder: (context, inpatientServicesVM, child) {
      return Container(
        decoration: RoundedRectangleBorder().toSmoothCornerDecoration(
          color: AppColors.whiteColor,
          borderRadius: 20.h,
          hasShadow: true,
        ),
        child: Padding(
          padding: EdgeInsets.all(16.h),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            mainAxisSize: MainAxisSize.max,
            children: [
              Wrap(
                alignment: WrapAlignment.start,
                direction: Axis.horizontal,
                spacing: 6.w,
                runSpacing: 6.h,
                children: [
                  AppCustomChipWidget(
                    labelText: inpatientServicesVM.isAdmitted ? LocaleKeys.InPatient.tr(context: context) : LocaleKeys.admissionReq.tr(context: context),
                    backgroundColor: AppColors.textColor,
                    textColor: AppColors.whiteColor,
                  ),
                  inpatientServicesVM.isAdmitted
                      ? AppCustomChipWidget(
                          labelText: "Room: ${inpatientServicesVM.getAdmissionInfoResponseModel!.roomID} • Bed: ${inpatientServicesVM.getAdmissionInfoResponseModel!.bedID}",
                          backgroundColor: AppColors.infoColor.withAlpha(30),
                          textColor: AppColors.infoColor,
                        )
                      : SizedBox(),
                ],
              ),
              SizedBox(height: 24.h),
              inpatientServicesVM.isAdmitted
                  ? "${LocaleKeys.admissionNo.tr(context: context)}: ${inpatientServicesVM.getAdmissionInfoResponseModel!.admissionNo}".toText16(isBold: true)
                  : "${LocaleKeys.admissionReqNo.tr(context: context)}: ${inpatientServicesVM.getAdmissionRequestInfoResponseModel!.admissionRequestNo}".toText16(isBold: true),
              SizedBox(height: 8.h),
              Wrap(
                alignment: WrapAlignment.start,
                direction: Axis.horizontal,
                spacing: 6.w,
                runSpacing: 6.h,
                children: [
                  AppCustomChipWidget(
                    labelText: inpatientServicesVM.isAdmitted
                        ? "${LocaleKeys.clinicName.tr(context: context)}: ${inpatientServicesVM.getAdmissionInfoResponseModel!.clinicName}"
                        : "${LocaleKeys.clinicName.tr(context: context)}: ${inpatientServicesVM.getAdmissionRequestInfoResponseModel!.clinicName}",
                  ),
                  AppCustomChipWidget(
                    labelText: inpatientServicesVM.isAdmitted
                        ? "${LocaleKeys.branch.tr(context: context)} ${inpatientServicesVM.getAdmissionInfoResponseModel!.projectName}"
                        : "${LocaleKeys.branch.tr(context: context)} ${inpatientServicesVM.getAdmissionRequestInfoResponseModel!.projectName}",
                  ),
                  AppCustomChipWidget(
                    labelText: inpatientServicesVM.isAdmitted
                        ? "${LocaleKeys.admissionDate.tr(context: context)}: ${DateUtil.formatDateToDate(DateUtil.convertStringToDate(inpatientServicesVM.getAdmissionInfoResponseModel!.admissionDate), false)}"
                        : "${LocaleKeys.admissionRequestDate.tr(context: context)}: ${DateUtil.formatDateToDate(DateUtil.convertStringToDate(inpatientServicesVM.getAdmissionRequestInfoResponseModel!.expectedAdmissionDate), false)}",
                  ),
                ],
              ),
              SizedBox(height: 16.h),
              CustomButton(
                text: LocaleKeys.viewDetails.tr(context: context),
                onPressed: () {
                  Navigator.of(context).push(
                    CustomPageRoute(
                      page: InpatientServicesHomepage(),
                    ),
                  );
                },
                backgroundColor: AppColors.secondaryLightRedColor,
                borderColor: AppColors.secondaryLightRedColor,
                textColor: AppColors.primaryRedColor,
                fontSize: (isFoldable || isTablet) ? 12.f : 14.f,
                fontWeight: FontWeight.w600,
                borderRadius: 12.r,
                padding: EdgeInsets.symmetric(horizontal: 10.w),
                height: isFoldable ? 36.h : 40.h,
              )
            ],
          ),
        ),
      );
    });
  }
}
