import 'package:blinking_text/blinking_text.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:hmg_qline/constants/app_constants.dart';
import 'package:hmg_qline/models/global_config_model.dart';
import 'package:hmg_qline/utilities/enums.dart';
import 'package:hmg_qline/utilities/extensions.dart';
import 'package:hmg_qline/views/common_widgets/app_general_widgets.dart';
import 'package:hmg_qline/views/common_widgets/app_texts_widget.dart';
import 'package:hmg_qline/views/view_helpers/size_config.dart';

class QueueItemCallingCard extends StatelessWidget {
  final String ticketNo;
  final String roomNo;
  final bool blink;
  final double scale;
  final bool isClinicAdded;
  final bool isGradientRequired;
  final bool isBorderRequired;
  final TextDirection textDirection;
  final String roomText;
  final String roomTextAr;
  final GlobalConfigurationsModel globalConfigurationsModel;
  final CallTypeEnum callTypeEnum;
  final ScreenTypeEnum screenTypeEnum;
  final LanguageEnum langTypeEnum;
  final QTypeEnum qTypeEnum;
  final bool isSingleTicket;

  const QueueItemCallingCard({
    super.key,
    required this.isClinicAdded,
    required this.ticketNo,
    required this.roomNo,
    required this.scale,
    required this.textDirection,
    required this.roomText,
    required this.roomTextAr,
    required this.globalConfigurationsModel,
    required this.callTypeEnum,
    required this.screenTypeEnum,
    required this.langTypeEnum,
    required this.qTypeEnum,
    this.isGradientRequired = false,
    this.isBorderRequired = false,
    this.isSingleTicket = false,
    this.blink = false,
  });

  String getFormattedTicket(String ticketNo, bool isClinicAdded) {
    if (isClinicAdded) {
      var formattedString = ticketNo.split(" ");
      if (formattedString.length > 1) {
        return "${formattedString[0]}   ${formattedString[1]}";
      } else {
        return ticketNo;
      }
    }
    return ticketNo;
  }

  @override
  Widget build(BuildContext context) {
    final text = callTypeEnum.getMessageByCallTypeForEnglish(globalConfigurationsModel, isListView: false) + (qTypeEnum == QTypeEnum.appointment ? ("| $roomText $roomNo") : "");
    return Stack(
      children: [
        customShadowSmoothContainerWithBackground(
          padding: EdgeInsets.symmetric(vertical: SizeConfig.getHeightMultiplier() * 0.1),
          callTypeEnum: callTypeEnum,
          child: Directionality(
            textDirection: textDirection,
            child: IntrinsicHeight(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: [
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Column(
                        children: [
                          Padding(
                            padding: EdgeInsets.only(
                              left: textDirection == TextDirection.rtl ? SizeConfig.getWidthMultiplier() * 3.5 : 0,
                              right: textDirection == TextDirection.ltr ? SizeConfig.getWidthMultiplier() * 3.5 : 0,
                            ),
                            child: callTypeEnum.getIconByCallType(SizeConfig.getHeightMultiplier() * 0.5, qTypeEnum),
                          ),
                          SizedBox(height: SizeConfig.getHeightMultiplier()! * 0.15),
                          IntrinsicWidth(
                            child: callTypeContainer(
                              textDirection: textDirection,
                              padding: EdgeInsets.all(SizeConfig.getHeightMultiplier() * 0.1),
                              color: callTypeEnum.getColorByCallType(),
                              child: engArabicTextWithSeparatorWidget(
                                englishText: roomNo.extractNumbersIfLong(),
                                arabicText: roomTextAr,
                                color: AppColors.whiteColor,
                                mainAxisAlignment: MainAxisAlignment.center,
                              ),
                            ),
                          ),
                        ],
                      ),
                      Padding(
                        padding: EdgeInsets.only(
                          left: textDirection == TextDirection.rtl ? SizeConfig.getWidthMultiplier() * 5 : 0,
                          right: textDirection == TextDirection.ltr ? SizeConfig.getWidthMultiplier() * 5 : 0,
                          top: SizeConfig.getHeightMultiplier() * 0.25,
                        ),
                        child: AppText(
                          getFormattedTicket(ticketNo, isClinicAdded),
                          fontSize: SizeConfig.getWidthMultiplier() * 7.4,
                          letterSpacing: -1,
                          fontHeight: 0.5,
                          color: AppColors.greyTextColor,
                          fontWeight: FontWeight.bold,
                          fontFamily: AppStrings.fontNamePoppins,
                        ),
                      ),
                    ],
                  ),
                  SizedBox(height: SizeConfig.getHeightMultiplier() * 0.17),
                  Padding(
                    padding: EdgeInsets.only(
                      left: textDirection == TextDirection.ltr ? SizeConfig.getWidthMultiplier() * 3.5 : 0,
                      right: textDirection == TextDirection.rtl ? SizeConfig.getWidthMultiplier() * 3.5 : 0,
                    ),
                    child: Row(
                      children: [
                        Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            AppText(
                              callTypeEnum.getMessageByCallTypeForArabic(globalConfigurationsModel, isListView: false),
                              color: AppColors.newVitalSignColor,
                              fontSize: SizeConfig.getWidthMultiplier() * 2.5,
                              fontHeight: 1,
                              fontFamily: AppStrings.fontNameGesTwo,
                            ),
                            SizedBox(height: SizeConfig.getHeightMultiplier() * 0.05),
                            ClipRRect(
                              child: AppText(
                                text,
                                color: AppColors.newVitalSignColor,
                                fontSize: SizeConfig.getWidthMultiplier() * 2.4,
                                fontFamily: AppStrings.fontNamePoppins,
                                textAlign: TextAlign.left,
                                textOverflow: TextOverflow.clip,
                                maxLines: 1,
                              ),
                            ),
                          ],
                        ),
                      ],
                    ),
                  ),
                ],
              ),
            ),
          ),
        ),
        Positioned(
          top: SizeConfig.getHeightMultiplier() * 0.1,
          left: SizeConfig.getWidthMultiplier() * 2,
          child: SvgPicture.asset(AppAssets.hmgLogoPatternDarkIcon, height: SizeConfig.getHeightMultiplier() * 1),
        ),
      ],
    );
  }
}
