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 bool isClinicAdded;
  final TextDirection textDirection;
  final String roomText;
  final String roomTextAr;
  final GlobalConfigurationsModel globalConfigurationsModel;
  final CallTypeEnum callTypeEnum;
  final ScreenTypeEnum screenTypeEnum;
  final QTypeEnum qTypeEnum;
  final LanguageEnum langTypeEnum;
  final double? height;
  final double? width;

  const QueueItemNormalCard({
    super.key,
    required this.isClinicAdded,
    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,
    required this.qTypeEnum,
    this.height,
    this.width,
  });

  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: [
        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(
                        getFormattedTicket(ticketNo, isClinicAdded),
                        fontSize: SizeConfig.getWidthMultiplier() * 5,
                        letterSpacing: -1,
                        fontHeight: 0.5,
                        color: AppColors.greyTextColor,
                        fontWeight: FontWeight.bold,
                        fontFamily: AppStrings.fontNamePoppins,
                      ),
                    ),
                  ),
                  Flexible(
                    flex: 3,
                    child: Padding(
                      padding: EdgeInsets.all(SizeConfig.getHeightMultiplier() * 0.07),
                      child: Row(
                        children: [
                          callTypeEnum.getIconByCallType(SizeConfig.getHeightMultiplier() * 0.35, qTypeEnum),
                        ],
                      ),
                    ),
                  ),
                  Flexible(
                    flex: 2,
                    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: qTypeEnum != QTypeEnum.appointment ? SizeConfig.getWidthMultiplier()! * 1.9 : 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,
          ),
        ),
      ],
    );
  }
}
