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 QueueItemNormalCard extends StatelessWidget {
  final String ticketNo;
  final String roomNo;
  final TextDirection textDirection;
  final String roomText;
  final String roomTextAr;
  final GlobalConfigurationsModel globalConfigurationsModel;
  final CallTypeEnum callTypeEnum;
  final ScreenTypeEnum screenTypeEnum;
  final LanguageEnum langTypeEnum;
  final double? height;
  final double? width;

  const QueueItemNormalCard({
    super.key,
    required this.ticketNo,
    required this.roomNo,
    required this.textDirection,
    required this.roomText,
    required this.roomTextAr,
    required this.globalConfigurationsModel,
    required this.callTypeEnum,
    required this.screenTypeEnum,
    required this.langTypeEnum,
    this.height,
    this.width,
  });

  bool shouldReduceSize(String ticketNo) {
    // Use regex to check if ticket starts with exactly 3 letters followed by " W-"
    final hasClinicPrefix = RegExp(r'^[A-Za-z]{3} W-').hasMatch(ticketNo);

    return hasClinicPrefix;
  }

  @override
  Widget build(BuildContext context) {
    final text = "${callTypeEnum.getMessageByCallTypeForEnglish(globalConfigurationsModel, isListView: false)} | $roomText $roomNo";
    return Stack(
      children: [
        customShadowSmoothContainer(
          height: height,
          width: width,
          padding: EdgeInsets.only(
            top: SizeConfig.getHeightMultiplier() * 0.05,
            left: SizeConfig.getWidthMultiplier() * 1.5,
            right: SizeConfig.getWidthMultiplier() * 1.5,
          ),
          child: Directionality(
            textDirection: textDirection,
            child: IntrinsicHeight(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: [
                  Flexible(
                    flex: 3,
                    child: Center(
                      child: AppText(
                        ticketNo,
                        fontSize: shouldReduceSize(ticketNo) ? SizeConfig.getWidthMultiplier() * 2.5 : SizeConfig.getWidthMultiplier() * 5,
                        letterSpacing: -1,
                        fontHeight: 0.5,
                        color: AppColors.greyTextColor,
                        fontWeight: FontWeight.bold,
                        fontFamily: AppStrings.fontNamePoppins,
                      ),
                    ),
                  ),
                  Flexible(
                    flex: 3,
                    child: Row(
                      children: [
                        callTypeEnum.getIconByCallType(SizeConfig.getHeightMultiplier() * 0.35),
                      ],
                    ),
                  ),
                  Flexible(
                    flex: 4,
                    child: Center(
                      child: AppText(
                        textAlign: TextAlign.center,
                        "${callTypeEnum.getMessageByCallTypeForArabic(globalConfigurationsModel, isListView: false)}  ",
                        color: AppColors.greyTextColor,
                        fontSize: SizeConfig.getWidthMultiplier() * 2,
                        fontHeight: 1,
                        fontFamily: AppStrings.fontNameGesTwo,
                        maxLines: 2,
                        textOverflow: TextOverflow.clip,
                      ),
                    ),
                  ),
                  Flexible(
                    flex: 2,
                    child: IntrinsicWidth(
                      child: callTypeContainer(
                        textDirection: textDirection,
                        isDisableRightBorderRadius: false,
                        padding: EdgeInsets.all(SizeConfig.getHeightMultiplier() * 0.05),
                        color: callTypeEnum.getColorByCallType(),
                        child: engArabicTextWithSeparatorWidget(
                          fontSize: SizeConfig.getWidthMultiplier()! * 1.8,
                          englishText: roomNo.extractNumbersIfLong(),
                          arabicText: roomTextAr,
                          color: AppColors.whiteColor,
                          mainAxisAlignment: MainAxisAlignment.center,
                        ),
                      ),
                    ),
                  ),
                  Flexible(
                    flex: 2,
                    child: Container(
                      alignment: Alignment.bottomCenter,
                      child: Center(
                        child: AppText(
                          text,
                          color: AppColors.greyTextColor,
                          fontSize: SizeConfig.getWidthMultiplier() * 1.5,
                          fontFamily: AppStrings.fontNamePoppins,
                          textAlign: TextAlign.center,
                          textOverflow: TextOverflow.clip,
                          fontHeight: 1.2,
                          maxLines: 1,
                        ),
                      ),
                    ),
                  ),
                ],
              ),
            ),
          ),
        ),
        Positioned(
          left: textDirection == TextDirection.rtl ? SizeConfig.getWidthMultiplier() * 2 : null,
          right: textDirection == TextDirection.ltr ? SizeConfig.getWidthMultiplier() * 2 : null,
          top: SizeConfig.getHeightMultiplier() * 0.1,
          child: SvgPicture.asset(
            AppAssets.hmgLogoPatternLightIcon,
            height: SizeConfig.getHeightMultiplier() * 0.8,
          ),
        ),
      ],
    );
  }
}
